开发者

CUDA/PyCUDA: Which GPU is running X11?

开发者 https://www.devze.com 2023-03-14 16:25 出处:网络
In a Linux system with multiple GPUs, how can you determine which GPU is running X11 and which is completely free to run CUDA kernels? In a system that has a low powered GPU to run X11 and a higher po

In a Linux system with multiple GPUs, how can you determine which GPU is running X11 and which is completely free to run CUDA kernels? In a system that has a low powered GPU to run X11 and a higher powered GPU to run kernels, this can be determined with some heuristics to use the faster card. But on a system with two equal cards, this method cannot be used. Is there a CUDA and/or X11 API to determine this?

UPDATE: The command 'nvidia-smi -a' shows a whether a "display" is connected or not. I have yet to determine if thi开发者_如何学Cs means physically connected, logically connected (running X11), or both. Running strace on this command shows lots of ioctls being invoked and no calls to X11, so assuming that the card is reporting that a display is physically connected.


There is a device property kernelExecTimeoutEnabled in the cudaDeviceProp structure which will indicate whether the device is subject to a display watchdog timer. That is the best indicator of whether a given CUDA device is running X11 (or the windows/Mac OS equivalent).

In PyCUDA you can query the device status like this:

In [1]: from pycuda import driver as drv

In [2]: drv.init()

In [3]: print drv.Device(0).get_attribute(drv.device_attribute.KERNEL_EXEC_TIMEOUT)
1

In [4]: print drv.Device(1).get_attribute(drv.device_attribute.KERNEL_EXEC_TIMEOUT)
0

Here device 0 has a display attached, and device 1 is a dedicated compute device.


I don't know any library function which could check that. However a one "hack" comes in mind: X11, or any other system component that manages a connected monitor must consume some of the GPU memory.

So, check if both devices report the same amount of available global memory through 'cudaGetDeviceProperties' and then check the value of 'totalGlobalMem' field. If it is the same, try allocating that (or only slightly lower) amount of memory on each of the GPU and see which one fails to do that (cudaMalloc returning an error flag).

Some time ago I read somewhere (I don't remember where) that when you increase your monitor resolution, while there is an active CUDA context on the GPU, the context may get invalidated. That hints that the above suggestion might work. Note however that I never actually tried it. It's just my wild guess.

If you manage to confirm that it works, or that it doesn't, let us know!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号