Step 9: Install cuDNN 7.1.4:
NVIDIA cuDNN is a GPU-accelerated library of primitives for deep neural networks.
Goto https://developer.nvidia.com/cudnn and download Login and agreement required
After login and accepting agreement.
Download the following:
cuDNN v7.1.4 Library for Linux
Goto downloaded folder and in terminal perform following:
tar -xf cudnn-9.2-linux-x64-v7.1.tgz sudo cp -R cuda/include/* /usr/local/cuda-9.2/include sudo cp -R cuda/lib64/* /usr/local/cuda-9.2/lib64
Step 10: Install NCCL 2.2.13:
NVIDIA Collective Communications Library (NCCL) implements multi-GPU and multi-node collective communication primitives that are performance optimized for NVIDIA GPUs
Go to https://developer.nvidia.com/nccl and attend survey to download Nvidia NCCL.
Download following after completing survey.
Download NCCL v2.2.13, for CUDA 9.2 -> NCCL 2.2.13 O/S agnostic and CUDA 9.2
Goto downloaded folder and in terminal perform following:
tar -xf nccl_2.2.13-1+cuda9.2_x86_64.txz cd nccl_2.2.13-1+cuda9.2_x86_64 sudo cp -R * /usr/local/cuda-9.2/targets/x86_64-linux/ sudo ldconfig
Step 11: Install Dependencies
sudo apt-get install libcupti-dev echo 'export LD_LIBRARY_PATH=/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
To install these packages for Python 2.7, issue the following command:
sudo apt-get install python-numpy python-dev python-pip python-wheel
To install these packages for Python 3.n, issue the following command:
sudo apt-get install python3-numpy python3-dev python3-pip python3-wheel
Step 12: Configure Tensorflow from source:
cd ~/ wget https://github.com/bazelbuild/bazel/releases/download/0.14.0/bazel-0.14.0-installer-linux-x86_64.sh chmod +x bazel-0.14.0-installer-linux-x86_64.sh ./bazel-0.14.0-installer-linux-x86_64.sh --user echo 'export PATH="$PATH:$HOME/bin"' >> ~/.bashrc
Reload environment variables
source ~/.bashrc sudo ldconfig
Start the process of building TensorFlow by downloading latest tensorflow 1.8.0 .
cd ~/ git clone https://github.com/tensorflow/tensorflow.git cd tensorflow git pull git checkout r1.8 ./configure
Give python path in
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3
Press enter two times
Do you wish to build TensorFlow with jemalloc as malloc support? [Y/n]: Y Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: Y Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: Y Do you wish to build TensorFlow with Amazon S3 File System support? [Y/n]: Y Do you wish to build TensorFlow with Apache Kafka Platform support? [Y/n]: Y Do you wish to build TensorFlow with XLA JIT support? [y/N]: N Do you wish to build TensorFlow with GDR support? [y/N]: N Do you wish to build TensorFlow with VERBS support? [y/N]: N Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: N Do you wish to build TensorFlow with CUDA support? [y/N]: Y Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to default to CUDA 9.0]: 9.2 Please specify the location where CUDA 9.2 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-9.2 Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7.0]: 7.1.4 Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-9.2]: /usr/local/cuda-9.2 Do you wish to build TensorFlow with TensorRT support? [y/N]: N Please specify the NCCL version you want to use. [Leave empty to default to NCCL 1.3]: 2.2 Please specify the location where NCCL 2 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-9.2]: /usr/local/cuda-9.2/targets/x86_64-linux
Now we need compute capability which we have noted at step 1 eg. 5.0
Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 5.0] 5.0
Do you want to use clang as CUDA compiler? [y/N]: N Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: /usr/bin/gcc Do you wish to build TensorFlow with MPI support? [y/N]: N Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: -march=native Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]:N
Step 13: Build Tensorflow using bazel
The next step in the process to install tensorflow GPU version will be to build tensorflow using bazel. This process takes a fairly long time.
To build a pip package for TensorFlow you would typically invoke the following command:
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
add "--config=mkl" if you want Intel MKL support for newer intel cpu for faster training on cpu add "--config=monolithic" if you want static monolithic build (try this if build failed) add "--local_resources 2048,.5,1.0" if your PC has low ram causing Segmentation fault or other related errors
This process will take a lot of time. It may take 1 – 2 hours or maybe even more.
Also if you got error like Segmentation Fault then try again it usually worked.
The bazel build command builds a script named build_pip_package. Running this script as follows will build a .whl file within the tensorflow_pkg directory:
To build whl file issue following command:
To install tensorflow with pip:
for existing virtual environment:
pip install tensorflow*.whl
With a new virtual environment using virtualenv:
sudo apt-get install virtualenv virtualenv tf_1.8.0_cuda9.2 -p /usr/bin/python3 source tf_1.8.0_cuda9.2/bin/activate pip install tensorflow*.whl
for python 2: (use sudo if required)
pip2 install tensorflow*.whl
for python 3: (use sudo if required)
pip3 install tensorflow*.whl
Note : if you got error like unsupported platform then make sure you are running correct pip command associated with the python you used while configuring tensorflow build.
You can check pip version and associated python by following command
Step 14: Verify Tensorflow installation
Run in terminal
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:
Success! You have now successfully installed tensorflow 1.8.0 on your machine. If you are on Windows OS, you might want to check out our other post here, How to install Tensorflow 1.7.0 GPU with CUDA 9.1 and cuDNN 7.1.2 for Python 3 on Windows OS. Cheers!!
For prebuilt wheel with optimization for AVX2 and cuda 9.2, cudnn 7.1.4, compute capability 5.0 go to this link .