|
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 |
2 | 11 |
|
3 | 12 | on: |
4 | 13 | workflow_dispatch: |
|
48 | 57 | uses: microsoft/setup-msbuild@v1.1 |
49 | 58 | - name: Setup NASM |
50 | 59 | 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 | + |
51 | 112 | - name: Build a package |
52 | 113 | # CMake 3.25 regression fix. See https://stackoverflow.com/questions/74162633/problem-compiling-from-source-opencv-with-mvsc2019-in-64-bit-version |
53 | 114 | run: | |
|
0 commit comments