4

I am using Ubuntu 16.04, on a dell XPS 9560 a laptop which is highly compatible with linux. This laptop provides two graphic cards:

  • NVIDIA GeForce GTX 1050
  • Intel HD Graphics 630

I wanted to use NVIDIA card only for CUDA, since it only have 4GB of RAM and the Intel Card for the graphical user interface.

Problems:

  • If it works the nvidia card is no longer visible. So if I call nvidia-smi the video card is disabled.
  • If do not works I get a black screen.
3

The solution is based on this post: https://gist.github.com/tomwwright/f88e2ddb344cf99f299935e1312da880

Information of my system:

  • Dell XPS 9560
  • I have already installed the CUDA 9.2 and Nvidia display driver 396.37
  • Ubuntu kernel is 4.15.0-24-generic
  • I am using gd3

Step 1

Modify your grub by editing this file:

sudo vim /etc/default/grub

And change:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

by:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_rev_override=1"

Finally update grub using this command:

sudo update-grub

If you want you can use the tool grub-customizer by adding the text highlighted in blue:

enter image description here

Restart your computer very important!!

Step 2

Create a service that will select the Intel GPU when the computer turns off, to this end create a new file:

sudo vim /etc/init.d/intel-gpu

With this contend:

#!/bin/bash
# /etc/init.d/intel-gpu

### BEGIN INIT INFO
# Provides:          intel-gpu
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Selects the intel GPU over the NVIDIA
### END INIT INFO

case "$1" in 
    start)
        ;;
    stop)
        /usr/bin/prime-select intel
        ;;
    *)
        echo "Usage: /etc/init.d/intel-gpu start|stop"
        exit 1
        ;;
esac

exit 0

Add executable rights:

sudo chmod +x /etc/init.d/intel-gpu

And register the new service:

sudo update-rc.d intel-gpu defaults

Step 3

Now we have ensured that when we start the computer the lightdm, gdm3, etc will use the Intel GPU since we have been enabled this GPU last time that we turned off the computer. Now we have to enable the NVIDIA GPU when we log into our account. However we need root access to do this and we don't want to prompt a window asking for a password each time we log in. To overcome this problem, we will create a command alias into the sudo configuration file.

First of all open the sudo configuration file using the following command:

sudo visudo

Then append this content to the end of the file:

User_Alias ADMINS = <your_user>
Cmnd_Alias PRIME_SELECT = /usr/bin/prime-select
ADMINS ALL = NOPASSWD: PRIME_SELECT

where is your user name.

This allows us to call prime-select without having to introduce a password.

Step 4

Add an autostart script to change the graphic card to NVIDIA once the lighdm has already started using the Intel's GPU. To this end append this command create a new file like this:

vim ~/.config/autostart/nvidia-gpu.desktop

And add this contend:

[Desktop Entry]
Name=NVIDIA GPU
Exec=sudo prime-select nvidia
Type=Application
Terminal=false

Restart you computer

Now you can use all the memory in your NVIDIA GPU. You can verify that by calling the command nvidia-smi:

enter image description here

| improve this answer | |
  • Lately I discovered that after configuring using this method, the nvidia card will only be enabled if the laptop is plugged into the power. So make sure that before turning on your laptop (and if you plan to use CUDA) plug the computer to the power!! – Marcus Jul 21 '18 at 23:49
0

To avoid problems when login off and login in some cases it is recommendable to avoid the step 4. It also helps to increase the battery life of your laptop if you only activate the NVIDIA card when it is needed. However it is not very practical since you have to open a terminal and write sudo prime-select nvidia each time. To overcome this "problem" I did a gnome 3 extension that does that.

To make it work you only have to go to this folder:

cd ~/.local/share/gnome-shell/extensions/

And then clone this repository:

git clone https://github.com/marcvivet/enable_cuda
mv enable_cuda enable_cuda@vivet.cat

Then press Alt+F2, enter 'r' (to restart the desktop) or just reboot.

Once your are done go to the gnome 3 Tweak Tool and enable the extension.

The result should be and NVIDIA gray icon when it is disabled:

enter image description here

And green when you click on the icon to enable CUDA.

enter image description here

This extension is very very simple and I do not make any check of the current state of the NVIDIA card. So If you use this icon do not use the terminal ...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.