Skip to content

Commit

Permalink
Merge pull request #3400 from cudawarped:add_cuda_first_class_support
Browse files Browse the repository at this point in the history
`cuda`: CMake add CUDA first class language support
  • Loading branch information
asmorkalov authored Dec 26, 2023
2 parents ab4bfc2 + 1ae5f03 commit d680f58
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 33 deletions.
37 changes: 25 additions & 12 deletions modules/cudaarithm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,35 @@ set(the_description "CUDA-accelerated Operations on Matrices")

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

ocv_add_module(cudaarithm opencv_core OPTIONAL opencv_cudev WRAP python)
set(extra_dependencies "")
set(optional_dependencies "")
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
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})
if(HAVE_CUBLAS)
list(APPEND optional_dependencies CUDA::cublas${CUDA_LIB_EXT})
if(NOT CUDA_VERSION VERSION_LESS 10.1)
list(APPEND optional_dependencies CUDA::cublasLt${CUDA_LIB_EXT})
endif()
endif()
if(HAVE_CUFFT)
# static version requires seperable compilation which is incompatible with opencv's current library structure
list(APPEND optional_dependencies CUDA::cufft)
endif()
else()
if(HAVE_CUBLAS)
list(APPEND optional_dependencies ${CUDA_cublas_LIBRARY})
endif()
if(HAVE_CUFFT)
list(APPEND optional_dependencies ${CUDA_cufft_LIBRARY})
endif()
endif()

ocv_add_module(cudaarithm opencv_core ${extra_dependencies} OPTIONAL opencv_cudev ${optional_dependencies} WRAP python)

ocv_module_include_directories()
ocv_glob_module_sources()

set(extra_libs "")

if(HAVE_CUBLAS)
list(APPEND extra_libs ${CUDA_cublas_LIBRARY})
endif()

if(HAVE_CUFFT)
list(APPEND extra_libs ${CUDA_cufft_LIBRARY})
endif()

ocv_create_module(${extra_libs})
ocv_create_module()

ocv_add_accuracy_tests(DEPENDS_ON opencv_imgproc)
ocv_add_perf_tests(DEPENDS_ON opencv_imgproc)
4 changes: 3 additions & 1 deletion modules/cudabgsegm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ endif()
set(the_description "CUDA-accelerated Background Segmentation")

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

if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
ocv_module_include_directories(${CUDAToolkit_INCLUDE_DIRS})
endif()
ocv_define_module(cudabgsegm opencv_video WRAP python)
23 changes: 21 additions & 2 deletions modules/cudacodec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ endif()

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

ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wshadow)
if(WIN32)
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512)
else()
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef -Wshadow -Wsign-compare -Wenum-compare)
endif()

set(required_dependencies opencv_core opencv_videoio opencv_cudaarithm opencv_cudawarping)
if(HAVE_NVCUVENC)
Expand All @@ -18,10 +22,25 @@ ocv_glob_module_sources()

set(extra_libs "")

if(WITH_NVCUVID AND NOT HAVE_NVCUVID)
message(WARNING "cudacodec::VideoReader requires Nvidia Video Codec SDK. Please resolve dependency or disable WITH_NVCUVID=OFF")
endif()

if(WITH_NVCUVENC AND NOT HAVE_NVCUVENC)
message(WARNING "cudacodec::VideoWriter requires Nvidia Video Codec SDK. Please resolve dependency or disable WITH_NVCUVENC=OFF")
endif()

if(HAVE_NVCUVID OR HAVE_NVCUVENC)
list(APPEND extra_libs ${CUDA_CUDA_LIBRARY})
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
list(APPEND extra_libs CUDA::cuda_driver)
else()
list(APPEND extra_libs ${CUDA_CUDA_LIBRARY})
endif()
if(HAVE_NVCUVID)
list(APPEND extra_libs ${CUDA_nvcuvid_LIBRARY})
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
list(APPEND extra_libs CUDA::nppicc${CUDA_LIB_EXT})
endif()
endif()
if(HAVE_NVCUVENC)
if(WIN32)
Expand Down
4 changes: 3 additions & 1 deletion modules/cudafeatures2d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ endif()
set(the_description "CUDA-accelerated Feature Detection and Description")

ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4100 /wd4324 /wd4512 /wd4515 -Wundef -Wmissing-declarations -Wshadow -Wunused-parameter -Wshadow)

if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
ocv_module_include_directories(${CUDAToolkit_INCLUDE_DIRS})
endif()
ocv_define_module(cudafeatures2d opencv_features2d opencv_cudafilters opencv_cudawarping WRAP python)
7 changes: 5 additions & 2 deletions modules/cudafilters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ endif()
set(the_description "CUDA-accelerated Image Filtering")

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

