Skip to content

Instantly share code, notes, and snippets.

@Hello1024
Last active May 19, 2020 22:55
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save Hello1024/bfbcb4616aadee62c68e to your computer and use it in GitHub Desktop.
Save Hello1024/bfbcb4616aadee62c68e to your computer and use it in GitHub Desktop.
#!/bin/bash
# Run this on This AMI on AWS:
# https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#LaunchInstanceWizard:ami=ami-b36981d8
# You should get yourself a fully working GPU enabled tensorflow installation.
cd ~
# grab cuda 7.0
wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_7.0-28_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1404_7.0-28_amd64.deb
# and sun java (for bazel)
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
# Get all the dependencies.
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 pkg-config zip g++ zlib1g-dev unzip python-numpy swig python-dev cuda-command-line-tools-7-0 cuda-cublas-dev-7-0 cuda-cufft-dev-7-0 cuda-curand-dev-7-0
# Get and install bazel
git clone https://github.com/bazelbuild/bazel.git
cd bazel
git checkout tags/0.1.0
./compile.sh
export PATH=$PATH:`pwd`/output
cd ..
# Get, patch and install tensorflow
git clone --recurse-submodules https://github.com/tensorflow/tensorflow
cd tensorflow
curl http://pastebin.com/raw.php?i=WYJR3T1s > patch
patch -p1 <patch
cat > third_party/gpus/cuda/cuda.config <<EOF
CUDA_TOOLKIT_PATH="/usr/local/cuda-7.0"
CUDNN_INSTALL_PATH="/usr/local/cuda-6.5"
EOF
(cd third_party/gpus/cuda; ./cuda_config.sh;)
# test a build (add --jobs 1 if you hit OOM's)
bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer
# Build and install the python stuff
bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
pip install /tmp/tensorflow_pkg/*.whl
@udibr
Copy link

udibr commented Nov 12, 2015

you need to add --config=cuda to
bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
and --use_gpu to
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

@cinjon
Copy link

cinjon commented Nov 12, 2015

Even with @udibr's edits and using the suggested AMI, this script didn't work. Two notable errors:

  • it couldn't find the Cuda 7.0 toolkit
  • the patch didn't apply correctly:
patching file third_party/gpus/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc
patch unexpectedly ends in middle of line
Hunk #1 succeeded at 233 with fuzz 1.
set_up_tensorflow.sh: 41: set_up_tensorflow.sh: EOF: not found

Thoughts?

@martinwicke
Copy link

Given some changes we've made upstream, the patch shouldn't be necessary any more. See http://www.tensorflow.org/get_started/os_setup.html#enabling-cuda-30

If you fix this, we'd love to point people at this gist or any other place where you write this up from our documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment