Figuring out which device is used by X11.

Is there a way to figure out which device is used by X11 using the CUDA API or something and then tell CUDA to use the other one (assuming there are two GPUs)

You need something like this:

int deviceCount;

cudaGetDeviceCount(&deviceCount);

for (int dev = 0; dev < deviceCount; ++dev)

{

	cudaDeviceProp deviceProp;

	cudaGetDeviceProperties(&deviceProp, dev);

	if (deviceProp.kernelExecTimeoutEnabled > 0)

	{

		// This device is running a display

	}

	else

	{

		// This device is not.

		// To use the first device that is not running a display:

		cudaSetDevice(dev);

		break;

	}

}

The device running the display will have kernelExecTimeoutEnabled set,

which stops a CUDA kernel freezing the display by running too long.

It is 5 seconds by default, I think. The other device will have this set to 0.

Then use cudaSetDevice() to choose which to use.

Of course if you are running two displays …

Didn’t know about the kernelExecTimeoutEnabled property. Thx for your quick replay :)