Skip to content

Instantly share code, notes, and snippets.

@kern
Last active January 6, 2016 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kern/ab56600768b9f4fc1f72 to your computer and use it in GitHub Desktop.
Save kern/ab56600768b9f4fc1f72 to your computer and use it in GitHub Desktop.
TensorFlow + CUDA 7.0 AWS g2 instance installation script.

First, install all of TensorFlow and CUDA's dependencies:

$ # When prompted: Keep the local version currently installed
$ curl https://gist.githubusercontent.com/kern/ab56600768b9f4fc1f72/raw/8d0b86a678d1398be2b82ac6e4ab1f8ad0698f01/install_deps.sh | sh

Wait for reboot, then run:

$ # When prompted: Scroll all the way down > accept > y > y > y > default (/usr/local/cuda-7.0) > y > n
$ curl https://gist.githubusercontent.com/kern/ab56600768b9f4fc1f72/raw/8d0b86a678d1398be2b82ac6e4ab1f8ad0698f01/install_nvidia.sh | sh
$ curl https://gist.githubusercontent.com/kern/ab56600768b9f4fc1f72/raw/8d0b86a678d1398be2b82ac6e4ab1f8ad0698f01/install_tensorflow.sh | sh

Clean up:

$ curl https://gist.githubusercontent.com/kern/ab56600768b9f4fc1f72/raw/8d0b86a678d1398be2b82ac6e4ab1f8ad0698f01/clean.sh | sh

And try out TensorFlow:

$ curl -O https://gist.githubusercontent.com/kern/ab56600768b9f4fc1f72/raw/8d0b86a678d1398be2b82ac6e4ab1f8ad0698f01/hello_world.py
$ python hello_world.py
rm -rf cudnn-6.5-linux-x64-v2
rm cuda_7.0.28_linux.run
rm cuda-repo-ubuntu1404_7.0-28_amd64.deb
rm cudnn-6.5-linux-x64-v2.tgz
rm install_*.sh
rm cleanup.sh
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print sess.run(hello)
a = tf.constant(10)
b = tf.constant(32)
print sess.run(a+b)
# !/bin/bash
cd ~
# When prompted: Keep the local version currently installed
sudo apt-get update
sudo apt-get -y install build-essential clang make git unzip libc++-dev pkg-config zip g++ zlib1g-dev unzip
sudo apt-get -y install python-numpy swig python-dev python-pip
sudo apt-get -y install linux-image-generic-lts-trusty linux-headers-generic-lts-trusty linux-headers-generic linux-source
# disable nouveau
echo | sudo tee /etc/modprobe.d/blacklist-nouveau.conf >/dev/null <<EOF
blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0
alias nouveau off
alias lbm-nouveau off
EOF
echo options nouveau modeset=0 | sudo tee /etc/modprobe.d/nouveau-kms.conf
sudo update-initramfs -u
# reboot
sudo reboot
# !/bin/bash
cd ~
# CUDA 7.0 toolkit
# When prompted: Scroll all the way down > accept > y > y > y > default (/usr/local/cuda-7.0) > y > n
curl -O http://developer.download.nvidia.com/compute/cuda/7_0/Prod/local_installers/cuda_7.0.28_linux.run
chmod +x cuda_7.0.28_linux.run
sudo ./cuda_7.0.28_linux.run
sudo modprobe nvidia
nvidia-smi
# CUDNN 6.5
curl -O https://s3.amazonaws.com/pavlov-utils/cudnn-6.5-linux-x64-v2.tgz
tar zxfv cudnn-6.5-linux-x64-v2.tgz
sudo cp cudnn-6.5-linux-x64-v2/cudnn.h /usr/local/cuda-7.0/include
sudo cp cudnn-6.5-linux-x64-v2/libcudnn* /usr/local/cuda-7.0/lib64
# env
echo | tee -a ~/.bash_profile >/dev/null <<EOF
export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/cuda/lib64
export CUDA_HOME=/usr/local/cuda
EOF
# !/bin/bash
# Based on Hello1024's gist: https://gist.github.com/Hello1024/bfbcb4616aadee62c68e
cd ~
# Java (for bazel)
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
sudo apt-get -y install oracle-java8-installer
# bazel
git clone https://github.com/bazelbuild/bazel.git
cd bazel
git checkout tags/0.1.0
./compile.sh
cd ..
# tensorflow
git clone --recurse-submodules https://github.com/pavlovml/tensorflow
cd tensorflow
(cd third_party/gpus/cuda; ./cuda_config.sh;)
../bazel/output/bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer
../bazel/output/bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/pip
sudo pip install /tmp/pip/*.whl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment