github.com/apptainer/singularity@v3.1.1+incompatible/examples/legacy/2.2/contrib/ubuntu16-tensorflow-0.12.1-gpu.def (about)

     1  # Defines a Singularity container with TensorFlow pre-installed
     2  #
     3  
     4  #
     5  # Before bootstrapping this container, you must ensure that the following files
     6  # are present in the current directory (alongside this definition file):
     7  #
     8  #   * cuda-linux64-rel-8.0.44-21122537.run  (* see below)
     9  #   * NVIDIA-Linux-x86_64-375.20.run        (* see below)
    10  #   * cudnn-8.0-linux-x64-v5.1.tgz          (https://developer.nvidia.com/cudnn)
    11  #
    12  # * The cuda-linux64 and NVIDIA-Linux files can be obtained by downloading the
    13  # NVIDIA CUDA local runfile `cuda_8.0.44_linux.run` from:
    14  #
    15  #   https://developer.nvidia.com/cuda-downloads
    16  #
    17  # Then extract the necessary files by running:
    18  #
    19  #   sh cuda_8.0.44_linux.run --extract=<absolute/path/to/bootstrap/directory>
    20  #
    21  # IF YOUR HPC SYSTEM IS USING A DIFFERENT VERSION OF CUDA AND/OR NVIDIA DRIVERS
    22  # YOU WILL NEED TO ADJUST THE ABOVE VERSION NUMBERS TO MATCH YOUR SYSTEM
    23  #
    24  # YOU WILL ALSO NEED TO DOWNLOAD THE APPROPRIATE DRIVER. For example,
    25  # cuda_8.0.44_linux.run returns driver version 367.48.
    26  #
    27  # If you use this to create a container inside a virtual machine with no access to
    28  # a GPU, comment out the final test.
    29  
    30  
    31  BootStrap: docker
    32  From: ubuntu:16.10
    33  
    34  
    35  %runscript
    36      # When executed, the container will run Python with the TensorFlow module
    37  
    38      # Check the current environment
    39      chk_nvidia_uvm=$(grep nvidia_uvm /proc/modules)
    40      if [ -z "$chk_nvidia_uvm" ]; then
    41          echo "Problem detected on the host: the Linux kernel module nvidia_uvm is not loaded"
    42          exit 1
    43      fi
    44  
    45      exec /usr/bin/python "$@"
    46  
    47  
    48  %setup
    49      # Runs from outside the container during Bootstrap
    50  
    51      NV_DRIVER_VERSION=375.20
    52      NV_CUDA_FILE=cuda-linux64-rel-8.0.44-21122537.run
    53      NV_CUDNN_FILE=cudnn-8.0-linux-x64-v5.1.tgz
    54      NV_DRIVER_FILE=NVIDIA-Linux-x86_64-${NV_DRIVER_VERSION}.run
    55  
    56      working_dir=$(pwd)
    57  
    58      echo "Unpacking NVIDIA driver into container..."
    59      cd ${SINGULARITY_ROOTFS}/usr/local/
    60      sh ${working_dir}/${NV_DRIVER_FILE} -x
    61      mv NVIDIA-Linux-x86_64-${NV_DRIVER_VERSION} NVIDIA-Linux-x86_64
    62      cd NVIDIA-Linux-x86_64/
    63      for n in *.$NV_DRIVER_VERSION; do
    64          ln -v -s $n ${n%.367.48}
    65      done
    66      ln -v -s libnvidia-ml.so.$NV_DRIVER_VERSION libnvidia-ml.so.1
    67      ln -v -s libcuda.so.$NV_DRIVER_VERSION libcuda.so.1
    68      cd $working_dir
    69  
    70      echo "Running NVIDIA CUDA installer..."
    71      sh $NV_CUDA_FILE -noprompt -nosymlink -prefix=${SINGULARITY_ROOTFS}/usr/local/cuda-8.0
    72      ln -r -s ${SINGULARITY_ROOTFS}/usr/local/cuda-8.0 ${SINGULARITY_ROOTFS}/usr/local/cuda
    73  
    74      echo "Unpacking cuDNN..."
    75      tar xvf $NV_CUDNN_FILE -C ${SINGULARITY_ROOTFS}/usr/local/
    76  
    77      echo "Adding NVIDIA PATHs to /environment..."
    78      NV_DRIVER_PATH=/usr/local/NVIDIA-Linux-x86_64
    79      echo "
    80  
    81  LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64:$NV_DRIVER_PATH:\$LD_LIBRARY_PATH
    82  PATH=$NV_DRIVER_PATH:\$PATH
    83  export PATH LD_LIBRARY_PATH
    84      
    85  " >> $SINGULARITY_ROOTFS/environment
    86  
    87  
    88  %post
    89      # Runs within the container during Bootstrap
    90  
    91      # Set up some required environment defaults
    92      export LC_ALL=C
    93      export PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH
    94  
    95      # Install the necessary packages (from repo)
    96      apt-get update && apt-get install -y --no-install-recommends \
    97          build-essential \
    98          curl \
    99          git \
   100          libcurl4-openssl-dev \
   101          libfreetype6-dev \
   102          libpng-dev \
   103          libzmq3-dev \
   104          python-pip \
   105          pkg-config \
   106          python-dev \
   107          rsync \
   108          software-properties-common \
   109          unzip \
   110          zip \
   111          zlib1g-dev
   112      apt-get clean
   113  
   114      # Update to the latest pip (newer than repo)
   115      pip install --no-cache-dir --upgrade pip
   116      
   117      # Install other commonly-needed packages
   118      pip install --no-cache-dir --upgrade \
   119          future \
   120          matplotlib \
   121          scipy \
   122          sklearn
   123  
   124      # TensorFlow package versions as listed here:
   125      #   https://www.tensorflow.org/get_started/os_setup#test_the_tensorflow_installation
   126      #
   127      # Ubuntu/Linux 64-bit, GPU enabled, Python 2.7 (Requires CUDA toolkit 8.0 and CuDNN v5)
   128      export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp27-none-linux_x86_64.whl
   129      pip install --no-cache-dir --ignore-installed --upgrade $TF_BINARY_URL
   130  
   131  
   132  %test
   133      # Sanity check that the container is operating
   134      export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64:/usr/local/NVIDIA-Linux-x86_64:$LD_LIBRARY_PATH
   135  
   136      # Ensure that TensorFlow can be imported
   137      /usr/bin/python -c "import tensorflow as tf"
   138  
   139      # Runs in less than 30 minutes on low-end CPU; in less than 2 minutes on GPU
   140      # Comment the following line if building the container inside a VM with no access to a GPU
   141      /usr/bin/python -m tensorflow.models.image.mnist.convolutional
   142