Skip to content

Commit b2e730e

Browse files
authored
misc: replace slow Jimver/cuda-toolkit (#2065)
* misc: replace slow Jimver/cuda-toolkit * add copyright
1 parent 0d600d2 commit b2e730e

File tree

4 files changed

+118
-12
lines changed

4 files changed

+118
-12
lines changed

.github/workflows/cuda11.8-whl-release.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ jobs:
6767
- name: Install python packages
6868
run: |
6969
pip install pybind11 wheel
70-
- uses: Jimver/[email protected]
70+
- name: Setup CUDA Toolkit
7171
id: cuda-toolkit
72-
with:
73-
cuda: '11.8.0'
74-
use-github-cache: false
72+
shell: pwsh
73+
run: ./builder/windows/setup_cuda.ps1
74+
env:
75+
INPUT_CUDA_VERSION: '11.8.0'
7576
- name: Build wheel
7677
run: |
7778
mkdir build

.github/workflows/pypi.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ jobs:
6666
- name: Install python packages
6767
run: |
6868
pip install pybind11 wheel
69-
- uses: Jimver/[email protected]
69+
- name: Setup CUDA Toolkit
7070
id: cuda-toolkit
71-
with:
72-
cuda: '12.1.0'
73-
use-github-cache: false
71+
shell: pwsh
72+
run: ./builder/windows/setup_cuda.ps1
73+
env:
74+
INPUT_CUDA_VERSION: '12.1.0'
7475
- name: Build wheel
7576
run: |
7677
mkdir build

.github/workflows/windows-x64-gpu.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ jobs:
4141
- name: Install python packages
4242
run: |
4343
pip install pybind11 wheel
44-
- uses: Jimver/[email protected]
44+
- name: Setup CUDA Toolkit
4545
id: cuda-toolkit
46-
with:
47-
cuda: ${{ matrix.cudaver }}
48-
use-github-cache: false
46+
shell: pwsh
47+
run: ./builder/windows/setup_cuda.ps1
48+
env:
49+
INPUT_CUDA_VERSION: ${{ matrix.cudaver }}
4950
- name: Build wheel
5051
run: |
5152
$env:BUILD_TEST="ON"

builder/windows/setup_cuda.ps1

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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

Comments
 (0)