Skip to content

Instantly share code, notes, and snippets.

@anandthakker
Last active August 29, 2015 14:24
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 anandthakker/6d0ccbac07bc2a64417d to your computer and use it in GitHub Desktop.
Save anandthakker/6d0ccbac07bc2a64417d to your computer and use it in GitHub Desktop.

From: http://tleyden.github.io/blog/2014/10/25/running-caffe-on-aws-gpu-instance-via-docker/

ls -la /dev | grep nvidia

You should see:

crw-rw-rw-  1 root root    195,   0 Oct 25 19:37 nvidia0
crw-rw-rw-  1 root root    195, 255 Oct 25 19:37 nvidiactl
crw-rw-rw-  1 root root    251,   0 Oct 25 19:37 nvidia-uvm

You’ll have to adapt the DOCKER_NVIDIA_DEVICES variable below to match your particular devices. Here’s how to start the docker container:

$ DOCKER_NVIDIA_DEVICES="--device /dev/nvidia0:/dev/nvidia0 --device /dev/nvidiactl:/dev/nvidiactl --device /dev/nvidia-uvm:/dev/nvidia-uvm"
$ sudo docker run -ti $DOCKER_NVIDIA_DEVICES tleyden5iwx/caffe-gpu-master /bin/bash

Test:

$ cd /opt/caffe
$ make test && make runtest
# Don't edit this file directly, since it was generated from a template,
# and you're changes will be *clobbered*. Edit the template instead.
FROM tleyden5iwx/ubuntu-cuda
ENV PYTHONPATH /opt/caffe/python
# Add caffe binaries to path
ENV PATH $PATH:/opt/caffe/.build_release/tools
# Get dependencies
RUN apt-get update && apt-get install -y \
bc \
cmake \
curl \
gcc-4.6 \
g++-4.6 \
gcc-4.6-multilib \
g++-4.6-multilib \
gfortran \
git \
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 \
unzip \
wget
# Use gcc 4.6
RUN 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
RUN echo "/usr/local/cuda/lib64" > /etc/ld.so.conf.d/cuda.conf && \
ldconfig
# Clone the Caffe repo
RUN cd /opt && git clone https://github.com/BVLC/caffe.git
# Glog
RUN 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
# Workaround for error loading libglog:
# error while loading shared libraries: libglog.so.0: cannot open shared object file
# The system already has /usr/local/lib listed in /etc/ld.so.conf.d/libc.conf, so
# running `ldconfig` fixes the problem (which is simpler than using $LD_LIBRARY_PATH)
# TODO: looks like this needs to be run _every_ time a new docker instance is run,
# so maybe LD_LIBRARY_PATh is a better approach (or add call to ldconfig in ~/.bashrc)
RUN ldconfig
# Gflags
RUN 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
# Build Caffe core
RUN 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
# Add ld-so.conf so it can find libcaffe.so
ADD caffe-ld-so.conf /etc/ld.so.conf.d/
# Run ldconfig again (not sure if needed)
RUN ldconfig
# Install python deps
RUN cd /opt/caffe && \
(pip install -r python/requirements.txt; easy_install numpy; pip install -r python/requirements.txt) && \
easy_install pillow
# Numpy include path hack - github.com/BVLC/caffe/wiki/Setting-up-Caffe-on-Ubuntu-14.04
RUN NUMPY_EGG=`ls /usr/local/lib/python2.7/dist-packages | grep -i numpy` && \
ln -s /usr/local/lib/python2.7/dist-packages/$NUMPY_EGG/numpy/core/include/numpy /usr/include/python2.7/numpy
# Build Caffe python bindings
RUN cd /opt/caffe && make pycaffe
FROM ubuntu:14.04
MAINTAINER Traun Leyden <traun.leyden@gmail.com>
# A docker container with the Nvidia kernel module and CUDA drivers installed
ENV CUDA_RUN http://developer.download.nvidia.com/compute/cuda/6_5/rel/installers/cuda_6.5.14_linux_64.run
RUN apt-get update && apt-get install -q -y \
wget \
build-essential
RUN cd /opt && \
wget $CUDA_RUN && \
chmod +x *.run && \
mkdir nvidia_installers && \
./cuda_6.5.14_linux_64.run -extract=`pwd`/nvidia_installers && \
cd nvidia_installers && \
./NVIDIA-Linux-x86_64-340.29.run -s -N --no-kernel-module
RUN cd /opt/nvidia_installers && \
./cuda-linux64-rel-6.5.14-18749181.run -noprompt
# Ensure the CUDA libs and binaries are in the correct environment variables
ENV LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-6.5/lib64
ENV PATH=$PATH:/usr/local/cuda-6.5/bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment