Skip to content

Instantly share code, notes, and snippets.

@kashefy
Last active May 15, 2018 09:23
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 kashefy/1c9460147ab133226748 to your computer and use it in GitHub Desktop.
Save kashefy/1c9460147ab133226748 to your computer and use it in GitHub Desktop.
# Installing Caffe dependencies without sudo privileges:
# The prefix serves as the installation directory for caffe dependencies
# that are not already installed on the system
#
# Set "inputs" according to host machine
export PREFIX_HOST=/mnt/scratch/$USER/caffe_deps
export PREFIX_CUDNN=$PREFIX_HOST/../build/cudnn-7.5
# Create necessary directories
mkdir -p $PREFIX_HOST
mkdir -p $PREFIX_HOST/../src
mkdir -p $PREFIX_HOST/../build
# Set environment variables accordingly
export PATH=$PREFIX_HOST/bin:$PATH
export C_INCLUDE_PATH=$PREFIX_CUDNN/include:$PREFIX_HOST/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=$PREFIX_CUDNN/include:$PREFIX_HOST/include:$CPLUS_INCLUDE_PATH
export LIBRARY_PATH=$PREFIX_HOST/lib:$LIBRARY_PATH
export LD_LIBRARY_PATH=$PREFIX_CUDNN/lib64:$PREFIX_HOST/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=$PREFIX_HOST/lib/pkgconfig:$PKG_CONFIG_PATH
# Add above exports to .bashrc
# cmake
# usually installed on Ubuntu via "sudo apt-get install cmake"
cd $PREFIX_HOST/../build
wget https://cmake.org/files/v3.5/cmake-3.5.2-Linux-x86_64.tar.gz
tar xf ./cmake-3.5.2-Linux-x86_64.tar.gz
mv cmake-3.5.2-Linux-x86_64/* $PREFIX_HOST
cmake --version # verify cmake version is correct
# google protobuf
# usually installed on Ubuntu via "sudo apt-get install libprotobuf-dev protobuf-compiler"
cd $PREFIX_HOST/../src
wget https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz
tar -xf ./protobuf-2.6.1.tar.gz
cd protobuf-2.6.1/
./configure --prefix=$PREFIX_HOST
make -j4
make install
# snappy (required by leveldb)
# usually installed on Ubuntu via "sudo apt-get install libsnappy-dev
cd $PREFIX_HOST/../src
wget https://github.com/google/snappy/releases/download/1.1.3/snappy-1.1.3.tar.gz
tar -xf snappy-1.1.3.tar.gz
cd snappy-1.1.3
./configure --prefix=$PREFIX_HOST
make
make install
# leveldb
# usually installed on Ubuntu via "sudo apt-get install libleveldb-dev libsnappy-dev
cd $PREFIX_HOST/../src
git clone https://github.com/google/leveldb.git
cd leveldb
make -j6
cp --preserve=links out-shared/libleveldb.* $PREFIX_HOST/lib
cp -r include/leveldb $PREFIX_HOST/include/
# OpenCV
cd $PREFIX_HOST/../src
git clone https://github.com/Itseez/opencv.git
cd $PREFIX_HOST/../build
mkdir opencv
cd opencv
#cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_DOCS=OFF -DCMAKE_INSTALL_PREFIX=$PREFIX_HOST $PREFIX_HOST/../src/opencv
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_DOCS=OFF -DBUILD_opencv_dnn=OFF -DBUILD_PROTOBUF=OFF -DCMAKE_INSTALL_PREFIX=$PREFIX_HOST $PREFIX_HOST/../src/opencv
make -j6 # takes a while to compile
make install
# HDF5
# usually installed on Ubuntu via "sudo apt-get install libhdf5-serial-dev", requires gfortran package
cd $PREFIX_HOST/../src
wget https://www.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8.17/src/hdf5-1.8.17.tar.gz
tar -xf hdf5-1.8.17.tar.gz
cd hdf5-1.8.17
./configure --prefix=$PREFIX_HOST --enable-fortran --enable-fortran2003 --with-default-api-version=v18 --enable-silent-rules
make -j6
make install
# GLog
#sudo apt-get install libgoogle-glog-dev
cd $PREFIX_HOST/../src
wget https://github.com/google/glog/archive/v0.3.4.zip
unzip v0.3.4.zip
cd glog-0.3.4
./configure --prefix=$PREFIX_HOST
make && make install
# GFlags
#sudo apt-get install libgflags-dev
cd $PREFIX_HOST/../src
wget https://github.com/schuhschuh/gflags/archive/master.zip
unzip master.zip
cd gflags-master
mkdir build && cd build
export CXXFLAGS="-fPIC" && cmake -DCMAKE_INSTALL_PREFIX=$PREFIX_HOST .. && make VERBOSE=1
make && make install
# LMDB
#sudo apt-get install liblmdb-dev
# this does NOT install the python lmdb package
cd $PREFIX_HOST/../src
git clone https://github.com/LMDB/lmdb
cd lmdb/libraries/liblmdb
make prefix=$PREFIX_HOST
make prefix=$PREFIX_HOST install
# OpenBLAS
cd $PREFIX_HOST/../src
git clone https://github.com/xianyi/OpenBLAS.git
cd OpenBLAS
make -j6
make install PREFIX=$PREFIX_HOST
# Boost
cd $PREFIX_HOST/../src
wget -O boost_1_60_0.tar.bz2 https://sourceforge.net/projects/boost/files/boost/1.60.0/boost_1_60_0.tar.bz2/download
tar -xf ./boost_1_60_0.tar.bz2
cd boost_1_60_0
./bootstrap.sh
./b2
./b2 install --prefix=$PREFIX_HOST
# apply patch (for version 1.60.0 only)
# issue described here: https://github.com/BVLC/caffe/issues/3578
# patch provided here: https://svn.boost.org/trac/boost/ticket/11852
cd $PREFIX_HOST/../src
wget https://svn.boost.org/trac/boost/raw-attachment/ticket/11852/float128GccNvcc.patch
cd $PREFIX_HOST
patch -p1 < $PREFIX_HOST/../src/float128GccNvcc.patch
# cuDNN
# Download manually from NVIDIA's website
cp <download location> $PREFIX_HOST/../build
$PREFIX_HOST/../build
tar -xzf cudnn-7.5-linux-x64-v5.0-prod.tgz
mv cuda cudnn-7.5
# DONE with dependencies
# Building Caffe from source
#cd $PREFIX_HOST/../src
cd <your source directory>
git clone git@github.com:BVLC/caffe.git # get latest master revision
cd caffe # we'll call this your CAFFE_ROOT
export CAFFE_ROOT=`pwd`
mkdir build && cd build
#cmake -DBLAS=Open -DCUDNN_INCLUDE=$PREFIX_CUDNN/include -DCUDNN_LIBRARY=$PREFIX_CUDNN/lib64/libcudnn.so ..
cmake -DBLAS=Open ..
make -j6
# no installation necessary
# To use caffe's python bindings:
# activate your virtual env
# Follow instructions on http://caffe.berkeleyvision.org/installation.html under "Python and/or MATLAB Caffe (optional)"
# make sure those installations are done to the virtualenv
export PYTHONPATH=$CAFFE_ROOT/python:$PYTHONPATH
export PYTHONPATH=$CAFFE_ROOT/tools/extra:$PYTHONPATH # log parser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment