Skip to content

Commit 8fec552

Browse files
committed
[dist] Build module with CUDA enabled
1 parent ba84fb8 commit 8fec552

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

.github/workflows/build_wheels_windows.yml

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
name: Windows x86_64
1+
# GitHub Actions Workflow: Build opencv-python with CUDA support on Windows
2+
#
3+
# This workflow compiles opencv-python from source with CUDA enabled on a
4+
# GitHub-hosted Windows runner. The resulting Python wheel is then uploaded
5+
# as a build artifact.
6+
#
7+
# This is a complex and long-running process. It is configured to run only
8+
# on manual trigger (workflow_dispatch).
9+
10+
name: Windows CUDA x64
211

312
on:
413
workflow_dispatch:
@@ -48,6 +57,58 @@ jobs:
4857
uses: microsoft/setup-msbuild@v1.1
4958
- name: Setup NASM
5059
uses: ilammy/setup-nasm@v1
60+
- name: Cache CUDA Toolkit Installer
61+
id: cache-cuda-installer
62+
uses: actions/cache@v3
63+
with:
64+
path: ./.cache/cuda_installer.exe
65+
key: cuda-installer-12.0.0
66+
- name: 🔧 Install NVIDIA CUDA Toolkit
67+
run: |
68+
$installer_path = "./.cache/cuda_installer.exe"
69+
if (-not (Test-Path $installer_path)) {
70+
echo "Downloading CUDA Toolkit..."
71+
$cuda_installer_url = "https://developer.download.nvidia.com/compute/cuda/12.0.0/network_installers/cuda_12.0.0_windows_network.exe"
72+
New-Item -Path (Split-Path $installer_path) -ItemType Directory -Force
73+
curl -L -o $installer_path $cuda_installer_url
74+
} else {
75+
echo "CUDA Toolkit installer found in cache."
76+
}
77+
echo "Installing CUDA Toolkit silently..."
78+
$arguments = "-s nvcc_12.0 cudart_12.0"
79+
Start-Process -FilePath $installer_path -ArgumentList $arguments -Wait -NoNewWindow
80+
echo "Adding CUDA to PATH..."
81+
$CUDA_PATH = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.0"
82+
echo "CUDA_PATH=$CUDA_PATH" | Out-File -FilePath $env:GITHUB_ENV -Append
83+
echo "$CUDA_PATH\bin" | Out-File -FilePath $env:GITHUB_PATH -Append
84+
echo "$CUDA_PATH\lib\x64" | Out-File -FilePath $env:GITHUB_PATH -Append
85+
echo "$CUDA_PATH"
86+
shell: pwsh
87+
- name: Cache CuDNN Installer
88+
id: cache-cudnn-installer
89+
uses: actions/cache@v3
90+
with:
91+
path: ./.cache/cudnn_installer.exe
92+
key: cudnn-installer-8.8.0.121-windows
93+
- name: 🔧 Install NVIDIA CuDNN
94+
run: |
95+
$installer_path = "./.cache/cudnn_installer.exe"
96+
if (-not (Test-Path $installer_path)) {
97+
echo "Downloading CuDNN..."
98+
$cudnn_installer_url = "https://developer.download.nvidia.com/compute/redist/cudnn/v8.8.0/local_installers/12.0/cudnn_8.8.0.121_windows.exe"
99+
New-Item -Path (Split-Path $installer_path) -ItemType Directory -Force
100+
curl -L -o $installer_path $cudnn_installer_url
101+
} else {
102+
echo "CuDNN installer found in cache."
103+
}
104+
echo "Installing CuDNN silently..."
105+
# The CuDNN local installer for Windows is a self-extracting executable.
106+
# We assume it installs to the correct CUDA Toolkit directory.
107+
# We use -s for silent installation.
108+
Start-Process -FilePath $installer_path -ArgumentList "-s" -Wait -NoNewWindow
109+
# TODO: Set CUDNN_LIBRARY CUDNN_INCLUDE_DIR so the build works correctly.
110+
shell: pwsh
111+
51112
- name: Build a package
52113
# CMake 3.25 regression fix. See https://stackoverflow.com/questions/74162633/problem-compiling-from-source-opencv-with-mvsc2019-in-64-bit-version
53114
run: |

setup.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ def main():
8686
if build_headless and not build_contrib:
8787
package_name = "opencv-python-headless"
8888

89-
if build_rolling:
90-
package_name += "-rolling"
89+
#if build_rolling:
90+
# package_name += "-rolling"
9191

9292
package_name = os.environ.get('OPENCV_PYTHON_PACKAGE_NAME', package_name)
9393

@@ -189,6 +189,10 @@ def main():
189189
"-DBUILD_DOCS=OFF",
190190
"-DPYTHON3_LIMITED_API=ON",
191191
"-DBUILD_OPENEXR=ON",
192+
"-DWITH_CUDA=ON",
193+
"-DCUDA_ARCH_BIN=\"6.0;6.1;7.0;7.5\"",
194+
"-DCUDA_ARCH_PTX=\"7.5\"",
195+
"-DOPENCV_ENABLE_NONFREE=ON",
192196
]
193197
+ (
194198
# CMake flags for windows/arm64 build

0 commit comments

Comments
 (0)