|
| 1 | +# |
| 2 | +# Installation script for relevant CUDA packages |
| 3 | +# on Microsoft Windows (10) systems |
| 4 | +# |
| 5 | +# Adapted from the version at : https://github.com/ptheywood |
| 6 | +# |
| 7 | +# Original version Copyright (c) 2021 Peter Heywood |
| 8 | +# Licensed under the terms of the MIT License; see: |
| 9 | +# https://github.com/ptheywood/cuda-cmake-github-actions/blob/master/LICENSE |
| 10 | +# |
| 11 | + |
| 12 | + |
| 13 | +## ------------------- |
| 14 | +## Constants |
| 15 | +## ------------------- |
| 16 | + |
| 17 | +# Dictionary of known cuda versions and thier download URLS, which do not follow a consistent pattern :( |
| 18 | +$CUDA_KNOWN_URLS = @{ |
| 19 | + "8.0.44" = "http://developer.download.nvidia.com/compute/cuda/8.0/Prod/network_installers/cuda_8.0.44_win10_network-exe"; |
| 20 | + "8.0.61" = "http://developer.download.nvidia.com/compute/cuda/8.0/Prod2/network_installers/cuda_8.0.61_win10_network-exe"; |
| 21 | + "9.0.176" = "http://developer.download.nvidia.com/compute/cuda/9.0/Prod/network_installers/cuda_9.0.176_win10_network-exe"; |
| 22 | + "9.1.85" = "http://developer.download.nvidia.com/compute/cuda/9.1/Prod/network_installers/cuda_9.1.85_win10_network"; |
| 23 | + "9.2.148" = "http://developer.download.nvidia.com/compute/cuda/9.2/Prod2/network_installers2/cuda_9.2.148_win10_network"; |
| 24 | + "10.0.130" = "http://developer.download.nvidia.com/compute/cuda/10.0/Prod/network_installers/cuda_10.0.130_win10_network"; |
| 25 | + "10.1.105" = "http://developer.download.nvidia.com/compute/cuda/10.1/Prod/network_installers/cuda_10.1.105_win10_network.exe"; |
| 26 | + "10.1.168" = "http://developer.download.nvidia.com/compute/cuda/10.1/Prod/network_installers/cuda_10.1.168_win10_network.exe"; |
| 27 | + "10.1.243" = "http://developer.download.nvidia.com/compute/cuda/10.1/Prod/network_installers/cuda_10.1.243_win10_network.exe"; |
| 28 | + "10.2.89" = "http://developer.download.nvidia.com/compute/cuda/10.2/Prod/network_installers/cuda_10.2.89_win10_network.exe"; |
| 29 | + "11.0.1" = "http://developer.download.nvidia.com/compute/cuda/11.0.1/network_installers/cuda_11.0.1_win10_network.exe"; |
| 30 | + "11.0.2" = "http://developer.download.nvidia.com/compute/cuda/11.0.2/network_installers/cuda_11.0.2_win10_network.exe"; |
| 31 | + "11.0.3" = "http://developer.download.nvidia.com/compute/cuda/11.0.3/network_installers/cuda_11.0.3_win10_network.exe"; |
| 32 | + "11.1.0" = "https://developer.download.nvidia.com/compute/cuda/11.1.0/network_installers/cuda_11.1.0_win10_network.exe"; |
| 33 | + "11.1.1" = "https://developer.download.nvidia.com/compute/cuda/11.1.1/network_installers/cuda_11.1.1_win10_network.exe"; |
| 34 | + "11.2.0" = "https://developer.download.nvidia.com/compute/cuda/11.2.0/network_installers/cuda_11.2.0_win10_network.exe"; |
| 35 | + "11.2.1" = "https://developer.download.nvidia.com/compute/cuda/11.2.1/network_installers/cuda_11.2.1_win10_network.exe"; |
| 36 | + "11.2.2" = "https://developer.download.nvidia.com/compute/cuda/11.2.2/network_installers/cuda_11.2.2_win10_network.exe"; |
| 37 | + "11.3.0" = "https://developer.download.nvidia.com/compute/cuda/11.3.0/network_installers/cuda_11.3.0_win10_network.exe"; |
| 38 | + "11.4.0" = "https://developer.download.nvidia.com/compute/cuda/11.4.0/network_installers/cuda_11.4.0_win10_network.exe"; |
| 39 | + "11.5.0" = "https://developer.download.nvidia.com/compute/cuda/11.5.0/network_installers/cuda_11.5.0_win10_network.exe"; |
| 40 | + "11.5.2" = "https://developer.download.nvidia.com/compute/cuda/11.5.2/network_installers/cuda_11.5.2_windows_network.exe"; |
| 41 | + "11.6.0" = "https://developer.download.nvidia.com/compute/cuda/11.6.0/network_installers/cuda_11.6.0_windows_network.exe"; |
| 42 | + "11.6.1" = "https://developer.download.nvidia.com/compute/cuda/11.6.1/network_installers/cuda_11.6.1_windows_network.exe"; |
| 43 | + "11.6.2" = "https://developer.download.nvidia.com/compute/cuda/11.6.2/network_installers/cuda_11.6.2_windows_network.exe"; |
| 44 | + "11.7.0" = "https://developer.download.nvidia.com/compute/cuda/11.7.0/network_installers/cuda_11.7.0_windows_network.exe"; |
| 45 | + "11.8.0" = "https://developer.download.nvidia.com/compute/cuda/11.8.0/network_installers/cuda_11.8.0_windows_network.exe"; |
| 46 | + "12.0.1" = "https://developer.download.nvidia.com/compute/cuda/12.0.1/network_installers/cuda_12.0.1_windows_network.exe"; |
| 47 | + "12.1.1" = "https://developer.download.nvidia.com/compute/cuda/12.1.1/network_installers/cuda_12.1.1_windows_network.exe"; |
| 48 | + "12.2.0" = "https://developer.download.nvidia.com/compute/cuda/12.2.0/network_installers/cuda_12.2.0_windows_network.exe"; |
| 49 | + "12.2.1" = "https://developer.download.nvidia.com/compute/cuda/12.2.1/network_installers/cuda_12.2.1_windows_network.exe"; |
| 50 | + "12.2.2" = "https://developer.download.nvidia.com/compute/cuda/12.2.2/network_installers/cuda_12.2.2_windows_network.exe"; |
| 51 | + "12.3.0" = "https://developer.download.nvidia.com/compute/cuda/12.3.0/network_installers/cuda_12.3.0_windows_network.exe"; |
| 52 | + "12.3.1" = "https://developer.download.nvidia.com/compute/cuda/12.3.1/network_installers/cuda_12.3.1_windows_network.exe"; |
| 53 | + "12.4.1" = "https://developer.download.nvidia.com/compute/cuda/12.4.1/network_installers/cuda_12.4.1_windows_network.exe"; |
| 54 | + "12.5.1" = "https://developer.download.nvidia.com/compute/cuda/12.5.1/network_installers/cuda_12.5.1_windows_network.exe"; |
| 55 | + "12.6.0" = "https://developer.download.nvidia.com/compute/cuda/12.6.0/network_installers/cuda_12.6.0_windows_network.exe"; |
| 56 | + "12.6.1" = "https://developer.download.nvidia.com/compute/cuda/12.6.1/network_installers/cuda_12.6.1_windows_network.exe"; |
| 57 | + "12.6.2" = "https://developer.download.nvidia.com/compute/cuda/12.6.2/network_installers/cuda_12.6.2_windows_network.exe"; |
| 58 | + "13.0.0" = "https://developer.download.nvidia.com/compute/cuda/13.0.0/network_installers/cuda_13.0.0_windows_network.exe"; |
| 59 | + "13.0.2" = "https://developer.download.nvidia.com/compute/cuda/13.0.2/network_installers/cuda_13.0.2_windows_network.exe"; |
| 60 | +} |
| 61 | + |
| 62 | +# @todo - change this to be based on _MSC_VER intead, or invert it to be CUDA keyed instead? |
| 63 | +$VISUAL_STUDIO_MIN_CUDA = @{ |
| 64 | + "2022" = "11.6.0"; |
| 65 | + "2019" = "10.1"; |
| 66 | + "2017" = "10.0"; # Depends on which version of 2017! 9.0 to 10.0 depending on version |
| 67 | + "2015" = "8.0"; # might support older, unsure. |
| 68 | +} |
| 69 | + |
| 70 | +# cuda_runtime.h is in nvcc <= 10.2, but cudart >= 11.0 |
| 71 | +# @todo - make this easier to vary per CUDA version. |
| 72 | +$CUDA_PACKAGES_IN = @( |
| 73 | + "nvcc"; |
| 74 | + "visual_studio_integration"; |
| 75 | + "curand_dev"; |
| 76 | + "nvrtc_dev"; |
| 77 | + "nsight_nvtx"; |
| 78 | + "nvtx"; |
| 79 | + "cudart"; |
| 80 | + "visual_studio_integration"; |
| 81 | + "cuda_profiler_api"; |
| 82 | +) |
| 83 | + |
| 84 | + |
| 85 | +## ------------------- |
| 86 | +## Select CUDA version |
| 87 | +## ------------------- |
| 88 | + |
| 89 | +# Get the cuda version from the environment as env:cuda. |
| 90 | +$CUDA_VERSION_FULL = $env:cuda |
| 91 | +# Make sure CUDA_VERSION_FULL is set and valid, otherwise error. |
| 92 | + |
| 93 | +if($CUDA_VERSION_FULL -eq "none"){ |
| 94 | + exit 0 |
| 95 | +} |
| 96 | + |
| 97 | +# Validate CUDA version, extracting components via regex |
| 98 | +$cuda_ver_matched = $CUDA_VERSION_FULL -match "^(?<major>[1-9][0-9]*)\.(?<minor>[0-9]+)\.(?<patch>[0-9]+)$" |
| 99 | +if(-not $cuda_ver_matched){ |
| 100 | + Write-Output "Invalid CUDA version specified, <major>.<minor>.<patch> required. '$CUDA_VERSION_FULL'." |
| 101 | + exit 1 |
| 102 | +} |
| 103 | +$CUDA_MAJOR=$Matches.major |
| 104 | +$CUDA_MINOR=$Matches.minor |
| 105 | +$CUDA_PATCH=$Matches.patch |
| 106 | + |
| 107 | +## --------------------------- |
| 108 | +## Visual studio support check |
| 109 | +## --------------------------- |
| 110 | +# Exit if visual studio is too new for the cuda version. |
| 111 | +$VISUAL_STUDIO = $env:visual_studio.trim() |
| 112 | +if ($VISUAL_STUDIO.length -ge 4) { |
| 113 | +$VISUAL_STUDIO_YEAR = $VISUAL_STUDIO.Substring($VISUAL_STUDIO.Length-4) |
| 114 | + if ($VISUAL_STUDIO_YEAR.length -eq 4 -and $VISUAL_STUDIO_MIN_CUDA.containsKey($VISUAL_STUDIO_YEAR)){ |
| 115 | + $MINIMUM_CUDA_VERSION = $VISUAL_STUDIO_MIN_CUDA[$VISUAL_STUDIO_YEAR] |
| 116 | + if ([version]$CUDA_VERSION_FULL -lt [version]$MINIMUM_CUDA_VERSION) { |
| 117 | + Write-Output "Error: Visual Studio $($VISUAL_STUDIO_YEAR) requires CUDA >= $($MINIMUM_CUDA_VERSION)" |
| 118 | + exit 1 |
| 119 | + } |
| 120 | + } |
| 121 | +} else { |
| 122 | + Write-Output "Warning: Unknown Visual Studio Version. CUDA version may be insufficient." |
| 123 | +} |
| 124 | + |
| 125 | +## ------------------------------------------------ |
| 126 | +## Select CUDA packages to install from environment |
| 127 | +## ------------------------------------------------ |
| 128 | + |
| 129 | +$CUDA_PACKAGES = "" |
| 130 | + |
| 131 | +if([version]$CUDA_VERSION_FULL -ge [version]"12.4") { |
| 132 | + $CUDA_PACKAGES_IN += "nvfatbin" |
| 133 | +} |
| 134 | + |
| 135 | +if([version]$CUDA_VERSION_FULL -ge [version]"13.0") { |
| 136 | + $CUDA_PACKAGES_IN += "thrust" |
| 137 | + $CUDA_PACKAGES_IN += "nvptxcompiler" |
| 138 | + $CUDA_PACKAGES_IN += "nvvm" |
| 139 | + $CUDA_PACKAGES_IN += "nvtx" |
| 140 | + $CUDA_PACKAGES_IN += "nvrtc" |
| 141 | + $CUDA_PACKAGES_IN += "nvrtc_dev" |
| 142 | + $CUDA_PACKAGES_IN += "nvml_dev" |
| 143 | + $CUDA_PACKAGES_IN += "npp" |
| 144 | + $CUDA_PACKAGES_IN += "npp_dev" |
| 145 | + $CUDA_PACKAGES_IN += "cublas" |
| 146 | + $CUDA_PACKAGES_IN += "cublas_dev" |
| 147 | + $CUDA_PACKAGES_IN += "crt" |
| 148 | + $CUDA_PACKAGES_IN += "ctadvisor" |
| 149 | + $CUDA_PACKAGES_IN += "cuda_profiler_api" |
| 150 | + $CUDA_PACKAGES_IN += "cufft" |
| 151 | + $CUDA_PACKAGES_IN += "cufft_dev" |
| 152 | + $CUDA_PACKAGES_IN += "cuobjdump" |
| 153 | + $CUDA_PACKAGES_IN += "cupti" |
| 154 | + $CUDA_PACKAGES_IN += "curand" |
| 155 | + $CUDA_PACKAGES_IN += "curand_dev" |
| 156 | + $CUDA_PACKAGES_IN += "cusolver" |
| 157 | + $CUDA_PACKAGES_IN += "cusparse" |
| 158 | + $CUDA_PACKAGES_IN += "cusparse_dev" |
| 159 | + $CUDA_PACKAGES_IN += "cuxxfilt" |
| 160 | + $CUDA_PACKAGES_IN += "nsight_compute" |
| 161 | + $CUDA_PACKAGES_IN += "nsight_systems" |
| 162 | + $CUDA_PACKAGES_IN += "nsight_vse" |
| 163 | + $CUDA_PACKAGES_IN += "nvcc" |
| 164 | + $CUDA_PACKAGES_IN += "nvdisasm" |
| 165 | + $CUDA_PACKAGES_IN += "nvjtlink" |
| 166 | + $CUDA_PACKAGES_IN += "nvtx" |
| 167 | +} |
| 168 | + |
| 169 | +Foreach ($package in $CUDA_PACKAGES_IN) { |
| 170 | + # Make sure the correct package name is used for nvcc. |
| 171 | + if($package -eq "cuda_profiler_api" -and [version]$CUDA_VERSION_FULL -lt [version]"11.8"){ |
| 172 | + $package="nvprof" |
| 173 | + } |
| 174 | + if($package -eq "nvtx" -and [version]$CUDA_VERSION_FULL -lt [version]"12.0"){ |
| 175 | + continue |
| 176 | + } |
| 177 | + if($package -eq "nsight_nvtx" -and [version]$CUDA_VERSION_FULL -ge [version]"12.0"){ |
| 178 | + continue |
| 179 | + } |
| 180 | + if($package -eq "nvcc" -and [version]$CUDA_VERSION_FULL -lt [version]"9.1"){ |
| 181 | + $package="compiler" |
| 182 | + } elseif($package -eq "compiler" -and [version]$CUDA_VERSION_FULL -ge [version]"9.1") { |
| 183 | + $package="nvcc" |
| 184 | + } |
| 185 | + $CUDA_PACKAGES += " $($package)_$($CUDA_MAJOR).$($CUDA_MINOR)" |
| 186 | + |
| 187 | +} |
| 188 | +echo "$($CUDA_PACKAGES)" |
| 189 | + |
| 190 | +## ----------------- |
| 191 | +## Prepare download |
| 192 | +## ----------------- |
| 193 | + |
| 194 | +# Select the download link if known, otherwise have a guess. |
| 195 | +$CUDA_REPO_PKG_REMOTE="" |
| 196 | +if($CUDA_KNOWN_URLS.containsKey($CUDA_VERSION_FULL)){ |
| 197 | + $CUDA_REPO_PKG_REMOTE=$CUDA_KNOWN_URLS[$CUDA_VERSION_FULL] |
| 198 | +} else{ |
| 199 | + # Guess what the url is given the most recent pattern (at the time of writing, 10.1) |
| 200 | + Write-Output "note: URL for CUDA ${$CUDA_VERSION_FULL} not known, taking an educated guess." |
| 201 | + $CUDA_REPO_PKG_REMOTE="http://developer.download.nvidia.com/compute/cuda/$($CUDA_MAJOR).$($CUDA_MINOR)/network_installers/cuda_$($CUDA_VERSION_FULL)_win10_network.exe" |
| 202 | +} |
| 203 | +$CUDA_REPO_PKG_LOCAL="cuda_$($CUDA_VERSION_FULL)_win10_network.exe" |
| 204 | + |
| 205 | + |
| 206 | +## ------------ |
| 207 | +## Install CUDA |
| 208 | +## ------------ |
| 209 | + |
| 210 | +# Get CUDA network installer |
| 211 | +Write-Output "Downloading CUDA Network Installer for $($CUDA_VERSION_FULL) from: $($CUDA_REPO_PKG_REMOTE)" |
| 212 | +Invoke-WebRequest $CUDA_REPO_PKG_REMOTE -OutFile $CUDA_REPO_PKG_LOCAL | Out-Null |
| 213 | +if(Test-Path -Path $CUDA_REPO_PKG_LOCAL){ |
| 214 | + Write-Output "Downloading Complete" |
| 215 | +} else { |
| 216 | + Write-Output "Error: Failed to download $($CUDA_REPO_PKG_LOCAL) from $($CUDA_REPO_PKG_REMOTE)" |
| 217 | + exit 1 |
| 218 | +} |
| 219 | + |
| 220 | +# Invoke silent install of CUDA (via network installer) |
| 221 | +Write-Output "Installing CUDA $($CUDA_VERSION_FULL). Subpackages $($CUDA_PACKAGES)" |
| 222 | +Start-Process -Wait -FilePath .\"$($CUDA_REPO_PKG_LOCAL)" -ArgumentList "-s $($CUDA_PACKAGES)" |
| 223 | + |
| 224 | +# Check the return status of the CUDA installer. |
| 225 | +if (!$?) { |
| 226 | + Write-Output "Error: CUDA installer reported error. $($LASTEXITCODE)" |
| 227 | + exit 1 |
| 228 | +} |
| 229 | + |
| 230 | +# Store the CUDA_PATH in the environment for the current session, to be forwarded in the action. |
| 231 | +$CUDA_PATH = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v$($CUDA_MAJOR).$($CUDA_MINOR)" |
| 232 | +$CUDA_PATH_VX_Y = "CUDA_PATH_V$($CUDA_MAJOR)_$($CUDA_MINOR)" |
| 233 | +$NVTOOLSEXT_PATH = "C:\Program Files\NVIDIA GPU Computing Toolkit\nvToolsExt" |
| 234 | +# Set environmental variables in this session |
| 235 | +$env:CUDA_PATH = "$($CUDA_PATH)" |
| 236 | +$env:CUDA_PATH_VX_Y = "$($CUDA_PATH_VX_Y)" |
| 237 | +$env:NVTOOLSEXT_PATH = "$($NVTOOLSEXT_PATH)" |
| 238 | +Write-Output "CUDA_PATH $($CUDA_PATH)" |
| 239 | +Write-Output "CUDA_PATH_VX_Y $($CUDA_PATH_VX_Y)" |
| 240 | +Write-Output "NVTOOLSEXT_PATH $($NVTOOLSEXT_PATH)" |
| 241 | + |
| 242 | +# PATH needs updating elsewhere, anything in here won't persist. |
| 243 | +# Append $CUDA_PATH/bin to path. |
| 244 | +# Set CUDA_PATH as an environmental variable |
| 245 | + |
| 246 | + |
| 247 | +# If executing on github actions, emit the appropriate echo statements to update environment variables |
| 248 | +if (Test-Path "env:GITHUB_ACTIONS") { |
| 249 | + # Set paths for subsequent steps, using $env:CUDA_PATH |
| 250 | + echo "Adding CUDA-related environment entries: CUDA_PATH, NVTOOLSEXT_PATH" |
| 251 | + echo "CUDA_PATH=$env:CUDA_PATH" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
| 252 | + echo "NVTOOLSEXT_PATH=$env:NVTOOLSEXT_PATH" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
| 253 | + echo "$env:CUDA_PATH_VX_Y=$env:CUDA_PATH" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
| 254 | + echo "$env:CUDA_PATH/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append |
| 255 | +} |
| 256 | + |
0 commit comments