Commit 24afb41e authored by DawnStone's avatar DawnStone Committed by Scott Cyphers

add GPU backend support for contrib/docker make process (#814)

* adding support for GPU backend to contrib/docker

added gpu dockerfiles

renamed Dockerfile for centos74

fixed NGRAPH_GPU_ENABLE cmake flag name

* Check for GPU support on the host system and fall back to CPU if not present

* removed double option for PREBUILT_LLVM

* updated README.md with additional references for GPU support

* added clarifying comments

cleaned up duplicate settings

* removed deprecated targets from the contrib/docker/Makefile

* resolved absolute vs. conditional assignment for variables based on reference OS

* removed example using a custom DOCKERFILE from README file
parent 777600c6
# Environment to build and unit-test ngraph on centos74 for GPU backend
# with gcc 4.8.5
# with python 2.7
# with pre-built cmake3
FROM nvidia/cuda:8.0-cudnn7-devel-centos7
RUN yum -y update && \
yum -y --enablerepo=extras install epel-release && \
yum -y install \
gcc gcc-c++ \
cmake3 make \
git \
wget patch diffutils zlib-devel ncurses-devel libtinfo-dev \
python python-devel python-setuptools \
doxygen \
which \
'perl(Data::Dumper)'
RUN ln -s /usr/bin/cmake3 /usr/bin/cmake
RUN ln -s /usr/local/cuda/include/cudnn.h /usr/local/cuda/include/cudnn_v7.h
RUN cmake --version
RUN make --version
RUN gcc --version
RUN c++ --version
RUN easy_install pip
RUN pip install virtualenv
# Install some pip packages
RUN pip install numpy
# need to use sphinx version 1.6 to build docs
# installing with apt-get install python-sphinx installs sphinx version 1.3.6 only
# added install for python-pip above and
# installed sphinx with pip to get the updated version 1.6.5
# allows for make html build under the doc/source directory as an interim build process
RUN pip install sphinx
# breathe package required to build documentation
RUN pip install breathe
WORKDIR /home
# ngraph-neon.cpu dockerfile used to build and test ngraph-neon on gpu platforms
FROM nvidia/cuda:8.0-cudnn7-devel-ubuntu16.04
# set the proxies
ENV http_proxy=http://proxy-us.intel.com:911
ENV https_proxy=https://proxy-us.intel.com:911
# try to install cudnn-dev packages
# RUN apt-get update && install -y libcudnn7-dev && apt-get clean autoclean && apt-get autoremove -y
RUN apt-get update && apt-get install -y sudo curl && \
apt-get clean autoclean && \
apt-get autoremove -y
RUN curl http://developer.download.nvidia.com/compute/cuda/repos/GPGKEY | sudo apt-key add -
# install standard python 2 and 3 environment stuff
RUN apt-get update && \
apt-get install -y python-dev python-pip software-properties-common && \
apt-get clean autoclean && \
apt-get autoremove -y
RUN pip install --upgrade pip
RUN pip install virtualenv pytest
RUN apt-get update && \
apt-get install -y python3 python3-pip python3-dev python3-venv && \
apt-get clean autoclean && \
apt-get autoremove -y
RUN pip3 install virtualenv pytest
#install onnx dependencies to install ngraph
RUN apt-get update && apt-get install -y protobuf-compiler libprotobuf-dev
RUN apt-get update && apt-get install -y \
build-essential cmake \
clang-3.9 clang-format-3.9 \
git \
wget patch diffutils zlib1g-dev libtinfo-dev \
doxygen && \
apt-get clean autoclean && \
apt-get autoremove -y
# create a symbolic link for gmake command
RUN ln -s /usr/bin/make /usr/bin/gmake
# need to use sphinx version 1.6 to build docs
# installing with apt-get install python-sphinx installs sphinx version 1.3.6 only
# added install for python-pip above and
# installed sphinx with pip to get the updated version 1.6.5
# allows for make html build under the doc/source directory as an interim build process
RUN pip install sphinx
# breathe package required to build documentation
RUN pip install breathe
WORKDIR /home
......@@ -48,11 +48,15 @@ GIT_COMMIT = $(shell git rev-parse HEAD)
DBUILD_VERSION = ${GIT_COMMIT}_${PYTHON_VERSION}
DBUILD_DIR = ${DIR}/contrib/docker/.build-${DBUILD_VERSION}
# Look for evidence if GPU backend is supported on the platform
NVIDIA_SMI = $(shell which nvidia-smi)
# Enable additional options to be added on the command line
ifndef CMAKE_OPTIONS_EXTRA
CMAKE_OPTIONS_EXTRA=
endif
# Allow linking pre-built third-party cache files (future)
ifndef THIRD_PARTY_CACHE_DIR
THIRD_PARTY_CACHE_DIR=
endif
......@@ -63,15 +67,31 @@ ifndef OS
OS="ubuntu1604"
endif
# Configuration for specific reference OS in Dockerfiles
ifeq ("$(shell echo ${OS} | grep centos)","centos74")
RUN_AS_USER_SCRIPT=${DOCKUSER_HOME}/ngraph-test/contrib/docker/run_as_centos_user.sh
DOCKERFILE=Dockerfile.ngraph.centos74
CPU_DOCKERFILE=Dockerfile.ngraph.centos74
else
DOCKERFILE ?= "Dockerfile.ngraph"
RUN_AS_USER_SCRIPT ?= ${DOCKUSER_HOME}/ngraph-test/contrib/docker/run_as_ubuntu_user.sh
CPU_DOCKERFILE="Dockerfile.ngraph.ubuntu1604"
RUN_AS_USER_SCRIPT=${DOCKUSER_HOME}/ngraph-test/contrib/docker/run_as_ubuntu_user.sh
CMAKE_OPTIONS_EXTRA+=-DNGRAPH_USE_PREBUILT_LLVM=TRUE
endif
# Build GPU backend if NVIDIA_SMI command is found
# Sets CMAKE_OPTIONS_EXTRA to introduce GPU build configuration to cmake
# Configuration for GPU backend in Dockerfiles with "_gpu" suffix
# The nvidia-docker command must be used for any targets that actually utilize GPU devices
ifneq ("$(shell echo ${NVIDIA_SMI} | grep nvidia-smi)","")
CMAKE_OPTIONS_EXTRA+=-DNGRAPH_GPU_ENABLE=TRUE
DOCKERFILE=${CPU_DOCKERFILE}_gpu
DOCKER_CMD=nvidia-docker
DOCKER_CMD_MESG=GPU appears to be supported on this platform. Building for GPU and CPU backend support.
else
DOCKERFILE=${CPU_DOCKERFILE}
DOCKER_CMD=docker
DOCKER_CMD_MESG=GPU does not appear to be supported on this platform. Building for CPU backend support only.
endif
# For gcc builds, we do NOT regard warnings as errors
# For clang builds, we DO make warnings into errors
CMAKE_OPTIONS_COMMON=-DNGRAPH_BUILD_DOXYGEN_DOCS=ON -DNGRAPH_BUILD_SPHINX_DOCS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo $(CMAKE_OPTIONS_EXTRA)
......@@ -106,6 +126,7 @@ all: check_gcc check_clang
# Docker actions
# Isolate specific dockerfiles in a .build_* subdirectory
expand_dockerfile_templates:
@echo "OS=${OS}"
@echo "DOCKERFILE=${DOCKERFILE}"
......@@ -124,6 +145,7 @@ build_docker: build_docker_image
# Build docs
docs: sphinx_doc
# Docs build does not depend on GPU dependencies
sphinx_doc: build_docker_image
# sphinx html docs build
docker run --rm --tty \
......@@ -137,11 +159,18 @@ sphinx_doc: build_docker_image
# Build
build_all: build_gcc build_clang
# Build targets ALWAYS clean build directories (BUILD-GCC, BUILD-CLANG) prior to building
# Always use docker command to build docker images
# nvidia-docker command is not appropriate
build_gcc: build_docker_image
@echo ""
@echo "${DOCKER_CMD_MESG}"
@echo ""
docker run --rm --tty \
${VOLUME} \
${DOCKER_RUN_ENV} \
--env BUILD_SUBDIR=BUILD-GCC \
--env CMAKE_OPTIONS_EXTRA="${CMAKE_OPTIONS_EXTRA}" \
--env PARALLEL=${PARALLEL} \
--env THIRD_PARTY_CACHE_DIR=${THIRD_PARTY_CACHE_DIR} \
--env CMD_TO_RUN='build_gcc' \
......@@ -150,11 +179,18 @@ build_gcc: build_docker_image
"build_ngraph:${DBUILD_VERSION}" \
sh -c "cd ${DOCKUSER_HOME}; ${RUN_AS_USER_SCRIPT}"
# Build targets ALWAYS clean build directories (BUILD-GCC, BUILD-CLANG) prior to building
# Always use docker command to build docker images
# nvidia-docker command is not appropriate
build_clang: build_docker_image
@echo ""
@echo "${DOCKER_CMD_MESG}"
@echo ""
docker run --rm --tty \
${VOLUME} \
${DOCKER_RUN_ENV} \
--env BUILD_SUBDIR=BUILD-CLANG \
--env CMAKE_OPTIONS_EXTRA="${CMAKE_OPTIONS_EXTRA}" \
--env PARALLEL=${PARALLEL} \
--env THIRD_PARTY_CACHE_DIR=${THIRD_PARTY_CACHE_DIR} \
--env CMD_TO_RUN='build_clang' \
......@@ -166,11 +202,14 @@ build_clang: build_docker_image
# Check (run unit-tests)
check_all: check_gcc check_clang
check_gcc: build_docker_image
docker run --rm --tty \
# Always use the platform-specific docker command to run unit tests
# ngraph make check target executes unit-test-check and style-check
check_gcc: build_gcc
${DOCKER_CMD} run --rm --tty \
${VOLUME} \
${DOCKER_RUN_ENV} \
--env BUILD_SUBDIR=BUILD-GCC \
--env CMAKE_OPTIONS_EXTRA="${CMAKE_OPTIONS_EXTRA}" \
--env PARALLEL=${PARALLEL} \
--env THIRD_PARTY_CACHE_DIR=${THIRD_PARTY_CACHE_DIR} \
--env CMD_TO_RUN=check_gcc \
......@@ -179,11 +218,14 @@ check_gcc: build_docker_image
"build_ngraph:${DBUILD_VERSION}" \
sh -c "cd ${DOCKUSER_HOME}; ${RUN_AS_USER_SCRIPT}"
check_clang: build_docker_image
docker run --rm --tty \
# Always use the platform-specific docker command to run unit tests
# ngraph make check target executes unit-test-check and style-check
check_clang: build_clang
${DOCKER_CMD} run --rm --tty \
${VOLUME} \
${DOCKER_RUN_ENV} \
--env BUILD_SUBDIR=BUILD-CLANG \
--env CMAKE_OPTIONS_EXTRA="${CMAKE_OPTIONS_EXTRA}" \
--env PARALLEL=${PARALLEL} \
--env THIRD_PARTY_CACHE_DIR=${THIRD_PARTY_CACHE_DIR} \
--env CMD_TO_RUN=check_clang \
......@@ -192,11 +234,13 @@ check_clang: build_docker_image
"build_ngraph:${DBUILD_VERSION}" \
sh -c "cd ${DOCKUSER_HOME}; ${RUN_AS_USER_SCRIPT}"
# Always use the platform-specific docker command to run unit tests
unit_test_check_gcc: build_gcc
docker run --rm --tty \
${DOCKER_CMD} run --rm --tty \
${VOLUME} \
${DOCKER_RUN_ENV} \
--env BUILD_SUBDIR=BUILD-GCC \
--env CMAKE_OPTIONS_EXTRA="${CMAKE_OPTIONS_EXTRA}" \
--env PARALLEL=${PARALLEL} \
--env THIRD_PARTY_CACHE_DIR=${THIRD_PARTY_CACHE_DIR} \
--env CMD_TO_RUN='unit-test-check_gcc' \
......@@ -205,11 +249,13 @@ unit_test_check_gcc: build_gcc
"build_ngraph:${DBUILD_VERSION}" \
sh -c "cd ${DOCKUSER_HOME}; ${RUN_AS_USER_SCRIPT}"
# Always use the platform-specific docker command to run unit tests
unit_test_check_clang: build_clang
docker run --rm --tty \
${DOCKER_CMD} run --rm --tty \
${VOLUME} \
${DOCKER_RUN_ENV} \
--env BUILD_SUBDIR=BUILD-CLANG \
--env CMAKE_OPTIONS_EXTRA="${CMAKE_OPTIONS_EXTRA}" \
--env PARALLEL=${PARALLEL} \
--env THIRD_PARTY_CACHE_DIR=${THIRD_PARTY_CACHE_DIR} \
--env CMD_TO_RUN='unit-test-check_clang' \
......@@ -224,11 +270,15 @@ style_check_clang: build_clang
install_all: install_gcc install_clang
# install targets do not depend on GPU dependencies
# no unit tests are executed
# build prerequisites include GPU dependencies in the docker image automatically
install_gcc: build_gcc
docker run --rm --tty \
${VOLUME} \
${DOCKER_RUN_ENV} \
--env BUILD_SUBDIR=BUILD-GCC \
--env CMAKE_OPTIONS_EXTRA="${CMAKE_OPTIONS_EXTRA}" \
--env PARALLEL=${PARALLEL} \
--env THIRD_PARTY_CACHE_DIR=${THIRD_PARTY_CACHE_DIR} \
--env CMD_TO_RUN=install_gcc \
......@@ -237,11 +287,15 @@ install_gcc: build_gcc
"build_ngraph:${DBUILD_VERSION}" \
sh -c "cd ${DOCKUSER_HOME}; ${RUN_AS_USER_SCRIPT}"
# install targets do not depend on GPU dependencies
# no unit tests are executed
# build prerequisites include GPU dependencies in the docker image automatically
install_clang: build_clang
docker run --rm --tty \
${VOLUME} \
${DOCKER_RUN_ENV} \
--env BUILD_SUBDIR=BUILD-CLANG \
--env CMAKE_OPTIONS_EXTRA="${CMAKE_OPTIONS_EXTRA}" \
--env PARALLEL=${PARALLEL} \
--env THIRD_PARTY_CACHE_DIR=${THIRD_PARTY_CACHE_DIR} \
--env CMD_TO_RUN=install_clang \
......@@ -252,9 +306,11 @@ install_clang: build_clang
# Interactive shell
# Always use the platform-specific docker command for the interactive shell
shell: build_docker_image
# "make shell" runs an interactive shell in the docker image, for debugging
docker run --rm --tty --interactive \
@echo "${DOCKER_CMD_MESG}"
${DOCKER_CMD} run --rm --tty --interactive \
${VOLUME} \
${DOCKER_RUN_ENV} \
--env RUN_UID="$(shell id -u)" \
......@@ -269,17 +325,3 @@ clean:
rm -fr "${DIR}"/BUILD-GCC
rm -fr "${DIR}"/BUILD-CLANG
rm -fr "${DIR}"/BUILD-DOCS
#
# DEPRECATED TARGETS -- These WILL BE REMOVED in a future revision.
# They exist here to maintain compatibility in Jenkins
# jobs on older development branches.
#
check_cpu: check_all
echo 'WARNING: "make check_cpu" is DEPRECATED and will be removed in a future revision'
echo ' "make check_cpu" runs "make check_all" now, building with all compilers (gcc and clang)'
build_ngraph_cpu: build_docker_image
echo 'WARNING: "make build_ngraph_cpu" is DEPRECATED and will be removed in a future revision'
echo ' "make build_ngraph_cpu" runs "make build_docker_image" now'
......@@ -16,7 +16,8 @@ The _make_ targets are designed to handle all aspects of building the _reference
In order to use the _make_ targets, you will need to do the following:
* Have docker installed on your computer with the docker daemon running.
* Have *docker* installed on your computer with the docker daemon running.
* For GPU support, also install *nvidia-docker* and start the nvidia-docker daemon.
* These scripts assume that you are able to run the `docker` command without using `sudo`. You will need to add your account to the `docker` group so this is possible.
* If your computer (running docker) sits behind a firewall, you will need to have the docker daemon properly configured to use proxies to get through the firewall, so that public docker registries and git repositories can be accessed.
* You should _not_ run `make check_*` targets from a directory in an NFS filesystem, if that NFS filesystem uses _root squash_ (see **Notes** section below). Instead, run `make check_*` targets from a cloned repo in a local filesystem.
......@@ -25,6 +26,8 @@ In order to use the _make_ targets, you will need to do the following:
The _make_ targets are designed to provide easy commands to run actions using the docker image. All _make_ targets should be issued on the host OS, and _not_ in a docker image.
GPU support will automatically be included for _make_ targets if the path of the `nvidia-smi` command is returned in response to `which nvidia-smi` on the host OS.
Most _make_ targets are structured in the form `<action>_<compiler>`. The `<action>` indicates what you want to do (e.g. build, check, install), while the `<compiler>` indicates what you want to build with (i.e. gcc or clang).
* In general, you simply need to run the command **`make check_all`**. This first makes the `build_docker_ngraph` target as a dependency. Then it makes the `build_*` and `check_*` targets, which will build ngraph using _cmake_ and _make_ and then run unit testing. Please keep in mind that `make check_*` targets do not work when your working directory is in an NFS filesystem that uses _root squash_ (see **Notes** section below).
......@@ -59,7 +62,7 @@ make check_clang
```
cd contrib/docker
make check_gcc OS=centos74 DOCKERFILE=Dockerfile.ngraph.centos74_cmake3
make check_gcc OS=centos74
```
## Helper Scripts
......@@ -105,29 +108,39 @@ A helper script to run as a normal user within a CentOS 7.4 docker container.
#### Ubuntu 16.04 (default)
```
Dockerfile: Dockerfile.ngraph
Dockerfile: Dockerfile.ngraph.ubuntu1604_gpu
Reference-OS: Ubuntu 16.04
GPU Support: Yes
BUILD-GCC: gcc 5.4
BUILD-CLANG: clang 3.9
pre-built LLVM
```
#### Ubuntu 16.04
```
Dockerfile: Dockerfile.ngraph.ubuntu1604
(same as above)
separate Dockerfile for ease of reference
Reference-OS: Ubuntu 16.04
GPU Support: No
BUILD-GCC: gcc 5.4
BUILD-CLANG: clang 3.9
pre-built LLVM
```
#### CentOS 7.4
```
Dockerfile: Dockerfile.ngraph.centos74_cmake3
Dockerfile: Dockerfile.ngraph.centos74_gpu
Reference-OS: Centos 7.4.1708
BUILD-GCC: gcc 4.8.5
GPU Support: Yes
BUILD-GCC: gcc 4.8
BUILD-CLANG: not supported
pre-built cmake3
LLVM built from source
```
```
Dockerfile: Dockerfile.ngraph.centos74
Reference-OS: Centos 7.4.1708
GPU Support: No
BUILD-GCC: gcc 4.8
BUILD-CLANG: not supported
pre-built cmake3
LLVM built from source
```
......@@ -24,7 +24,9 @@ echo 'Contents of /home/dockuser:'
ls -la /home/dockuser
echo ' '
export CMAKE_OPTIONS_EXTRA=""
if [ -z ${CMAKE_OPTIONS_EXTRA} ]; then
export CMAKE_OPTIONS_EXTRA=''
fi
# setting for make -j
if [ -z ${PARALLEL} ] ; then
......@@ -41,17 +43,7 @@ if [ -z ${BUILD_SUBDIR} ] ; then
BUILD_SUBDIR=BUILD
fi
# Option to build with GPU backend
# default builds with CPU only
if [ -z ${NGRAPH_GPU_ENABLE} ] ; then
NGRAPH_GPU_ENABLE=false
fi
# Set up the environment
if $NGRAPH_GPU_ENABLE; then
export CMAKE_OPTIONS_EXTRA="-DNGRAPH_GPU_ENABLE=TRUE"
fi
export NGRAPH_REPO=/home/dockuser/ngraph-test
if [ -z ${OUTPUT_DIR} ]; then
......@@ -81,8 +73,12 @@ fi
GCC_VERSION=` gcc --version | grep gcc | cut -f 2 -d ')' | cut -f 2 -d ' ' | cut -f 1,2 -d '.'`
# Set the -DNGRAPH_USE_PREBUILT_LLVM=TRUE for appropriate build environments
# if it is not set
if [ "${GCC_VERSION}" != "4.8" ] ; then
export CMAKE_OPTIONS_EXTRA="${CMAKE_OPTIONS_EXTRA} -DNGRAPH_USE_PREBUILT_LLVM=TRUE"
if [ "$(echo ${CMAKE_OPTIONS_EXTRA} | grep PREBUILT_LLVM | wc -l)" == "0" ]; then
export CMAKE_OPTIONS_EXTRA="${CMAKE_OPTIONS_EXTRA} -DNGRAPH_USE_PREBUILT_LLVM=TRUE"
fi
fi
# Print the environment, for debugging
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment