Skip to content

Commit 06a0a19

Browse files
committed
[build] Add CUDA 12/13 build matrix with full GPU compatibility
1 parent 53658c8 commit 06a0a19

3 files changed

Lines changed: 103 additions & 29 deletions

File tree

.github/workflows/build_wheels_windows.yml

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ name: Windows CUDA x64
1212
on:
1313
workflow_dispatch:
1414
inputs:
15+
# TODO: Add cuda_version input to allow running only CUDA 12 or 13 builds for debugging
1516
# TODO: Right now we don't correctly determine when things have changed and we require a
1617
# rebuild, so for now we just manually trigger rebuilds between runs.
1718
restore_build_cache:
@@ -33,19 +34,44 @@ on:
3334

3435
jobs:
3536
Build:
36-
runs-on: windows-2025
37+
runs-on: ${{ matrix.runs-on }}
3738
strategy:
3839
fail-fast: false
3940
matrix:
4041
python-version: ['3.13']
4142
platform: [x64]
43+
cuda-version: ['12']
44+
include:
45+
# CUDA 12: Supports Maxwell (5.0) through Blackwell (10.0)
46+
- cuda-version: '12'
47+
runs-on: 'windows-2025'
48+
cuda-installer: 'cuda_12.9.1_windows_network.exe'
49+
cuda-path-version: 'v12.9'
50+
cudnn-archive: 'cudnn-windows-x86_64-9.18.1.3_cuda12-archive.zip'
51+
cudnn-folder: 'cudnn-windows-x86_64-9.18.1.3_cuda12-archive'
52+
cuda-arch-bin: '5.0;5.2;6.0;6.1;7.0;7.5;8.0;8.6;8.9;9.0;10.0'
53+
cuda-arch-ptx: '10.0'
54+
cache-key: 'nvidia-deps-cuda-12.9.1-cudnn-9.18.1.3'
55+
# TODO: Re-enable CUDA 13 after updating to OpenCV 4.13+
56+
# CUDA 13: Supports Turing (7.5) through Blackwell (12.0)
57+
# - cuda-version: '13'
58+
# runs-on: 'windows-2025'
59+
# cuda-installer: 'cuda_13.1.1_windows_network.exe'
60+
# cuda-path-version: 'v13.1'
61+
# cudnn-archive: 'cudnn-windows-x86_64-9.18.1.3_cuda13-archive.zip'
62+
# cudnn-folder: 'cudnn-windows-x86_64-9.18.1.3_cuda13-archive'
63+
# cuda-arch-bin: '7.5;8.0;8.6;8.9;9.0;10.0;12.0'
64+
# cuda-arch-ptx: '12.0'
65+
# cache-key: 'nvidia-deps-cuda-13.1.1-cudnn-9.18.1.3'
4266
env:
4367
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
4468
SDIST: 0
4569
ENABLE_HEADLESS: 0
4670
ENABLE_CONTRIB: 1
4771
ENABLE_ROLLING: ${{ inputs.rolling_build && 1 || 0 }}
4872
OPENCV_TEST_DATA_PATH: ${{ github.workspace }}\opencv_extra\testdata
73+
CUDA_ARCH_BIN: ${{ matrix.cuda-arch-bin }}
74+
CUDA_ARCH_PTX: ${{ matrix.cuda-arch-ptx }}
4975
steps:
5076
- name: Cleanup
5177
shell: bash
@@ -72,7 +98,7 @@ jobs:
7298
uses: actions/cache@v3
7399
with:
74100
path: .deps/Nvidia
75-
key: nvidia-deps-cuda-12.4.0-cudnn-8.9.7.29
101+
key: ${{ matrix.cache-key }}
76102
- name: Clone NVIDIA dependencies
77103
if: steps.cache-nvidia-deps.outputs.cache-hit != 'true'
78104
env:
@@ -85,27 +111,26 @@ jobs:
85111
shell: bash
86112
- name: 🔧 Install NVIDIA CUDA Toolkit
87113
run: |
88-
$installer_path = ".deps/Nvidia/cuda_12.4.0_windows_network.exe"
114+
$installer_path = ".deps/Nvidia/${{ matrix.cuda-installer }}"
89115
if (-not (Test-Path $installer_path)) {
90116
throw "CUDA Toolkit installer not found at $installer_path"
91117
}
92-
echo "Installing CUDA Toolkit silently..."
93-
$arguments = "-s nvcc_12.4 cudart_12.4 cublas_12.4 cublas_dev_12.4 cufft_12.4 cufft_dev_12.4 npp_12.4 npp_dev_12.4"
94-
Start-Process -FilePath $installer_path -ArgumentList $arguments -Wait -NoNewWindow
118+
echo "Installing CUDA ${{ matrix.cuda-version }} Toolkit silently..."
119+
Start-Process -FilePath $installer_path -ArgumentList "-s" -Wait -NoNewWindow
95120
echo "Adding CUDA to PATH..."
96-
$CUDA_PATH = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4"
121+
$CUDA_PATH = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\${{ matrix.cuda-path-version }}"
97122
echo "CUDA_PATH=$CUDA_PATH" | Out-File -FilePath $env:GITHUB_ENV -Append
98123
Copy-Item -Path "$CUDA_PATH/bin/*" -Destination . -Include "*.dll"
99124
shell: pwsh
100125
- name: 🔧 Install NVIDIA CuDNN
101126
run: |
102-
$cudnn_path = ".deps/Nvidia/cudnn-windows-x86_64-8.9.7.29_cuda12-archive.zip"
127+
$cudnn_path = ".deps/Nvidia/${{ matrix.cudnn-archive }}"
103128
if (-not (Test-Path $cudnn_path)) {
104129
throw "CuDNN archive not found at $cudnn_path"
105130
}
106-
echo "Installing CuDNN..."
131+
echo "Installing CuDNN for CUDA ${{ matrix.cuda-version }}..."
107132
7z x $cudnn_path
108-
$CUDNN_PATH = "D:/a/opencv-python-cuda/opencv-python-cuda/cudnn-windows-x86_64-8.9.7.29_cuda12-archive"
133+
$CUDNN_PATH = "D:/a/opencv-python-cuda/opencv-python-cuda/${{ matrix.cudnn-folder }}"
109134
echo "CUDNN_LIBRARY=$CUDNN_PATH/lib/x64/cudnn.lib" | Out-File -FilePath $env:GITHUB_ENV -Append
110135
echo "CUDNN_INCLUDE_DIR=$CUDNN_PATH/include" | Out-File -FilePath $env:GITHUB_ENV -Append
111136
Copy-Item -Path "$CUDNN_PATH/bin/*" -Destination . -Include "*.dll"
@@ -116,9 +141,9 @@ jobs:
116141
if: ${{ inputs.restore_build_cache && !inputs.rolling_build }}
117142
with:
118143
path: _skbuild
119-
key: ${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/CMakeLists.txt') }}
144+
key: ${{ runner.os }}-${{ matrix.python-version }}-cuda${{ matrix.cuda-version }}-${{ hashFiles('**/CMakeLists.txt') }}
120145
restore-keys: |
121-
${{ runner.os }}-${{ matrix.python-version }}-
146+
${{ runner.os }}-${{ matrix.python-version }}-cuda${{ matrix.cuda-version }}-
122147
123148
- name: Build a package
124149
# CMake 3.25 regression fix. See https://stackoverflow.com/questions/74162633/problem-compiling-from-source-opencv-with-mvsc2019-in-64-bit-version
@@ -140,11 +165,11 @@ jobs:
140165
if: ${{ inputs.save_build_cache && !inputs.rolling_build }}
141166
with:
142167
path: _skbuild
143-
key: ${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/CMakeLists.txt') }}
168+
key: ${{ runner.os }}-${{ matrix.python-version }}-cuda${{ matrix.cuda-version }}-${{ hashFiles('**/CMakeLists.txt') }}
144169
- name: Saving all wheels
145170
uses: actions/upload-artifact@v4
146171
with:
147-
name: wheel-cuda-${{ matrix.platform }}
172+
name: wheel-cuda${{ matrix.cuda-version }}-${{ matrix.platform }}
148173
path: wheelhouse/opencv*
149174

150175
Test:
@@ -158,6 +183,7 @@ jobs:
158183
matrix:
159184
python-version: ['3.12']
160185
platform: [x64]
186+
cuda-version: ['12'] # TODO: Re-enable '13' after updating to OpenCV 4.13+
161187
env:
162188
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
163189
OPENCV_TEST_DATA_PATH: ${{ github.workspace }}\opencv_extra\testdata
@@ -182,7 +208,7 @@ jobs:
182208
- name: Download a wheel accordingly to matrix
183209
uses: actions/download-artifact@v4
184210
with:
185-
name: wheel-cuda-${{ matrix.platform }}
211+
name: wheel-cuda${{ matrix.cuda-version }}-${{ matrix.platform }}
186212
path: wheelhouse/
187213
- name: Package installation
188214
run: |
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Simple workflow to cache NVIDIA dependencies
2+
# Run this once to populate the cache, then disable or delete
3+
4+
name: Cache NVIDIA Dependencies
5+
6+
on:
7+
workflow_dispatch:
8+
9+
jobs:
10+
cache-deps:
11+
runs-on: windows-2025
12+
strategy:
13+
matrix:
14+
include:
15+
- cuda-version: '12'
16+
cache-key: 'nvidia-deps-cuda-12.9.1-cudnn-9.18.1.3'
17+
- cuda-version: '13'
18+
cache-key: 'nvidia-deps-cuda-13.1.1-cudnn-9.18.1.3'
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
submodules: false
24+
fetch-depth: 1
25+
- name: Cache NVIDIA dependencies (CUDA ${{ matrix.cuda-version }})
26+
id: cache-nvidia-deps
27+
uses: actions/cache@v3
28+
with:
29+
path: .deps/Nvidia
30+
key: ${{ matrix.cache-key }}
31+
- name: Clone NVIDIA dependencies
32+
if: steps.cache-nvidia-deps.outputs.cache-hit != 'true'
33+
env:
34+
SSH_PRIVATE_KEY: ${{ secrets.DEPS_REPO_SSH_KEY }}
35+
run: |
36+
eval "$(ssh-agent -s)"
37+
ssh-add - <<< "${SSH_PRIVATE_KEY}"
38+
ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null
39+
git clone git@github.com:Breakthrough/opencv-python-cuda-deps.git .deps
40+
shell: bash
41+
- name: Cache populated
42+
run: |
43+
echo "NVIDIA dependencies for CUDA ${{ matrix.cuda-version }} cached successfully!"
44+
ls -la .deps/Nvidia/ || echo "Cache was already populated"
45+
shell: bash

setup.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,14 @@ def main():
2222
build_java = "ON" if get_build_env_var_by_name("java") else "OFF"
2323
build_rolling = get_build_env_var_by_name("rolling")
2424

25-
# TODO(@Breakthrough): What architectures should we ship?
26-
# fermi = "2.0"
27-
# kepler = "3.0;3.5;3.7"
28-
# maxwell = "5.0;5.2"
29-
# pascal = "6.0;6.1"
30-
# volta = "7.0"
31-
# turing = "7.5"
32-
# ampere = "8.0;8.6"
33-
# lovelace = "8.9"
34-
# hopper = "9.0"
35-
# blackwell = "10.0;12.0"
36-
cuda_arch_bin = "5.0;5.2;6.0;6.1;7.0;7.5,8.0"
37-
cuda_arch_ptx = "8.0"
25+
# CUDA architecture configuration - can be overridden via environment variables
26+
# CUDA 12.x supports: 5.0+ (Maxwell through Hopper)
27+
# CUDA 13.x supports: 7.5+ (Turing through Hopper)
28+
# Reference architectures:
29+
# maxwell=5.0;5.2, pascal=6.0;6.1, volta=7.0, turing=7.5,
30+
# ampere=8.0;8.6, lovelace=8.9, hopper=9.0
31+
cuda_arch_bin = os.environ.get("CUDA_ARCH_BIN", "7.5;8.0;8.6;8.9;9.0")
32+
cuda_arch_ptx = os.environ.get("CUDA_ARCH_PTX", "9.0")
3833

3934
# NOTE: since 2.3.0 numpy upgraded from manylinux2014 to manylinux_2_28
4035
# see https://numpy.org/doc/stable/release/2.3.0-notes.html#numpy-2-3-0-release-notes
@@ -159,7 +154,7 @@ def main():
159154
files_outside_package_dir = {"cv2": ["LICENSE.txt", "LICENSE-3RD-PARTY.txt","*.dll"]}
160155

161156
ci_cmake_generator = (
162-
["-G", "Visual Studio 17 2022"]
157+
["-G", "Visual Studio 17 2022", "-T", "v143"]
163158
if os.name == "nt"
164159
else ["-G", "Unix Makefiles"]
165160
)
@@ -203,6 +198,14 @@ def main():
203198
f"-DCUDNN_LIBRARY={cudnn_library}",
204199
f"-DCUDNN_INCLUDE_DIR={cudnn_include_dir}",
205200
]
201+
+ (
202+
# CUDA 12.9+ requires MSVC's conformant preprocessor for CCCL headers.
203+
# -Xcompiler passes the flag from nvcc to the host compiler (MSVC).
204+
# See: https://github.com/NVIDIA/cccl/issues/5166
205+
["-DCUDA_NVCC_FLAGS=-Xcompiler /Zc:preprocessor"]
206+
if sys.platform == "win32"
207+
else []
208+
)
206209
+ (
207210
# CMake flags for windows/arm64 build
208211
["-DCMAKE_GENERATOR_PLATFORM=ARM64",

0 commit comments

Comments
 (0)