From 81cc89a3ce1e92b24ee46bf95728efe5e6d0f29f Mon Sep 17 00:00:00 2001 From: Kumataro Date: Thu, 24 Aug 2023 04:53:11 +0900 Subject: [PATCH] Merge pull request #24179 from Kumataro:fix24145 * core:add OPENCV_IPP_MEAN/MINMAX/SUM option to enable IPP optimizations * fix: to use guard HAVE_IPP and ocv_append_source_file_compile_definitions() macro. * support OPENCV_IPP_ENABLE_ALL * add document for OPENCV_IPP_ENABLE_ALL * fix OPENCV_IPP_ENABLE_ALL comment --- .../config_reference.markdown | 11 ++++++++++ modules/core/CMakeLists.txt | 20 +++++++++++++++++++ modules/core/src/mean.dispatch.cpp | 4 ++++ modules/core/src/minmax.cpp | 2 ++ modules/core/src/sum.dispatch.cpp | 2 ++ modules/imgproc/CMakeLists.txt | 10 ++++++---- 6 files changed, 45 insertions(+), 4 deletions(-) diff --git a/doc/tutorials/introduction/config_reference/config_reference.markdown b/doc/tutorials/introduction/config_reference/config_reference.markdown index 2528baf41d..4fd256dd93 100644 --- a/doc/tutorials/introduction/config_reference/config_reference.markdown +++ b/doc/tutorials/introduction/config_reference/config_reference.markdown @@ -224,6 +224,16 @@ Following options can be used to produce special builds with instrumentation or @see [Link time optimization](https://gcc.gnu.org/wiki/LinkTimeOptimization) @see [ThinLTO](https://clang.llvm.org/docs/ThinLTO.html) +## Enable IPP optimization + +Following options can be used to enables IPP optimizations for each functions but increases the size of the opencv library. All options are disabled by default. + +| Option | Functions | + roughly size | +| -------| --------- | -------------- | +| `OPENCV_IPP_GAUSSIAN_BLUR` | GaussianBlur() | +8Mb | +| `OPENCV_IPP_MEAN` | mean() / meanStdDev() | +0.2Mb | +| `OPENCV_IPP_MINMAX` | minMaxLoc() / minMaxIdx() | +0.2Mb | +| `OPENCV_IPP_SUM` | sum() | +0.1Mb | # Functional features and dependencies {#tutorial_config_reference_func} @@ -565,6 +575,7 @@ Following options can be used to change installation layout for common scenarios | ------ | ------- | ----------- | | `OPENCV_ENABLE_NONFREE` | _OFF_ | Some algorithms included in the library are known to be protected by patents and are disabled by default. | | `OPENCV_FORCE_3RDPARTY_BUILD`| _OFF_ | Enable all `BUILD_` options at once. | +| `OPENCV_IPP_ENABLE_ALL`| _OFF_ | Enable all `OPENCV_IPP_` options at once. | | `ENABLE_CCACHE` | _ON_ (on Unix-like platforms) | Enable [ccache](https://en.wikipedia.org/wiki/Ccache) auto-detection. This tool wraps compiler calls and caches results, can significantly improve re-compilation time. | | `ENABLE_PRECOMPILED_HEADERS` | _ON_ (for MSVC) | Enable precompiled headers support. Improves build time. | | `BUILD_DOCS` | _OFF_ | Enable documentation build (_doxygen_, _doxygen_cpp_, _doxygen_python_, _doxygen_javadoc_ targets). [Doxygen](http://www.doxygen.org/index.html) must be installed for C++ documentation build. Python and [BeautifulSoup4](https://en.wikipedia.org/wiki/Beautiful_Soup_(HTML_parser)) must be installed for Python documentation build. Javadoc and Ant must be installed for Java documentation build (part of Java SDK). | diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index 1b3f574275..ba5b61ef5f 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -60,6 +60,26 @@ if(CV_TRACE AND HAVE_ITT) add_definitions(-DOPENCV_WITH_ITT=1) endif() +# https://github.com/opencv/opencv/issues/24145 +if(HAVE_IPP) + OCV_OPTION(OPENCV_IPP_ENABLE_ALL "Enable all OPENCV_IPP_ options at once" OFF) + OCV_OPTION(OPENCV_IPP_MEAN "Enable IPP optimizations for mean (+200Kb in binary size)" OPENCV_IPP_ENABLE_ALL) + OCV_OPTION(OPENCV_IPP_MINMAX "Enable IPP optimizations for minMaxLoc/minMaxIdx (+200Kb in binary size)" OPENCV_IPP_ENABLE_ALL) + OCV_OPTION(OPENCV_IPP_SUM "Enable IPP optimizations for sum (+100Kb in binary size)" OPENCV_IPP_ENABLE_ALL) + + if(OPENCV_IPP_MEAN) + ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/mean.dispatch.cpp "OPENCV_IPP_MEAN=1") + endif() + + if(OPENCV_IPP_MINMAX) + ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/minmax.cpp "OPENCV_IPP_MINMAX=1") + endif() + + if(OPENCV_IPP_SUM) + ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/sum.dispatch.cpp "OPENCV_IPP_SUM=1") + endif() +endif() + file(GLOB lib_cuda_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/cuda/*.hpp" "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/cuda/*.h") diff --git a/modules/core/src/mean.dispatch.cpp b/modules/core/src/mean.dispatch.cpp index 6a5275ab43..0f94e5421a 100644 --- a/modules/core/src/mean.dispatch.cpp +++ b/modules/core/src/mean.dispatch.cpp @@ -8,20 +8,24 @@ #include "opencv2/core/openvx/ovx_defs.hpp" #include "stat.hpp" +#ifndef OPENCV_IPP_MEAN #undef HAVE_IPP #undef CV_IPP_RUN_FAST #define CV_IPP_RUN_FAST(f, ...) #undef CV_IPP_RUN #define CV_IPP_RUN(c, f, ...) +#endif // OPENCV_IPP_MEAN #include "mean.simd.hpp" #include "mean.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content +#ifndef OPENCV_IPP_MEAN #undef HAVE_IPP #undef CV_IPP_RUN_FAST #define CV_IPP_RUN_FAST(f, ...) #undef CV_IPP_RUN #define CV_IPP_RUN(c, f, ...) +#endif // OPENCV_IPP_MEAN namespace cv { diff --git a/modules/core/src/minmax.cpp b/modules/core/src/minmax.cpp index 092c5e9234..bf2471a076 100644 --- a/modules/core/src/minmax.cpp +++ b/modules/core/src/minmax.cpp @@ -11,11 +11,13 @@ #include +#ifndef OPENCV_IPP_MINMAX #undef HAVE_IPP #undef CV_IPP_RUN_FAST #define CV_IPP_RUN_FAST(f, ...) #undef CV_IPP_RUN #define CV_IPP_RUN(c, f, ...) +#endif // OPENCV_IPP_MINMAX #define IPP_DISABLE_MINMAXIDX_MANY_ROWS 1 // see Core_MinMaxIdx.rows_overflow test diff --git a/modules/core/src/sum.dispatch.cpp b/modules/core/src/sum.dispatch.cpp index a1f7d73868..fade948336 100644 --- a/modules/core/src/sum.dispatch.cpp +++ b/modules/core/src/sum.dispatch.cpp @@ -10,11 +10,13 @@ #include "sum.simd.hpp" #include "sum.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content +#ifndef OPENCV_IPP_SUM #undef HAVE_IPP #undef CV_IPP_RUN_FAST #define CV_IPP_RUN_FAST(f, ...) #undef CV_IPP_RUN #define CV_IPP_RUN(c, f, ...) +#endif // OPENCV_IPP_SUM namespace cv { diff --git a/modules/imgproc/CMakeLists.txt b/modules/imgproc/CMakeLists.txt index 8ee300c320..10aed6bedd 100644 --- a/modules/imgproc/CMakeLists.txt +++ b/modules/imgproc/CMakeLists.txt @@ -12,8 +12,10 @@ ocv_add_dispatched_file(smooth SSE2 SSE4_1 AVX2) ocv_add_dispatched_file(sumpixels SSE2 AVX2 AVX512_SKX) ocv_define_module(imgproc opencv_core WRAP java objc python js) -ocv_check_environment_variables(OPENCV_IPP_GAUSSIAN_BLUR) -option(OPENCV_IPP_GAUSSIAN_BLUR "Enable IPP optimizations for GaussianBlur (+8Mb in binary size)" OFF) -if(OPENCV_IPP_GAUSSIAN_BLUR) - ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/smooth.dispatch.cpp "ENABLE_IPP_GAUSSIAN_BLUR=1") +if(HAVE_IPP) + # OPENCV_IPP_ENABLE_ALL is defined in modules/core/CMakeList.txt + OCV_OPTION(OPENCV_IPP_GAUSSIAN_BLUR "Enable IPP optimizations for GaussianBlur (+8Mb in binary size)" OPENCV_IPP_ENABLE_ALL) + if(OPENCV_IPP_GAUSSIAN_BLUR) + ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/smooth.dispatch.cpp "ENABLE_IPP_GAUSSIAN_BLUR=1") + endif() endif()