Skip to content

Instantly share code, notes, and snippets.

@dnkirill
Created December 22, 2016 14:04
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 dnkirill/6af17d6934c787e8343e441726bd6af3 to your computer and use it in GitHub Desktop.
Save dnkirill/6af17d6934c787e8343e441726bd6af3 to your computer and use it in GitHub Desktop.
echo
echo "This installation sets up a P2 instance on AWS (Ubuntu 14.04 only), installs all necessary packages"
echo "which are required for CUDA, TensorFlow, Keras, Caffe and Torch."
echo
# Install dependencies
sudo apt-get update
sudo apt-get --assume-yes 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 zip
sudo pip install -U pip
# Install latest python 2.7.12
sudo apt-add-repository ppa:fkrull/deadsnakes-python2.7 -y
sudo apt-get update
sudo apt-get --assume-yes install python2.7 python2.7-dev
# Install CUDA
wget https://developer.nvidia.com/compute/cuda/8.0/prod/local_installers/cuda-repo-ubuntu1404-8-0-local_8.0.44-1_amd64-deb
sudo dpkg -i cuda-repo-ubuntu1404-8-0-local_8.0.44-1_amd64-deb
sudo apt-get update
sudo apt-get install -y cuda
# Install cuDNN
wget https://s3-eu-west-1.amazonaws.com/kd-allstate/cudnn-8.0-linux-x64-v5.1.tgz
tar -zxf cudnn-8.0-linux-x64-v5.1.tgz
sudo cp cuda/lib64/* /usr/local/cuda/lib64/
sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
# Add environmental variables
echo >> .bashrc
echo "export CUDA_HOME=/usr/local/cuda" >> .bashrc
echo "export CUDA_ROOT=/usr/local/cuda" >> .bashrc
echo "export PATH=$PATH:/usr/local/cuda/bin:$HOME/bin" >> .bashrc
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64" >> .bashrc
# Install TensorFlow
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0rc1-cp27-none-linux_x86_64.whl
sudo pip install --upgrade $TF_BINARY_URL
sudo pip install --upgrade keras numpy scipy sklearn pandas
# Install jupyter
sudo pip install jupyter
jupyter notebook --generate-config
echo "c.NotebookApp.port = 8888" >> ~/.jupyter/jupyter_notebook_config.py
echo "c.NotebookApp.open_browser = False" >> ~/.jupyter/jupyter_notebook_config.py
echo "c.NotebookApp.ip = '*'" >> ~/.jupyter/jupyter_notebook_config.py
nohup jupyter notebook & >> jupyter.log
echo
# Caffe
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev protobuf-compiler libjpeg62 libfreeimage-dev libatlas-base-dev libgoogle-glog-dev libbz2-dev libxml2-dev libxslt-dev libffi-dev libssl-dev libgflags-dev liblmdb-dev python-yaml
sudo apt-get install -y opencl-headers libprotoc-dev hdf5-tools libopencv-core-dev libopencv-highgui-dev libsnappy1 cmake libstdc++6-4.8-dbg
sudo apt-get install -y linux-image-extra-`uname -r` linux-headers-`uname -r` linux-image-`uname -r`
sudo sh -c "sudo echo '/usr/local/cuda/lib64' > /etc/ld.so.conf.d/cuda_hack.conf"
git clone https://github.com/BVLC/caffe.git
cd caffe; cd python
for req in $(cat requirements.txt); do sudo pip install $req; done
echo "export PYTHONPATH=$(pwd):\$PYTHONPATH" >> ~/.bashrc
cd ../
cp Makefile.config.example Makefile.config
if [ -f "../cudnn-8.0-linux-x64-v5.1.tgz" ] ; then
sed -i '/^# USE_CUDNN := 1/s/^# //' Makefile.config
fi
sed -i '/^# WITH_PYTHON_LAYER := 1/s/^# //' Makefile.config
sed -i '/^PYTHON_INCLUDE/a /usr/local/lib/python2.7/dist-packages/numpy/core/include/ \\' Makefile.config
# Ignoring tests compilation...
make -j 8 all py
sudo ln /dev/null /dev/raw1394
cd ../
# MAGMA for Torch
wget http://icl.cs.utk.edu/projectsfiles/magma/downloads/magma-2.2.0.tar.gz
tar -zxf magma-2.2.0.tar.gz
echo "export OPENBLASDIR=/opt/OpenBLAS" >> .bashrc
echo "export CUDADIR=/usr/local/cuda" >> .bashrc
cd magma-2.2.0; cp make.inc-examples/make.inc.openblas make.inc
sed -i '/^#OPENBLASDIR/ c\OPENBLASDIR=\/opt\/OpenBLAS' make.inc
sed -i '/^#CUDADIR/ c\CUDADIR=\/usr\/local\/cuda' make.inc
make
sudo make install
cd ../
# Torch
git clone https://github.com/torch/distro.git torch --recursive
cd torch; bash install-deps; bash install.sh
echo "$(pwd)/install/bin/torch-activate" >> ~/.bashrc
. ~/.bashrc
# Completed. Some notes to remember:
echo
echo "CONFIGURATION COMPLETE"
echo "Add to the imports of your python file to resolve problems with Keras:"
echo
echo ">> import tensorflow as tf"
echo ">> tf.python.control_flow_ops = tf"
echo
echo "Use nvidia-smi to check the installation and load of gpu"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment