Dynamic CUDA support library reimplemented as OpenCV module.
authorAlexander Smorkalov <alexander.smorkalov@itseez.com>
Thu, 19 Dec 2013 12:42:11 +0000 (16:42 +0400)
committerAlexander Smorkalov <alexander.smorkalov@itseez.com>
Thu, 19 Dec 2013 12:42:11 +0000 (16:42 +0400)
CMakeLists.txt
cmake/OpenCVModule.cmake
modules/core/CMakeLists.txt
modules/core/cuda/CMakeLists.txt [deleted file]
modules/core/src/gpumat.cpp
modules/dynamicuda/CMakeLists.txt [new file with mode: 0644]
modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp [moved from modules/core/src/gpumat_cuda.hpp with 100% similarity]
modules/dynamicuda/src/cuda/matrix_operations.cu [moved from modules/core/src/cuda/matrix_operations.cu with 100% similarity]
modules/dynamicuda/src/main.cpp [moved from modules/core/cuda/main.cpp with 96% similarity]
modules/java/CMakeLists.txt

index 56c1764..cf25084 100644 (file)
@@ -128,7 +128,6 @@ OCV_OPTION(WITH_1394           "Include IEEE1394 support"                    ON
 OCV_OPTION(WITH_AVFOUNDATION   "Use AVFoundation for Video I/O"              ON   IF IOS)
 OCV_OPTION(WITH_CARBON         "Use Carbon for UI instead of Cocoa"          OFF  IF APPLE )
 OCV_OPTION(WITH_CUDA           "Include NVidia Cuda Runtime support"         ON   IF (CMAKE_VERSION VERSION_GREATER "2.8" AND NOT IOS) )
-OCV_OPTION(DYNAMIC_CUDA_SUPPORT "Make CUDA support dynamic"                  OFF  IF (WITH_CUDA) AND NOT IOS AND NOT WINDOWS)
 OCV_OPTION(WITH_CUFFT          "Include NVidia Cuda Fast Fourier Transform (FFT) library support"            ON  IF (CMAKE_VERSION VERSION_GREATER "2.8" AND NOT IOS) )
 OCV_OPTION(WITH_CUBLAS         "Include NVidia Cuda Basic Linear Algebra Subprograms (BLAS) library support" OFF IF (CMAKE_VERSION VERSION_GREATER "2.8" AND NOT IOS) )
 OCV_OPTION(WITH_NVCUVID        "Include NVidia Video Decoding library support"                               OFF IF (CMAKE_VERSION VERSION_GREATER "2.8" AND NOT ANDROID AND NOT IOS AND NOT APPLE) )
@@ -842,7 +841,6 @@ if(HAVE_CUDA)
   status("")
   status("  NVIDIA CUDA")
 
-  status("    Dynamic CUDA support:" DYNAMIC_CUDA_SUPPORT THEN YES ELSE NO)
   status("    Use CUFFT:"            HAVE_CUFFT   THEN YES ELSE NO)
   status("    Use CUBLAS:"           HAVE_CUBLAS  THEN YES ELSE NO)
   status("    USE NVCUVID:"          HAVE_NVCUVID THEN YES ELSE NO)
index d7e7c4a..3dd749b 100644 (file)
@@ -488,7 +488,7 @@ macro(ocv_glob_module_sources)
   file(GLOB lib_cuda_srcs "src/cuda/*.cu")
   set(cuda_objs "")
   set(lib_cuda_hdrs "")
-  if(HAVE_CUDA AND lib_cuda_srcs)
+  if(HAVE_CUDA)
     ocv_include_directories(${CUDA_INCLUDE_DIRS})
     file(GLOB lib_cuda_hdrs "src/cuda/*.hpp")
 
index 07fa089..e89d6f2 100644 (file)
@@ -1,50 +1,18 @@
 set(the_description "The Core Functionality")
 
-macro(ocv_glob_module_sources_no_cuda)
-  file(GLOB_RECURSE lib_srcs "src/*.cpp")
-  file(GLOB_RECURSE lib_int_hdrs "src/*.hpp" "src/*.h")
-  file(GLOB lib_hdrs "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h")
-  file(GLOB lib_hdrs_detail "include/opencv2/${name}/detail/*.hpp" "include/opencv2/${name}/detail/*.h")
-
-  set(cuda_objs "")
-  set(lib_cuda_hdrs "")
-  if(HAVE_CUDA)
-    ocv_include_directories(${CUDA_INCLUDE_DIRS})
-    file(GLOB lib_cuda_hdrs "src/cuda/*.hpp")
-  endif()
-
-  source_group("Src" FILES ${lib_srcs} ${lib_int_hdrs})
-
-  file(GLOB cl_kernels "src/opencl/*.cl")
-  if(HAVE_opencv_ocl AND cl_kernels)
-    ocv_include_directories(${OPENCL_INCLUDE_DIRS})
-    add_custom_command(
-      OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.cpp" "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.hpp"
-      COMMAND ${CMAKE_COMMAND} -DCL_DIR="${CMAKE_CURRENT_SOURCE_DIR}/src/opencl" -DOUTPUT="${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.cpp" -P "${OpenCV_SOURCE_DIR}/cmake/cl2cpp.cmake"
-      DEPENDS ${cl_kernels} "${OpenCV_SOURCE_DIR}/cmake/cl2cpp.cmake")
-    source_group("OpenCL" FILES ${cl_kernels} "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.cpp" "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.hpp")
-    list(APPEND lib_srcs ${cl_kernels} "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.cpp" "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.hpp")
-  endif()
-
-  source_group("Include" FILES ${lib_hdrs})
-  source_group("Include\\detail" FILES ${lib_hdrs_detail})
-
-  ocv_set_module_sources(${ARGN} HEADERS ${lib_hdrs} ${lib_hdrs_detail}
-                                 SOURCES ${lib_srcs} ${lib_int_hdrs} ${cuda_objs} ${lib_cuda_hdrs})
-endmacro()
-
-if (DYNAMIC_CUDA_SUPPORT)
+if (HAVE_opencv_dynamicuda)
   ocv_add_module(core PRIVATE_REQUIRED ${ZLIB_LIBRARIES})
 else()
   ocv_add_module(core PRIVATE_REQUIRED ${ZLIB_LIBRARIES} ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY})
 endif()
