Nvidia Drivers – Install Nvidia Drivers, CUDA, CUDNN, and Tensorflow GPU on Ubuntu 18.04

18.04cudagpu

How can I easily get tensorflow gpu running?

Best Answer

I just installed Tensorflow GPU on Ubuntu 18.04. There are a lot instructions for it, however I think the fastest and easiest way is usually not used and I want to share it:

NVIDIA DRIVER:

ubuntu-drivers devices
sudo ubuntu-drivers autoinstall
nvidia-smi

CUDA:

Normally: "sudo apt install nvidia-cuda-toolkit" However this installs version 9.1, too new at the moment and tensorflow will not run. Instead download CUDA 9.0: https://developer.nvidia.com/cuda-90-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1704&target_type=runfilelocal Then run (Additional Details on the first line can be found at: How can I install CUDA 9 on Ubuntu 17.10):

sudo sh cuda_9.0.176_384.81_linux.run --override
sudo ln -s /usr/bin/gcc-6 /usr/local/cuda/bin/gcc
sudo ln -s /usr/bin/g++-6 /usr/local/cuda/bin/g++
cd ~
sudo nano .bashrc

add at the end of the file:
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}}
CTL+X to save and exit

CuDNN:

register at nvidia developers https://developer.nvidia.com/cudnn Download 9.1 runtime & developer library for 16.04 (Files cuDNN v7.1.3 Runtime Library for Ubuntu16.04 (Deb) & cuDNN v7.1.3 Developer Library for Ubuntu16.04 (Deb)) Open the files with software manager and install them. Check with:

cat /usr/include/x86_64-linux-gnu/cudnn_v*.h | grep CUDNN_MAJOR -A 2

Install libraries and tensorflow:

sudo apt-get install libcupti-dev
pip3 install tensorflow-gpu

Check:

in tensorflow check for GPU support 
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

Note: Start tensorflow or your development environment from terminal, otherwise for me it does not load the PATH variables.