Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use integrated graphics for display and NVIDIA GPU for CUDA on Ubuntu 14.04

This was tested on a ThinkPad P70 laptop with an Intel integrated graphics and an NVIDIA GPU:

lspci | egrep 'VGA|3D'
00:02.0 VGA compatible controller: Intel Corporation Device 191b (rev 06)
01:00.0 VGA compatible controller: NVIDIA Corporation GM204GLM [Quadro M3000M] (rev a1)

A reason to use the integrated graphics for display is if installing the NVIDIA drivers causes the display to stop working properly. In my case, Ubuntu would get stuck in a login loop after installing the NVIDIA drivers. This happened regardless if I installed the drivers from the "Additional Drivers" tab in "System Settings" or the ppa:graphics-drivers/ppa in the command-line.

The solution is described in the answer from this post.

Install the NVIDIA drivers

Download the driver installation runfile from their website (e.g. the 375.26 driver runfile). Run the script with the option --no-opengl-files:

sudo ./NVIDIA-Linux-x86_64-375.26.run --no-opengl-files

Reboot.

Install CUDA

Download the CUDA installation runfile from their website. It's important to download the "runfile (local)" file so that we can explicitly prevent from overwriting the driver that was just installed. Run the script:

sudo ./cuda_8.0.44_linux.run 

Respond "no" when asked "Install NVIDIA accelerated Graphics Driver for Linux-x86_65 375.26?".

Configure xorg.conf

Modify or create the file /etx/X11/xorg.conf to specify that the NVIDIA GPU should be used for a secondary screen so that it has entries in nvidia-settings. Mine looks like this:

Section "ServerLayout"
    Identifier "layout"
    Screen 0 "intel"
    Screen 1 "nvidia"
EndSection

Section "Device"
    Identifier "intel"
    Driver "intel"
    BusID "PCI:0@0:2:0"
    Option "AccelMethod" "SNA"
EndSection

Section "Screen"
    Identifier "intel"
    Device "intel"
EndSection

Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
    BusID "PCI:1@0:0:0"
    Option "ConstrainCursor" "off"
EndSection

Section "Screen"
    Identifier "nvidia"
    Device "nvidia"
    Option "AllowEmptyInitialConfiguration" "on"
    Option "IgnoreDisplayDevices" "CRT"
EndSection

The BusID should match what the lspci command above returned.

Reboot.

Miscellaneous tips

If installing the NVIDIA drivers messes up the OS (e.g. it gets stuck in a login loop or it shows a black screen before the login step), you can uninstall the drivers by openning a console with Ctrl-Alt-F1 and running:

sudo apt-get remove --purge nvidia-*
sudo apt-get autoremove
echo "nouveau" | sudo tee -a /etc/modules

Reboot.

@Aviksaikat
Copy link

Aviksaikat commented Jan 5, 2022

I don't have a VGA port. I don't know what's happening with the technology . Stupid design

@imakin
Copy link

imakin commented Mar 11, 2022

thanks for sharing, it's working fine in my desktop. also if you have more gpus you could add more screen (one screen per GPU)

so this is my /etc/X11/xorg.conf

Section "ServerLayout"
        Identifier     "layout"
        Screen      0  "amdgpu"
        Screen      1  "nvidia"
EndSection

Section "Device"
        Identifier  "amdgpu"
        Driver      "amdgpu"
        BusID       "PCI:7:0:0"
EndSection

Section "Screen"
        Identifier "amdgpu"
        Device     "amdgpu"
EndSection

Section "Device"
        Identifier  "nvidia"
        Driver      "nvidia"
        BusID       "PCI:1:0:0"
EndSection

Section "Screen"
        Identifier "nvidia"
        Device     "nvidia"
        Option     "AllowEmptyInitialConfiguration" "true"
EndSection

and optionally this is my /usr/share/X11/xorg.conf.d/10-nvidia.conf with coolbits to enable clock adjustment, you can also define screen here especially if all multiple gpus are nvidia

Section "OutputClass"
    Identifier "nvidia"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "AllowEmptyInitialConfiguration"
    Option "Coolbits" "12"
    ModulePath "/usr/lib/x86_64-linux-gnu/nvidia/xorg"
EndSection

@unaisp
Copy link

unaisp commented Apr 5, 2022

It worked for me in Ubuntu 20.04 with nvidia-driver-510.

PCI details:

lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor Integrated Graphics Controller (rev 06)
05:00.0 VGA compatible controller: NVIDIA Corporation Device 2489 (rev a1)

Updated xorg.conf as follows.

$ cat /etc/X11/xorg.conf
Section "ServerLayout"
    Identifier  "layout"
    Screen 0 	"intel"
    Screen 1 	"nvidia"
EndSection

Section "Device"
    Identifier  "intel"
    Driver 	"intel"
    BusID       "PCI:0:2:0"
    Option 	"AccelMethod" "SNA"
EndSection

Section "Screen"
    Identifier  "intel"
    Device 	"intel"
EndSection

Section "Device"
    Identifier "nvidia"
    Driver 	"nvidia"
    BusID       "PCI:5:0:0"
    Option 	"ConstrainCursor" "off"
EndSection

Section "Screen"
    Identifier  "nvidia"
    Device 	"nvidia"
    Option 	"AllowEmptyInitialConfiguration" "true"
EndSection

Updated the following file with coolbits to enable the cpu/memory/fan overclocking with nvidia-settings

$ cat /usr/share/X11/xorg.conf.d/10-nvidia.conf 
Section "OutputClass"
    Identifier "nvidia"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "AllowEmptyInitialConfiguration"
    Option "Coolbits" "12"
    ModulePath "/usr/lib/x86_64-linux-gnu/nvidia/xorg"
EndSection

Currently, nvidia-smi looks as follows. All other processes including chrome, firefox, TeamViewer, and ms-teams are using integrated GPU and one of my target applications is using the dedicated Nvidia gpu.

$ nvidia-smi
Tue Apr  5 10:40:07 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.54       Driver Version: 510.54       CUDA Version: 11.6     |
|-------------------------------+----------------------+----------------------+
| 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  NVIDIA GeForce ...  Off  | 00000000:05:00.0 Off |                  N/A |
| 95%   63C    P2   159W / 160W |   5110MiB /  8192MiB |    100%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1228      G   /usr/lib/xorg/Xorg                  5MiB |
|    0   N/A  N/A      1795      G   /usr/lib/xorg/Xorg                  6MiB |
|    0   N/A  N/A      3304      C   .../t-rex-0.25.8-linux/t-rex     5093MiB |
+-----------------------------------------------------------------------------+


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment