Skip to content

Instantly share code, notes, and snippets.

@dexhunter
Last active July 4, 2017 02:21
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 dexhunter/df8a7dcc2c30e99f242bc1a8fe8c7ca3 to your computer and use it in GitHub Desktop.
Save dexhunter/df8a7dcc2c30e99f242bc1a8fe8c7ca3 to your computer and use it in GitHub Desktop.
# On Ubuntu 14.04 with Titan X (compute capability 5.2)
# There are some missing parts that you have to specify, and some files you have to download manaully from web, so don't run this script file as it is.
# Configure CUDA paths
echo export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64" >> ~/.bashrc
echo export CUDA_HOME="/usr/local/cuda" >> ~/.bashrc
source ~/.bashrc
 
# Set up java
# Dependencies for Bazel
# Download jdk 8
# For most recent version, Go here: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
mkdir jdk
cd jdk
wget https://s3-us-west-2.amazonaws.com/minjoon/jdk/jdk-8u74-linux-x64.gz
tar -zxvf jdk-8u74-linux-x64.gz
cd ..
 
echo export JAVA_HOME="$HOME/jdk/jdk1.8.0_74" >> ~/.bashrc
echo export PATH="$JAVA_HOME/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
 
# Install Bazel
wget https://github.com/bazelbuild/bazel/releases/download/0.2.0/bazel-0.2.0-installer-linux-x86_64.sh
chmod +x bazel-0.2.0-installer-linux-x86_64.sh
./bazel-0.2.0-installer-linux-x86_64.sh --user
 
# Custom Python install
wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz
tar -zxvf Python-2.7.11.tgz
cd Python-2.7.11
./configure --prefix $HOME
make
make install
cd ..
 
# Custom Python3 install
wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz
tar -zxvf Python-3.5.1.tgz
cd Python-3.5.1
./configure --prefix $HOME
make
make install
cd ..
pip3 install wheel  # for tensorflow wheel installation
 
echo export PATH="$HOME/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
 
# Install pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
# Install wheel
pip install wheel
 
# Numpy install
pip install numpy
 
# Swig install
# download the file and extract, and then cd to the folder
wget https://s3-us-west-2.amazonaws.com/minjoon/swig/swig-3.0.8.tar.gz
tar -zxvf swig-3.0.8.tar.gz
cd swig-3.0.8/
./configure --prefix $HOME
make
make install
cd ..
 
# If you want to use prebuilt pip package,
# pip3.4 install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.7.1-cp34-none-linux_x86_64.whl
 
# Download TensorFlow source code
mkdir workspace
cd workspace
git clone --recurse-submodules https://github.com/tensorflow/tensorflow
cd tensorflow
./configure
 
# Install!
# If swig is installed locally, you have to do the following:
# 1. Open tensorflow/tensorflow.bzl with vim
# 2. Go to _py_wrap_cc_impl() and find ctx.action() function
# 3. Add a parameter: use_default_shell_env=True,
# 4. When running bazel below, add argument: --genrule_strategy=standalone --spawn_strategy=standalone
# For more info, see https://github.com/tensorflow/tensorflow/issues/706
# bazel build -c opt --config=cuda --genrule_strategy=standalone --spawn_strategy=standalone //tensorflow/tools/pip_package:build_pip_package
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
pip install /tmp/tensorflow_pkg/SOME_NAME_THAT_DEPENDS --user
 
# Now lets try if we can use gpu(s).
tmux
cd tensorflow/models/image/cifar10
python cifar10_train.py
# CUDA_VISIBLE_DEVICES=N python cifar10_train.py  # for AI2 machine only
# CUDA_VISIBLE_DEVICES=N1,N2 python cifar10_multi_gpu_train.py --num_gpus 4  # if you are using multiple GPUs
 
# Verify that you are using GPUs (use tmux or open another ssh)
nvidia-smi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment