From e0e3287a3bc64d8023f2fbc972b66a92413cd4b9 Mon Sep 17 00:00:00 2001 From: Roman Grundkiewicz Date: Thu, 12 May 2022 16:23:58 +0000 Subject: [PATCH] Merged PR 23840: Update CUDA installation script for Ubuntu Updates CUDA deb/key fetching https://developer.nvidia.com/blog/updating-the-cuda-linux-gpg-repository-key/ --- scripts/ci/install_cuda_ubuntu.sh | 87 ++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 13 deletions(-) diff --git a/scripts/ci/install_cuda_ubuntu.sh b/scripts/ci/install_cuda_ubuntu.sh index de60a5b6..41fcee46 100755 --- a/scripts/ci/install_cuda_ubuntu.sh +++ b/scripts/ci/install_cuda_ubuntu.sh @@ -17,6 +17,33 @@ if [[ $# -lt 1 ]]; then exit 2 fi + +## ------------------------------------------------------------------ +## Bash functions +## ------------------------------------------------------------------ + +# returns 0 (true) if a >= b +function version_ge() { + [ "$#" != "2" ] && echo "${FUNCNAME[0]} requires exactly 2 arguments." && exit 1 + [ "$(printf '%s\n' "$@" | sort -V | head -n 1)" == "$2" ] +} +# returns 0 (true) if a > b +function version_gt() { + [ "$#" != "2" ] && echo "${FUNCNAME[0]} requires exactly 2 arguments." && exit 1 + [ "$1" = "$2" ] && return 1 || version_ge $1 $2 +} +# returns 0 (true) if a <= b +function version_le() { + [ "$#" != "2" ] && echo "${FUNCNAME[0]} requires exactly 2 arguments." && exit 1 + [ "$(printf '%s\n' "$@" | sort -V | head -n 1)" == "$1" ] +} +# returns 0 (true) if a < b +function version_lt() { + [ "$#" != "2" ] && echo "${FUNCNAME[0]} requires exactly 2 arguments." && exit 1 + [ "$1" = "$2" ] && return 1 || version_le $1 $2 +} + + ## ------------------------------------------------------------------ ## Find CUDA and OS versions ## ------------------------------------------------------------------ @@ -53,22 +80,52 @@ fi ## Select CUDA packages to install ## ------------------------------------------------------------------ +# Ideally choose from the list of meta-packages to minimise variance between cuda versions (although it does change too). Some of these packages may not be availble pre cuda 10. CUDA_PACKAGES_IN=( - "command-line-tools" - "libraries-dev" + "cuda-compiler" + "cuda-cudart-dev" + "cuda-nvtx" + "cuda-nvrtc-dev" + "libcublas-dev" + "libcurand-dev" # 11-0+ + "libcusparse-dev" # 11-0+ + "cuda-cccl" # 11.4+, provides cub and thrust. On 11.3 knwon as cuda-thrust-11-3 ) CUDA_PACKAGES="" for package in "${CUDA_PACKAGES_IN[@]}"; do # @todo This is not perfect. Should probably provide a separate list for diff versions # cuda-compiler-X-Y if CUDA >= 9.1 else cuda-nvcc-X-Y - if [[ "${package}" == "nvcc" ]] && version_ge "$CUDA_VERSION_MAJOR_MINOR" "9.1" ; then - package="compiler" - elif [[ "${package}" == "compiler" ]] && version_lt "$CUDA_VERSION_MAJOR_MINOR" "9.1" ; then - package="nvcc" + if [[ "${package}" == "cuda-nvcc" ]] && version_ge "$CUDA_VERSION_MAJOR_MINOR" "9.1" ; then + package="cuda-compiler" + elif [[ "${package}" == "cuda-compiler" ]] && version_lt "$CUDA_VERSION_MAJOR_MINOR" "9.1" ; then + package="cuda-nvcc" + # CUB/Thrust are packages in cuda-thrust in 11.3, but cuda-cccl in 11.4+ + elif [[ "${package}" == "cuda-thrust" || "${package}" == "cuda-cccl" ]]; then + # CUDA cuda-thrust >= 11.4 + if version_ge "$CUDA_VERSION_MAJOR_MINOR" "11.4" ; then + package="cuda-cccl" + # Use cuda-thrust > 11.2 + elif version_ge "$CUDA_VERSION_MAJOR_MINOR" "11.3" ; then + package="cuda-thrust" + # Do not include this pacakge < 11.3 + else + continue + fi + fi + # CUDA 11+ includes lib* / lib*-dev packages, which if they existed previously where cuda-cu*- / cuda-cu*-dev- + if [[ ${package} == libcu* ]] && version_lt "$CUDA_VERSION_MAJOR_MINOR" "11.0" ; then + if [[ ${package} != libcublas* ]]; then + package="${package/libcu/cuda-cu}" + fi + fi + + if [[ ${package} == libcublas* ]] && version_lt "$CUDA_VERSION_MAJOR_MINOR" "11.0" ; then + CUDA_PACKAGES+=" ${package}" + else + # Build the full package name and append to the string. + CUDA_PACKAGES+=" ${package}-${CUDA_MAJOR}-${CUDA_MINOR}" fi - # Build the full package name and append to the string. - CUDA_PACKAGES+=" cuda-${package}-${CUDA_MAJOR}-${CUDA_MINOR}" done echo "CUDA_PACKAGES ${CUDA_PACKAGES}" @@ -77,14 +134,18 @@ echo "CUDA_PACKAGES ${CUDA_PACKAGES}" ## Prepare to install ## ------------------------------------------------------------------ +CPU_ARCH="x86_64" PIN_FILENAME="cuda-ubuntu${UBUNTU_VERSION}.pin" -PIN_URL="https://developer.download.nvidia.com/compute/cuda/repos/ubuntu${UBUNTU_VERSION}/x86_64/${PIN_FILENAME}" -APT_KEY_URL="https://developer.download.nvidia.com/compute/cuda/repos/ubuntu${UBUNTU_VERSION}/x86_64/7fa2af80.pub" -REPO_URL="https://developer.download.nvidia.com/compute/cuda/repos/ubuntu${UBUNTU_VERSION}/x86_64/" +PIN_URL="https://developer.download.nvidia.com/compute/cuda/repos/ubuntu${UBUNTU_VERSION}/${CPU_ARCH}/${PIN_FILENAME}" +# apt keyring package now available https://developer.nvidia.com/blog/updating-the-cuda-linux-gpg-repository-key/ +KERYRING_PACKAGE_FILENAME="cuda-keyring_1.0-1_all.deb" +KEYRING_PACKAGE_URL="https://developer.download.nvidia.com/compute/cuda/repos/ubuntu${UBUNTU_VERSION}/${CPU_ARCH}/${KERYRING_PACKAGE_FILENAME}" +REPO_URL="https://developer.download.nvidia.com/compute/cuda/repos/ubuntu${UBUNTU_VERSION}/${CPU_ARCH}/" echo "PIN_FILENAME ${PIN_FILENAME}" echo "PIN_URL ${PIN_URL}" -echo "APT_KEY_URL ${APT_KEY_URL}" +echo "KEYRING_PACKAGE_URL ${KEYRING_PACKAGE_URL}" +echo "REPO_URL ${REPO_URL}" ## ------------------------------------------------------------------ ## Install CUDA @@ -93,7 +154,7 @@ echo "APT_KEY_URL ${APT_KEY_URL}" echo "Adding CUDA Repository" wget ${PIN_URL} sudo mv ${PIN_FILENAME} /etc/apt/preferences.d/cuda-repository-pin-600 -sudo apt-key adv --fetch-keys ${APT_KEY_URL} +wget ${KEYRING_PACKAGE_URL} && sudo dpkg -i ${KERYRING_PACKAGE_FILENAME} && rm ${KERYRING_PACKAGE_FILENAME} sudo add-apt-repository "deb ${REPO_URL} /" sudo apt-get update