Ubuntu – Use NVIDIA Hybrid gpu only for CUDA and not for KDE Plasma

cudanvidianvidia-primexorg

There is a similar question and I have been following this answer here on askubuntu: https://askubuntu.com/a/1158183/254943. This solution worked exactly as I want. Sadly after the most recent update, the solution stopped working and Xorg is now using nvidia again.

  • | NVIDIA-SMI 450.66 Driver Version: 450.66 CUDA Version: 11.0 |
  • Linux XXX 5.4.0-48-generic #52-Ubuntu SMP Thu Sep 10 10:58:49 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
  • plasmashell 5.18.5 | Qt: 5.12.8 | KDE Frameworks: 5.68.0 | kf5-config: 1.0
$ cat  /usr/share/X11/xorg.conf.d/11-nvidia-prime.conf

# DO NOT EDIT. AUTOMATICALLY GENERATED BY gpu-manager

Section "OutputClass"
    Identifier "Nvidia Prime"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "AllowEmptyInitialConfiguration"
    Option "IgnoreDisplayDevices" "CRT"
    # Option "PrimaryGPU" "Yes"   <<< commented out
    ModulePath "/x86_64-linux-gnu/nvidia/xorg"
EndSection


# added 
Section "OutputClass"
    Identifier "intel"
    MatchDriver "i915"
    Driver "modesetting"
    Option "PrimaryGPU" "yes"    
EndSection

I have tried to debug It by myself but I can't get it fixed.

$ nvidia-smi  # shows running process /usr/lib/xorg/Xorg

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.66       Driver Version: 450.66       CUDA Version: 11.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 105...  Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   50C    P8    N/A /  N/A |      6MiB /  4040MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1257      G   /usr/lib/xorg/Xorg                  4MiB |
+-----------------------------------------------------------------------------+

Best Answer

I think have figured it out. First I have re-moved the 10-nvidia.conf file. Instead I have added a 10-intel.conf. Then I have commented out every line the 11-nvidia-prime.conf, it is basically an empty file. Since this file gets created/overwritten at every start/stop of xserver one needs to protect it with chattr +i

$ pwd
/usr/share/X11

$ ls -l xorg.conf.d/
total 36K
drwxr-xr-x 2 root root 4.0K Okt 20 20:15 .
drwxr-xr-x 6 root root 4.0K Okt 20 18:12 ..
-rw-r--r-- 1 root root   92 Okt 22  2019 10-amdgpu.conf
-rw-r--r-- 1 root root  327 Okt 20 18:10 10-intel-only.conf
-rw-r--r-- 1 root root 1.4K Sep  4 15:34 10-quirks.conf
-rw-r--r-- 1 root root   92 Okt 22  2019 10-radeon.conf
-rw-r--r-- 1 root root  341 Okt 20 20:15 11-nvidia-prime.conf
-rw-r--r-- 1 root root 1.5K Mai 30 15:34 40-libinput.conf
-rw-r--r-- 1 root root 3.4K Mär 11  2020 70-wacom.conf

ls -l bak.xorg/
drwxr-xr-x 2 root root 4.0K Okt 20 20:08 .
drwxr-xr-x 6 root root 4.0K Okt 20 18:12 ..
-rw-r--r-- 1 root root  206 Okt  5 11:19 10-nvidia.conf
-rw-r--r-- 1 root root  333 Okt 20 20:08 11-nvidia-prime.conf

$ cat xorg.conf.d/10-intel-only.conf 
Section "ServerLayout"
    Identifier "Layout0"
    Option "AutoAddGPU" "false"
    Screen 0 "IntelScreen"
EndSection

Section "Device"
    Identifier "IntelDevice"
    BusID "PCI:0:2:0"
    Driver "intel" # or maybe "modesetting"?
EndSection

Section "Screen"
    Identifier "IntelScreen"
    Device "IntelDevice"
EndSection

enter image description here

Related Question