|
| 1 | +# Copyright (c) OpenMMLab. All rights reserved. |
| 2 | +# Adapted from https://github.com/thewh1teagle/vibe/blob/5d7b75568ca65ab635bdf0ce912bbc975a043066/scripts/setup_cuda.ps1 |
| 3 | + |
| 4 | +$CUDA_VERSION_FULL = $env:INPUT_CUDA_VERSION # v12.1.0 or v11.8.0 |
| 5 | + |
| 6 | +# Make sure CUDA_VERSION_FULL is set and valid, otherwise error. |
| 7 | +# Validate CUDA version, extracting components via regex |
| 8 | +$cuda_ver_matched = $CUDA_VERSION_FULL -match "^(?<major>[1-9][0-9]*)\.(?<minor>[0-9]+)\.(?<patch>[0-9]+)$" |
| 9 | +if(-not $cuda_ver_matched){ |
| 10 | + Write-Output "Invalid CUDA version specified, <major>.<minor>.<patch> required. '$CUDA_VERSION_FULL'." |
| 11 | + exit 1 |
| 12 | +} |
| 13 | +$CUDA_MAJOR=$Matches.major |
| 14 | +$CUDA_MINOR=$Matches.minor |
| 15 | +$CUDA_PATCH=$Matches.patch |
| 16 | + |
| 17 | +Write-Output "Selected CUDA version: $CUDA_VERSION_FULL" |
| 18 | + |
| 19 | +$src = "cuda" |
| 20 | +$dst = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v$($CUDA_MAJOR).$($CUDA_MINOR)" |
| 21 | +$installer = "cuda.exe" |
| 22 | + |
| 23 | +if ($CUDA_VERSION_FULL -eq "12.1.0") { |
| 24 | + $downloadUrl = "https://developer.download.nvidia.com/compute/cuda/12.1.0/local_installers/cuda_12.1.0_531.14_windows.exe" |
| 25 | +} elseif ($CUDA_VERSION_FULL -eq "11.8.0") { |
| 26 | + $downloadUrl = "https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_522.06_windows.exe" |
| 27 | +} else { |
| 28 | + Write-Output "Unsupported CUDA version specified" |
| 29 | + exit 1 |
| 30 | +} |
| 31 | + |
| 32 | +# Download cuda |
| 33 | +Write-Output "Downloading CUDA from: $downloadUrl" |
| 34 | +if (-not (Test-Path -Path $installer)) { |
| 35 | + Write-Output "Downloading CUDA installer..." |
| 36 | + # If the file does not exist, download it |
| 37 | + & "C:\msys64\usr\bin\wget" $downloadUrl -O $installer -q |
| 38 | +} |
| 39 | + |
| 40 | +# Extract cuda |
| 41 | +if (-not (Test-Path -Path $src -Type Container)) { |
| 42 | + # Extract CUDA using 7-Zip |
| 43 | + Write-Output "Extracting CUDA using 7-Zip..." |
| 44 | + mkdir "$src" |
| 45 | + & 'C:\Program Files\7-Zip\7z' x $installer -o"$src" |
| 46 | +} |
| 47 | + |
| 48 | +# Create destination directory if it doesn't exist |
| 49 | +if (-Not (Test-Path -Path $dst)) { |
| 50 | + Write-Output "Creating destination directory: $dst" |
| 51 | + New-Item -Path $dst -ItemType Directory |
| 52 | +} |
| 53 | + |
| 54 | +# Get directories to process from the source path |
| 55 | +$directories = Get-ChildItem -Directory -Path $src |
| 56 | +$whitelist = @("CUDA_Toolkit_Release_Notes.txt", "DOCS", "EULA.txt", "LICENSE", "README", "version.json") |
| 57 | + |
| 58 | +foreach ($dir in $directories) { |
| 59 | + # Get all subdirectories and files in the current directory |
| 60 | + $items = Get-ChildItem -Path (Join-Path $src $dir.Name) |
| 61 | + |
| 62 | + foreach ($item in $items) { |
| 63 | + if ($item.PSIsContainer) { |
| 64 | + # If the item is a directory, copy its contents |
| 65 | + Write-Output "Copying contents of directory $($item.FullName) to $dst" |
| 66 | + Copy-Item -Path "$($item.FullName)\*" -Destination $dst -Recurse -Force |
| 67 | + } else { |
| 68 | + if ($whitelist -contains $item.Name) { |
| 69 | + Write-Output "Copying file $($item.FullName) to $dst" |
| 70 | + Copy-Item -Path $item.FullName -Destination $dst -Force |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +# Add msbuild cuda extensions |
| 77 | +$msBuildExtensions = (Get-ChildItem "$src\visual_studio_integration\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions").fullname |
| 78 | +(Get-ChildItem 'C:\Program Files\Microsoft Visual Studio\2022\*\MSBuild\Microsoft\VC\*\BuildCustomizations').FullName | ForEach-Object { |
| 79 | + $destination = $_ |
| 80 | + $msBuildExtensions | ForEach-Object { |
| 81 | + $extension = $_ |
| 82 | + Copy-Item $extension -Destination $destination -Force |
| 83 | + Write-Output "Copied $extension to $destination" |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +# Add to Github env |
| 88 | +Write-Output "Setting environment variables for GitHub Actions..." |
| 89 | + |
| 90 | +Write-Output "CUDA_PATH=$dst" |
| 91 | +Write-Output "CUDA_PATH_V$($CUDA_MAJOR)_$($CUDA_MINOR)=$dst" |
| 92 | +Write-Output "CUDA_PATH_VX_Y=CUDA_PATH_V$($CUDA_MAJOR)_$($CUDA_MINOR)" |
| 93 | +Write-Output "CUDA_VERSION=$CUDA_VERSION_FULL" |
| 94 | + |
| 95 | +Write-Output "CUDA_PATH=$dst" >> $env:GITHUB_ENV |
| 96 | +Write-Output "CUDA_PATH_V$($CUDA_MAJOR)_$($CUDA_MINOR)=$dst" >> $env:GITHUB_ENV |
| 97 | +Write-Output "CUDA_PATH_VX_Y=CUDA_PATH_V$($CUDA_MAJOR)_$($CUDA_MINOR)" >> $env:GITHUB_ENV |
| 98 | +Write-Output "CudaToolkitDir=$dst" >> $env:GITHUB_ENV |
| 99 | +Write-Output "CMAKE_CUDA_COMPILER=$dst\bin\nvcc.exe" >> $env:GITHUB_ENV |
| 100 | +Write-Output "NVCC_APPEND_FLAGS=-allow-unsupported-compiler" >> $env:GITHUB_ENV |
| 101 | + |
| 102 | +Write-Output "CUDA_VERSION=$CUDA_VERSION_FULL" >> $env:GITHUB_ENV |
| 103 | +Write-Output "Setup completed." |
0 commit comments