Skip to content

Commit c279897

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 c279897

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

.github/workflows/build_wheels_windows.yml

Lines changed: 32 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,37 @@ 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+
# Remove from project root (where setup.py picks up *.dll)
175+
# and from _skbuild (where they persist in the build cache)
176+
$search_paths = @(".")
177+
$search_paths += Get-ChildItem -Path "_skbuild\*\cmake-install\cv2" -ErrorAction SilentlyContinue |
178+
Select-Object -ExpandProperty FullName
179+
foreach ($dir in $search_paths) {
180+
Get-ChildItem -Path $dir -Filter "*.dll" -ErrorAction SilentlyContinue | Where-Object {
181+
$name = $_.Name
182+
$is_cuda = $name -match '^\w+64_\d'
183+
$is_kept = $false
184+
foreach ($pattern in $keep) {
185+
if ($name -like $pattern) { $is_kept = $true; break }
186+
}
187+
$is_cuda -and -not $is_kept
188+
} | ForEach-Object {
189+
$size = [math]::Round($_.Length / 1MB)
190+
echo "Removing $($_.Name) (${size} MB) from $dir"
191+
Remove-Item $_.FullName
192+
}
193+
}
194+
shell: pwsh
195+
165196
- name: Build a package
166197
# CMake 3.25 regression fix. See https://stackoverflow.com/questions/74162633/problem-compiling-from-source-opencv-with-mvsc2019-in-64-bit-version
167198
run: |

0 commit comments

Comments
 (0)