-ocv_module_include_directories(${ZLIB_INCLUDE_DIR})
+
+ocv_module_include_directories("${OpenCV_SOURCE_DIR}/modules/dynamicuda/include/" ${ZLIB_INCLUDE_DIR})
 
 if(HAVE_WINRT)
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW /GS /Gm- /AI\"${WINDOWS_SDK_PATH}/References/CommonConfiguration/Neutral\" /AI\"${VISUAL_STUDIO_PATH}/vcpackages\"")
 endif()
 
-if(DYNAMIC_CUDA_SUPPORT)
+if(HAVE_opencv_dynamicuda)
   add_definitions(-DDYNAMIC_CUDA_SUPPORT)
 else()
   add_definitions(-DUSE_CUDA)
@@ -58,15 +26,23 @@ endif()
 file(GLOB lib_cuda_hdrs        "include/opencv2/${name}/cuda/*.hpp"        "include/opencv2/${name}/cuda/*.h")
 file(GLOB lib_cuda_hdrs_detail "include/opencv2/${name}/cuda/detail/*.hpp" "include/opencv2/${name}/cuda/detail/*.h")
 
+if (NOT HAVE_opencv_dynamicuda)
+  file(GLOB lib_cuda               "../dynamicuda/src/cuda/*.cu*")
+endif()
+
 source_group("Cuda Headers"         FILES ${lib_cuda_hdrs})
 source_group("Cuda Headers\\Detail" FILES ${lib_cuda_hdrs_detail})
 
-if (DYNAMIC_CUDA_SUPPORT)
-  ocv_glob_module_sources_no_cuda(SOURCES "${opencv_core_BINARY_DIR}/version_string.inc"
-                                  HEADERS ${lib_cuda_hdrs} ${lib_cuda_hdrs_detail})
-else()
+if (NOT HAVE_opencv_dynamicuda)
+  source_group("Src\\Cuda"      FILES ${lib_cuda} ${lib_cuda_hdrs})
+endif()
+
+if (HAVE_opencv_dynamicuda)
   ocv_glob_module_sources(SOURCES "${opencv_core_BINARY_DIR}/version_string.inc"
                           HEADERS ${lib_cuda_hdrs} ${lib_cuda_hdrs_detail})
+else()
+  ocv_glob_module_sources(SOURCES "${opencv_core_BINARY_DIR}/version_string.inc" ${lib_cuda}
+                          HEADERS ${lib_cuda_hdrs} ${lib_cuda_hdrs_detail})
 endif()
 
 ocv_create_module()
