Skip to content

Instantly share code, notes, and snippets.

@unsalted
Last active July 5, 2017 14:24
Show Gist options
  • Save unsalted/294c7b128ac37ef70df5bbc1528effa9 to your computer and use it in GitHub Desktop.
Save unsalted/294c7b128ac37ef70df5bbc1528effa9 to your computer and use it in GitHub Desktop.
Ubuntu 16.04 - Tensorflow (GPU) setup

Tensorflow (GPU) setup

Update nvidia key for cuda8.0

[https://developer.nvidia.com/cuda-downloads]

wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/7fa2af80.pub

as root not sudo

add

cat 7fa2af80.pub | apt-key add -

remove old

apt-key del 5C37D3BE

sudo dpkg -i cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda

Install CUDNN 5.0

https://www.tensorflow.org/versions/r0.11/get_started/os_setup.html#optional-linux-enable-gpu-support

Download [https://developer.nvidia.com/cudnn]

tar xvzf cudnn-8.0-linux-x64-v5.1-ga.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

Conda env setup

Python 3.4

create env

conda create -n tensorflow python=3.4

Activate

source activate tensorflow

set Binary

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp34-cp34m-linux_x86_64.whl

Install (pip3 didn't work this did)

pip install --ignore-installed --upgrade $TF_BINARY_URL

Set conda envs to enable GPU

[http://conda.pydata.org/docs/using/envs.html#linux-and-macos]

[https://www.tensorflow.org/versions/r0.11/get_started/os_setup.html#optional-linux-enable-gpu-support]

cd /home/jsmith/anaconda3/envs/analytics
mkdir -p ./etc/conda/activate.d
mkdir -p ./etc/conda/deactivate.d

nano ./etc/conda/activate.d/env_vars.sh

# add these lines
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64"
export CUDA_HOME=/usr/local/cuda

nano ./etc/conda/deactivate.d/env_vars.sh

# different
unset LD_LIBRARY_PATH
unset CUDA_HOME

Test

$ python
...
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a + b))
42
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment