Skip to content

Commit 4e12596

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 4e12596

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

.github/workflows/build_wheels_windows.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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,30 @@ 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_*", "cufft64_*",
171+
"nppc64_*", "nppial64_*", "nppicc64_*", "nppidei64_*", "nppif64_*",
172+
"nppig64_*", "nppim64_*", "nppist64_*", "nppitc64_*"
173+
)
174+
Get-ChildItem -Path . -Filter "*.dll" | Where-Object {
175+
$name = $_.Name
176+
$is_cuda = $name -match '^\w+64_\d'
177+
$is_kept = $false
178+
foreach ($pattern in $keep) {
179+
if ($name -like $pattern) { $is_kept = $true; break }
180+
}
181+
$is_cuda -and -not $is_kept
182+
} | ForEach-Object {
183+
$size = [math]::Round($_.Length / 1MB)
184+
echo "Removing $($_.Name) (${size} MB)"
185+
Remove-Item $_.FullName
186+
}
187+
shell: pwsh
188+
165189
- name: Build a package
166190
# CMake 3.25 regression fix. See https://stackoverflow.com/questions/74162633/problem-compiling-from-source-opencv-with-mvsc2019-in-64-bit-version
167191
run: |

0 commit comments

Comments
 (0)