2018年5月31日 星期四

How to install Nvidia Driver, CUDA, cuDNN, Tensorflow on Ubuntu 16.04

Versions:
Ubuntu 16.04
Nvidia 384.130
CUDA 9.0
cuDNN 7.0.5
TensorFlow 1.8.0

Installation Order:
Nvidia Driver -> CUDA -> cuDNN -> Tensorflow
Notice that the version between CUDA, cuDNN and Tensorflow should be matched.

1. Install Nvidia Driver
Install Nvidia Driver via Ubuntu GUI
System Settings/ Software & Updates/ Additional Drivers,select "Using NVIDIA binary driver ...",not "...Nouveau..."

2. Upgrade the system, and reboot if required.
run the following command
$ sudo apt update
$ sudo apt upgrade
$ [ -e /var/run/reboot-required ] && sudo reboot

3. Install CUDA
a. The official installation guide: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/
I strongly suggest you to read the installation guide, especially for the verification part, I will skip it in this article.

b. download cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb from official site.

c. run the following command
$ sudo dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb
$ sudo apt-key add /var/cuda-repo-9-0-local/7fa2af80.pub
$ sudo dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb
$ sudo apt-get update
$ sudo apt-get install cuda

d. do Post-installation Actions
$ export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
$ export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

e. add the commands in step(d) to the file ~/.bashrc

f. reboot
$ sudo reboot

g. verify the installation
$ cat /usr/local/cuda/version.txt
$ nvcc --version
$ nvidia-smi

4. Install cuDNN
a. The official installation guide: https://docs.nvidia.com/deeplearning/sdk/cudnn-install/

b. download the following three files from official site.
libcudnn7_7.0.5.15-1+cuda9.0_amd64.deb
libcudnn7-dev_7.0.5.15-1+cuda9.0_amd64.deb
libcudnn7-doc_7.0.5.15-1+cuda9.0_amd64.deb

c. run the following command
$ sudo dpkg -i libcudnn7_7.0.5.15-1+cuda9.0_amd64.deb
$ sudo dpkg -i libcudnn7-dev_7.0.5.15-1+cuda9.0_amd64.deb
$ sudo dpkg -i libcudnn7-doc_7.0.5.15-1+cuda9.0_amd64.deb

d. verify the installation
Copy the cuDNN sample to a writable path.
$ cp -r /usr/src/cudnn_samples_v7/ $HOME
Go to the writable path.
$ cd  $HOME/cudnn_samples_v7/mnistCUDNN
Compile the mnistCUDNN sample.
$ make clean && make
Run the mnistCUDNN sample.
$ ./mnistCUDNN
If cuDNN is properly installed and running on your Linux system, you will see a message similar to the following:
Test passed!

e. reboot
$ sudo reboot

5. Install TensorFlow
a. run the following command
$ sudo apt-get install cuda-command-line-tools-9-0
$ wget https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1404/x86_64/nvinfer-runtime-trt-repo-ubuntu1404-3.0.4-ga-cuda9.0_1.0-1_amd64.deb
$ sudo dpkg -i nvinfer-runtime-trt-repo-ubuntu1404-3.0.4-ga-cuda9.0_1.0-1_amd64.deb
$ sudo apt-get update
$ sudo apt-get install -y --allow-downgrades libnvinfer-dev libcudnn7-dev=7.0.5.15-1+cuda9.0 libcudnn7=7.0.5.15-1+cuda9.0
$ sudo apt-mark hold libcudnn7 libcudnn7-dev
$ sudo pip3 install tensorflow-gpu
$ sudo apt-mark unhold libcudnn7 libcudnn7-dev

b. to validate your installation, run the following program
# Python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

沒有留言:

張貼留言