How to build TensorFlow, a fast & flexible Deep learning platform with GPU Support on Ubuntu?

How to build TensorFlow, a fast & flexible Deep learning platform with GPU Support on Ubuntu?
Installing Tensorflow

With the increasing velocity of data from all the directions, providing data scientists with the best tool is tough. Thanks to Google for open sourcing TensorFlow and syntaxnet an open source neural net framework for NLP.

Often Deep Learning demands high computing capabilities and using GPU's for computation is recommended. So how can you build tensorflow (here after 'tf') on your workstation with GPU support?

  • This post explains about building tf with GPU support on Ubuntu 16.04, if you are looking for lower versions or other distro's refer TensorFlow official setup

TF needs Cuda Toolkit 7.5 and cuDNN v4 to be installed.
Install Cuda Tool Kit
The official Nvidia releases support 14.04 & 15.04 only, Xenial+ppa repo has the CUDA tool kit, to install driver & CUDA tool kit:

Add the ppa repo
$ sudo add-apt-repository ppa:graphics-drivers/ppa

$ sudo apt-get update

Install the recommended driver (currently nvidia-367)
$ sudo ubuntu-drivers autoinstall

$ sudo reboot

If you had any problem with unmet dependancies, try installing this. $ sudo apt-get install libglu1-mesa libxi-dev libxmu-dev

Everything under nvidia specific for connected understanding
$ sudo apt-get install nvidia-{prime,profiler,settings,visual-profiler}

$ sudo apt-get install nvidia-cuda-{dev,doc,gdb,toolkit} $ sudo apt-get install libcupti-dev zlib1g-dev

The CUDA folder is
/usr/lib/nvidia-cuda-toolkit

TF expects the default installation folder at /usr/local/cuda so puut symlinks in /usr/local/cuda.

sudo mkdir /usr/local/cuda

cd /usr/local/cuda

sudo ln -s /usr/lib/x86_64-linux-gnu/ lib64

sudo ln -s /usr/include/ include

sudo ln -s /usr/bin/ bin

sudo ln -s /usr/lib/x86_64-linux-gnu/ nvvm

sudo mkdir -p extras/CUPTI

cd extras/CUPTI

sudo ln -s /usr/lib/x86_64-linux-gnu/ lib64

sudo ln -s /usr/include/ include

Install Cudnn
Register an nvidia developer account and download cudnn here (about 80 MB)
[Users installed CUDA using above steps can bypass the below step]

If you have already installed CUDA before and not sure about the installation path, whether check where your cuda installation is at /usr/lib/ and /usr/include or /urs/local/cuda/

You can check it with ldconfig -p | grep cuda

Extract and unzip the Cudnn file downloaded and:
cd ~/Downloads/cuda

sudo cp include/cudnn.h /usr/include

sudo cp lib64/libcudnn* /usr/lib/x86_64-linux-gnu/

sudo chmod a+r /usr/lib/x86_64-linux-gnu/libcudnn*

add below commands to ~/.bash_profile
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"

export CUDA_HOME=/usr/local/cuda

Install TensorFlow
Check http://tensorflow.org for latest version though, be sure about GPU enabled package.
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

PS:
TensorFlow supports GPU's which have 3.5 and above computate capability, You can find your GPU capability at https://developer.nvidia.com/cuda-gpus. [After installing everything on my workstation i realized,GPU capability of the system is just 2.1 and tf ignores GPU and uses only CPU]

Not sure your GPU model? try this:
lspci -vnn | grep -i VGA -A 12

Love to listen what you are trying to build using tf, share your thoughts.