Skip to content

Commit d2113a1

Browse files
authored
feat(ci): re-enable Windows CUDA wheels (abetlen#2198)
* feat(ci): re-enable Windows CUDA wheel builds * fix(ci): use ninja for Windows CUDA wheels * fix(ci): normalize Windows CUDA CMake paths * feat(ci): add CUDA 12.5 wheel builds * fix(ci): avoid Windows CUDA 12.5 toolkit meta-package * fix(ci): include CUDA 12.5 Windows libraries * chore(ci): simplify Windows CUDA wheel workflow * docs: update changelog for Windows CUDA wheels
1 parent 587d94a commit d2113a1

2 files changed

Lines changed: 69 additions & 65 deletions

File tree

.github/workflows/build-wheels-cuda.yaml

Lines changed: 68 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ jobs:
2020
id: set-matrix
2121
run: |
2222
$matrix = @{
23-
'os' = @('ubuntu-22.04') #, 'windows-2022')
24-
'pyver' = @("3.9", "3.10", "3.11", "3.12")
25-
'cuda' = @("12.1.1", "12.2.2", "12.3.2", "12.4.1") #, "12.5.1", "12.6.1")
23+
'os' = @('ubuntu-22.04', 'windows-2022')
24+
# wheel.py-api = "py3" makes the CUDA wheel interpreter-agnostic,
25+
# so one builder per toolkit version is sufficient.
26+
'pyver' = @("3.9")
27+
'cuda' = @("12.1.1", "12.2.2", "12.3.2", "12.4.1", "12.5.1")
2628
'releasetag' = @("basic")
2729
}
2830
@@ -43,11 +45,11 @@ jobs:
4345
AVXVER: ${{ matrix.releasetag }}
4446

4547
steps:
46-
- name: Add MSBuild to PATH
48+
- name: Set up MSVC
4749
if: runner.os == 'Windows'
48-
uses: microsoft/setup-msbuild@v2
50+
uses: ilammy/msvc-dev-cmd@v1
4951
with:
50-
vs-version: '[16.11,16.12)'
52+
arch: x64
5153

5254
- uses: actions/checkout@v4
5355
with:
@@ -67,32 +69,6 @@ jobs:
6769
add-pip-as-python-dependency: true
6870
auto-activate-base: false
6971

70-
- name: VS Integration Cache
71-
id: vs-integration-cache
72-
if: runner.os == 'Windows'
73-
uses: actions/cache@v4
74-
with:
75-
path: ./MSBuildExtensions
76-
key: cuda-${{ matrix.cuda }}-vs-integration
77-
78-
- name: Get Visual Studio Integration
79-
if: runner.os == 'Windows' && steps.vs-integration-cache.outputs.cache-hit != 'true'
80-
run: |
81-
if ($env:CUDAVER -eq '12.1.1') {$x = '12.1.0'} else {$x = $env:CUDAVER}
82-
$links = (Invoke-RestMethod 'https://raw.githubusercontent.com/Jimver/cuda-toolkit/master/src/links/windows-links.ts').Trim().split().where({$_ -ne ''})
83-
for ($i=$q=0;$i -lt $links.count -and $q -lt 2;$i++) {if ($links[$i] -eq "'$x',") {$q++}}
84-
Invoke-RestMethod $links[$i].Trim("'") -OutFile 'cudainstaller.zip'
85-
& 'C:\Program Files\7-Zip\7z.exe' e cudainstaller.zip -oMSBuildExtensions -r *\MSBuildExtensions\* > $null
86-
Remove-Item 'cudainstaller.zip'
87-
88-
- name: Install Visual Studio Integration
89-
if: runner.os == 'Windows'
90-
run: |
91-
$y = (gi '.\MSBuildExtensions').fullname + '\*'
92-
(gi 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VC\*\BuildCustomizations').fullname.foreach({cp $y $_})
93-
$cupath = 'CUDA_PATH_V' + $env:CUDAVER.Remove($env:CUDAVER.LastIndexOf('.')).Replace('.','_')
94-
echo "$cupath=$env:CONDA_PREFIX" >> $env:GITHUB_ENV
95-
9672
- name: Install Dependencies
9773
env:
9874
MAMBA_DOWNLOAD_FAILFAST: "0"
@@ -101,52 +77,87 @@ jobs:
10177
$cudaVersion = $env:CUDAVER
10278
$cudaChannel = "nvidia/label/cuda-$cudaVersion"
10379
if ($IsLinux) {
104-
# Keep nvcc, cudart, and headers on the same NVIDIA label so the
105-
# detected toolkit version matches the published wheel tag.
106-
mamba install -y --channel-priority flexible --override-channels -c $cudaChannel "$cudaChannel::cuda-toolkit=$cudaVersion" "$cudaChannel::cuda-nvcc_linux-64=$cudaVersion" "$cudaChannel::cuda-cudart" "$cudaChannel::cuda-cudart-dev"
80+
mamba install -y --channel-priority flexible --override-channels -c $cudaChannel "${cudaChannel}::cuda-toolkit=$cudaVersion" "${cudaChannel}::cuda-nvcc_linux-64" "${cudaChannel}::cuda-cudart" "${cudaChannel}::cuda-cudart-dev"
81+
} elseif ($IsWindows) {
82+
if ($cudaVersion -like '12.5.*') {
83+
# The Windows 12.5 toolkit meta-package pulls compiler activation
84+
# scripts that overflow cmd.exe after MSVC is already initialized.
85+
mamba install -y --channel-priority flexible --override-channels -c $cudaChannel "${cudaChannel}::cuda-nvcc_win-64" "${cudaChannel}::cuda-libraries-dev=$cudaVersion" "${cudaChannel}::cuda-cudart" "${cudaChannel}::cuda-cudart-dev"
86+
} else {
87+
mamba install -y --channel-priority flexible --override-channels -c $cudaChannel "${cudaChannel}::cuda-toolkit=$cudaVersion" "${cudaChannel}::cuda-nvcc_win-64" "${cudaChannel}::cuda-cudart" "${cudaChannel}::cuda-cudart-dev"
88+
}
10789
} else {
108-
mamba install -y --channel-priority flexible --override-channels -c $cudaChannel "$cudaChannel::cuda-toolkit=$cudaVersion"
90+
throw 'Unsupported CUDA wheel build platform'
10991
}
11092
if ($LASTEXITCODE -ne 0) {
11193
exit $LASTEXITCODE
11294
}
113-
python -m pip install build wheel
95+
if ($IsWindows) {
96+
python -m pip install build wheel ninja
97+
} else {
98+
python -m pip install build wheel
99+
}
114100
115101
- name: Build Wheel
116102
run: |
117-
$env:CUDA_PATH = $env:CONDA_PREFIX
118-
$env:CUDA_HOME = $env:CONDA_PREFIX
119-
$env:CUDA_TOOLKIT_ROOT_DIR = $env:CONDA_PREFIX
103+
$pathSeparator = if ($IsWindows) { ';' } else { ':' }
104+
if ($IsWindows) {
105+
$cudaRoot = Join-Path $env:CONDA_PREFIX 'Library'
106+
} elseif (Test-Path (Join-Path $env:CONDA_PREFIX 'targets/x86_64-linux/include/cuda_runtime.h')) {
107+
$cudaRoot = Join-Path $env:CONDA_PREFIX 'targets/x86_64-linux'
108+
} else {
109+
$cudaRoot = $env:CONDA_PREFIX
110+
}
111+
112+
$env:CUDA_PATH = $cudaRoot
113+
$env:CUDA_HOME = $cudaRoot
114+
$env:CUDAToolkit_ROOT = $cudaRoot
115+
$env:CUDA_TOOLKIT_ROOT_DIR = $cudaRoot
120116
$cudaHostCompilerArg = ''
121-
$env:CMAKE_ARGS = ''
117+
$cudaRootCmake = $cudaRoot.Replace('\', '/')
118+
$env:CMAKE_ARGS = "-DCUDAToolkit_ROOT=$cudaRootCmake -DCUDA_TOOLKIT_ROOT_DIR=$cudaRootCmake"
122119
if ($IsLinux) {
123120
if (Test-Path '/usr/bin/g++-12') {
124121
$env:CC = '/usr/bin/gcc-12'
125122
$env:CXX = '/usr/bin/g++-12'
126123
$env:CUDAHOSTCXX = '/usr/bin/g++-12'
127124
$cudaHostCompilerArg = " -DCMAKE_CUDA_HOST_COMPILER=$env:CUDAHOSTCXX"
128125
}
129-
if (Test-Path (Join-Path $env:CONDA_PREFIX 'include/cuda_runtime.h')) {
130-
$env:CUDAToolkit_ROOT = $env:CONDA_PREFIX
131-
$env:CUDA_TOOLKIT_ROOT_DIR = $env:CONDA_PREFIX
132-
$env:CMAKE_ARGS = "-DCUDAToolkit_ROOT=$env:CONDA_PREFIX -DCUDA_TOOLKIT_ROOT_DIR=$env:CONDA_PREFIX$cudaHostCompilerArg"
133-
$env:CPATH = "$env:CONDA_PREFIX/include:$env:CPATH"
134-
$env:CPLUS_INCLUDE_PATH = "$env:CONDA_PREFIX/include:$env:CPLUS_INCLUDE_PATH"
135-
$env:LIBRARY_PATH = "$env:CONDA_PREFIX/lib:$env:LIBRARY_PATH"
136-
$env:LD_LIBRARY_PATH = "$env:CONDA_PREFIX/lib:$env:LD_LIBRARY_PATH"
137-
} else {
138-
$env:CMAKE_ARGS = $cudaHostCompilerArg.Trim()
139-
}
126+
$env:CMAKE_ARGS = "-DCUDAToolkit_ROOT=$cudaRoot -DCUDA_TOOLKIT_ROOT_DIR=$cudaRoot$cudaHostCompilerArg"
127+
$env:CPATH = "$cudaRoot/include$pathSeparator$env:CPATH"
128+
$env:CPLUS_INCLUDE_PATH = "$cudaRoot/include$pathSeparator$env:CPLUS_INCLUDE_PATH"
129+
$env:LIBRARY_PATH = "$cudaRoot/lib$pathSeparator$env:CONDA_PREFIX/lib$pathSeparator$env:LIBRARY_PATH"
130+
$env:LD_LIBRARY_PATH = "$cudaRoot/lib$pathSeparator$env:CONDA_PREFIX/lib$pathSeparator$env:LD_LIBRARY_PATH"
131+
} elseif ($IsWindows) {
132+
$ninjaPath = ((Get-Command ninja -ErrorAction Stop).Source).Replace('\', '/')
133+
$env:CMAKE_GENERATOR = 'Ninja'
134+
$env:CMAKE_MAKE_PROGRAM = $ninjaPath
135+
$env:PATH = "$(Join-Path $cudaRoot 'bin')$pathSeparator$env:PATH"
140136
}
141-
$nvccPath = Join-Path $env:CONDA_PREFIX 'bin/nvcc'
142-
if (-not (Test-Path $nvccPath)) {
143-
$nvccPath = Join-Path $env:CONDA_PREFIX 'targets/x86_64-linux/bin/nvcc'
137+
138+
if ($IsWindows) {
139+
$nvccCandidates = @(
140+
(Join-Path $cudaRoot 'bin\nvcc.exe'),
141+
(Join-Path $env:CONDA_PREFIX 'Library\bin\nvcc.exe'),
142+
(Join-Path $env:CONDA_PREFIX 'bin\nvcc.exe')
143+
)
144+
} else {
145+
$nvccCandidates = @(
146+
(Join-Path $env:CONDA_PREFIX 'bin/nvcc'),
147+
(Join-Path $env:CONDA_PREFIX 'targets/x86_64-linux/bin/nvcc')
148+
)
144149
}
145-
if (-not (Test-Path $nvccPath)) {
150+
$nvccPath = $nvccCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1
151+
if (-not $nvccPath) {
146152
throw 'Failed to find nvcc in the conda environment'
147153
}
148154
$env:CUDACXX = $nvccPath
149-
$env:PATH = "$(Split-Path $nvccPath):$env:PATH"
155+
$env:PATH = "$(Split-Path $nvccPath)$pathSeparator$env:PATH"
156+
if ($IsWindows) {
157+
$nvccPathCmake = $nvccPath.Replace('\', '/')
158+
$env:CUDACXX = $nvccPathCmake
159+
$env:CMAKE_ARGS = "-DCMAKE_CUDA_COMPILER=$nvccPathCmake -DCMAKE_MAKE_PROGRAM=$env:CMAKE_MAKE_PROGRAM $env:CMAKE_ARGS"
160+
}
150161
$nvccVersion = ((& $nvccPath --version) | Select-String 'release ([0-9]+\.[0-9]+)').Matches[0].Groups[1].Value
151162
if (-not $nvccVersion) {
152163
throw 'Failed to detect the installed CUDA toolkit version'
@@ -157,15 +168,7 @@ jobs:
157168
# one forward-compatible PTX target instead of embedding PTX for every
158169
# SM. This keeps the wheel under GitHub's 2 GiB release-asset limit.
159170
$env:CMAKE_ARGS = "-DGGML_CUDA_FORCE_MMQ=ON -DGGML_CUDA=on -DCMAKE_CUDA_ARCHITECTURES=70-real;75-real;80-real;86-real;89-real;90-real;90-virtual -DCMAKE_CUDA_FLAGS=--allow-unsupported-compiler $env:CMAKE_ARGS"
160-
# if ($env:AVXVER -eq 'AVX') {
161171
$env:CMAKE_ARGS = $env:CMAKE_ARGS + ' -DGGML_AVX2=off -DGGML_FMA=off -DGGML_F16C=off'
162-
# }
163-
# if ($env:AVXVER -eq 'AVX512') {
164-
# $env:CMAKE_ARGS = $env:CMAKE_ARGS + ' -DGGML_AVX512=on'
165-
# }
166-
# if ($env:AVXVER -eq 'basic') {
167-
# $env:CMAKE_ARGS = $env:CMAKE_ARGS + ' -DGGML_AVX=off -DGGML_AVX2=off -DGGML_FMA=off -DGGML_F16C=off'
168-
# }
169172
python -m build --wheel
170173
# Publish tags that reflect the actual installed toolkit version.
171174
Write-Output "CUDA_VERSION=$cudaTagVersion" >> $env:GITHUB_ENV

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010
- feat: Update llama.cpp to ggerganov/llama.cpp@63d93d173
11+
- feat(ci): Re-enable Windows CUDA wheels and add CUDA 12.5.1 wheel builds
1112

1213
## [0.3.21]
1314

0 commit comments

Comments
 (0)