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. Try the following on a terminal
nvidia-smi --format=csv --query-gpu=index,display_mode,display_active
For more information check the nvidia-smi documentation and nvidia-smi --help-query-gpu
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.