Linux (Ubuntu 18.04) and two graphics cards in a laptop (MSI)

My laptop (MSI GL73 8RC) has two graphic cards:

  • Intel VGA compatible (i915)
  • Nvidia GeForce GTX 1050 Mobile

Here I will describe how I can use both of them in Ubuntu, Intel i915 for X-server (display server) and Gnome display manager (GDM), and Nvidia GTX1050 for CUDA and python etc

1. Find out what graphic cards are actually in your system

inxi -F     
or
inxi -CGS

System:    Host: alex-GL73-8RC Kernel: 5.4.0-56-generic x86_64 bits: 64
Desktop: Gnome 3.28.4 Distro: Ubuntu 18.04.3 LTS
CPU:       6 core Intel Core i7-8750H (-MT-MCP-) cache: 9216 KB
clock speeds: max: 4100 MHz 1: 4062 MHz 2: 3909 MHz 3: 4097 MHz
4: 4045 MHz 5: 3908 MHz 6: 3908 MHz 7: 3909 MHz 8: 4084 MHz
9: 4089 MHz 10: 4026 MHz 11: 4087 MHz 12: 4090 MHz
Graphics:  Card-1: Intel Device 3e9b
Card-2: NVIDIA GP107M [GeForce GTX 1050 Mobile]
Display Server: x11 (X.Org 1.19.6 )
drivers: fbdev (unloaded: modesetting,vesa)
Resolution: 1920×1080@60.00hz
OpenGL: renderer: llvmpipe (LLVM 10.0.0, 256 bits)
version: 3.3 Mesa 20.0.8

hwinfo --gfxcard

13: PCI 100.0: 0302 3D controller                               
[Created at pci.378]
Unique ID: VCu0.p_bAc0E2VBF
Parent ID: vSkL.lROesgnSisF
SysFS ID: /devices/pci0000:00/0000:00:01.0/0000:01:00.0
SysFS BusID: 0000:01:00.0
Hardware Class: graphics card
Model: “nVidia GP107M [GeForce GTX 1050 Mobile]”
Vendor: pci 0x10de “nVidia Corporation”
Device: pci 0x1c8d “GP107M [GeForce GTX 1050 Mobile]”
SubVendor: pci 0x1462 “Micro-Star International Co., Ltd. [MSI]”
SubDevice: pci 0x121a
Revision: 0xa1
Driver: “nvidia”
Driver Modules: “nvidia”
Memory Range: 0xa3000000-0xa3ffffff (rw,non-prefetchable)
Memory Range: 0x90000000-0x9fffffff (ro,non-prefetchable)
Memory Range: 0xa0000000-0xa1ffffff (ro,non-prefetchable)
I/O Ports: 0x5000-0x507f (rw)
Memory Range: 0xa4000000-0xa407ffff (ro,non-prefetchable,disabled)
IRQ: 129 (1073 events)
Module Alias: “pci:v000010DEd00001C8Dsv00001462sd0000121Abc03sc02i00”
Driver Info #0:
Driver Status: nvidiafb is not active
Driver Activation Cmd: “modprobe nvidiafb”
Driver Info #1:
Driver Status: nouveau is not active
Driver Activation Cmd: “modprobe nouveau”
Driver Info #2:
Driver Status: nvidia_drm is not active
Driver Activation Cmd: “modprobe nvidia_drm”
Driver Info #3:
Driver Status: nvidia is active
Driver Activation Cmd: “modprobe nvidia”
Config Status: cfg=new, avail=yes, need=no, active=unknown
Attached to: #10 (PCI bridge)

21: PCI 02.0: 0300 VGA compatible controller (VGA)
[Created at pci.378]
Unique ID: _Znp.8ScOSjjBdqA
SysFS ID: /devices/pci0000:00/0000:00:02.0
SysFS BusID: 0000:00:02.0
Hardware Class: graphics card
Device Name: “Onboard – Video”
Model: “Intel VGA compatible controller”
Vendor: pci 0x8086 “Intel Corporation”
Device: pci 0x3e9b
SubVendor: pci 0x1462 “Micro-Star International Co., Ltd. [MSI]”
SubDevice: pci 0x121a
Driver: “i915”
Driver Modules: “i915”
Memory Range: 0xa2000000-0xa2ffffff (rw,non-prefetchable)
Memory Range: 0x80000000-0x8fffffff (ro,non-prefetchable)
I/O Ports: 0x6000-0x603f (rw)
Memory Range: 0x000c0000-0x000dffff (rw,non-prefetchable,disabled)
IRQ: 128 (6750 events)
I/O Port: 0x00 (rw)
Module Alias: “pci:v00008086d00003E9Bsv00001462sd0000121Abc03sc00i00”
Driver Info #0:
Driver Status: i915 is active
Driver Activation Cmd: “modprobe i915”
Config Status: cfg=new, avail=yes, need=no, active=unknown

