From bc72f4d2a2bb75af19edeb6bf5ed0128b891a2cd Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 20 Dec 2013 16:32:34 +0400 Subject: [PATCH] Code review fixes. --- CMakeLists.txt | 19 ++++++++++++++++++- modules/core/CMakeLists.txt | 6 ++++-- modules/core/include/opencv2/core/gpumat.hpp | 13 +++++-------- modules/core/src/gpumat.cpp | 15 +++++++++------ modules/dynamicuda/CMakeLists.txt | 4 ++-- .../include/opencv2/dynamicuda/dynamicuda.hpp | 4 ++-- modules/stitching/CMakeLists.txt | 6 +++++- .../opencv2/stitching/detail/seam_finders.hpp | 2 +- .../opencv2/stitching/detail/warpers.hpp | 4 ++-- .../include/opencv2/stitching/warpers.hpp | 2 +- modules/videostab/CMakeLists.txt | 6 +++++- 11 files changed, 54 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c5165c1e..06863804d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -201,7 +201,7 @@ OCV_OPTION(INSTALL_TO_MANGLED_PATHS "Enables mangled install paths, that help wi # OpenCV build options # =================================================== -OCV_OPTION(ENABLE_DYNAMIC_CUDA "Enabled dynamic CUDA linkage" ON IF ANDROID OR LINUX) +OCV_OPTION(ENABLE_DYNAMIC_CUDA "Enabled dynamic CUDA linkage" ON IF ANDROID ) OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers" ON IF (NOT IOS) ) OCV_OPTION(ENABLE_SOLUTION_FOLDERS "Solution folder in Visual Studio or in other IDEs" (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) IF (CMAKE_VERSION VERSION_GREATER "2.8.0") ) OCV_OPTION(ENABLE_PROFILING "Enable profiling in the GCC compiler (Add flags: -g -pg)" OFF IF CMAKE_COMPILER_IS_GNUCXX ) @@ -459,6 +459,23 @@ if(WITH_OPENCL) include(cmake/OpenCVDetectOpenCL.cmake) endif() +# ---------------------------------------------------------------------------- +# Add CUDA libraries (needed for apps/tools, samples) +# ---------------------------------------------------------------------------- +if(NOT HAVE_CUDA) + set(ENABLE_DYNAMIC_CUDA OFF) +endif() + +if(HAVE_CUDA AND NOT ENABLE_DYNAMIC_CUDA) + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) + if(HAVE_CUBLAS) + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CUDA_cublas_LIBRARY}) + endif() + if(HAVE_CUFFT) + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CUDA_cufft_LIBRARY}) + endif() +endif() + # ---------------------------------------------------------------------------- # Solution folders: # ---------------------------------------------------------------------------- diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index 0d985f288..a1e71bf4f 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -28,8 +28,10 @@ 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 (HAVE_CUDA AND NOT ENABLE_DYNAMIC_CUDA) +if(HAVE_CUDA AND NOT ENABLE_DYNAMIC_CUDA) file(GLOB lib_cuda "../dynamicuda/src/cuda/*.cu*") + ocv_include_directories(${CUDA_INCLUDE_DIRS}) + ocv_cuda_compile(cuda_objs ${lib_cuda}) endif() source_group("Cuda Headers" FILES ${lib_cuda_hdrs}) @@ -43,7 +45,7 @@ if (NOT HAVE_CUDA OR ENABLE_DYNAMIC_CUDA) 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} + ocv_glob_module_sources(SOURCES "${opencv_core_BINARY_DIR}/version_string.inc" ${lib_cuda} ${cuda_objs} HEADERS ${lib_cuda_hdrs} ${lib_cuda_hdrs_detail}) endif() diff --git a/modules/core/include/opencv2/core/gpumat.hpp b/modules/core/include/opencv2/core/gpumat.hpp index d0f415ec3..193c9aa70 100644 --- a/modules/core/include/opencv2/core/gpumat.hpp +++ b/modules/core/include/opencv2/core/gpumat.hpp @@ -112,13 +112,13 @@ namespace cv { namespace gpu // Creates DeviceInfo object for the given GPU DeviceInfo(int device_id) : device_id_(device_id) { query(); } - std::string name() const; + std::string name() const { return name_; } // Return compute capability versions - int majorVersion() const; - int minorVersion() const; + int majorVersion() const { return majorVersion_; } + int minorVersion() const { return minorVersion_; } - int multiProcessorCount() const; + int multiProcessorCount() const { return multi_processor_count_; } size_t sharedMemPerBlock() const; @@ -132,12 +132,9 @@ namespace cv { namespace gpu // Checks whether the GPU module can be run on the given device bool isCompatible() const; - int deviceID() const; + int deviceID() const { return device_id_; } private: - // Private section is fictive to preserve bin compatibility. - // Changes in the private fields there have no effects. - // see deligate code. void query(); int device_id_; diff --git a/modules/core/src/gpumat.cpp b/modules/core/src/gpumat.cpp index 310aabd58..94bb54823 100644 --- a/modules/core/src/gpumat.cpp +++ b/modules/core/src/gpumat.cpp @@ -263,12 +263,15 @@ size_t cv::gpu::DeviceInfo::freeMemory() const { return deviceInfoFuncTable()->f size_t cv::gpu::DeviceInfo::totalMemory() const { return deviceInfoFuncTable()->totalMemory(); } bool cv::gpu::DeviceInfo::supports(FeatureSet feature_set) const { return deviceInfoFuncTable()->supports(feature_set); } bool cv::gpu::DeviceInfo::isCompatible() const { return deviceInfoFuncTable()->isCompatible(); } -int cv::gpu::DeviceInfo::deviceID() const { return deviceInfoFuncTable()->deviceID(); }; -int cv::gpu::DeviceInfo::majorVersion() const { return deviceInfoFuncTable()->majorVersion(); } -int cv::gpu::DeviceInfo::minorVersion() const { return deviceInfoFuncTable()->minorVersion(); } -std::string cv::gpu::DeviceInfo::name() const { return deviceInfoFuncTable()->name(); } -int cv::gpu::DeviceInfo::multiProcessorCount() const { return deviceInfoFuncTable()->multiProcessorCount(); } -void cv::gpu::DeviceInfo::query() { deviceInfoFuncTable()->query(); } + +void cv::gpu::DeviceInfo::query() +{ + deviceInfoFuncTable()->query(); + name_ = deviceInfoFuncTable()->name(); + multi_processor_count_ = deviceInfoFuncTable()->multiProcessorCount(); + majorVersion_ = deviceInfoFuncTable()->majorVersion(); + minorVersion_ = deviceInfoFuncTable()->minorVersion(); +} void cv::gpu::printCudaDeviceInfo(int device) { deviceInfoFuncTable()->printCudaDeviceInfo(device); } void cv::gpu::printShortCudaDeviceInfo(int device) { deviceInfoFuncTable()->printShortCudaDeviceInfo(device); } diff --git a/modules/dynamicuda/CMakeLists.txt b/modules/dynamicuda/CMakeLists.txt index 031b5e48d..f67879ef9 100644 --- a/modules/dynamicuda/CMakeLists.txt +++ b/modules/dynamicuda/CMakeLists.txt @@ -1,4 +1,4 @@ -if(NOT ANDROID OR NOT HAVE_CUDA) +if(NOT DYNAMIC_CUDA_SUPPORT) ocv_module_disable(dynamicuda) endif() @@ -11,5 +11,5 @@ 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}) + ocv_define_module(dynamicuda opencv_core PRIVATE_REQUIRED ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) endif() diff --git a/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp b/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp index c5057ab99..8973c5304 100644 --- a/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp +++ b/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp @@ -539,7 +539,7 @@ private: DeviceProps deviceProps; -class CudaDeviceInfoFuncTable: DeviceInfoFuncTable +class CudaDeviceInfoFuncTable : public DeviceInfoFuncTable { public: size_t sharedMemPerBlock() const @@ -1109,4 +1109,4 @@ public: } }; #endif -#endif \ No newline at end of file +#endif diff --git a/modules/stitching/CMakeLists.txt b/modules/stitching/CMakeLists.txt index fda44591f..6e9a35ba7 100644 --- a/modules/stitching/CMakeLists.txt +++ b/modules/stitching/CMakeLists.txt @@ -1,2 +1,6 @@ set(the_description "Images stitching") -ocv_define_module(stitching opencv_imgproc opencv_features2d opencv_calib3d opencv_objdetect OPTIONAL opencv_gpu opencv_nonfree) +if (ENABLE_DYNAMIC_CUDA) + ocv_define_module(stitching opencv_imgproc opencv_features2d opencv_calib3d opencv_objdetect OPTIONAL opencv_nonfree) +else() + ocv_define_module(stitching opencv_imgproc opencv_features2d opencv_calib3d opencv_objdetect OPTIONAL opencv_gpu opencv_nonfree) +endif() \ No newline at end of file diff --git a/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp b/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp index 09a1a106f..9301dc5eb 100644 --- a/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp @@ -227,7 +227,7 @@ private: }; -#ifdef HAVE_OPENCV_GPU +#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) class CV_EXPORTS GraphCutSeamFinderGpu : public GraphCutSeamFinderBase, public PairwiseSeamFinder { public: diff --git a/modules/stitching/include/opencv2/stitching/detail/warpers.hpp b/modules/stitching/include/opencv2/stitching/detail/warpers.hpp index 2bd46f75a..d44bfe69e 100644 --- a/modules/stitching/include/opencv2/stitching/detail/warpers.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/warpers.hpp @@ -46,7 +46,7 @@ #include "opencv2/core/core.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/opencv_modules.hpp" -#ifdef HAVE_OPENCV_GPU +#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) # include "opencv2/gpu/gpu.hpp" #endif @@ -331,7 +331,7 @@ public: }; -#ifdef HAVE_OPENCV_GPU +#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) class CV_EXPORTS PlaneWarperGpu : public PlaneWarper { public: diff --git a/modules/stitching/include/opencv2/stitching/warpers.hpp b/modules/stitching/include/opencv2/stitching/warpers.hpp index 7475d1304..87efa7e80 100644 --- a/modules/stitching/include/opencv2/stitching/warpers.hpp +++ b/modules/stitching/include/opencv2/stitching/warpers.hpp @@ -145,7 +145,7 @@ public: -#ifdef HAVE_OPENCV_GPU +#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) class PlaneWarperGpu: public WarperCreator { public: diff --git a/modules/videostab/CMakeLists.txt b/modules/videostab/CMakeLists.txt index ac5cb0d69..84ec1d2e8 100644 --- a/modules/videostab/CMakeLists.txt +++ b/modules/videostab/CMakeLists.txt @@ -1,2 +1,6 @@ set(the_description "Video stabilization") -ocv_define_module(videostab opencv_imgproc opencv_features2d opencv_video opencv_photo opencv_calib3d opencv_highgui OPTIONAL opencv_gpu) +if(ENABLE_DYNAMIC_CUDA) + ocv_define_module(videostab opencv_imgproc opencv_features2d opencv_video opencv_photo opencv_calib3d opencv_highgui) +else() + ocv_define_module(videostab opencv_imgproc opencv_features2d opencv_video opencv_photo opencv_calib3d opencv_highgui OPTIONAL opencv_gpu) +endif()