After jumping through many hoops, my Ubuntu 16.04 LTS with NVidia GTX 1080 runs tensorflow 0.9 with GPU support. !! At the time of this writing, a simple “pip install tensorflow” does not get your the goodies of the GPU. Hopefully, someone will benefit from a recollection of my experiences.

The first step is actually get the nvidia display drivers working on Ubuntu 16.04 LTS for the GTX 1080. Finish that step first and then get started on this adventure to install tensorflow on your machine.

Note: If in spite of installing the correct NVidia Driver’s for Ubuntu 16.04 LTS, you are staring at a black screen, it is possible that is a display resolution related issue. Please check out the detailed and helpful comment by Constantin below for the fix.

Step 1: Install NVidia Cuda Toolkit

  1. Download the latest cuda toolkit. From the Nvidia website, I would recommend the latest 0.80 cuda toolkit version as that has support for the Pascal architecture that the GTX 1080 has. You will need to become a member of the NVidia Accelerated computing developer program, but that merely means providing an email address. Easy.
  2. chmod +x

    Know where you are installing it. Better to use the default “/usr/local/cuda”

  3. Test that it actually works by running one of the examples in /usr/local/cuda/samples

Step 2: Install NVidia CuDNN

    1. Now download the latest CuDNN library. At the time of this writing, the latest version was CuDNN v5.1
    2. Extract the files and copy the entire contents of the directory to their final destinations
      cp -r cuda/* /usr/local/cuda/
    3. Set appropriate permissions
chmod a+r /usr/local/cuda/include/cudnn.h

chmod a+r /usr/local/cuda/lib64/libcudnn*
  1. add these libraries to your path
    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"
    export CUDA_HOME=/usr/local/cuda'

Step 3: Install Tensorflow dependencies

  1. apt-get install swig python-dev python-numpy python-wheel
  2. Google uses its own build tool bazel for building tensorflow. Download bazel. Unfortunately, the pre-packaged apt-get versions are not available for Ubuntu 16.04 LTS, so it will not work for you. Instead download the packages listed at the bottom. One the bazel installer itself, and one the appropriate jdk version. Here’s two files that I downloaded.
  3. Installed pre-requisities:
    apt-get install pkg-config zip g++ zlib1g-dev unzip
  4. Make the installer executable and install it. Perform similar steps for the jdk installer.
    chmod +x
    ./ --user

Step 4. Configure and build tensorflow

  1. Get the latest version of tensorflow
  2. While this step is not mentioned on the tensorflow installation site, it is crucial, else your installation will fail. Open the file under the tensorflow source directory at third_party/gpus/crosstool/CROSSTOOL. In that file, add the following directive below every location you see a cxx_builtin_include_directory
    cxx_builtin_include_directory: "/usr/local/cuda-8.0/include"

    . Save the file and get back to the command prompt

  3. Build the tensorflow package using bazel. From the source tree of the tensorflow directory
    bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
  4. Package the built package into a pip installable
     bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
  5. Install the package using pip
    pip install /tmp/tensorflow_pkg/tensorflow-0.9.0-py2-none-any.whl


Now, if all the steps are complete, you should have a working tensorflow installation. Easy to find out if it is indeed working for you. Trying this simple short script which should tell if you GPU is being used as one of the devices

#!/usr/bin/env python

# Author: Abhay Harpale
# Website:

gpu test for tensorflow

import tensorflow as tf

# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.

If the system is indeed using the GPU as the device, it should output:

I tensorflow/stream_executor/] successfully opened CUDA library locally
I tensorflow/stream_executor/] successfully opened CUDA library locally
I tensorflow/stream_executor/] successfully opened CUDA library locally
I tensorflow/stream_executor/] successfully opened CUDA library locally
I tensorflow/stream_executor/] successfully opened CUDA library locally
I tensorflow/stream_executor/cuda/] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
I tensorflow/core/common_runtime/gpu/] Found device 0 with properties:
name: GeForce GTX 1080
major: 6 minor: 1 memoryClockRate (GHz) 1.835
pciBusID 0000:01:00.0
Total memory: 7.92GiB
Free memory: 7.56GiB
I tensorflow/core/common_runtime/gpu/] DMA: 0
I tensorflow/core/common_runtime/gpu/] 0:   Y
I tensorflow/core/common_runtime/gpu/] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:01:00.0)
I tensorflow/core/common_runtime/] Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX 1080, pci bus id: 0000:01:00.0

I tensorflow/core/common_runtime/] MatMul: /job:localhost/replica:0/task:0/gpu:0
I tensorflow/core/common_runtime/] b: /job:localhost/replica:0/task:0/gpu:0
I tensorflow/core/common_runtime/] a: /job:localhost/replica:0/task:0/gpu:0
Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX 1080, pci bus id: 0000:01:00.0
MatMul: /job:localhost/replica:0/task:0/gpu:0
b: /job:localhost/replica:0/task:0/gpu:0
a: /job:localhost/replica:0/task:0/gpu:0
[[ 22.  28.]
[ 49.  64.]]

Now, go fire up some deep learning jobs and take it to the next level.

If this article has worked for you, it is highly likely that some of your friends and followers will benefit from it too. Please share by clicking on the appropriate channels.

Please comment about your experience with getting Tensorflow to work with Ubuntu 16.04 LTS and new GPU’s from the NVidia Pascal line-up, including GTX 1080, GTX 1070, GTX Titan X, and GTX 1060. If you had to customize these steps for your system, please also provide those specifics so that other people visiting this blog as can benefit. Thanks for visiting!