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.
- 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.
- 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
- 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
- Purge all nvidia driver:
dpkg --get-selections | grep nvidia
sudo apt remove --purge [packages ..]
- Purge any CUDA leftovers:
dpkg --get-selections | grep cuda
sudo dpkg --purge [packages ..]
- Purge any cuDNN leftovers:
dpkg --get-selections | grep libcudnn
sudo dpkg --purge [packages ..]
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.
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
-
Download cuDNN (requires an Nvidia Developer account) from here: Runtime and Developer.
-
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
- 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
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).
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.