There is very little by the way of official documentation regarding how to use multiple GPUs on Linux.

What you see everywhere is "set DRI_PRIME=1 in your environment to use your discrete GPU". Optimus is the closest thing I've found to upstream documentation; this applies to non-NVIDIA GPUs even though it's only mentioned on the Nouveau project's wiki. But what does 1 actually mean? DRI_PRIME=2 doesn't seem to work, so what if you have more than two GPUs? And what if you want a stable GPU identifier rather than relying on enumeration order?

As far as I'm aware this is completely undocumented, but some tools hint that DRI_PRIME can be set to a string identifying a PCI device which can be used as a stable identifier:

$ switcherooctl list
Device: 0
  Name:        IntelĀ® HD Graphics 620
  Default:     yes
  Environment: DRI_PRIME=pci-0000_00_0s_0

This tool tells you the value of DRI_PRIME for each enumerated GPU.

Now, let's look for code that consumes the DRI_PRIME environment variable. I ended up looking at the Mesa 3D Graphics Library.


CategoryTechnote

robots.org.uk: LinuxMultiGPUDeviceSelection (last edited 2022-02-22 17:10:48 by sam)

© Sam Morris <sam@robots.org.uk>.
Content may be distributed and modified providing this notice is preserved.