ocv_define_module(cudafilters opencv_imgproc opencv_cudaarithm WRAP python)
set(extra_libs "")
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
set(extra_libs CUDA::nppif${CUDA_LIB_EXT} CUDA::nppim${CUDA_LIB_EXT})
endif()
ocv_define_module(cudafilters opencv_imgproc opencv_cudaarithm ${extra_libs} WRAP python)
7 changes: 5 additions & 2 deletions modules/cudaimgproc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ endif()
set(the_description "CUDA-accelerated Image Processing")

ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4100 /wd4324 /wd4512 /wd4515 -Wundef -Wmissing-declarations -Wshadow -Wunused-parameter)

ocv_define_module(cudaimgproc opencv_imgproc OPTIONAL opencv_cudev opencv_cudaarithm opencv_cudafilters WRAP python)
set(extra_libs "")
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
set(extra_libs CUDA::nppial${CUDA_LIB_EXT} CUDA::nppist${CUDA_LIB_EXT} CUDA::nppicc${CUDA_LIB_EXT} CUDA::nppidei${CUDA_LIB_EXT})
endif()
ocv_define_module(cudaimgproc opencv_imgproc ${extra_libs} OPTIONAL opencv_cudev opencv_cudaarithm opencv_cudafilters WRAP python)
4 changes: 3 additions & 1 deletion modules/cudalegacy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ endif()
set(the_description "CUDA-accelerated Computer Vision (legacy)")

ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4130 /wd4324 /wd4512 /wd4310 -Wundef -Wmissing-declarations -Wuninitialized -Wshadow -Wdeprecated-declarations -Wstrict-aliasing -Wtautological-compare)

if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
ocv_module_include_directories(${CUDAToolkit_INCLUDE_DIRS})
endif()
ocv_define_module(cudalegacy opencv_core opencv_video
OPTIONAL opencv_objdetect opencv_imgproc opencv_calib3d opencv_cudaarithm opencv_cudafilters opencv_cudaimgproc)
4 changes: 3 additions & 1 deletion modules/cudastereo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ endif()
set(the_description "CUDA-accelerated Stereo Correspondence")

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

if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
ocv_module_include_directories(${CUDAToolkit_INCLUDE_DIRS})
endif()
ocv_define_module(cudastereo opencv_calib3d OPTIONAL opencv_cudev WRAP python)
7 changes: 5 additions & 2 deletions modules/cudawarping/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ endif()
set(the_description "CUDA-accelerated Image Warping")

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

ocv_define_module(cudawarping opencv_core opencv_imgproc OPTIONAL opencv_cudev WRAP python)
set(extra_libs "")
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
set(extra_libs CUDA::nppial${CUDA_LIB_EXT} CUDA::nppig${CUDA_LIB_EXT})
endif()
ocv_define_module(cudawarping opencv_core opencv_imgproc ${extra_libs} OPTIONAL opencv_cudev WRAP python)
22 changes: 14 additions & 8 deletions modules/cudev/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@ if(OCV_DEPENDENCIES_FOUND)

ocv_cuda_filter_options()

if(CUDA_VERSION VERSION_LESS "11.0")
ocv_update(OPENCV_CUDA_OPTIONS_opencv_test_cudev "-std=c++11")
set(target_libs ${test_deps} ${OPENCV_LINKER_LIBS})
if(NOT ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
ocv_check_windows_crt_linkage()
set(target_libs ${target_libs} ${CUDA_LIBRARIES})
if(CUDA_VERSION VERSION_LESS "11.0")
ocv_update(OPENCV_CUDA_OPTIONS_opencv_test_cudev "-std=c++11")
else()
ocv_update(OPENCV_CUDA_OPTIONS_opencv_test_cudev "-std=c++14")
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wdeprecated-declarations)
endif()
CUDA_ADD_EXECUTABLE(${the_target} ${OPENCV_TEST_${the_module}_SOURCES} OPTIONS ${OPENCV_CUDA_OPTIONS_opencv_test_cudev})
else()
ocv_update(OPENCV_CUDA_OPTIONS_opencv_test_cudev "-std=c++14")
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wdeprecated-declarations)
ocv_add_executable(${the_target} ${OPENCV_TEST_${the_module}_SOURCES})
endif()

CUDA_ADD_EXECUTABLE(${the_target} ${OPENCV_TEST_${the_module}_SOURCES} OPTIONS ${OPENCV_CUDA_OPTIONS_opencv_test_cudev})
ocv_target_link_libraries(${the_target} PRIVATE
${test_deps} ${OPENCV_LINKER_LIBS} ${CUDA_LIBRARIES}
)
ocv_target_link_libraries(${the_target} PRIVATE ${target_libs})

add_dependencies(opencv_tests ${the_target})

set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL}")
Expand Down
5 changes: 4 additions & 1 deletion modules/hfs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
if(HAVE_CUDA)
add_definitions(-D_HFS_CUDA_ON_)
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef)
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
ocv_module_include_directories(${CUDAToolkit_INCLUDE_DIRS})
endif()
endif()

set(the_description "Hierarchical Feature Selection for Efficient Image Segmentation")
ocv_define_module(hfs opencv_core opencv_imgproc WRAP python)
ocv_define_module(hfs opencv_core opencv_imgproc OPTIONAL WRAP python)

0 comments on commit d680f58

Please sign in to comment.