Here’s a guide on installing TensorFlow 0.6 on an Amazon EC2 Instance with GPU Support. Additionally, a Public AMI (ami-e191b38b) is provided with the configured setup for convenience.
Note: Updated on Jan 28, 2016, to reflect the requirement of Bazel 0.1.4 and to export environment variables in ~/.bashrc.
The installation includes:
- Essentials
- Cuda Toolkit 7.0
- cuDNN Toolkit 6.5
- Bazel 0.1.4 (requires Java 8)
- TensorFlow 0.6
To begin, it’s recommended to request a spot instance to save costs. Launch a g2.2xlarge instance using the Ubuntu Server 14.04 LTS AMI.
After instance launch, install essentials:
bash
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential git python-pip libfreetype6-dev libxft-dev libncurses-dev libopenblas-dev gfortran python-matplotlib libblas-dev liblapack-dev libatlas-base-dev python-dev python-pydot linux-headers-generic linux-image-extra-virtual unzip python-numpy swig python-pandas python-sklearn unzip wget pkg-config zip g++ zlib1g-dev
sudo pip install -U pip
Next, install CUDA Toolkit 7.0:
bash
wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1410/x86_64/cuda-repo-ubuntu1410_7.0-28_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1410_7.0-28_amd64.deb
rm cuda-repo-ubuntu1410_7.0-28_amd64.deb
sudo apt-get update
sudo apt-get install -y cuda
Download and install cuDNN Toolkit 6.5:
bash
tar -zxf cudnn-6.5-linux-x64-v2.tgz && rm cudnn-6.5-linux-x64-v2.tgz
sudo cp -R cudnn-6.5-linux-x64-v2/lib* /usr/local/cuda/lib64/
sudo cp cudnn-6.5-linux-x64-v2/cudnn.h /usr/local/cuda/include/
Reboot the instance:
bash
sudo reboot
Set environment variables:
bash
echo "export CUDA_HOME=/usr/local/cuda" >> ~/.bashrc
echo "export CUDA_ROOT=/usr/local/cuda" >> ~/.bashrc
echo "export PATH=$PATH:$CUDA_ROOT/bin" >> ~/.bashrc
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDA_ROOT/lib64" >> ~/.bashrc
source ~/.bashrc
Install Java 8 and Bazel 0.1.4:
bash
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
sudo apt-get install -y oracle-java8-installer
sudo apt-get install pkg-config zip g++ zlib1g-dev
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
rm bazel-0.1.4-installer-linux-x86_64.sh
Clone TensorFlow repo:
bash
git clone --recurse-submodules https://github.com/tensorflow/tensorflow
cd tensorflow
Build TensorFlow with GPU support:
bash
TF_UNOFFICIAL_SETTING=1 ./configure
During configuration, choose CUDA version 3.0. Then, build TensorFlow:
bash
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
sudo pip install --upgrade /tmp/tensorflow_pkg/tensorflow-0.6.0-cp27-none-linux_x86_64.whl
Congratulations! TensorFlow is now installed with GPU support. Test the installation by running Python code that utilizes TensorFlow. You should see GPU-related messages indicating successful setup.
This guide is a compilation of instructions from various sources, with credits and thanks to the original contributors. For more information and options, refer to TensorFlow’s official installation instructions.