diff --git a/CLA b/CLA new file mode 100644 index 00000000..23961a8e --- /dev/null +++ b/CLA @@ -0,0 +1,160 @@ + The NVIDIA DIGITS + Software Grant and Corporate Contributor License Agreement ("Agreement") + + Thank you for your interest in the NVIDIA DIGITS Project (the + "Project"). In order to clarify the intellectual property license + granted with Contributions from any person or entity, NVIDIA + Corporation (the “Copyright Holders") must have a Contributor License + Agreement (CLA) on file that has been signed by each Contributor, + indicating agreement to the license terms below. This license is + for your protection as a Contributor as well as the protection of the + Project and its users; it does not change your rights to use your own + Contributions for any other purpose. + + This version of the Agreement allows an entity (the "Corporation") to + submit Contributions to the Project, to authorize Contributions + submitted by its designated employees to the Project, and to grant + copyright and patent licenses thereto to the Copyright Holders. + + If you have not already done so, please complete and sign, then scan and + email a pdf file of this Agreement to digits@nvidia.com. + Please read this document carefully before signing and keep a copy for + your records. + + Corporation name: ________________________________________________ + + Corporation address: ________________________________________________ + + ________________________________________________ + + ________________________________________________ + + Point of Contact: ________________________________________________ + + E-Mail: ________________________________________________ + + Telephone: _____________________ Fax: _____________________ + + + You accept and agree to the following terms and conditions for Your + present and future Contributions submitted to the Project. In + return, the Copyright Holders shall not use Your Contributions in a way + that is contrary to the public benefit or inconsistent with its nonprofit + status and bylaws in effect at the time of the Contribution. Except + for the license granted herein to the Copyright Holders and recipients of + software distributed by the Copyright Holders, You reserve all right, title, + and interest in and to Your Contributions. + + 1. Definitions. + + "You" (or "Your") shall mean the copyright owner or legal entity + authorized by the copyright owner that is making this Agreement + with the Copyright Holders. For legal entities, the entity making a + Contribution and all other entities that control, are controlled by, + or are under common control with that entity are considered to be a + single Contributor. For the purposes of this definition, "control" + means (i) the power, direct or indirect, to cause the direction or + management of such entity, whether by contract or otherwise, or + (ii) ownership of fifty percent (50%) or more of the outstanding + shares, or (iii) beneficial ownership of such entity. + + "Contribution" shall mean the code, documentation or other original + works of authorship expressly identified in Schedule B, as well as + any original work of authorship, including + any modifications or additions to an existing work, that is intentionally + submitted by You to the Copyright Holders for inclusion in, or + documentation of, any of the products owned or managed by the + Copyright Holders (the "Work"). For the purposes of this definition, + "submitted" means any form of electronic, verbal, or written + communication sent to the Copyright Holders or its representatives, + including but not limited to communication on electronic mailing + lists, source code control systems, and issue tracking systems + that are managed by, or on behalf of, the Copyright Holders for the + purpose of discussing and improving the Work, but excluding + communication that is conspicuously marked or otherwise designated + in writing by You as "Not a Contribution." + + 2. Grant of Copyright License. Subject to the terms and conditions + of this Agreement, You hereby grant to the Copyright Holders and to + recipients of software distributed by the Copyright Holders a + perpetual, worldwide, non-exclusive, no-charge, royalty-free, + irrevocable copyright license to reproduce, prepare derivative works + of, publicly display, publicly perform, sublicense, and distribute + Your Contributions and such derivative works. + + 3. Grant of Patent License. Subject to the terms and conditions of + this Agreement, You hereby grant to the Copyright Holders and to + recipients of software distributed by the Copyright Holders + a perpetual, worldwide, non-exclusive, no-charge, royalty-free, + irrevocable (except as stated in this section) patent license + to make, have made, use, offer to sell, sell, import, and otherwise + transfer the Work, where such license applies only to those + patent claims licensable by You that are necessarily infringed + by Your Contribution(s) alone or by combination of Your Contribution(s) + with the Work to which such Contribution(s) were submitted. + If any entity institutes patent litigation against You or any + other entity (including a cross-claim or counterclaim in a lawsuit) + alleging that your Contribution, or the Work to which you have + contributed, constitutes direct or contributory patent infringement, + then any patent licenses granted to that entity under this Agreement + for that Contribution or Work shall terminate as of the date such + litigation is filed. + + 4. You represent that You are legally entitled to grant the above + license. You represent further that each employee of the + Corporation designated on Schedule A below (or in a subsequent + written modification to that Schedule) is authorized to submit + Contributions on behalf of the Corporation. + + 5. You represent that each of Your Contributions is Your original + creation (see section 7 for submissions on behalf of others). + + 6. You are not expected to provide support for Your Contributions, + except to the extent You desire to provide support. You may provide + support for free, for a fee, or not at all. Unless required by + applicable law or agreed to in writing, You provide Your + Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS + OF ANY KIND, either express or implied, including, without + limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, + MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. + + 7. Should You wish to submit work that is not Your original creation, + You may submit it to the Copyright Holders separately from any + Contribution, identifying the complete details of its source and + of any license or other restriction (including, but not limited + to, related patents, trademarks, and license agreements) of which + you are personally aware, and conspicuously marking the work as + "Submitted on behalf of a third-party: [named here]". + + 8. It is your responsibility to notify the Copyright Holders when any change + is required to the list of designated employees authorized to submit + Contributions on behalf of the Corporation, or to the Corporation's + Point of Contact with the Copyright Holders. + + + + Please sign: __________________________________ Date: _______________ + + Title: __________________________________ + + Corporation: __________________________________ + + + + +Schedule A + + [Initial list of designated employees. NB: authorization is not + tied to particular Contributions.] + + + + + + +Schedule B + + [Identification of optional concurrent software grant. Would be + left blank or omitted if there is no concurrent software grant.] + + diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..2d3ee373 --- /dev/null +++ b/LICENSE @@ -0,0 +1,25 @@ +Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of NVIDIA CORPORATION nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 00000000..73e46d65 --- /dev/null +++ b/README.md @@ -0,0 +1,83 @@ +# NVIDIA Docker +This repository includes utilities to build and run NVIDIA Docker images. +See ```samples/``` for a list of Dockerfile examples. + +![docker](https://cloud.githubusercontent.com/assets/3028125/10951709/c9b9dd6e-82f3-11e5-9e55-4d7ffd4f1246.png) + +### Building images + +Images can be built on any machine running Docker, it doesn't require a NVIDIA GPU nor any driver installation. + +Building images is done through the Docker CLI or using the ```nvidia-docker``` wrapper similarly: +```sh +# With latest versions +$ docker build -t cuda ubuntu/cuda/latest +``` + +```sh +# With specific versions +$ docker build -t cuda:7.5 ubuntu-14.04/cuda/7.5 +``` + +Alternatively, one can build an image directly from this repository: +```sh +# With latest versions +$ docker build -t cuda github.com/NVIDIA/nvidia-docker#:ubuntu/cuda/latest +``` +```sh +# With specific versions +$ docker build -t cuda:7.5 github.com/NVIDIA/nvidia-docker#:ubuntu-14.04/cuda/7.5 +``` + +### NVIDIA Docker wrapper + +The ```nvidia-docker``` script is a drop-in replacement for ```docker``` CLI. In addition, it takes care of setting up the NVIDIA host driver environment inside Docker containers for proper execution. + +GPUs are exported through a list of comma-separated IDs using the environment variable ```GPU```. +The numbering is the same as reported by ```nvidia-smi``` or when running CUDA code with ```CUDA_DEVICE_ORDER=PCI_BUS_ID```, it is however **different** from the default CUDA ordering. + +```sh +$ GPU=0,1 ./nvidia-docker +``` + +### CUDA requirements + +Running a CUDA container requires a machine with at least one CUDA-capable GPU and a driver compatible with the CUDA toolkit version you are using. + +NVIDIA drivers are **backward-compatible** with CUDA toolkits versions: + +CUDA toolkit version | Minimum driver version +:---------------------:|:-----------------------: + 7.0 | >= 346.46 + 7.5 | >= 352.39 + + +### Samples + +Once you have built the required images, a few examples are provided in the folder ```samples```. +The following assumes that you have an image in your repository named ```cuda``` (see ```samples/deviceQuery/Dockerfile```): +```sh +# Run deviceQuery with one selected GPU +$ docker build -t device_query samples/deviceQuery +$ GPU=0 ./nvidia-docker run device_query + +[ NVIDIA ] =INFO= Driver version: 352.39 +[ NVIDIA ] =INFO= CUDA image version: 7.5 + +./deviceQuery Starting... + + CUDA Device Query (Runtime API) version (CUDART static linking) + +Detected 1 CUDA Capable device(s) + +Device 0: "GeForce GTX 980" + [...] + +deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 7.5, CUDA Runtime Version = 7.5, NumDevs = 1, Device0 = GeForce GTX 980 +Result = PASS +``` + +# Issues and Contributing +* Please let us know by [filing a new issue](https://github.com/NVIDIA/nvidia-docker/issues/new) +* You can contribute by opening a [pull request](https://help.github.com/articles/using-pull-requests/) +You will need to send a signed copy of the [Contributor License Agreement](CLA) to digits@nvidia.com before your change can be accepted. diff --git a/nvidia-docker b/nvidia-docker new file mode 100755 index 00000000..f7ff6e24 --- /dev/null +++ b/nvidia-docker @@ -0,0 +1,221 @@ +#! /bin/sh +# Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved. + +NV_DEVICE="/dev/nvidia" +UVM_DEVICE="${NV_DEVICE}-uvm" +CTL_DEVICE="${NV_DEVICE}ctl" + +CUDA_VERSION_LABEL="com.nvidia.cuda.version" + +NV_BINS_VOLUME="/usr/local/bin" +NV_BINS="nvidia-cuda-mps-control \ + nvidia-cuda-mps-server \ + nvidia-debugdump \ + nvidia-persistenced \ + nvidia-smi" + +NV_LIBS_VOLUME="/usr/local/nvidia" +NV_LIBS_CUDA="cuda \ + nvcuvid \ + nvidia-compiler \ + nvidia-encode \ + nvidia-ml" + +NV_DOCKER_ARGS="" + +__log() +{ + local level="$1" + local msg="$2" + + printf "[ NVIDIA ] =$level= $msg\n" >&2 +} + +__image_label() +{ + local image="$1" + local label="$2" + + echo $( docker inspect --format="{{index .Config.Labels \"$label\"}}" $image ) +} + +__nvsmi_query() +{ + local section="$1" + local gpu_id="$2" # optional + local cmd="nvidia-smi -q" + + if [ $# -eq 2 ]; then + cmd="$cmd -i $gpu_id" + fi + echo $( $cmd | grep "$section" | awk '{print $4}' ) +} + +__library_paths() +{ + local lib="$1" + + echo $( ldconfig -p | grep "lib${lib}.so" | awk '{print $4}' ) +} + +__library_arch() +{ + local lib="$1" + + echo $( file -L $lib | awk '{print $3}' | cut -d- -f1 ) +} + +__filter_duplicate_paths() +{ + local paths="$1" + + local sums="$( md5sum $paths | sed 's/[^/]*$/ &/' )" + local uniq="$( echo "$sums" | uniq -u -f2 | awk '{print $2$3}')" + local dupl="$( echo "$sums" | uniq --all-repeated=separate -f2 \ + | uniq -w 32 | awk 'NF {print $2$3}')" + echo $uniq $dupl +} + +check_prerequisites() +{ + local cmds="docker nvidia-smi nvidia-modprobe" + + for cmd in $cmds; do + command -v $cmd >/dev/null && continue + __log ERROR "Command not found: $cmd" + exit 1 + done +} + +parse_docker_args() +{ + local args="$1" + local help="$2" + + local shift=1 + local skip=0 + local non_bool_args="$( docker help $help | \ + sed '/^\s*\(-[^=]\+\)=[^{true}{false}].*/!d;s//\1/;s/, /\n/' )" + + for arg in $args; do + test $skip -eq 1 && skip=0 && continue + case $arg in + -*) + for nb_arg in $non_bool_args; do + test $arg = $nb_arg && skip=1 && break + done + shift=$((shift+$skip+1)) ;; + *) + return $shift ;; + esac + done + return 0 +} + +check_image_version() +{ + local image="$1" + local driver_version="$( __nvsmi_query "Driver Version" )" + local cuda_image_version="$( __image_label $image $CUDA_VERSION_LABEL )" + + if [ -z $cuda_image_version ]; then + __log INFO "Not a CUDA image, nothing to be done" + return 1 + fi + __log INFO "Driver version: $driver_version" + __log INFO "CUDA image version: $cuda_image_version" + return 0 +} + +load_uvm() +{ + if [ ! -e $UVM_DEVICE ]; then + nvidia-modprobe -u -c=0 + fi +} + +build_docker_args() +{ + local args="--device=$CTL_DEVICE --device=$UVM_DEVICE" + + for gpu in $( echo $GPU | tr -s ", " " " ); do + local minor="$( __nvsmi_query "Minor Number" $gpu )" + if [ -z $minor ]; then + __log WARN "Could not find GPU device: $gpu" + continue + fi + args="$args --device=${NV_DEVICE}$minor" + done + + for lib in $NV_LIBS_CUDA; do + local paths="$( __library_paths $lib )" + if [ -z "$paths" ]; then + __log WARN "Could not find library: $lib" + continue + fi + for path in $( __filter_duplicate_paths "$paths" ); do + args="$args -v $path:$path" + case $( __library_arch "$path" ) in + 32) args="$args -v $path:$NV_LIBS_VOLUME/lib/$(basename $path)" ;; + 64) args="$args -v $path:$NV_LIBS_VOLUME/lib64/$(basename $path)" ;; + esac + done + done + + for bin in $NV_BINS; do + local path="$( which $bin )" + if [ -z $path ]; then + __log WARN "Could not find binary: $bin" + continue + fi + args="$args -v $path:$NV_BINS_VOLUME/$bin" + done + + NV_DOCKER_ARGS=$args +} + +print_debug() +{ + if [ ! -z $NVDEBUG ]; then + seq -s= 60 | tr -d '[:digit:]' + echo $NV_DOCKER_ARGS | sed 's/-[-v][^/]*//g' | tr ' ' '\n' + seq -s= 60 | tr -d '[:digit:]' + fi +} + +setup() +{ + local image="$1" + + check_image_version $image + if [ $? -eq 0 ]; then + build_docker_args + load_uvm + print_debug >&2 + fi + echo +} + +check_prerequisites +parse_docker_args "$*"; ret=$? + +DOCKER_ARGS="" +CMD="$( eval echo \$$ret )" + +i=0; while [ $i -lt $ret ]; do + DOCKER_ARGS="$DOCKER_ARGS $1" + i=$((i+1)) + shift +done + +case $CMD in + run|create) + parse_docker_args "$*" $CMD; ret=$? + if [ $ret -gt 0 ]; then + image="$( eval echo \$$ret )" + setup $image + fi + ;; +esac + +docker $DOCKER_ARGS $NV_DOCKER_ARGS $@ diff --git a/samples/bandwidthTest/Dockerfile b/samples/bandwidthTest/Dockerfile new file mode 100644 index 00000000..9bdd2fea --- /dev/null +++ b/samples/bandwidthTest/Dockerfile @@ -0,0 +1,6 @@ +FROM cuda:latest + +WORKDIR /usr/local/cuda/samples/1_Utilities/bandwidthTest +RUN make + +CMD ./bandwidthTest --mode=shmoo diff --git a/samples/deviceQuery/Dockerfile b/samples/deviceQuery/Dockerfile new file mode 100644 index 00000000..f49d8d65 --- /dev/null +++ b/samples/deviceQuery/Dockerfile @@ -0,0 +1,6 @@ +FROM cuda:latest + +WORKDIR /usr/local/cuda/samples/1_Utilities/deviceQuery +RUN make + +CMD ./deviceQuery diff --git a/samples/matrixMulCUBLAS/Dockerfile b/samples/matrixMulCUBLAS/Dockerfile new file mode 100644 index 00000000..c9f67ba5 --- /dev/null +++ b/samples/matrixMulCUBLAS/Dockerfile @@ -0,0 +1,6 @@ +FROM cuda:latest + +WORKDIR /usr/local/cuda/samples/0_Simple/matrixMulCUBLAS +RUN make + +CMD ./matrixMulCUBLAS -sizemult=10 diff --git a/samples/nvidia-smi/Dockerfile b/samples/nvidia-smi/Dockerfile new file mode 100644 index 00000000..d7f0a2e7 --- /dev/null +++ b/samples/nvidia-smi/Dockerfile @@ -0,0 +1,3 @@ +FROM cuda:latest + +CMD nvidia-smi -q diff --git a/ubuntu b/ubuntu new file mode 120000 index 00000000..796071e3 --- /dev/null +++ b/ubuntu @@ -0,0 +1 @@ +ubuntu-14.04 \ No newline at end of file diff --git a/ubuntu-14.04/cuda/7.0/Dockerfile b/ubuntu-14.04/cuda/7.0/Dockerfile new file mode 100644 index 00000000..fb910b10 --- /dev/null +++ b/ubuntu-14.04/cuda/7.0/Dockerfile @@ -0,0 +1,23 @@ +FROM ubuntu:14.04 +MAINTAINER NVIDIA CORPORATION + +RUN apt-get update && apt-get install -y wget + +RUN wget -q -O - http://developer.download.nvidia.com/compute/cuda/repos/GPGKEY | apt-key add - && \ + echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64 /" > /etc/apt/sources.list.d/cuda.list && \ + apt-get update + +ENV CUDA_VERSION 7.0 +LABEL com.nvidia.cuda.version="7.0" + +RUN apt-get install -y --no-install-recommends --force-yes "cuda-toolkit-7.0" + +RUN echo "/usr/local/cuda/lib" >> /etc/ld.so.conf.d/cuda.conf && \ + echo "/usr/local/cuda/lib64" >> /etc/ld.so.conf.d/cuda.conf && \ + ldconfig + +RUN echo "/usr/local/nvidia/lib" >> /etc/ld.so.conf.d/nvidia.conf && \ + echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf + +ENV PATH /usr/local/cuda/bin:${PATH} +ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} diff --git a/ubuntu-14.04/cuda/7.5/Dockerfile b/ubuntu-14.04/cuda/7.5/Dockerfile new file mode 100644 index 00000000..cfbc2bbd --- /dev/null +++ b/ubuntu-14.04/cuda/7.5/Dockerfile @@ -0,0 +1,23 @@ +FROM ubuntu:14.04 +MAINTAINER NVIDIA CORPORATION + +RUN apt-get update && apt-get install -y wget + +RUN wget -q -O - http://developer.download.nvidia.com/compute/cuda/repos/GPGKEY | apt-key add - && \ + echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64 /" > /etc/apt/sources.list.d/cuda.list && \ + apt-get update + +ENV CUDA_VERSION 7.5 +LABEL com.nvidia.cuda.version="7.5" + +RUN apt-get install -y --no-install-recommends --force-yes "cuda-toolkit-7.5" + +RUN echo "/usr/local/cuda/lib" >> /etc/ld.so.conf.d/cuda.conf && \ + echo "/usr/local/cuda/lib64" >> /etc/ld.so.conf.d/cuda.conf && \ + ldconfig + +RUN echo "/usr/local/nvidia/lib" >> /etc/ld.so.conf.d/nvidia.conf && \ + echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf + +ENV PATH /usr/local/cuda/bin:${PATH} +ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} diff --git a/ubuntu-14.04/cuda/latest b/ubuntu-14.04/cuda/latest new file mode 120000 index 00000000..72906051 --- /dev/null +++ b/ubuntu-14.04/cuda/latest @@ -0,0 +1 @@ +7.5 \ No newline at end of file