Setup Tensorflow GPU

Setup Tensorflow GPU

Donny Donny
August 26, 2018
August 26, 2018

0. install GPU drivers

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
sudo apt install nvidia-390

1. install cuda tookit and cudnn SDK (and CUPTI)

Following the instructions at Installing Tensorflow on Ubuntu.

# Adds NVIDIA package repository.
sudo apt-key adv --fetch-keys
sudo dpkg -i cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
sudo dpkg -i nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb
sudo apt-get update
# Includes optional NCCL 2.x.
sudo apt-get install cuda9.0 cuda-cublas-9-0 cuda-cufft-9-0 cuda-curand-9-0 \
  cuda-cusolver-9-0 cuda-cusparse-9-0 libcudnn7= \
   libnccl2=2.2.13-1+cuda9.0 cuda-command-line-tools-9-0
# Optionally install TensorRT runtime, must be done after above cuda install.
sudo apt-get update
sudo apt-get install libnvinfer4=4.1.2-1+cuda9.0

2. *setup $PATH and $LD_LIBRARY_PATH in /etc/environment

export PATH=$PATH:/usr/local/cuda/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64

Than, logout and login again to apply environment change.

3. check with nvcc

Check nvcc with:

nvcc -V

Should output something like:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176

4. install tensorflow

pip install tensorflow-gpu
pip install --ignore-installed --upgrade tensorflow-gpu

5. check with

from tensorflow.python.client import device_lib

from keras import backend as K

Some other problems

  • Missing dependencies for SOCKS support.

    1. Method 1
    $ all_proxy=$https_proxy
    1. Method 2
    $ pip install pysocks