0

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)

einpoklum
  • 118,144
  • 57
  • 340
  • 684

2 Answers2

1

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

Zois Tasoulas
  • 1,242
  • 1
  • 11
  • 23
  • 1. Why do I need the first function if I have the second? 2. Can you please quote the signature and semantics of the function(s)? – einpoklum Dec 19 '22 at 09:37
  • Added signatures, reorder the functions. The OP talks about a physical display, but the question is more general. I think someone might find `nvmlDeviceGetDisplayActive` useful as well, to check whether X server is running on a GPU. – Zois Tasoulas Dec 20 '22 at 05:43
0

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

Zois Tasoulas
  • 1,242
  • 1
  • 11
  • 23
  • 1
    That's nice to know (i.e. beats grepping for Xorg), but I asked about doing it programmatically, not from the command-line. I don't want to spawn a process just to do that. – einpoklum Aug 31 '22 at 20:57