Recent

Sunday, June 3, 2018

How To Install Nvidia CUDA 9.0 Toolkit on Ubuntu 18.04

If the purpose of installing the CUDA toolkit 9.0 on Ubuntu 18.04 is purely to use tensorflow-gpu, I strongly advise you to use the Docker method documented here, as you get better hardware and code isolation and easy portability to the cloud later.
TensorFlow Docker Installation incorrectly indicates that the host machine needs the CUDA toolkit and cuDNN libraries to be installed on the host machine. This is not true. I have reached out Tensorflow community to correct this.

How To

If you need to install CUDA 9.0 toolkit on Ubuntu 18.04, here are the instructions.

Uninstall Nvidia Drivers

Uninstall any Nvidia drivers. To uninstall do:
sudo apt-get remove --purge nvidia-*
sudo apt-get remove --purge libnvidia-*
This will avoid any versioning conflicts. CUDA Toolkit 9.0 and 9.1 requires nvidia-390_390.30 drivers. 

Install CUDA Toolkit 9.0 (using Ubuntu 17.04 repository meta-data)

The CUDA Toolkit is available at https://developer.nvidia.com/cuda-toolkit. You will have to navigate to the archives to find the install for CUDA 9.0 repository meta-data file for Ubuntu 17.04

Direct link:
https://developer.nvidia.com/cuda-90-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1704&target_type=debnetwork

The required steps are:
1) Download the network repository meta-data. Navigate to the folder and install
2) Installing the CUDA public GPG key
3) Update the apt repository cache
4) Install CUDA

To perform the steps:
sudo apt-get -i cuda-repo-ubuntu1704_9.0.176-1_amd64.deb
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1704/x86_64/7fa2af80.pub
sudo apt-get update
sudo apt-get install cuda-9-0

Be sure to explicitly type out the desired version. If you do not it will install 9.1! I don't know why it does this, but it happened.

Now, the install process can take a bit of time. If all goes well you will not have an installation error.
If you come across an error use this to fix the install:
sudo apt-get install -f
If you get:
Unpacking nvidia-390 (390.30-0ubuntu1) ...
dpkg: error processing archive /var/cache/apt/archives/nvidia-390_390.30-0ubuntu1_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/x86_64-linux-gnu/libGLX_indirect.so.0', which is also in package libglx-mesa0:amd64 18.0.0~rc5-1ubuntu1
Errors were encountered while processing:
 /var/cache/apt/archives/nvidia-390_390.30-0ubuntu1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

To fix this, check if the libGX_indirect.so.0 file exists. If it exists make a backup:
sudo mv /usr/lib/x86_64-linux-gnu/libGLX_indirect.so.0 /usr/lib/x86_64-linux-gnu/libGLX_indirect.so.0.old
The weird thing for me is the file didn't exist! Nonetheless, this command will install force the install of the drivers:
dpkg -i --force-overwrite /var/cache/apt/archives/nvidia-390_390.30-0ubuntu1_amd64.deb
Run the install again, and succeed!
sudo apt-get install cuda-9-0

Install cuDNN 7.1.4 (using Ubuntu 16.04 repository meta-data)

Go to: https://developer.nvidia.com/cudnn and register a free Nvidia Developer Account to get access. Use the latest 7.1.4 version of cuDNN corresponding to CUDA toolkit 9.0.

Select the Ubuntu 16.04 Deb files:

cuDNN v7.1.4 Runtime Library for Ubuntu16.04 (Deb)
cuDNN v7.1.4 Developer Library for Ubuntu16.04 (Deb)
cuDNN v7.1.4 Code Samples and User Guide for Ubuntu16.04 (Deb)

Install all three packages by:
sudo dpkg -i ./libcudnn7_7.1.4.18-1+cuda9.2_amd64.deb
sudo dpkg -i ./libcudnn7-dev_7.1.4.18-1+cuda9.0_amd64.deb
sudo dpkg -i ./libcudnn7-doc_7.1.4.18-1+cuda9.0_amd64.deb

4 comments: