Problem with setting which device?!

Hi. I have got two cards installed, a compute card and a graphics card. I’m calling cudaGetDeviceProperties (borrowed code from a sample) and then picking which one is the compute card; text output verifies that this is happening correctly. Then I call cudaDeviceReset(). Often the result of this is that it works perfectly. Sometimes it seems to be calling cudaResetDevice on the graphics card; the display hangs (though sometimes I still get a mouse cursor). This usually ends up with me powering off the computer manually, which I am worried is going to eventually damage a hard disk.

The code:

 int nDevices, iWhich;
cudaDeviceProp prop;
for (int i = 0; i < nDevices; i++) {
	cudaGetDeviceProperties(&prop, i);
	printf("Device Number: %d\n", i);
	printf("  Device name: %s\n",;
	printf("  Memory Clock Rate (KHz): %d\n",
	printf("  Memory Bus Width (bits): %d\n",
	if (prop.memoryBusWidth == 384) iWhich = i;
printf("Picked %d \n", iWhich);


The output (every single time):

Device Number: 0
Device name: Tesla K40m
Memory Clock Rate (KHz): 3004000
Memory Bus Width (bits): 384

Device Number: 1
Device name: GeForce GT 1030
Memory Clock Rate (KHz): 3004000
Memory Bus Width (bits): 64

Picked 0

Thank you anyone that has any ideas.