From 88bacce9d70c4332c3539796816a87d180c2e42b Mon Sep 17 00:00:00 2001 From: Ling Wang Date: Sat, 22 Feb 2025 23:27:31 +0100 Subject: [PATCH 1/3] ENABLE_CUDA_FIRST_CLASS_LANGUAGE works --- modules/cudev/CMakeLists.txt | 41 +++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/modules/cudev/CMakeLists.txt b/modules/cudev/CMakeLists.txt index 742f7c8ae55..02e17460c97 100644 --- a/modules/cudev/CMakeLists.txt +++ b/modules/cudev/CMakeLists.txt @@ -6,20 +6,41 @@ set(the_description "CUDA device layer") ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4189 /wd4505 -Wundef -Wmissing-declarations -Wunused-function -Wunused-variable -Wenum-compare -Wshadow) -ocv_add_module(cudev) - -ocv_module_include_directories(opencv_core) - -file(GLOB_RECURSE lib_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.hpp") -file(GLOB lib_srcs "${CMAKE_CURRENT_LIST_DIR}/src/*.cpp") - -source_group("Include" FILES ${lib_hdrs}) -source_group("Src" FILES ${lib_srcs}) +set(extra_dependencies "") +set(optional_dependencies "") + +if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE) + if(UNIX AND NOT BUILD_SHARED_LIBS AND CUDA_VERSION_STRING VERSION_GREATER_EQUAL 9.2 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.23) + set(CUDA_FFT_LIB_EXT "_static_nocallback") + endif() + 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 + # the cufft_static_nocallback variant does not requires seperable compilation. callbacks are currently not used. + list(APPEND optional_dependencies CUDA::cufft${CUDA_FFT_LIB_EXT}) + 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_glob_module_sources(HEADERS ${lib_hdrs} SOURCES ${lib_srcs}) +ocv_add_module(cudev opencv_core ${extra_dependencies} OPTIONAL opencv_cudev ${optional_dependencies} WRAP python) +ocv_module_include_directories() +ocv_glob_module_sources() ocv_create_module() + if(BUILD_TESTS AND NOT BUILD_opencv_world) add_subdirectory(test) endif() From 0228cfa83ae02d7e80933a8cce210c7ac9926197 Mon Sep 17 00:00:00 2001 From: Ling Wang Date: Sat, 22 Feb 2025 23:55:35 +0100 Subject: [PATCH 2/3] clean up unnecessary libs for cudev --- modules/cudev/CMakeLists.txt | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/modules/cudev/CMakeLists.txt b/modules/cudev/CMakeLists.txt index 02e17460c97..45cea0dc09a 100644 --- a/modules/cudev/CMakeLists.txt +++ b/modules/cudev/CMakeLists.txt @@ -13,28 +13,11 @@ if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE) if(UNIX AND NOT BUILD_SHARED_LIBS AND CUDA_VERSION_STRING VERSION_GREATER_EQUAL 9.2 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.23) set(CUDA_FFT_LIB_EXT "_static_nocallback") endif() - 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 - # the cufft_static_nocallback variant does not requires seperable compilation. callbacks are currently not used. - list(APPEND optional_dependencies CUDA::cufft${CUDA_FFT_LIB_EXT}) - endif() -else() - if(HAVE_CUBLAS) - list(APPEND optional_dependencies ${CUDA_cublas_LIBRARY}) - endif() - if(HAVE_CUFFT) - list(APPEND optional_dependencies ${CUDA_cufft_LIBRARY}) - endif() + list(APPEND extra_dependencies CUDA::cudart_static) + endif() -ocv_add_module(cudev opencv_core ${extra_dependencies} OPTIONAL opencv_cudev ${optional_dependencies} WRAP python) +ocv_add_module(cudev opencv_core ${extra_dependencies} OPTIONAL ${optional_dependencies} WRAP python) ocv_module_include_directories() ocv_glob_module_sources() From 9d717fb9d74aedf35e99dc8be649b9577fd90bcf Mon Sep 17 00:00:00 2001 From: Ling Wang Date: Sun, 23 Feb 2025 00:48:27 +0100 Subject: [PATCH 3/3] fix python build: avoid link to opencv_core --- modules/cudev/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/cudev/CMakeLists.txt b/modules/cudev/CMakeLists.txt index 45cea0dc09a..f6d51a501ce 100644 --- a/modules/cudev/CMakeLists.txt +++ b/modules/cudev/CMakeLists.txt @@ -17,9 +17,9 @@ if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE) endif() -ocv_add_module(cudev opencv_core ${extra_dependencies} OPTIONAL ${optional_dependencies} WRAP python) +ocv_add_module(cudev ${extra_dependencies} OPTIONAL ${optional_dependencies} WRAP python) -ocv_module_include_directories() +ocv_module_include_directories(opencv_core) ocv_glob_module_sources() ocv_create_module()