Skip to content

Instantly share code, notes, and snippets.

@chizhang529
Last active December 9, 2018 01:57
Show Gist options
  • Save chizhang529/3c414428cd1c82e38e7dde0be70e2955 to your computer and use it in GitHub Desktop.
Save chizhang529/3c414428cd1c82e38e7dde0be70e2955 to your computer and use it in GitHub Desktop.
CUDA cuDNN Setup

Choose Versions of cuDNN, CUDA and Tensorflow

Tensorflow Version

Installation (CUDA8.0 + cuDNN 6.0 + Tensorflow 1.4.0)

Nvidia 384 Driver

CUDA 8.0 and higher versions require at least nvidia-384 driver:

sudo apt-get purge nvidia*
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update && sudo apt-get install nvidia-384 nvidia-settings

By now, you should be able to see your graphics card by entering nvidia-smi in terminal.

CUDA 8.0

Go to CUDA Toolkit 8.0-Feb 2017 and download the deb(local) file, then

sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda

You can check the installation using commands below

cd /usr/local/cuda/samples/1_Utilities/deviceQuery #由自己的安装目录决定
sudo make
sudo ./deviceQuery

You should be able to see CUDA version if the installation is successful. Now, configure the environment variables of CUDA:

export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export CUDA_HOME=/usr/local/cuda
source ~/.bashrc

Note: If you have installed a higher version of CUDA and want to downgrade to 8.0, the commands below will help you:

sudo apt-get remove cuda
sudo apt autoremove
sudo apt-get autoclean
sudo apt-get install cuda8.0

It is okay to see that CUDA Driver Version = 9.1,CUDA Runtime Version = 8.0 when testing CUDA version.

cuDNN 6.0 (Download Link)

The installation of CuDNN is just copying some files. Hence to check if CuDNN is installed (and which version you have), you only need to check those files. Check where your cuda installation is before installing cuDNN. For most people, it will be /usr/local/cuda/. You can check it with which nvcc.

tar -zxvf cudnn-8.0-linux-x64-v6.0.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/ -d
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*

Note: If you need a higher version of cuDNN, then register an nvidia developer account and download cudnn here (about 80 MB). You might need nvcc --version to check your cuda version before downloading compatible cuDNN.

Tensorflow GPU 1.4.0

It is pretty easy using pip:

pip install tensorflow-gpu==1.4.0

Version Checking Commands

For CUDA:

nvcc --version

For cuDNN:

cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

For Tensorflow:

[Python Console]
>>> import tensorflow as tf
>>> print(tf.__version__)
1.4.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment