There is no single command, because “which GPU is active” is three questions. For which GPU the kernel bound a driver to, run lspci -nnk -d ::03xx. For which GPU a program will render on, run glxinfo -B inside that program’s environment. For which GPU is busy right now, run nvtop. Use the first one if you only run one:
$ lspci -nnk -d ::03xx
Note -d ::03xx, not | grep VGA. That is the single most common error in guides on this topic.
Table of Contents
Why grep VGA misses your discrete GPU
PCI class 03 is “Display controller”, and it has four subclasses. From the canonical pci.ids registry:
C 03 Display controller
00 VGA compatible controller
00 VGA controller
01 8514 controller
01 XGA compatible controller
02 3D controller
80 Display controller
grep VGA matches subclass 00 only. On hybrid laptops the discrete GPU frequently enumerates as 0302, “3D controller” — it has no display outputs wired to it, so it is not a VGA-compatible device — and a grep VGA pipeline reports one GPU on a two-GPU machine. The lspci man page documents -d as accepting a class with x wildcards, so -d ::03xx filters on the class field itself rather than on English text. Adding -k prints a Kernel driver in use: line per device, which tells you which module (i915, amdgpu, nouveau, nvidia, xe) is bound — not which GPU is rendering.
Which GPU an application will actually use
glxinfo -B prints a line beginning OpenGL renderer string:. The important part is that this is a per-process answer, not a system-wide one: it reports the renderer that process got. Prefixing the environment changes the answer, which is the point.
glxinfo -B | grep "OpenGL renderer string"
DRI_PRIME=1 glxinfo -B | grep "OpenGL renderer string"
__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia glxinfo -B | grep vendor
Mesa documents DRI_PRIME as selecting a non-default GPU, accepting an index (DRI_PRIME=1), a PCI address (DRI_PRIME=pci-0000_02_00_0) or a vendor:device pair. The two __NV_*/__GLX_* variables are NVIDIA’s PRIME render offload mechanism and are documented in the driver’s README. glxinfo is a GLX client, so under Wayland it answers through Xwayland; eglinfo or vulkaninfo give a native answer. On Debian and Ubuntu glxinfo comes from mesa-utils; on Fedora and RHEL the package is glx-utils, not mesa-utils.
Hybrid laptops: switcherooctl, not vgaswitcheroo
switcherooctl list is the modern answer, from the switcheroo-control package. It prints a block per GPU with Device:, Name:, Default:, Discrete: and Environment: — the last being the environment variables needed to run something on that GPU, which is exactly what the previous section needs. switcherooctl launch <command> runs a program on the discrete GPU. It is the same D-Bus service GNOME uses to decide whether to offer “Launch Using Discrete Graphics Card”. Which GPU drives the panel is a separate question from what resolution the panel runs at, and on a Wayland session xrandr cannot change that resolution at all — it only sees the XWayland surface.
The /sys/kernel/debug/vgaswitcheroo/switch interface still exists, but the kernel’s vga_switcheroo documentation limits it: “For muxless machines, the IGD/DIS, DIGD/DDIS and MIGD/MDIS commands should not be used.” Muxless — one GPU wired to the outputs, the other used only for offload — describes essentially every hybrid laptop since about 2010. Where the driver’s runtime power management is in charge, the default on Optimus and PowerXpress, “the ON and OFF commands are a no-op.” It also needs debugfs mounted and root, and on most current laptops the file never appears. Treat it as legacy, for muxed hardware.
Which GPU is busy, and which processes are on it
nvtop is the closest thing to a universal answer: it is a top-like monitor covering AMD, Intel, NVIDIA, Apple, Qualcomm Adreno, Broadcom VideoCore and Rockchip, and it shows per-process GPU usage. radeontop and intel_gpu_top (from intel-gpu-tools) are the vendor-specific equivalents. Those answer “right now”; for a utilisation figure you can log over a run rather than glance at, nvidia-smi --query-gpu=… --format=csv -l 1 writes one sample a second.
For “what has the GPU open right now”, prefer the vendor-neutral DRM nodes over the NVIDIA ones:
sudo fuser -v /dev/dri/*
sudo lsof /dev/nvidia* only ever covers the NVIDIA proprietary driver’s device nodes, and on a machine running nouveau, amdgpu, i915 or xe the glob does not expand to anything. /dev/dri/card* and /dev/dri/renderD* exist regardless of vendor.
cat /sys/class/drm/card*/device/boot_vga returns 1 for the device firmware picked as the primary display adapter — the closest thing to a definitive flag. nvidia-smi cannot answer the question alone: it never sees the integrated GPU, and its Display Active field only means a display is initialised on the card, which can be true with no monitor attached.
The macOS contrast, which I could actually run
macOS has no lspci. The equivalent is system_profiler SPDisplaysDataType, and on the machine used for this article it returns:
$ system_profiler SPDisplaysDataType
Graphics/Displays:
Apple M3 Max:
Chipset Model: Apple M3 Max
Type: GPU
Bus: Built-In
Total Number of Cores: 30
Vendor: Apple (0x106b)
Metal Support: Metal 4
Displays:
Color LCD:
Display Type: Built-in Liquid Retina XDR Display
Resolution: 3456 x 2234 Retina
Main Display: Yes
One GPU, Bus: Built-In. On Apple Silicon the question does not arise — a single integrated GPU on unified memory, nothing to switch between and no equivalent of PRIME offload. Intel Macs with a discrete GPU list two entries, and the one with Main Display: Yes beneath it drives the screen; I do not have such a machine and will not print invented output for it.
Add -json to script it. The per-GPU keys are sppci_model, sppci_bus, sppci_cores and spdisplays_vendor, and the display carrying "spdisplays_main": "spdisplays_yes" identifies the active GPU.
What was and was not executed
The macOS output and the pci.ids listing are real. Every Linux command here is documentation-cited and was not run: all ten Linux GPU tools are absent on this machine, so no output attributed to them could have been genuine. I have also not verified that any particular Optimus laptop reports its discrete GPU as class 0302 — the claim is that the class exists and grep VGA misses it.