Preliminary

sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev

GCC/G++

CUDA 9.0 does not support gcc/g++ 7. Install gcc/g++ 6:

sudo apt-get install gcc-6 g++-6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 50
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 40
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 40
sudo update-alternatives --config gcc

NVidia Driver

Install:

sudo add-apt-repository ppa:graphics-drivers
sudo apt-get update
sudo apt-cache search nvidia
sudo apt-get install nvidia-396

Base Installer

wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1704/x86_64/cuda-repo-ubuntu1704_9.0.176-1_amd64.deb
sudo dpkg -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

CUDA Toolkit

It seems Tensorflow does not supports CUDA toolkit 9.1 right now. Recommend to use runfile installation type.

wget https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda_9.0.176_384.81_linux-run

Follow the instruction:

You are attempting to install on an unsupported configuration. Do you wish to continue?
y
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81?
n
Install the CUDA 9.0 Toolkit?
y
Enter Toolkit Location
[default location]
Do you want to install a symbolic link at /usr/local/cuda?
y
Install the CUDA 9.0 Samples?
y
Enter CUDA Samples Location
[default location]

Uninstall (refer https://docs.nvidia.com/cuda/cuda-installation-guide-linux/#runfile-uninstallation):

sudo /usr/local/cuda-9.0/bin/uninstall_cuda_9.0.pl

Environment setup:

export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

Reference:

https://askubuntu.com/questions/967332/how-can-i-install-cuda-9-on-ubuntu-17-10 https://archerfmy.github.io/2017/04/12/How-to-switch-your-gcc-g-version-in-ubuntu/

cuDNN

.Download cuDNN

Download the latest cnDNN from https://developer.nvidia.com/rdp/cudnn-download

For example: cuDNN v7.1 Runtime Library for Ubuntu16.04 (Deb) cuDNN v7.1 Developer Library for Ubuntu16.04 (Deb) cuDNN v7.1 Code Samples and User Guide for Ubuntu16.04 (Deb)

Installation refers to http://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html:

sudo dpkg -i libcudnn7_7.1.1.5-1+cuda9.0_amd64.deb
sudo dpkg -i libcudnn7-dev_7.1.1.5-1+cuda9.0_amd64.deb
sudo dpkg -i libcudnn7-doc_7.1.1.5-1+cuda9.0_amd64.deb

.Verifying

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.

sudo 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!

.Reference http://www.cs.virginia.edu/~mwb7w/cuda_support/libcudart.html

###= libcupti-dev library

sudo apt-get install cuda-command-line-tools-9.0

Install Tensorflow with Anaconda

conda create --name tensorflow python=3.6.5
source activate tensorflow
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.8.0-cp36-cp36m-linux_x86_64.whl

Validate Installation

Invoke python from your shell as follows:

python

Enter the following short program inside the python interactive shell:

# Python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

If the system outputs the following, then you are ready to begin writing TensorFlow programs:

Hello, TensorFlow!