Install CUDA and cuDNN on ubuntu 18.04

1 Install nvidia gpu driver

$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt update # (re-run if any warning/error messages)
$ sudo apt-get install nvidia-<version> #(press tab to see latest).

Reboot to let graphics driver take effect.

2 Install and test CUDA

To use TensorFlow with NVIDIA GPUs, the first step is to install the CUDA Toolkit by following the official documentation. Steps for CUDA 9.0 for quick reference as follow:

Navigate to https://developer.nvidia.com/cuda-downloads.

For 9.0: https://developer.nvidia.com/cuda-90-download-archive

Select Linux, x86_64, Ubuntu, 16.04, deb (local).

$ sudo dpkg -i cuda-repo-ubuntu1704-9-0-local_9.0.176-1_amd64.deb (this is the deb file you've downloaded)
$ sudo apt-get update
$ sudo apt-get install cuda

# Hold the cuda version
$ sudo apt-mark hold cuda

# Then install all patches.

$ export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}

3 Install cuDNN

Download cuDNN from: https://developer.nvidia.com/rdp/cudnn-download,

  1. cuDNN v7.2.1 Runtime Library for Ubuntu16.04 (Deb)
  2. cuDNN v7.2.1 Developer Library for Ubuntu16.04 (Deb)
  3. cuDNN v7.2.1 Code Samples and User Guide for Ubuntu16.04 (Deb)
$ sudo dpkg -i libcudnn7_7.0.3.11-1+cuda9.0_amd64.deb libcudnn7-dev_7.0.3.11-1+cuda9.0_amd64.deb libcudnn7-doc_7.0.3.11-1+cuda9.0_amd64.deb
$ sudo apt-mark hold libcudnn7 libcudnn7-dev libcudnn7-doc

4 Install gcc-6

$ sudo apt install gcc-6 g++-6
$ sudo ln -s /usr/bin/gcc-6 /usr/local/cuda/bin/gcc
$ sudo ln -s /usr/bin/g++-6 /usr/local/cuda/bin/g++

5 Test cuDNN

$ cp -r /usr/src/cuDNN_samples_v7 /tmp
$ cd /tmp/cuDNN_samples_v7/mnistcuDNN
$ make clean && make
$ ./mnistcuDNN

© 2015-2020 tendant