Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zakkak/8a5a99a2ff6e3b11f49ac6d9a3f077af to your computer and use it in GitHub Desktop.
Save zakkak/8a5a99a2ff6e3b11f49ac6d9a3f077af to your computer and use it in GitHub Desktop.
Making Nvidia Drivers + CUDA 8 + Bumblebee work together on XPS 15 Early 2017 9560 kabylake. Ubuntu, KDE Neon, Linux Mint, debian.
# As of writing this, 4.11 kernel fails, 4.10.15 fails, 4.11rc8 seems to be working. Apply the graphics patches first.
# Install Intel Graphics Patch Firmwares (This should reboot your system):
bash -c "$(curl -fsSL http://bit.ly/IGFWL-install)"
# Update to 4.11.2 kernel. nvidia-375 compiles fine >=4.11.1
cd /tmp
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.11.2/linux-headers-4.11.2-041102_4.11.2-041102.201705201036_all.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.11.2/linux-headers-4.11.2-041102-generic_4.11.2-041102.201705201036_amd64.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.11.2/linux-image-4.11.2-041102-generic_4.11.2-041102.201705201036_amd64.deb
sudo dpkg -i *.deb
# Add Nvidia repository
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
# Install via ubuntu drivers
sudo ubuntu-drivers autoinstall
# <optional for ML Folks> Install CUDA 8 (if you're interested in using gpu for ML) ~> requires nvidia stable drivers
# This acts as repo so install it somewhere safe and do not delete
cd ~/Downloads
wget https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64-deb
sudo dpkg -i cuda*.deb; sudo apt update; sudo apt install cuda
# Update Path to have /usr/local/cuda/bin incase using dotfiles.
# if you get this message:
# /sbin/ldconfig.real: /usr/lib/nvidia-375/libEGL.so.1 is not a symbolic link
# /sbin/ldconfig.real: /usr/lib32/nvidia-375/libEGL.so.1 is not a symbolic link
# Manually override using https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-375/+bug/1662860/comments/14
# <optional for ML Folks> Install CuDNN for running things like tensorflow
# Download cudnn from nvidia
tar -xvzf cudnn-8.0-linux-x64-v6.0.tgz
sudo rsync -K -a cuda/* /usr/local/cuda/
# The version of prime-select is BS. Patch prime select like this
# Update: it's been fixed, just leaving here if something fails.
# cd /usr/bin
# sudo mv prime-select prime-select.bkup
# sudo wget https://raw.githubusercontent.com/C11235/nvidia-prime-bugfix/master/prime-select
# sudo chmod 755 prime-select
# sudo reboot now
# Testing cuda.
$ sudo prime-select intel
$ nvidia-smi
# This should give an error, no drivers found
# Try this
$ sudo prime-select nvidia
# displays CUDA info.
# At this point the nvidia drivers work well enough. Search for "nvidia x server settings"
# in your applications menu and you can switch between intel and nvidia PRIME profiles.
# But the nvidia card is still ON (bbswitch will report it off, but the battery consumption is (20 +- 5) Watts
# You can leave it here if you're not worried about battery but if you are then continue with this.
# Install powertop and tlp
sudo apt install tlp powertop
# Run powertop:
sudo powertop
# You should see battery discharge around 20w +/- 5W, this eats up my battery 4 times faster.
# Add command line params:
sudo nano /etc/default/grub
# Make the following look like this, do not ask why.
GRUB_CMDLINE_LINUX_DEFAULT='pcie_port_pm=off acpi_backlight=none acpi_osi=Linux acpi_osi=! acpi_osi="Windows 2009"'
sudo update-grub2
# Install bumblebee - now this is the danger zone, this software has not been updated in a while and I am not sure when will this available.
# Avoid updating your system if you're fine with this.
sudo add-apt-repository ppa:bumblebee/testing
sudo apt update
sudo apt install bumblebee bumblebee-nvidia
# at the time of writing this, the latest is nvidia-381 but cuda 8 requires the stable, which is nvidia-375
# add them to bumblebee config file.
sudo nano /etc/bumblebee/bumblebee.conf
# Change 'Driver=' to 'Driver=nvidia'
# Change all occurences of 'nvidia-current' to 'nvidia-xxx'
# Change KernelDriver=nvidia-375
# save and run
sudo service bumblebeed restart
# this should give you daemon already running
sudo bumblebeed
# Since the driver load will now be handled by bumblebee, we need to stop the OS from loading it.
sudo nano /etc/modprobe.d/bumblebee.conf
# Make the following section look like this (the drm line will be added):
#375
blacklist nvidia-375
blacklist nvidia-375-drm
blacklist nvidia-375-updates
blacklist nvidia-experimental-375
# once that is done, you'll need bbswitch dkms module
sudo apt-get install bbswitch-dkms
# Load this with the kernel.
sudo nano /etc/modules-load.d/modules.conf
# add following
i915
bbswitch
# now make sure nvidia-settings has nvidia prime profile selected.
# So what actually happened:
# The control for switching between graphics has been moved from nvidia's driver to bumblebee. This helps
# maximize battery life because now you can selectively switch between which graphics card to use. In case
# you want to provide access to nvidia gpu for the current application run it using optirun.
# e.g. if you want to run steam with nvidia gpu, run something like: $ optirun steam
# or if you're using gpu to run ml tasks, just run them with optirun and they would work just fine.
# Additional
# TLP is known to interfere with bumblebee, make it avoid using this https://wiki.archlinux.org/index.php/Talk:Bumblebee#Bumblebee_and_TLP_interferening
# Run powertop to see if battery consumption is in check: 10w +/- 5W
# Testing bumblebee
cat /proc/acpi/bbswitch # Ouput:0000:01:00.0 OFF
optirun glxgears -info # Runs the Gears demo
optirun nvidia-smi # Should give an error
sudo prime-select nvidia # Should select nvidia hardware for cuda
optirun nvidia-smi # Outputs:
Mon Feb 20 21:51:18 2017
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 375.39 Driver Version: 375.39 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 1050 Off | 0000:01:00.0 Off | N/A |
| N/A 41C P3 N/A / N/A | 6MiB / 4041MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 3351 G /usr/lib/xorg/Xorg 6MiB |
+-----------------------------------------------------------------------------+
cat /proc/acpi/bbswitch # Still Outputs:0000:01:00.0 OFF which means, we're using nvida hardware only when we run applications using optirun
# Getting mouse freezes, random misses?
dmesg -w | grep psmouse #check if your trackpad is out of sync frequently
# Add this boot flag:
"psmouse.resetafter=0"
# Other Helpful links:
http://en.community.dell.com/techcenter/os-applications/f/4613/t/19629103
https://karlgrz.com/dell-xps-15-ubuntu-tweaks/
https://hemenkapadia.github.io/blog/2016/05/07/Ubuntu-with-Nvidia-Bumblebee.html
https://askubuntu.com/questions/879856/nvidia-prime-cant-switch-to-intel/885487
http://www.webupd8.org/2016/08/how-to-install-and-configure-bumblebee.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment