Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexlee-gk/61e59479c76c5f96b68c4203394b9062 to your computer and use it in GitHub Desktop.
Save alexlee-gk/61e59479c76c5f96b68c4203394b9062 to your computer and use it in GitHub Desktop.
Installing TensorFlow on Instructional Machines with GPU support

Installing TensorFlow on Instructional Machines with GPU support

These instructions were adapted from here.

The following was tested on the hive machines (e.g. hive10.cs.berkeley.edu).

Install cuDNN and setup CUDA environment variables

Download and install cuDNN.

https://developer.nvidia.com/cudnn

Uncompress and copy the cuDNN files into the ~/local directory.

mkdir local
mv cuda local

Define CUDA and cuDNN environment variables and add them to the path so that TensorFlow can find them. You may add these at the end of your ~/.bashrc so that they are automatically defined next time you log in (assuming you are using bash as your shell).

export CUDA_HOME=/usr/local/cuda-7.5
export CUDA_ROOT=/usr/local/cuda-7.5
export PATH=$PATH:$CUDA_ROOT/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDA_ROOT/lib64
export CUDNN_ROOT=~/local/cuda
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDNN_ROOT/lib64

Install Bazel (needed to compile TensorFlow)

Download and install Bazel.

wget https://github.com/bazelbuild/bazel/releases/download/0.1.4/bazel-0.1.4-installer-linux-x86_64.sh
chmod +x bazel-0.1.4-installer-linux-x86_64.sh
./bazel-0.1.4-installer-linux-x86_64.sh --user

If the installation was successful, the compiled Basel binaries should be in ~/bin. Add this directory to your PATH.

export PATH=~/bin:$PATH

Install TensorFlow

Clone the TensorFlow repo and initialize all submodules using their default settings.

git clone --recurse-submodules https://github.com/tensorflow/tensorflow
cd tensorflow

Configure the TensorFlow options to build it with GPU support using CUDA compute capability 3.0 (this is what the instructional machines support) via the unofficial settings.

TF_UNOFFICIAL_SETTING=1 ./configure

You will be asked for settings and you should specify the following answers (or press ENTER to specify the default one).

Please specify the location of python. [Default is /usr/bin/python]: 
Do you wish to build TensorFlow with GPU support? [y/N] y
GPU support will be enabled for TensorFlow
Please specify which gcc nvcc should use as the host compiler. [Default is /usr/bin/gcc]: 
Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 7.5
Please specify the location where CUDA 7.5 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-7.5
Please specify the Cudnn version you want to use. [Leave empty to use system default]: 
Please specify the location where cuDNN  library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-7.5]: ~/local/cuda
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size.
[Default is: "3.5,5.2"]: 3.0
Setting up Cuda include
Setting up Cuda lib64
Setting up Cuda bin
Setting up Cuda nvvm
Configuration finished

Build TensorFlow using Bazel. This should take a few minutes.

bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer && \
bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package && \
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

Install the built binaries using pip so that your python program can find the TensorFlow libaries.

pip install --user --upgrade /tmp/tensorflow_pkg/tensorflow-0.7.1-cp27-none-linux_x86_64.whl

If the installation was succesful, you should be able to import and use TensorFlow in python. Make sure you start python outside the tensorflow directory.

import tensorflow as tf
tf_session = tf.Session()
x = tf.constant(1)
y = tf.constant(1)
tf_session.run(x + y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment