einpoklum
einpoklum

Reputation: 131525

How do I check which of my NVIDIA GPUs is used for display?

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)

Upvotes: 0

Views: 401

Answers (2)

Zois Tasoulas
Zois Tasoulas

Reputation: 1533

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.

Link to documentation

Upvotes: 1

Zois Tasoulas
Zois Tasoulas

Reputation: 1533

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

Upvotes: 0

Related Questions