@@ -74,7 +50,3 @@ ocv_add_precompiled_headers(${the_module})
 
 ocv_add_accuracy_tests()
 ocv_add_perf_tests()
-
-if (DYNAMIC_CUDA_SUPPORT)
-  add_subdirectory(cuda)
-endif()
diff --git a/modules/core/cuda/CMakeLists.txt b/modules/core/cuda/CMakeLists.txt
deleted file mode 100644 (file)
index 828e13b..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-project(opencv_core_cuda)
-add_definitions(-DUSE_CUDA)
-include_directories(${CUDA_INCLUDE_DIRS}
-                    "../src/"
-                    "../include/opencv2/core/"
-                    "${OpenCV_SOURCE_DIR}/modules/gpu/include"
-                   )
-ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef)
-cuda_add_library(opencv_core_cuda SHARED main.cpp ../src/cuda/matrix_operations.cu)
-if(BUILD_FAT_JAVA_LIB)
-  target_link_libraries(opencv_core_cuda ${OPENCV_BUILD_DIR}/${LIBRARY_OUTPUT_PATH}/libopencv_java.so ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY})
-else()
-  target_link_libraries(opencv_core_cuda ${OPENCV_BUILD_DIR}/${LIBRARY_OUTPUT_PATH}/libopencv_core.so ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY})
-endif()
\ No newline at end of file
index 03dcad2..590685b 100644 (file)
@@ -82,7 +82,7 @@ using namespace cv::gpu;
 
 #define throw_nogpu CV_Error(CV_GpuNotSupported, "The library is compiled without CUDA support")
 
-#include "gpumat_cuda.hpp"
+#include "opencv2/dynamicuda/dynamicuda.hpp"
 
 #ifdef DYNAMIC_CUDA_SUPPORT
 
@@ -183,7 +183,7 @@ static bool loadCudaSupportLib()
         dlclose(handle);
         return false;
     }
-    
+
     gpuFactory = (GpuFactoryType)dlsym(handle, "gpuFactory");
     if (!gpuFactory)
     {
diff --git a/modules/dynamicuda/CMakeLists.txt b/modules/dynamicuda/CMakeLists.txt
new file mode 100644 (file)
index 0000000..2ae5cf8
--- /dev/null
@@ -0,0 +1,14 @@
+if(NOT ANDROID)
+  ocv_module_disable(dynamicuda)
+endif()
+
+set(the_description "Dynamic CUDA linkage")
+
+add_definitions(-DUSE_CUDA)
+ocv_module_include_directories("${OpenCV_SOURCE_DIR}/modules/gpu/include")
+set(OPENCV_MODULE_TYPE SHARED)
+if (BUILD_FAT_JAVA_LIB)
+  ocv_define_module(dynamicuda opencv_java PRIVATE_REQUIRED ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY})
+else()
+  ocv_define_module(dynamicuda opencv_core PRIVATE_REQUIRED q${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY})
+endif()
similarity index 96%
rename from modules/core/cuda/main.cpp
rename to modules/dynamicuda/src/main.cpp
index 4f47dc7..4a05d86 100644 (file)
@@ -27,7 +27,7 @@ using namespace cv::gpu;
 
 #define throw_nogpu CV_Error(CV_GpuNotSupported, "The library is compiled without CUDA support")
 
-#include "gpumat_cuda.hpp"
+#include "opencv2/dynamicuda/dynamicuda.hpp"
 
 #ifdef HAVE_CUDA
 static CudaDeviceInfoFuncTable deviceInfoTable;
@@ -38,7 +38,7 @@ static EmptyFuncTable gpuTable;
 #endif
 
 extern "C" {
-   
+
 DeviceInfoFuncTable* deviceInfoFactory()
 {
     return (DeviceInfoFuncTable*)&deviceInfoTable;
index 5012f91..291295f 100644 (file)
@@ -297,6 +297,12 @@ if(BUILD_FAT_JAVA_LIB)
       list(REMOVE_ITEM __deps ${m})
     endif()
   endforeach()
+  if (HAVE_opencv_dynamicuda)
+    list(REMOVE_ITEM __deps "opencv_dynamicuda")
+  endif()
+  if (ANDROID AND HAVE_opencv_gpu)
+    list(REMOVE_ITEM __deps "opencv_gpu")
+  endif()
   ocv_list_unique(__deps)
   set(__extradeps ${__deps})
   ocv_list_filterout(__extradeps "^opencv_")