From 38c3a641af397b0b0e5e7fdd3bd326f4648ab851 Mon Sep 17 00:00:00 2001 From: Ryangx100 <3393299598@qq.com> Date: Thu, 12 Jun 2025 23:11:15 +0800 Subject: [PATCH 1/2] Update build_wheels_windows.yml --- .github/workflows/build_wheels_windows.yml | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_wheels_windows.yml b/.github/workflows/build_wheels_windows.yml index a1a36ff8..75c4e443 100644 --- a/.github/workflows/build_wheels_windows.yml +++ b/.github/workflows/build_wheels_windows.yml @@ -28,12 +28,14 @@ jobs: with_contrib: [0, 1] without_gui: [0, 1] build_sdist: [0] + cuda: [0, 1] # 添加 CUDA 选项,0 表示禁用,1 表示启用 env: ACTIONS_ALLOW_UNSECURE_COMMANDS: true SDIST: ${{ matrix.build_sdist || 0 }} ENABLE_HEADLESS: ${{ matrix.without_gui }} ENABLE_CONTRIB: ${{ matrix.with_contrib }} OPENCV_TEST_DATA_PATH: ${{ github.workspace }}\opencv_extra\testdata + WITH_CUDA: ${{ matrix.cuda }} # 定义 CUDA 环境变量 steps: - name: Cleanup shell: bash @@ -61,6 +63,11 @@ jobs: uses: microsoft/setup-msbuild@v1.1 - name: Setup NASM uses: ilammy/setup-nasm@v1 + - name: Setup CUDA Toolkit + if: ${{ matrix.cuda == 1 }} + uses: Jimver/cuda-toolkit@v0.2.1 + with: + cuda: '11.8.0' # 指定 CUDA 版本 - name: Build a package # CMake 3.25 regression fix. See https://stackoverflow.com/questions/74162633/problem-compiling-from-source-opencv-with-mvsc2019-in-64-bit-version run: | @@ -69,12 +76,26 @@ jobs: python -m pip install --upgrade setuptools python -m pip install cmake==3.24.2 python -m pip install toml && python -c "import toml; c = toml.load('pyproject.toml'); print('\n'.join(c['build-system']['requires']))" >> requirements.txt | python -m pip install -r requirements.txt + + # 设置 CUDA 相关环境变量 + if "%WITH_CUDA%"=="1" ( + set "ENABLE_CUDA=1" + set "ENABLE_CUDNN=1" + set "CUDA_ARCH_BIN=5.2 6.0 6.1 7.0 7.5 8.0 8.6" # 支持的 CUDA 架构 + set "BUILD_opencv_cudacodec=1" + echo "CUDA support enabled" + ) else ( + set "ENABLE_CUDA=0" + echo "CUDA support disabled" + ) + + # 构建命令,添加 CUDA 相关选项 set "CI_BUILD=1" && python setup.py bdist_wheel --py-limited-api=cp37 --dist-dir=%cd%\wheelhouse -v shell: cmd - name: Saving all wheels uses: actions/upload-artifact@v4 with: - name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}-${{ matrix.platform }} + name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}-${{ matrix.platform }}-${{ matrix.cuda }} path: wheelhouse/opencv* Test: @@ -91,6 +112,7 @@ jobs: with_contrib: [0, 1] without_gui: [0, 1] build_sdist: [0] + cuda: [0, 1] # 添加 CUDA 选项 env: ACTIONS_ALLOW_UNSECURE_COMMANDS: true OPENCV_TEST_DATA_PATH: ${{ github.workspace }}\opencv_extra\testdata @@ -115,7 +137,7 @@ jobs: - name: Download a wheel accordingly to matrix uses: actions/download-artifact@v4 with: - name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}-${{ matrix.platform }} + name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}-${{ matrix.platform }}-${{ matrix.cuda }} path: wheelhouse/ - name: Package installation run: | From 47772ce7fd7e99d80b25f240a25c8acab24891c3 Mon Sep 17 00:00:00 2001 From: Ryangx100 <3393299598@qq.com> Date: Fri, 13 Jun 2025 19:35:04 +0800 Subject: [PATCH 2/2] Update build_wheels_windows.yml --- .github/workflows/build_wheels_windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wheels_windows.yml b/.github/workflows/build_wheels_windows.yml index 75c4e443..abcf9429 100644 --- a/.github/workflows/build_wheels_windows.yml +++ b/.github/workflows/build_wheels_windows.yml @@ -67,7 +67,7 @@ jobs: if: ${{ matrix.cuda == 1 }} uses: Jimver/cuda-toolkit@v0.2.1 with: - cuda: '11.8.0' # 指定 CUDA 版本 + cuda: '12.9.0' # 指定 CUDA 版本 - name: Build a package # CMake 3.25 regression fix. See https://stackoverflow.com/questions/74162633/problem-compiling-from-source-opencv-with-mvsc2019-in-64-bit-version run: |