Skip to content

Instantly share code, notes, and snippets.

@alexlee-gk
Last active March 19, 2024 17:47
Show Gist options
  • Save alexlee-gk/76a409f62a53883971a18a11af93241b to your computer and use it in GitHub Desktop.
Save alexlee-gk/76a409f62a53883971a18a11af93241b to your computer and use it in GitHub Desktop.
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.

@joaomamede
Copy link

In my RHEL8 I allow gdm to select wayland even with nvidia drivers installed.
Then if I want passthrough I select xorg.
If I want nvidia only for computing I just start my session in wayland.

@dedetuga
Copy link

dedetuga commented Oct 6, 2020

Confirmed on Ubuntu 18.04LTS !!!!!

I Almost want to kiss you!!!!

...Almost...

🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇

@scaomath
Copy link

Thanks for the post. I was able to get the iGPU in 10th gen Intel running using the xorg.conf given, as well as CUDA running VSCode. However, I got all pixelated and weird color strips across the screen. So I did some Google-fu and found that in order that X works on Intel UHD 630 (8th-10th gen desktop CPU). The iGPU part needs to be changed to:

Section "Device"
    Identifier  "Intel Graphics"
    Driver      "modesetting"
    BusID       "PCI:0:2:0"
EndSection

The driver has to be modesetting which is in xserver-xorg-core. Just to be safe, it is recommended to uninstall xserver-xorg-video-intel as well.

@K4R7IK
Copy link

K4R7IK commented Aug 3, 2021

What are changes to be made to make it work on AMD (Integrated) as I have Amd/Nvidia combo with AMD as iGPU and Nvidia as dGPU

@svh-pad
Copy link

svh-pad commented Dec 14, 2021

I am using an AMD integrated GPU (on 5800H) and NVIDIA 3070 in a laptop. These instructions worked for me with the following xorg.conf:

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

Section "Device"
	Identifier  "amdgpu"
	Driver      "amdgpu"
	BusID       "PCI:6: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 with NVIDIA-Linux-x86_64-470.94.run, cuda_11.5.1_495.29.05_linux.run and the mainline 5.12 kernel on Ubuntu 20.04.

@Aviksaikat
Copy link

Aviksaikat commented Jan 4, 2022

Hi i’m using hp pavilion 15-ec2xxx

AMD Ryzen 5600H with radeon graphics + nvidia gtx 1650

I’m using parrot-lts with kde

i’m having problem while using external monitor i switched to nvidia & the external display works fine but my laptop display is blank. How to fix this? is there any way to use a hybrid system like radeon for laptop and nvidia to external monitor simultaneously like we do in windows ? or can we run both the displays on nvidia ?

~ xrandr --listproviders 
Providers: number : 2
Provider 0: id: 0x1b8 cap: 0x1, Source Output crtcs: 4 outputs: 1 associated providers: 0 name:NVIDIA-0
Provider 1: id: 0x1f7 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 4 outputs: 1 associated providers: 0 name:Unknown AMD Radeon GPU @ pci:0000:05:00.0

nvidia-smi

Tue Jan  4 11:23:57 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.57.02    Driver Version: 470.57.02    CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+
| 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 ...  On   | 00000000:01:00.0  On |                  N/A |
| N/A   45C    P8     6W /  N/A |    505MiB /  3911MiB |      9%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1238      G   /usr/lib/xorg/Xorg                224MiB |
|    0   N/A  N/A      2317      G   /usr/bin/kwin_x11                  77MiB |
|    0   N/A  N/A      2401      G   /usr/bin/plasmashell               40MiB |
|    0   N/A  N/A      2442      G   /usr/bin/latte-dock                41MiB |
|    0   N/A  N/A      2731      G   ...akonadi_archivemail_agent        1MiB |
|    0   N/A  N/A      2739      G   .../akonadi_mailfilter_agent        1MiB |
|    0   N/A  N/A      2743      G   ...n/akonadi_sendlater_agent        1MiB |
|    0   N/A  N/A      2744      G   ...nadi_unifiedmailbox_agent        1MiB |
|    0   N/A  N/A      5142      G   ...AAAAAAAAA= --shared-files       63MiB |
|    0   N/A  N/A      8915      G   /usr/bin/kitty                      2MiB |
|    0   N/A  N/A     59428      G   ...AAAAAAAAA= --shared-files       38MiB |
+-----------------------------------------------------------------------------+
~ lspci -k | grep -A 2 -E "(VGA|3D)"                                                 
01:00.0 VGA compatible controller: NVIDIA Corporation TU117M (rev a1)
	DeviceName: NVIDIA Graphics Device
	Subsystem: Hewlett-Packard Company TU117M
--
05:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Cezanne (rev c6)
	DeviceName:  Onboard IGD
	Subsystem: Hewlett-Packard Company Device 88dd

I removed the xorg.conf file but still no output on laptop display

Device info

CPU: AMD Ryzen 5 5600H with Radeon Graphics (12) @ 3.3GHz
PRETTY_NAME="Parrot OS 5.0 (LTS)"
NAME="Parrot OS"
VERSION_ID="5.0"
VERSION="5.0 (LTS)"
VERSION_CODENAME=bullseye
ID=debian

@SwaySZ
Copy link

SwaySZ commented Jan 5, 2022

FOR DESKTOP ONLY: A very straightforward way is to set the BIOS to use your onboard device (i.e., Intel graphics) if possible. Your Nvidia card will be powered but 100% idle. Tested on Intel UHD graphics 630 on Ubuntu 20.04.3, and the Nvidia driver is the latest 495.46.
See details here

@Aviksaikat
Copy link

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 |
+-----------------------------------------------------------------------------+


@haipnh
Copy link

haipnh commented Jun 28, 2022

Hi,

Here is my system. But the PCI ID of the GTX 1080 Ti randomly changes between 01:00.0 and 03:00.0 after reboot. How can I make it static?

$ lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Device 9bc5 (rev 05)
01:00.0 VGA compatible controller: NVIDIA Corporation GP102 [GeForce GTX 1080 Ti] (rev a1)
06:00.0 VGA compatible controller: NVIDIA Corporation Device 1f82 (rev a1)

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