Wednesday, October 18, 2017

Ubuntu 16.04 Nvidia GPU Driver, CUDA, and CUDNN setup for Tensorflow

Installation instructions for the Nvidia driver, cuda, and cudnn 
Compatible with Tensoflow running on a GPU.

Uses:
Ubuntu 16.04 (Nvidia cuda 8.0 supports 14.04 and 16.04)
Python 3.5
Tensorflow 1.0 (requires cuda 8.0 and cudnn 5.1)
Cuda 8.0
Cudnn 5.1
Keras 2.0
Nvidia driver 387
Cuda 387
Cudnn
Tensorflow has Nvidia driver and lib deps


I used the following commands for CUDA installation. Lets make sure that the driver version and the CUDA versions are the same. You cannot see the CUDA version in the deb package name but you can see the CUDA version in the run file name. If you want to use the deb file first select the run file and get the version so that you know what driver version to install.

ssh to the machine with the GPU and execute the following commands.


################################################################################
# From https://devtalk.nvidia.com/default/topic/876432/no-cuda-capable-device-is-detected/
# Clean the Nvidia drivers

################################################################################
sudo apt-get purge nvidia*


################################################################################
# Install the Nvidia driver
# Version 387 in this post
################################################################################

sudo add-apt-repository ppa:graphics-drivers

# If you want to use the system settings to do the driver installation
sudo apt-get install xserver-xorg-video-nouveau 

sudo reboot

# For the driver version select 387 in the system settings
# and then the software and updates additional drivers installation
# select the driver that you want to use



sudo reboot

# check the driver versions that are installed.
sudo dpkg --list | grep nvidia

#check that the driver is working (we will check it again after installing cuda to make sure that there is not a driver/cuda conflict

nvidia-smi

Wed Oct 18 19:07:04 2017       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.90                 Driver Version: 384.90                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 106...  Off  | 00000000:01:00.0 Off |                  N/A |
|  0%   32C    P8     6W / 200W |     64MiB /  6072MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1139      G   /usr/lib/xorg/Xorg                            61MiB |
+-----------------------------------------------------------------------------+

################################################################################

# Cuda installation
# install version 384
# Get the deb package link from Nvidia
#Browse to https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1604&target_type=debnetwork
# Select the version you want that matches the Nvidia driver version that you installed
################################################################################

wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.0.176-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1604_9.0.176-1_amd64.deb
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda-8-0

# check that the driver is still working 

nvidia-smi

Wed Oct 18 19:07:04 2017       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.90                 Driver Version: 384.90                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 106...  Off  | 00000000:01:00.0 Off |                  N/A |
|  0%   32C    P8     6W / 200W |     64MiB /  6072MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1139      G   /usr/lib/xorg/Xorg                            61MiB |
+-----------------------------------------------------------------------------+

nvcc --version
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


################################################################################

# CUDNN Installation
# Download and install cuDNN v5.1 in a shell


################################################################################

cd /usr/local 
export CUDNN_VERSION=5.1
export CUDNN_TAR_FILE="cudnn-8.0-linux-x64-v${CUDNN_VERSION}.tgz"
sudo wget http://developer.download.nvidia.com/compute/redist/cudnn/v${CUDNN_VERSION}/${CUDNN_TAR_FILE}
sudo tar -xzvf ${CUDNN_TAR_FILE}
#sudo cp -fr cuda/* /usr/local/cudnn # modified gist
sudo chmod a+r /usr/local/cuda/lib64/*

# Install Tensorlfow using the instructions at the link below

http://programmingmatrix.blogspot.com/2017/04/clean-ubuntu-1604-tensorflow-10-cuda-80.html

No comments:

Post a Comment