Help: A problem with cudaSetDevice()

I have two CUDA cards (one is GTS 250, another is 9600 GT) in my system,
and I have wrote a CUDA calculation test program as following:

int deviceCount;
int device;
cudaDeviceProp deviceProp;

cudaGetDeviceCount(&deviceCount);
for (device = 0; device < deviceCount; device++)
{
cudaGetDeviceProperties(&deviceProp, device);
if(deviceProp.major<1)
continue;

[b]cudaSetDevice(device);[/b]

.......do CUDA thread optimization calculation......

}

When I run the program, it was teminated when device = 1.
If I deleted cudaSetDevice(device) statement from the program,
it worked fine!

Can someone tell me that is why ?

what does the error code say?

Just a wild guess, what happens if you add a cudaThreadExit() at the end of the for loop? I’m not sure if the cuda runtime api is able to handle to active devices (i.e call cudaSetDevice when another device is already active). You code will try to run on both devices as the 9600 is 1.1, not sure about the 250, I think that it’s 1.1 as well and not 1.2.

for (device = 0; device < deviceCount; device++)

{

cudaGetDeviceProperties(&deviceProp, device);

if(deviceProp.major<1)

    continue;

cudaSetDevice(device);

…do CUDA thread optimization calculation…

cudaThreadExit();

}

Cannot get error code, because the program is forceed to exit when CUDA calculation start.

Random guess, are displays connected to only one of the cards? And is the card that successfully runs your program the one with no displays?

Just wondering if you’re running into a watchdog timer that terminates your app if it’s “long running”. But last I checked that was 5 seconds.

Random guess #2. Do the cards have different amounts of memory? Does one have 512MB and the other 1GB? Does your program fit?

Are you on Windows, Linux, Mac?

Whatever the case, you should try to obtain the error code.

… the return value from cudaSetDevice

ps the guess about needing to call cudaThreadExit is correct