Skip to content

Commit d680f58

Browse files
authored
Merge pull request #3400 from cudawarped:add_cuda_first_class_support
`cuda`: CMake add CUDA first class language support
2 parents ab4bfc2 + 1ae5f03 commit d680f58

File tree

11 files changed

+91
-33
lines changed

11 files changed

+91
-33
lines changed

modules/cudaarithm/CMakeLists.txt

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,35 @@ set(the_description "CUDA-accelerated Operations on Matrices")
66

77
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations -Wshadow)
88

9-
ocv_add_module(cudaarithm opencv_core OPTIONAL opencv_cudev WRAP python)
9+
set(extra_dependencies "")
10+
set(optional_dependencies "")
11+
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
12+
list(APPEND extra_dependencies CUDA::cudart_static CUDA::nppial${CUDA_LIB_EXT} CUDA::nppc${CUDA_LIB_EXT} CUDA::nppitc${CUDA_LIB_EXT} CUDA::nppig${CUDA_LIB_EXT} CUDA::nppist${CUDA_LIB_EXT} CUDA::nppidei${CUDA_LIB_EXT})
13+
if(HAVE_CUBLAS)
14+
list(APPEND optional_dependencies CUDA::cublas${CUDA_LIB_EXT})
15+
if(NOT CUDA_VERSION VERSION_LESS 10.1)
16+
list(APPEND optional_dependencies CUDA::cublasLt${CUDA_LIB_EXT})
17+
endif()
18+
endif()
19+
if(HAVE_CUFFT)
20+
# static version requires seperable compilation which is incompatible with opencv's current library structure
21+
list(APPEND optional_dependencies CUDA::cufft)
22+
endif()
23+
else()
24+
if(HAVE_CUBLAS)
25+
list(APPEND optional_dependencies ${CUDA_cublas_LIBRARY})
26+
endif()
27+
if(HAVE_CUFFT)
28+
list(APPEND optional_dependencies ${CUDA_cufft_LIBRARY})
29+
endif()
30+
endif()
31+
32+
ocv_add_module(cudaarithm opencv_core ${extra_dependencies} OPTIONAL opencv_cudev ${optional_dependencies} WRAP python)
1033

1134
ocv_module_include_directories()
1235
ocv_glob_module_sources()
1336

14-
set(extra_libs "")
15-
16-
if(HAVE_CUBLAS)
17-
list(APPEND extra_libs ${CUDA_cublas_LIBRARY})
18-
endif()
19-
20-
if(HAVE_CUFFT)
21-
list(APPEND extra_libs ${CUDA_cufft_LIBRARY})
22-
endif()
23-
24-
ocv_create_module(${extra_libs})
37+
ocv_create_module()
2538

2639
ocv_add_accuracy_tests(DEPENDS_ON opencv_imgproc)
2740
ocv_add_perf_tests(DEPENDS_ON opencv_imgproc)

modules/cudabgsegm/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ endif()
55
set(the_description "CUDA-accelerated Background Segmentation")
66

77
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations -Wshadow)
8-
8+
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
9+
ocv_module_include_directories(${CUDAToolkit_INCLUDE_DIRS})
10+
endif()
911
ocv_define_module(cudabgsegm opencv_video WRAP python)

modules/cudacodec/CMakeLists.txt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ endif()
44

55
set(the_description "CUDA-accelerated Video Encoding/Decoding")
66

7-
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wshadow)
7+
if(WIN32)
8+
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512)
9+
else()
10+
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef -Wshadow -Wsign-compare -Wenum-compare)
11+
endif()
812

913
set(required_dependencies opencv_core opencv_videoio opencv_cudaarithm opencv_cudawarping)
1014
if(HAVE_NVCUVENC)
@@ -18,10 +22,25 @@ ocv_glob_module_sources()
1822

1923
set(extra_libs "")
2024

25+
if(WITH_NVCUVID AND NOT HAVE_NVCUVID)
26+
message(WARNING "cudacodec::VideoReader requires Nvidia Video Codec SDK. Please resolve dependency or disable WITH_NVCUVID=OFF")
27+
endif()
28+
29+
if(WITH_NVCUVENC AND NOT HAVE_NVCUVENC)
30+
message(WARNING "cudacodec::VideoWriter requires Nvidia Video Codec SDK. Please resolve dependency or disable WITH_NVCUVENC=OFF")
31+
endif()
32+
2133
if(HAVE_NVCUVID OR HAVE_NVCUVENC)
22-
list(APPEND extra_libs ${CUDA_CUDA_LIBRARY})
34+
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
35+
list(APPEND extra_libs CUDA::cuda_driver)
36+
else()
37+
list(APPEND extra_libs ${CUDA_CUDA_LIBRARY})
38+
endif()
2339
if(HAVE_NVCUVID)
2440
list(APPEND extra_libs ${CUDA_nvcuvid_LIBRARY})
41+
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
42+
list(APPEND extra_libs CUDA::nppicc${CUDA_LIB_EXT})
43+
endif()
2544
endif()
2645
if(HAVE_NVCUVENC)
2746
if(WIN32)

modules/cudafeatures2d/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ endif()
55
set(the_description "CUDA-accelerated Feature Detection and Description")
66

77
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4100 /wd4324 /wd4512 /wd4515 -Wundef -Wmissing-declarations -Wshadow -Wunused-parameter -Wshadow)
8-
8+
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
9+
ocv_module_include_directories(${CUDAToolkit_INCLUDE_DIRS})
10+
endif()
911
ocv_define_module(cudafeatures2d opencv_features2d opencv_cudafilters opencv_cudawarping WRAP python)

modules/cudafilters/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ endif()
55
set(the_description "CUDA-accelerated Image Filtering")
66

