Table of Contents

Ubuntu - GPU - Run a program on your dedicated AMD graphics card

Check that your dedicated AMD graphics card shows up

lspci

returns:

...
0b:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Navi 10 [Radeon RX 5600 OEM/5600 XT / 5700/5700 XT] (rev c1)
...

Check that the amdgpu kernel module is loaded

lsmod | grep -i amd

returns:

edac_mce_amd           32768  0
kvm_amd               102400  0
kvm                   729088  1 kvm_amd
amdgpu               5341184  17
iommu_v2               20480  1 amdgpu
gpu_sched              36864  1 amdgpu
ttm                   102400  1 amdgpu
drm_kms_helper        225280  1 amdgpu
ccp                   102400  1 kvm_amd
drm                   561152  10 gpu_sched,drm_kms_helper,amdgpu,ttm
i2c_algo_bit           16384  2 igb,amdgpu

Test to see if we can run anything on it

glxinfo | grep "OpenGL renderer"
DRI_PRIME=1 glxinfo | grep "OpenGL renderer"

NOTE: The above runs glxinfo twice.

The first one would pick up any integrated graphics cards.

The second one should pick up the dedicated graphics card. The key here is the DRI_PRIME=1 environment variable - this tells the amdgpu driver that this process should run on the dedicated graphics and not the integrated graphics card.

returns:

OpenGL renderer string: AMD Radeon RX 5700 XT (NAVI10, DRM 3.38.0, 5.8.2-050802-generic, LLVM 10.0.1)
OpenGL renderer string: AMD Radeon RX 5700 XT (NAVI10, DRM 3.38.0, 5.8.2-050802-generic, LLVM 10.0.1)

The lines in this case are identical as there is no integrated GPU so it only returns the dedicated GPU.


Run a program against the dedicated card

DRI_PRIME=1 inkscape
 
DRI_PRIME=1 python3 path/to/script.py

NOTE: If errors are received using the DRI_PRIME=1 statement:

Add radeon.runpm=0 to the file /etc/default/grub in the GRUB_CMDLINE_LINUX_DEFAULT section, and then add DRI_PRIME=1 to the end of the file /etc/environment.

Then run sudo update-grub before rebooting.


To have DRI_PRIME=1 automatically added for all running processes

Edit the file at /etc/environment.

sudo vi /etc/environment

and add DRI_PRIME=1 on a new line and then reboot.

NOTE: This should add the environment variable to all running processes.

  • You can check it has worked (after a reboot) with htop.
  • Execute htop, and then navigate to a process you would like to check.
  • Then press e on your keyboard, and it will show a list of environment variables for that process - which should include DRI_PRIME=1.