2.  Turn off automatic start of Gnome desktop manager (GDM)

When experimenting with drivers, GDM may crash (for example because a chosen driver is incomaptible)  – To have a chance to make changes to your system do not run GDM automatically:

sudo systemctl enable multi-user.target
sudo systemctl set-default multi-user.target

Now start GDM manually (after reboot) with:

 sudo systemctl start gdm3

3. Install Nvidia drivers

Find out what drivers are available for your system:

ubuntu-drivers devices

== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00001C8Dsv00001462sd0000121Abc03sc02i00
vendor   : NVIDIA Corporation
model    : GP107M [GeForce GTX 1050 Mobile]
driver   : nvidia-driver-455 – third-party free recommended
driver   : nvidia-driver-418-server – distro non-free
driver   : nvidia-driver-390 – distro non-free
driver   : nvidia-driver-440-server – distro non-free
driver   : nvidia-driver-450-server – distro non-free
driver   : xserver-xorg-video-nouveau – distro free builtin

== /sys/devices/pci0000:00/0000:00:14.3 ==
modalias : pci:v00008086d0000A370sv00008086sd000002A4bc02sc80i00
vendor   : Intel Corporation
manual_install: True
driver   : backport-iwlwifi-dkms – distro free

Install them  with:

sudo ubuntu-drivers autoinstall

4. Experiment with the kernel parameters via GRUB config:

sudo nano /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT=”acpi=on”

‘acpi=on’  will be required for MSI laptop touch pad to work

Save GRUB config with:

sudo update-grub

5. Important: set the graphics card X server should use and get rid of flickering issues:

This is the tricky part. You have to make sure that X-server (GDM) chooses the correct graphic card. Since it may crash for the Nvidia driver, we will use the Intel graphic card!

There should be X11 .conf files for both Intel and Nvidia in

ls /usr/share/X11/xorg.conf.d/

10-intel.conf
20-nvidia.conf

If X11 config for Intel graphics is missing, create one:

sudo nano /usr/share/X11/xorg.conf.d/10-intel.conf

Section “OutputClass”
Identifier “Intel”
MatchDriver “i915”
Driver “intel”
Option      “TripleBuffer” “true”
Option      “TearFree”     “true”
Option      “DRI”          “false”
Option      “DPMS”
Option      “AccelMethod”   “sna”
Option      “EXAPixmaps”   “false”
EndSection

The last three options are important to get rid of flickering in Gnome! Also, make sure the X11 config for Nvidia graphics is starting with “20”, so it has lower priority than Intel graphics.

Try starting X-server :

sudo systemctl start gdm3

And look if the correct graphics card was chosen by X-server:

cat /var/log/Xorg.0.log

26.550] (–) PCI:*(0:0:2:0) 8086:3e9b:1462:121a rev 0, Mem @ 0xa2000000/16777216, 0x80000000/268435456, I/O @ 0x00006000/64, BIOS @ 0x????????/131072

The chosen driver is marked with a star (*). In this case it’s the Intel graphics driver (compare PCI description with point 1 of this tutorial).

Alternatively, you can verify with Nvidia tools:

nvidia-smi

It will show if any process is running on the Nvidia graphics card.

Additionally, you can choose the selected graphics card with:

sudo prime-select intel
sudi prime-select nvidia

6. CUDA toolkit

Optional: Install CUDA toolkit via Conda:

conda install -c anaconda cudatoolkit
conda install -c anaconda cudn

conda list

cudatoolkit               11.0.221             h6bb024c_0    anaconda
python                    3.6.6                h6e4f718_2
pytorch                   1.7.0           py3.6_cuda11.0.221_cudnn8.0.3_0    pytorch
tensorflow-gpu            1.9.0                hf154084_0    anaconda

Leave a Reply

Your email address will not be published. Required fields are marked *

IMPORTANT! To be able to proceed, please enter the magic word 'denaag' so we know hat you are a human)

Enter the magic word:
Please leave these two fields as-is:

A blog on projects with robotics, computer vision, 3D printing, microcontrollers, car diagnostics, localization & mapping, digital filters, LiDAR and more