cudaSetDevice always returns cudaSuccess

Hello,
I have a GTX-480 and I can run all the examples in the SDK. Everything seems to be ok.

Today, I tried experimenting with error codes returned by CUDA calls. All seemed to be working well until I got to cudaSetDevice. No matter what device ID I give, cudaSetDevice always returns cudaSuccess. Here’s my code:

cudaSetDevice(-999);
cudaError_t error = cudaGetLastError();
if (error != cudaSuccess)
printf(“Device not set %d\n”, error);

Can anyone please explain the reason for this. Thanks.

cudaSetDevice merely sets the ID. The context is not initialized until the next real cuda call, that is the one you need to check for errors. The officially supported (Tim said so) way to initialize the context without otherwise doing anything is cudaFree(0)

ok, thanks.