77
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations -Wshadow)
8-
9-
ocv_define_module(cudafilters opencv_imgproc opencv_cudaarithm WRAP python)
8+
set(extra_libs "")
9+
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
10+
set(extra_libs CUDA::nppif${CUDA_LIB_EXT} CUDA::nppim${CUDA_LIB_EXT})
11+
endif()
12+
ocv_define_module(cudafilters opencv_imgproc opencv_cudaarithm ${extra_libs} WRAP python)

modules/cudaimgproc/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ endif()
55
set(the_description "CUDA-accelerated Image Processing")
66

77
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4100 /wd4324 /wd4512 /wd4515 -Wundef -Wmissing-declarations -Wshadow -Wunused-parameter)
8-
9-
ocv_define_module(cudaimgproc opencv_imgproc OPTIONAL opencv_cudev opencv_cudaarithm opencv_cudafilters WRAP python)
8+
set(extra_libs "")
9+
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
10+
set(extra_libs CUDA::nppial${CUDA_LIB_EXT} CUDA::nppist${CUDA_LIB_EXT} CUDA::nppicc${CUDA_LIB_EXT} CUDA::nppidei${CUDA_LIB_EXT})
11+
endif()
12+
ocv_define_module(cudaimgproc opencv_imgproc ${extra_libs} OPTIONAL opencv_cudev opencv_cudaarithm opencv_cudafilters WRAP python)

modules/cudalegacy/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ endif()
55
set(the_description "CUDA-accelerated Computer Vision (legacy)")
66

77
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4130 /wd4324 /wd4512 /wd4310 -Wundef -Wmissing-declarations -Wuninitialized -Wshadow -Wdeprecated-declarations -Wstrict-aliasing -Wtautological-compare)
8-
8+
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
9+
ocv_module_include_directories(${CUDAToolkit_INCLUDE_DIRS})
10+
endif()
911
ocv_define_module(cudalegacy opencv_core opencv_video
1012
OPTIONAL opencv_objdetect opencv_imgproc opencv_calib3d opencv_cudaarithm opencv_cudafilters opencv_cudaimgproc)

modules/cudastereo/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ endif()
55
set(the_description "CUDA-accelerated Stereo Correspondence")
66

77
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations -Wshadow)
8-
8+
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
9+
ocv_module_include_directories(${CUDAToolkit_INCLUDE_DIRS})
10+
endif()
911
ocv_define_module(cudastereo opencv_calib3d OPTIONAL opencv_cudev WRAP python)

modules/cudawarping/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ endif()
55
set(the_description "CUDA-accelerated Image Warping")
66

77
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations -Wshadow)
8-
9-
ocv_define_module(cudawarping opencv_core opencv_imgproc OPTIONAL opencv_cudev WRAP python)
8+
set(extra_libs "")
9+
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
10+
set(extra_libs CUDA::nppial${CUDA_LIB_EXT} CUDA::nppig${CUDA_LIB_EXT})
11+
endif()
12+
ocv_define_module(cudawarping opencv_core opencv_imgproc ${extra_libs} OPTIONAL opencv_cudev WRAP python)

modules/cudev/test/CMakeLists.txt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,23 @@ if(OCV_DEPENDENCIES_FOUND)
1515

1616
ocv_cuda_filter_options()
1717

18-
if(CUDA_VERSION VERSION_LESS "11.0")
19-
ocv_update(OPENCV_CUDA_OPTIONS_opencv_test_cudev "-std=c++11")
18+
set(target_libs ${test_deps} ${OPENCV_LINKER_LIBS})
19+
if(NOT ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
20+
ocv_check_windows_crt_linkage()
21+
set(target_libs ${target_libs} ${CUDA_LIBRARIES})
22+
if(CUDA_VERSION VERSION_LESS "11.0")
23+
ocv_update(OPENCV_CUDA_OPTIONS_opencv_test_cudev "-std=c++11")
24+
else()
25+
ocv_update(OPENCV_CUDA_OPTIONS_opencv_test_cudev "-std=c++14")
26+
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wdeprecated-declarations)
27+
endif()
28+
CUDA_ADD_EXECUTABLE(${the_target} ${OPENCV_TEST_${the_module}_SOURCES} OPTIONS ${OPENCV_CUDA_OPTIONS_opencv_test_cudev})
2029
else()
21-
ocv_update(OPENCV_CUDA_OPTIONS_opencv_test_cudev "-std=c++14")
22-
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wdeprecated-declarations)
30+
ocv_add_executable(${the_target} ${OPENCV_TEST_${the_module}_SOURCES})
2331
endif()
2432

25-
CUDA_ADD_EXECUTABLE(${the_target} ${OPENCV_TEST_${the_module}_SOURCES} OPTIONS ${OPENCV_CUDA_OPTIONS_opencv_test_cudev})
26-
ocv_target_link_libraries(${the_target} PRIVATE
27-
${test_deps} ${OPENCV_LINKER_LIBS} ${CUDA_LIBRARIES}
28-
)
33+
ocv_target_link_libraries(${the_target} PRIVATE ${target_libs})
34+
2935
add_dependencies(opencv_tests ${the_target})
3036

3137
set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL}")

modules/hfs/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
if(HAVE_CUDA)
22
add_definitions(-D_HFS_CUDA_ON_)
33
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef)
4+
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
5+
ocv_module_include_directories(${CUDAToolkit_INCLUDE_DIRS})
6+
endif()
47
endif()
58

69
set(the_description "Hierarchical Feature Selection for Efficient Image Segmentation")
7-
ocv_define_module(hfs opencv_core opencv_imgproc WRAP python)
10+
ocv_define_module(hfs opencv_core opencv_imgproc OPTIONAL WRAP python)

0 commit comments

Comments
 (0)