The solution is based on this GitHub gist
Information on 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
Modify the GRUB configuration by editing this file:
sudo vim /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_rev_override=1"
Finally update GRUB using this command:
If you want you can use the tool grub-customizer by adding the text highlighted in blue:
Restart your computer - very important!!
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 content:
### 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
echo "Usage: /etc/init.d/intel-gpu start|stop"
Add executable rights:
sudo chmod +x /etc/init.d/intel-gpu
And register the new service:
sudo update-rc.d intel-gpu defaults
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:
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
<your_user> is your user name.
This allows us to call prime-select without having to introduce a password.
Add an autostart script to change the graphics 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:
And add this content:
Exec=sudo prime-select nvidia
Restart you computer
Now you can use all the memory in your NVIDIA GPU. You can verify that by calling the command `nvidia-smi: