@@ -28,12 +28,14 @@ jobs:
28
28
with_contrib : [0, 1]
29
29
without_gui : [0, 1]
30
30
build_sdist : [0]
31
+ cuda : [0, 1] # 添加 CUDA 选项,0 表示禁用,1 表示启用
31
32
env :
32
33
ACTIONS_ALLOW_UNSECURE_COMMANDS : true
33
34
SDIST : ${{ matrix.build_sdist || 0 }}
34
35
ENABLE_HEADLESS : ${{ matrix.without_gui }}
35
36
ENABLE_CONTRIB : ${{ matrix.with_contrib }}
36
37
OPENCV_TEST_DATA_PATH : ${{ github.workspace }}\opencv_extra\testdata
38
+ WITH_CUDA : ${{ matrix.cuda }} # 定义 CUDA 环境变量
37
39
steps :
38
40
- name : Cleanup
39
41
shell : bash
61
63
uses : microsoft/setup-msbuild@v1.1
62
64
- name : Setup NASM
63
65
uses : ilammy/setup-nasm@v1
66
+ - name : Setup CUDA Toolkit
67
+ if : ${{ matrix.cuda == 1 }}
68
+ uses : Jimver/cuda-toolkit@v0.2.1
69
+ with :
70
+ cuda : ' 11.8.0' # 指定 CUDA 版本
64
71
- name : Build a package
65
72
# CMake 3.25 regression fix. See https://stackoverflow.com/questions/74162633/problem-compiling-from-source-opencv-with-mvsc2019-in-64-bit-version
66
73
run : |
@@ -69,12 +76,26 @@ jobs:
69
76
python -m pip install --upgrade setuptools
70
77
python -m pip install cmake==3.24.2
71
78
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
79
+
80
+ # 设置 CUDA 相关环境变量
81
+ if "%WITH_CUDA%"=="1" (
82
+ set "ENABLE_CUDA=1"
83
+ set "ENABLE_CUDNN=1"
84
+ set "CUDA_ARCH_BIN=5.2 6.0 6.1 7.0 7.5 8.0 8.6" # 支持的 CUDA 架构
85
+ set "BUILD_opencv_cudacodec=1"
86
+ echo "CUDA support enabled"
87
+ ) else (
88
+ set "ENABLE_CUDA=0"
89
+ echo "CUDA support disabled"
90
+ )
91
+
92
+ # 构建命令,添加 CUDA 相关选项
72
93
set "CI_BUILD=1" && python setup.py bdist_wheel --py-limited-api=cp37 --dist-dir=%cd%\wheelhouse -v
73
94
shell : cmd
74
95
- name : Saving all wheels
75
96
uses : actions/upload-artifact@v4
76
97
with :
77
- name : wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}-${{ matrix.platform }}
98
+ name : wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}-${{ matrix.platform }}-${{ matrix.cuda }}
78
99
path : wheelhouse/opencv*
79
100
80
101
Test :
91
112
with_contrib : [0, 1]
92
113
without_gui : [0, 1]
93
114
build_sdist : [0]
115
+ cuda : [0, 1] # 添加 CUDA 选项
94
116
env :
95
117
ACTIONS_ALLOW_UNSECURE_COMMANDS : true
96
118
OPENCV_TEST_DATA_PATH : ${{ github.workspace }}\opencv_extra\testdata
@@ -115,7 +137,7 @@ jobs:
115
137
- name : Download a wheel accordingly to matrix
116
138
uses : actions/download-artifact@v4
117
139
with :
118
- name : wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}-${{ matrix.platform }}
140
+ name : wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}-${{ matrix.platform }}-${{ matrix.cuda }}
119
141
path : wheelhouse/
120
142
- name : Package installation
121
143
run : |
0 commit comments