|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +INSTALL_CUDNN=${INSTALLCUDNN} |
| 6 | +INSTALL_NVTX=${INSTALLNVTX} |
| 7 | +CUDA_VERSION=${CUDAVERSION} |
| 8 | +CUDNN_VERSION=${CUDNNVERSION} |
| 9 | + |
| 10 | +if [ "$(id -u)" -ne 0 ]; then |
| 11 | + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' |
| 12 | + exit 1 |
| 13 | +fi |
| 14 | + |
| 15 | +# Install dependencies |
| 16 | +apt-get update -yq |
| 17 | +apt-get install -yq wget ca-certificates |
| 18 | + |
| 19 | +# Add NVIDIA's package repository to apt so that we can download packages |
| 20 | +# Always use the ubuntu2004 repo because the other repos (e.g., debian11) are missing packages |
| 21 | +NVIDIA_REPO_URL="https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64" |
| 22 | +KEYRING_PACKAGE="cuda-keyring_1.0-1_all.deb" |
| 23 | +KEYRING_PACKAGE_URL="$NVIDIA_REPO_URL/$KEYRING_PACKAGE" |
| 24 | +KEYRING_PACKAGE_PATH="$(mktemp -d)" |
| 25 | +KEYRING_PACKAGE_FILE="$KEYRING_PACKAGE_PATH/$KEYRING_PACKAGE" |
| 26 | +wget -O "$KEYRING_PACKAGE_FILE" "$KEYRING_PACKAGE_URL" |
| 27 | +apt-get install -yq "$KEYRING_PACKAGE_FILE" |
| 28 | +apt-get update -yq |
| 29 | + |
| 30 | +# Ensure that the requested version of CUDA is available |
| 31 | +cuda_pkg="cuda-libraries-${CUDA_VERSION/./-}" |
| 32 | +nvtx_pkg="cuda-nvtx-${CUDA_VERSION/./-}" |
| 33 | +if ! apt-cache show "$cuda_pkg"; then |
| 34 | + echo "The requested version of CUDA is not available: CUDA $CUDA_VERSION" |
| 35 | + exit 1 |
| 36 | +fi |
| 37 | + |
| 38 | +# Ensure that the requested version of cuDNN is available AND compatible |
| 39 | +cudnn_pkg_version="libcudnn8=${CUDNN_VERSION}-1+cuda${CUDA_VERSION}" |
| 40 | +if ! apt-cache show "$cudnn_pkg_version"; then |
| 41 | + echo "The requested version of cuDNN is not available: cuDNN $CUDNN_VERSION for CUDA $CUDA_VERSION" |
| 42 | + exit 1 |
| 43 | +fi |
| 44 | + |
| 45 | +echo "Installing CUDA libraries..." |
| 46 | +apt-get install -yq "$cuda_pkg" |
| 47 | + |
| 48 | +if [ "$INSTALL_CUDNN" = "true" ]; then |
| 49 | + echo "Installing cuDNN libraries..." |
| 50 | + apt-get install -yq "$cudnn_pkg_version" |
| 51 | +fi |
| 52 | + |
| 53 | +if [ "$INSTALL_NVTX" = "true" ]; then |
| 54 | + echo "Installing NVTX..." |
| 55 | + apt-get install -yq "$nvtx_pkg" |
| 56 | +fi |
| 57 | + |
| 58 | +echo "Done!" |
0 commit comments