Skip to content

Commit a1a2e91

Browse files
committed
[build] Only bundle CUDA DLLs that cv2.pyd actually needs
PE import analysis shows ~1.3 GB of CUDA toolkit DLLs bundled in the wheel are never referenced by cv2.pyd or its transitive dependencies. Switch from copying all CUDA bin/*.dll to an allowlist of only the DLLs that are actually linked: cublas, cublasLt, cudart, cufft, and the npp libraries.
1 parent 0faece6 commit a1a2e91

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

.github/workflows/build_wheels_windows.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ on:
2424
description: "Save build cache."
2525
required: false
2626
type: boolean
27-
default: true
27+
default: false
2828
rolling_build:
2929
description: "Use latest commit from upstream OpenCV repo. Cache settings will be ignored."
3030
required: false
@@ -124,7 +124,7 @@ jobs:
124124
echo "Adding CUDA to PATH..."
125125
$CUDA_PATH = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\${{ matrix.cuda-path-version }}"
126126
echo "CUDA_PATH=$CUDA_PATH" | Out-File -FilePath $env:GITHUB_ENV -Append
127-
Copy-Item -Path "$CUDA_PATH/bin/*" -Destination . -Include "*.dll"
127+
Copy-Item -Path "$CUDA_PATH\bin\*.dll" -Destination .
128128
shell: pwsh
129129
- name: 🔧 Install NVIDIA CuDNN
130130
run: |
@@ -162,6 +162,35 @@ jobs:
162162
restore-keys: |
163163
${{ runner.os }}-${{ matrix.python-version }}-cuda${{ matrix.cuda-version }}-
164164
165+
- name: Remove unused CUDA DLLs
166+
# Only bundle CUDA DLLs that cv2.pyd actually needs (determined via PE import analysis).
167+
# This removes ~1.3 GB of unused libraries (cusparse, cusolver, curand, nvrtc, etc.)
168+
run: |
169+
$keep = @(
170+
"cublas64_*", "cublasLt64_*", "cudart64_*", "cudnn*", "cufft64_*",
171+
"nppc64_*", "nppial64_*", "nppicc64_*", "nppidei64_*", "nppif64_*",
172+
"nppig64_*", "nppim64_*", "nppist64_*", "nppitc64_*"
173+
)
174+
# Remove from project root (where setup.py picks up *.dll)
175+
# and recursively from _skbuild (cmake-install and setuptools staging dirs)
176+
foreach ($dir in @(".", "_skbuild")) {
177+
Get-ChildItem -Path $dir -Filter "*.dll" -Recurse -ErrorAction SilentlyContinue | Where-Object {
178+
$name = $_.Name
179+
$is_cuda = $name -match '^\w+64_\d'
180+
$is_kept = $false
181+
foreach ($pattern in $keep) {
182+
if ($name -like $pattern) { $is_kept = $true; break }
183+
}
184+
$is_cuda -and -not $is_kept
185+
} | ForEach-Object {
186+
$size = [math]::Round($_.Length / 1MB)
187+
$rel = Resolve-Path -Relative $_.FullName
188+
echo "Removing $rel (${size} MB)"
189+
Remove-Item $_.FullName
190+
}
191+
}
192+
shell: pwsh
193+
165194
- name: Build a package
166195
# CMake 3.25 regression fix. See https://stackoverflow.com/questions/74162633/problem-compiling-from-source-opencv-with-mvsc2019-in-64-bit-version
167196
run: |

0 commit comments

Comments
 (0)