Showing posts with label gpu. Show all posts
Showing posts with label gpu. Show all posts

Tuesday, January 12, 2016

Install Caffe with GPU support without pain

This is my cheatsheet to install caffe with gpu support on an ubuntu machine.
https://gist.github.com/hasantayyar/1023dbdb01647b0c9559


apt-get update && apt-get install -q -y \
  wget \
  build-essential \
  module-init-tools

cd /opt && \
  wget http://developer.download.nvidia.com/compute/cuda/7_0/Prod/local_installers/cuda_7.0.28_linux.run && \
  chmod +x *.run && \
  mkdir nvidia_installers && \
  ./cuda_7.0.28_linux.run -extract=`pwd`/nvidia_installers && \
  cd nvidia_installers && \
  ./NVIDIA-Linux-x86_64-346.46.run -s -N --no-kernel-module && \
  ./cuda-linux64-rel-7.0.28-19326674.run -noprompt

#ENV LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-7.0/lib64

#ENV PYTHONPATH=/opt/caffe/python

#ENV PATH $PATH:/opt/caffe/.build_release/tools

apt-get update && apt-get install -y \
  bc cmake curl git
  gcc-4.6 g++-4.6 gcc-4.6-multilib g++-4.6-multilib \
  gfortran unzip wget \
  libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev \
  libboost-all-dev \
  libhdf5-serial-dev \
  liblmdb-dev libjpeg62 libfreeimage-dev libatlas-base-dev \
  pkgconf protobuf-compiler \
  python-dev python-pip python-yaml python-numpy

# you may not need to change your gcc version
# update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-4.6 30 && \
  update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-4.6 30 && \
  update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 30 && \
  update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 30

# Allow it to find CUDA libs
echo "/usr/local/cuda/lib64" > /etc/ld.so.conf.d/cuda.conf && \
ldconfig
# Clone caffe
cd /opt && git clone https://github.com/BVLC/caffe.git

# you may not need to install glog. but caffe will log warnings until you've glog installed.
cd /opt && wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz && \
  tar zxvf glog-0.3.3.tar.gz && \
  cd /opt/glog-0.3.3 && \
  ./configure && \
  make && \
  make install

ldconfig

cd /opt && \
  wget https://github.com/schuhschuh/gflags/archive/master.zip && \
  unzip master.zip && \
  cd /opt/gflags-master && \
  mkdir build && \
  cd /opt/gflags-master/build && \
  export CXXFLAGS="-fPIC" && \
  cmake .. && \
  make VERBOSE=1 && make && make install

cd /opt/caffe && \
  cp Makefile.config.example Makefile.config

# echo "CXX := /usr/bin/g++-4.6" >> Makefile.config && sed -i 's/CXX :=/CXX ?=/' Makefile && \
make all -j8

# link caffe-ld-so.conf under /etc/ld.so.conf.d/

ldconfig

# you can install pillow from apt python-pil
easy_install pillow 

# You can find apt alternatives for these python deps.
cd /opt/caffe/python ; \
      for req in $(cat requirements.txt); do pip install $req; done

cd /opt/caffe && make py

# Done