Skip to content

Commit 28fed84

Browse files
committed
[dist] Build module with CUDA enabled
1 parent ba84fb8 commit 28fed84

2 files changed

Lines changed: 70 additions & 3 deletions

File tree

.github/workflows/build_wheels_windows.yml

Lines changed: 63 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,59 @@ 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 cublas_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+
ls $CUDA_PATH
83+
echo "CUDA_PATH=$CUDA_PATH" | Out-File -FilePath $env:GITHUB_ENV -Append
84+
#echo "$CUDA_PATH\bin" | Out-File -FilePath $env:GITHUB_PATH -Append
85+
#echo "$CUDA_PATH\lib\x64" | Out-File -FilePath $env:GITHUB_PATH -Append
86+
#echo "$CUDA_PATH"
87+
shell: pwsh
88+
- name: Cache CuDNN Installer
89+
id: cache-cudnn-installer
90+
uses: actions/cache@v3
91+
with:
92+
path: ./.cache/cudnn.zip
93+
key: cudnn-8.9.7.29-cuda-12-windows
94+
- name: 🔧 Install NVIDIA CuDNN
95+
run: |
96+
$cudnn_path = "./.cache/cudnn.zip"
97+
if (-not (Test-Path $cudnn_path)) {
98+
echo "Downloading CuDNN..."
99+
$cudnn_installer_url = "https://developer.download.nvidia.com/compute/cudnn/redist/cudnn/windows-x86_64/cudnn-windows-x86_64-8.9.7.29_cuda12-archive.zip"
100+
New-Item -Path (Split-Path $cudnn_path) -ItemType Directory -Force
101+
curl -L -o $cudnn_path $cudnn_installer_url
102+
} else {
103+
echo "CuDNN installer found in cache."
104+
}
105+
echo "Installing CuDNN..."
106+
7z x $cudnn_path
107+
$CUDNN_PATH = "/a/opencv-python-cuda/opencv-python-cuda/cudnn-windows-x86_64-8.9.7.29_cuda12-archive"
108+
ls $CUDNN_PATH
109+
echo "CUDNN_LIBRARY=$CUDNN_PATH/lib/x64" | Out-File -FilePath $env:GITHUB_ENV -Append
110+
echo "CUDNN_INCLUDE_DIR=$CUDNN_PATH/include" | Out-File -FilePath $env:GITHUB_ENV -Append
111+
shell: pwsh
112+
51113
- name: Build a package
52114
# CMake 3.25 regression fix. See https://stackoverflow.com/questions/74162633/problem-compiling-from-source-opencv-with-mvsc2019-in-64-bit-version
53115
run: |

setup.py

Lines changed: 7 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,11 @@ def main():
189189
"-DBUILD_DOCS=OFF",
190190
"-DPYTHON3_LIMITED_API=ON",
191191
"-DBUILD_OPENEXR=ON",
192+
"-DWITH_CUDA=ON",
193+
"-DWITH_NVCUVID=OFF",
194+
"-DCUDA_ARCH_BIN=\"6.0;6.1;7.0;7.5\"",
195+
"-DCUDA_ARCH_PTX=\"7.5\"",
196+
"-DOPENCV_ENABLE_NONFREE=ON",
192197
]
193198
+ (
194199
# CMake flags for windows/arm64 build

0 commit comments

Comments
 (0)