Skip to content

Instantly share code, notes, and snippets.

@ErikGartner
Last active February 22, 2021 00:36
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ErikGartner/ca01aa56e3752ce3d9e0e8dc09b255c9 to your computer and use it in GitHub Desktop.
Save ErikGartner/ca01aa56e3752ce3d9e0e8dc09b255c9 to your computer and use it in GitHub Desktop.
A CUDA installations guide

A Magical Guide to Installing CUDA

This guide tries to make sense of installing Nvidia CUDA on Ubuntu.

A forewarning: installing CUDA is a somewhat tedious and problematic process. This guide worked for me, though if you have an unusual configuration you might need additional preparations to make this work. For reference here are Nvidia's official guides for CUDA and cuDNN.

Versions

  • Ubuntu 16.04
  • CUDA 8.0 GA2 (patched)
  • NVIDIA driver 384
  • cuDNN 6.0

Note: Installing more recent versions of CUDA (e.g. 9.0) and on Ubuntu 18.04 should follow similar steps, but haven't yet been tested.

Preparations

  1. Blacklist Nouveau drivers:
sudo -i
rm /etc/modprobe.d/blacklist-nouveau.conf
echo 'blacklist nouveau' >> /etc/modprobe.d/blacklist-nouveau.conf
echo 'options nouveau modeset=0' >> /etc/modprobe.d/blacklist-nouveau.conf
update-initramfs -u
exit
  1. If you have previously installed CUDA using the runfile you need to remove it. Check by running and look for a folder named cuda-X.X
ls /usr/local/

If you have CUDA installed execute the follow after replacing X.X with your version.

cd /usr/local/cuda-X.X/
sudo ./bin/uninstall_cuda.X.X.pl
sudo /usr/bin/nvidia-uninstall
  1. Purge all nvidia driver:
dpkg --get-selections | grep nvidia
sudo apt remove --purge [packages ..]
  1. Purge any CUDA leftovers:
dpkg --get-selections | grep cuda
sudo dpkg --purge [packages ..]
  1. Purge any cuDNN leftovers:
dpkg --get-selections | grep libcudnn
sudo dpkg --purge [packages ..]

Installation

This guide uses the local deb file and installs the held back version with drivers. In English: this guide installs the Debian package along with graphic drivers in a way that disables automatic update.

  1. Download the drivers from here: Package and Patch.

  2. Install the packages using:

sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-cublas-performance-update_8.0.61-1_amd64.deb
sudo apt update
sudo apt install cuda-8-0
  1. Download cuDNN (requires an Nvidia Developer account) from here: Runtime and Developer.

  2. Install the packages:

sudo dpkg -i libcudnn6_6.0.20-1+cuda8.0_amd64.deb
sudo dpkg -i libcudnn6-dev_6.0.20-1+cuda8.0_amd64.deb
sudo apt install libcudnn6-dev libcudnn6
  1. Setup shell environment. Add the followin lines to ~/.bashrc or similar. Restart your terminal/shell afterwards.
export CUDA_HOME=/usr/local/cuda-8.0
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64
PATH=${CUDA_HOME}/bin:${PATH}
export PATH

Test everything (fingers crossed):

nvcc -V

Should output:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61

Run:

nvidia-smi

Should output a list of your graphic cards. Then run:

cp -r /usr/src/cudnn_samples_v6/ $HOME
cd  $HOME/cudnn_samples_v6/mnistCUDNN
make clean && make
./mnistCUDNN

It should output (among other stuff):

Test passed!

Reboot your computer (fingers crossed even more this time).

Troubleshooting / Common Issues

The Xserver doesn't properly start

The root cause of this can be unclear and just reinstalling the Nvidia drivers might not help.

Here are som suggestions:

  • Creating a new Xorg.conf, see this old guide.
  • Checking the default display manager, making sure it's correctly configured and perhaps reinstalling it: cat etc/X11/default-display-manager, more here.
  • If you have multiple displays it might help to temporarily only use one display until the problem is resolved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment