I'm on a system with multiple NVIDIA GPUs. One or more of them may - or may not - be used to drive a physical monitor. In my compute work, I want to avoid using that one (or more).
How can I, programmatically, check which GPUs are used for display?
If there's no robust way of doing that, I'll settle for getting those GPUs which are used by an Xorg process (which is what nvidia-smi
gives me on the command-line)
In case you want to use the same process, you can check the NVML API functions nvmlDeviceGetDisplayActive
and nvmlDeviceGetDisplayMode
.
Specifically,
nvmlReturn_t nvmlDeviceGetDisplayMode ( nvmlDevice_t device, nvmlEnableState_t* display )
can be used to detect if a physical display is connected to a device.nvmlReturn_t nvmlDeviceGetDisplayActive ( nvmlDevice_t device, nvmlEnableState_t* isActive )
can be used to check if X server is attached to a device, it can be possible that an X server is running, without an attached physical display.