Skip to content

Instantly share code, notes, and snippets.

@truatpasteurdotfr
Created January 27, 2017 17:26
Show Gist options
  • Save truatpasteurdotfr/15a68a69b5d3da8537103e930f5da869 to your computer and use it in GitHub Desktop.
Save truatpasteurdotfr/15a68a69b5d3da8537103e930f5da869 to your computer and use it in GitHub Desktop.
#!/bin/bash
# download the required file
. ./env.sh || exit 1
if [ ! -f ${working_dir}/${TF_FILE} ]; then
echo "getting ${TF_URL}"
wget -O ${working_dir}/${TF_FILE} ${TF_URL}
fi
if [ ! -f ${working_dir}/${NV_CUDA_FILE} ]; then
echo "getting ${NV_CUDA_URL}"
wget -O ${working_dir}/${NV_CUDA_FILE} ${NV_CUDA_URL}
fi
if [ ! -f ${working_dir}/${NV_DRIVER_FILE} ]; then
echo "getting ${NV_DRIVER_URL}"
wget -O ${working_dir}/${NV_DRIVER_FILE} ${NV_DRIVER_URL}
fi
if [ ! -f ${working_dir}/${NV_CUDNN_FILE} ]; then
echo "***** missing **** ${working_dir}/${NV_CUDNN_FILE}"
echo "download from https://developer.nvidia.com/cudnn requires an account and accept EULA"
exit 1
fi
#!/bin/sh
# download the required file
working_dir=$(pwd)
export working_dir
NV_CUDA_FILE=cuda_8.0.44_linux-run
NV_CUDA_URL=https://developer.nvidia.com/compute/cuda/8.0/prod/local_installers/
${NV_CUDA_FILE}
export NV_CUDA_URL NV_CUDA_FILE
NV_CUDNN_FILE=cudnn-8.0-linux-x64-v5.1.tgz
export NV_CUDNN_FILE
NV_DRIVER_VERSION=367.57
NV_DRIVER_FILE=NVIDIA-Linux-x86_64-${NV_DRIVER_VERSION}.run
NV_DRIVER_URL=http://us.download.nvidia.com/XFree86/Linux-x86_64/${NV_DRIVER_VER
SION}/${NV_DRIVER_FILE}
export NV_DRIVER_URL NV_DRIVER_FILE NV_DRIVER_VERSION
TF_FILE=tensorflow_gpu-0.12.1-cp27-none-linux_x86_64.whl
TF_URL=https://storage.googleapis.com/tensorflow/linux/gpu/$TF_FILE
BootStrap: docker
From: ubuntu:16.04
%runscript
echo "This is what happens when you run the container..."
bash
%setup
/bin/bash setup.sh
%post
# non interactive debian
DEBIAN_FRONTEND=noninteractive
# Install the necessary packages (from repo)
apt-get update && apt-get install -y --no-install-recommends curl
#
/bin/bash /tmp/post.sh
/bin/bash /tmp/pip-install.sh
# more packages
apt-get update && apt-get install -y environment-modules vim
%test
python -c 'import tensorflow'
#!/bin/bash
#
PATH=/usr/local/bin:$PATH
export PATH
pip install --no-cache-dir --upgrade \
backports-abc \
backports.shutil-get-terminal-size \
backports.ssl-match-hostname \
certifi \
cffi \
configparser \
cryptography \
cycler \
decorator \
entrypoints \
enum34 \
funcsigs \
functools32 \
idna \
ipaddress \
ipykernel \
ipython \
ipython-genutils \
ipywidgets \
Jinja2 \
jsonschema \
jupyter \
jupyter-client \
jupyter-console \
jupyter-core \
Keras \
MarkupSafe \
matplotlib \
mistune \
mock \
nbconvert \
nbformat \
notebook \
numpy \
pathlib2 \
pbr \
pexpect \
pickleshare \
pip \
prompt-toolkit \
protobuf \
ptyprocess \
pyasn1 \
pycparser \
Pygments \
pyOpenSSL \
pyparsing \
python-dateutil \
pytz \
PyYAML \
pyzmq \
qtconsole \
scipy \
setuptools \
simplegeneric \
singledispatch \
six \
terminado \
Theano \
tornado \
traitlets \
urllib3 \
wcwidth \
wheel \
widgetsnbextension
#%post
# Runs within the container during Bootstrap
. /tmp/env.sh || exit 1
. /tmp/env.sh && /bin/rm /tmp/env.sh
# where the downloaded files have been copied:
working_dir=/tmp
# Set up some required environment defaults
export LC_ALL=C
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH
# non interactive debian
DEBIAN_FRONTEND=noninteractive
# Install the necessary packages (from repo)
apt-get update && apt-get install -y --no-install-recommends \
libssl-dev libffi-dev \
kmod \
build-essential \
curl \
git \
libcurl3-dev \
libfreetype6-dev \
libpng12-dev \
libzmq3-dev \
python-pip \
pkg-config \
python-dev \
rsync \
software-properties-common \
unzip \
zip \
zlib1g-dev
apt-get clean
echo "Unpacking NVIDIA driver into container..."
cd /usr/local/
sh ${working_dir}/${NV_DRIVER_FILE} \
--silent \
--no-kernel-module \
--no-x-check \
--no-install-compat32-libs \
--no-network \
--no-kernel-module-source \
--no-nouveau-check \
--skip-module-unload --no-nvidia-modprobe \
--tmpdir=/dev/shm && rm ${working_dir}/${NV_DRIVER_FILE}
echo "Installing Cuda toolkit"
sh ${working_dir}/${NV_CUDA_FILE} \
--silent \
--verbose \
--toolkitpath=/usr/local/cuda-8.0 \
--toolkit \
--tmpdir=/dev/shm && rm ${working_dir}/${NV_CUDA_FILE}
# we want everything under the same /usr/local/cuda-$version
# but cuDNN installs in /usr/local/cuda
(cd /usr/local && ln -f -s cuda-8.0 cuda)
echo "Unpacking cuDNN..."
tar xvf ${working_dir}/${NV_CUDNN_FILE} -C /usr/local/ && rm ${working_dir}/${NV_CUDNN_FILE}
# Update to the latest pip (newer than repo)
pip install --no-cache-dir --upgrade pip
# missing setuptools
pip install --no-cache-dir --upgrade setuptools
# Install other commonly-needed packages
pip install --no-cache-dir --upgrade \
setuptools \
future \
matplotlib \
scipy \
sklearn
pip install --no-cache-dir --ignore-installed --upgrade ${working_dir}/${TF_FILE} && rm ${working_dir}/${TF_FILE}
echo "Fixing /environment..."
echo "/usr/local/cuda-8.0/lib64" > /etc/ld.so.conf.d/ld-so-nvidia.conf
echo "/usr/local/cuda-8.0/extras/CUPTI/lib64" >> /etc/ld.so.conf.d/ld-so-nvidia.conf
# keras
ldconfig -v
pip install --no-cache-dir --upgrade keras
# local setup
# ERC/Bis
# Bis hostfs
mkdir -p /c6/shared/rpm /c6/eb
mkdir -p /local-storage /Bis/Scratch2
mkdir -p /selinux /misc /net
mkdir -p /baycells/home /baycells/scratch /mnt/beegfs
mkdir -p /local/gensoft2
#%setup
# Runs from outside the container during Bootstrap
. download.sh
for i in ${TF_FILE} ${NV_CUDA_FILE} ${NV_CUDNN_FILE} ${NV_DRIVER_FILE} post.sh pip-install.sh env.sh
do
echo "copying ${i} into the container"
cp ${working_dir}/${i} ${SINGULARITY_ROOTFS}/tmp || exit 1
done
#!/bin/sh
# image size in MB
IMG_SIZE=4400
# where the container images go
IMG_DIR=/home/tru/singularity-img
IMG_DIR=/dev/shm
# assume the argument is the singularity container.def
#
if [ $# -eq 1 ] && [ -f "$1" ]; then
O=`basename $1 .def`
# where the container definition are stored
DEF_DIR=`dirname "$1"`
IMG_FILE="${IMG_DIR}/${O}.img"
IMG_DEF="${DEF_DIR}/${1}"
IMG_LOG="${IMG_DIR}/${O}.log"
echo "${IMG_FILE}" "${IMG_LOG}"
\rm -f ${IMG_FILE}
sudo singularity create --size ${IMG_SIZE} ${IMG_FILE}
sudo singularity bootstrap ${IMG_FILE} ${IMG_DEF} 2>&1 | tee ${IMG_LOG}
else
echo usage $0 my.def
echo
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment