126

I have 2 GPU's in my netbook. How do I know which one I'm actually using at any given moment?

0

12 Answers 12

86

I've just gone through a hell of a time trying to get my discrete graphics to work in Ubuntu, and answering this question was constantly a challenge, since the lspci method mentioned earlier can sometimes say that both are [VGA controller].

I think the following command should give you an indication of your active chip:

$ glxinfo | grep -E "OpenGL vendor|OpenGL renderer"
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Sandybridge Mobile

For me, this is telling me that my Intel graphics are running the show.

glxinfo is available from the mesa-utils package, so you will need to install it if you haven't already.  On Ubuntu 22.04, for example, run:

sudo apt-get install mesa-utils

If you're using an NVIDIA chip, and you're using the bumblebee package, you can put optirun in front of that line, and it should tell you that you're running the NVIDIA chip (optirun is basically telling the computer to use the discrete chip to run whatever command follows, but everything else is still using the integrated chip).

$ optirun glxinfo | grep -E "OpenGL vendor|OpenGL renderer"
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce GT 555M/PCIe/SSE2

glxheads is another helpful command from mesa-utils that tells you some useful information about which graphics card is in use (mostly repeats glxinfo in a more compact and easy-to-read form, though), and it gives you a nice rendering of a rotating triangle.

1
  • For context, [VGA controller] is specifically derived from prog-if of 0x030000 in /sys/<devicepath>/class, which will match that for any GPU. The text itself comes from the classes at the bottom of (depending on your distro) /usr/share/hwdata/pci.ids, which is used by tools like lspci and even root daemons like udevd.
    – Tcll
    Apr 25 at 13:28
30

To check which GPU is currently in command (that means which is an active VGA controller) type in

lspci -vnnn | perl -lne 'print if /^\d+\:.+(\[\S+\:\S+\])/' | grep VGA

Any controller with [VGA controller] at the end is your currently active GPU. The others are switched off. In the following example the Intel card is active while the nVidia one is not in use:

00:02.0 VGA compatible controller [0300]: Intel Corporation Core Processor
Integrated Graphics Controller [8086:0046] (rev 02) (prog-if 00 [VGA 
controller])
01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GF108 [GeForce
GT 540M] [10de:0df4] (rev ff) (prog-if ff)
6
  • 24
    Um... so what does it mean if both cards have VGA controller at the end?
    – naught101
    Nov 11, 2014 at 5:38
  • 1
    00:02.0 VGA compatible controller [0300]: Intel Corporation 4th Gen Core Processor Integrated Graphics Controller [8086:0416] (rev 06) (prog-if 00 [VGA controller]) 01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GK106GLM [Quadro K2100M] [10de:11fc] (rev a1) (prog-if 00 [VGA controller]) what does it mean?
    – Asaf Magen
    Jul 9, 2015 at 11:36
  • 1
    Maybe you're using SLI? Jul 9, 2015 at 11:58
  • 3
    in my case both has that at the end: 00:02.0 VGA compatible controller [0300]: Intel Corporation Device [8086:591b] (rev 04) (prog-if 00 [VGA controller]) 01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GP106M [GeForce GTX 1060 Mobile] [10de:1c20] (rev a1) (prog-if 00 [VGA controller]) Oct 21, 2018 at 11:28
  • 1
    In my case, both are end with [VGA controller], so how can I know the exact one?
    – Bonn
    Nov 25, 2020 at 3:50
12

nvidia-settings GUI

On Ubuntu 15.10, after I installed nvidia-352 and the GPU seems to work:

nvidia-settings

shows something like:

enter image description here

Note how it shows:

GPU 0 - (NVS 5400M)

where NVS 5400M is my GPU model.

Then if I fire glxgears, the "GPU Utilization" goes to > 90%.

So I expect that if you had multiple GPUs, you could see how much each one was being used at a time.

4
11
nvidia-smi -L

This gave me what I wanted. This command shows the list of GPUs present on your machine. This might help you figure which are active ones.

got the command from thread here: Ubuntu Box with multiple NVIDIA GPU Cards | devtalk.nvidia.com

5
  • 1
    anybody figured out how to find the free GPUs out of the ones returned by this command?
    – pcko1
    Jan 21, 2020 at 16:02
  • Just curious, will this command list an Intel integrated GPU if you decided to disable your Nvidia GPU?
    – kas
    Nov 14, 2020 at 18:11
  • 1
    This only lists Nvidia GPUS and gives no indication if active for desktop or not..
    – RichieHH
    Apr 12, 2021 at 22:57
  • This answer is Nvidia-specific, but the OP didn't specify a vendor. What about AMD? I have an AMD laptop with integrated and dedicated GPUs.
    – unfa
    May 5, 2021 at 14:54
  • Again, this is Nvidia specific. Not a usable answer. Feb 25, 2022 at 17:23
2

Just type nvidia-smi in the terminal. Then check for the percentage of usage. That will indicate which GPU is in use.

enter image description here

1

Which OS are you using? If you use lspci on most linux machines you get a list of your pci devices, just grep for graphics devices and it should pop up both of them. After that just check out the config on each of them, you should see details of up/on/active or something to that nature.

1
  • 1
    ubuntu 11.04. and lspci is showing all two gpu's. Jul 11, 2011 at 3:41
1

Before suggesting a "tool" to be installed, better to propose a native linux way.

  1. ls /sys/class/graphics/fb0/device/ 
    
  2. You should see

    lrwxrwxrwx 1 root root 0  1 apr 17.19 /sys/class/graphics/fb0/device -> ../../../0000:0b:00.0
    
  3. lspci look for the video card

    0b:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Ellesmere [Radeon RX 470/480/570/570X/580/580X/590] (rev e1)
    
1
  • just want to note the /sys/class/graphics/fb0/ folder doesn't seem to always exist, my cases where it does involves the drivers radeon and i915, and the cases where it doesn't involves the drivers nvidia and pcieport (/sys/class/drm/ttm/ VoidLinux install where nouveau can't initialize and nvidia can't compile, yet xorg still just barely functions)
    – Tcll
    Apr 23 at 14:24
0

nvidia-smi is very useful, but at times I've found that it doesn't always include everything. It seems when processes crash they aren't always listed.

sudo lsof /dev/nvidia* has always worked for me. It will also work without sudo, but will only show processes owned by you. If you are working on a multiuser machine or are using docker, you will probably get better results with sudo.

If you see a discrepancy between the 2 commands, you may want to consider killing the extra processes found with lsof.

0

In Ubuntu 20.04 this can be done from the GUI with the NVIDIA settings application:

enter image description here

0

I found another method, just in case anyone needs to detect the model of your NVIDIA graphics card and the recommended driver.

ubuntu-drivers devices

I got this from here: https://linuxconfig.org/how-to-install-the-nvidia-drivers-on-ubuntu-20-04-focal-fossa-linux

0

Another method:

sudo cat /sys/kernel/debug/vgaswitcheroo/switch

Discrete card (DIS) will be Off (or DynOff) when not in use. Integrated card (IGD) is always energized (Pwr).

0

I think I may have found a native solution, but I don't have enough ability to actually verify it as of yet...

As far as I can tell, every machine I have with dual GPUs seems to list the primary GPU is being:
/sys/bus/pci/drivers/<driver>/<device>/boot_vga = 1
<driver> being anything from nvidia,radeon,nouveau,amdgpu,i915, to the generic pcieport if no driver is initialized but xorg still functions.
(note that pcieport places boot_vga in <port>/<device>/)

I have yet to try anything with 3 or 4 GPUs, but I assume only the primary GPU of all of those will have boot_vga as 1.

I also have yet to try running multiple X servers with different GPUs to see if that changes boot_vga to 1 for current or all active.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .