From: mshabunin Date: Wed, 23 Nov 2016 09:44:44 +0000 (+0300) Subject: Updated TBB search script and code checks X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~1382^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=695c518384c2cdfe15053968652da657068b1ab9;p=platform%2Fupstream%2Fopencv.git Updated TBB search script and code checks --- diff --git a/3rdparty/tbb/CMakeLists.txt b/3rdparty/tbb/CMakeLists.txt index eddeaef..f6d5969 100644 --- a/3rdparty/tbb/CMakeLists.txt +++ b/3rdparty/tbb/CMakeLists.txt @@ -70,20 +70,6 @@ ocv_warnings_disable(CMAKE_CXX_FLAGS -Wshadow) #set(tbb_md5 "4669e7d4adee018de7a7b8b972987218") #set(tbb_version_file "version_string.tmp") -# 4.0 update 2 - works fine -#set(tbb_ver "tbb40_20111130oss") -#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20111130oss_src.tgz") -#set(tbb_md5 "1e6926b21e865e79772119cd44fc3ad8") -#set(tbb_version_file "version_string.tmp") -#set(tbb_need_GENERIC_DWORD_LOAD_STORE TRUE) - -# 4.0 update 1 - works fine -#set(tbb_ver "tbb40_20111003oss") -#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20111003oss_src.tgz") -#set(tbb_md5 "7b5d94eb35a563b29ef402e0fd8f15c9") -#set(tbb_version_file "version_string.tmp") -#set(tbb_need_GENERIC_DWORD_LOAD_STORE TRUE) - set(tbb_tarball "${CMAKE_CURRENT_SOURCE_DIR}/${tbb_ver}_src.tgz") set(tbb_src_dir "${CMAKE_CURRENT_BINARY_DIR}/${tbb_ver}") @@ -127,8 +113,6 @@ if(NOT EXISTS "${tbb_src_dir}") endif() endif() -set(TBB_INCLUDE_DIRS "${tbb_src_dir}/include" PARENT_SCOPE) - ocv_include_directories("${tbb_src_dir}/include" "${tbb_src_dir}/src/" "${tbb_src_dir}/src/rml/include" @@ -173,6 +157,9 @@ endif() if (CMAKE_COMPILER_IS_GNUCXX) add_definitions(-DTBB_USE_GCC_BUILTINS=1) #required for ARM GCC + if (NOT CMAKE_OPENCV_GCC_VERSION_NUM LESS 600) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flifetime-dse=1") # workaround for GCC 6.x + endif() endif() if(ANDROID_COMPILER_IS_CLANG) @@ -180,12 +167,6 @@ if(ANDROID_COMPILER_IS_CLANG) ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-prototypes) endif() -if(tbb_need_GENERIC_DWORD_LOAD_STORE) - #needed by TBB 4.0 update 1,2; fixed in TBB 4.0 update 3 but it has 2 new problems - add_definitions(-D__TBB_USE_GENERIC_DWORD_LOAD_STORE=1) - set(tbb_need_GENERIC_DWORD_LOAD_STORE ON PARENT_SCOPE) -endif() - set(TBB_SOURCE_FILES ${lib_srcs} ${lib_hdrs}) if (ARM AND NOT WIN32) @@ -199,6 +180,8 @@ endif() set(TBB_SOURCE_FILES ${TBB_SOURCE_FILES} "${CMAKE_CURRENT_SOURCE_DIR}/${tbb_version_file}") add_library(tbb ${TBB_SOURCE_FILES}) +target_compile_definitions(tbb PRIVATE TBB_USE_GCC_BUILTINS=1 __TBB_GCC_BUILTIN_ATOMICS_PRESENT=1) +target_include_directories(tbb SYSTEM PUBLIC $) if (WIN32) if (ARM) @@ -251,5 +234,4 @@ ocv_install_target(tbb EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev ) -# get TBB version -ocv_parse_header("${tbb_src_dir}/include/tbb/tbb_stddef.h" TBB_VERSION_LINES TBB_VERSION_MAJOR TBB_VERSION_MINOR TBB_INTERFACE_VERSION CACHE) +ocv_tbb_read_version("${tbb_src_dir}/include") diff --git a/apps/traincascade/boost.cpp b/apps/traincascade/boost.cpp index c2e7fb7..f53caad 100644 --- a/apps/traincascade/boost.cpp +++ b/apps/traincascade/boost.cpp @@ -33,16 +33,12 @@ using cv::ParallelLoopBody; #include "cxmisc.h" #include "cvconfig.h" + #ifdef HAVE_TBB -# include "tbb/tbb_stddef.h" -# if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202 -# include "tbb/tbb.h" -# include "tbb/task.h" -# undef min -# undef max -# else -# undef HAVE_TBB -# endif +# include "tbb/tbb.h" +# include "tbb/task.h" +# undef min +# undef max #endif #ifdef HAVE_TBB diff --git a/cmake/OpenCVDetectTBB.cmake b/cmake/OpenCVDetectTBB.cmake index 2acf347..89e4970 100644 --- a/cmake/OpenCVDetectTBB.cmake +++ b/cmake/OpenCVDetectTBB.cmake @@ -1,94 +1,85 @@ -if(BUILD_TBB) - add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/tbb") - include_directories(SYSTEM ${TBB_INCLUDE_DIRS}) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb) - add_definitions(-DTBB_USE_GCC_BUILTINS=1 -D__TBB_GCC_BUILTIN_ATOMICS_PRESENT=1) - if(tbb_need_GENERIC_DWORD_LOAD_STORE) - add_definitions(-D__TBB_USE_GENERIC_DWORD_LOAD_STORE=1) - endif() - set(HAVE_TBB 1) -elseif(UNIX AND NOT APPLE) - PKG_CHECK_MODULES(TBB tbb) +# Search TBB library (4.1 - 4.4, 2017) +# +# Own TBB (3rdparty/tbb): +# - set cmake option BUILD_TBB to ON +# +# External TBB (from system): +# - Fedora: install 'tbb-devel' package +# - Ubuntu: install 'libtbb-dev' package +# +# External TBB (from official site): +# - Linux/OSX: +# - in tbbvars.sh replace 'SUBSTITUTE_INSTALL_DIR_HERE' with absolute path to TBB dir +# - in terminal run 'source tbbvars.sh intel64 linux' ('source tbbvars.sh' in OSX) +# - Windows: +# - in terminal run 'tbbvars.bat intel64 vs2015' +# +# Return: +# - HAVE_TBB set to TRUE +# - "tbb" target exists and added to OPENCV_LINKER_LIBS - if(TBB_FOUND) - set(HAVE_TBB 1) - if(NOT ${TBB_INCLUDE_DIRS} STREQUAL "") - ocv_include_directories(${TBB_INCLUDE_DIRS}) +function(ocv_tbb_verify) + if (NOT "$ENV{TBBROOT}" STREQUAL "") + # check that library and include dir are inside TBBROOT location + get_filename_component(_root "$ENV{TBBROOT}" ABSOLUTE) + get_filename_component(_lib "${TBB_ENV_LIB}" ABSOLUTE) + get_filename_component(_inc "${TBB_ENV_INCLUDE}" ABSOLUTE) + string(FIND "${_lib}" "${_root}" _lib_pos) + string(FIND "${_inc}" "${_root}" _inc_pos) + if (NOT (_lib_pos EQUAL 0 AND _inc_pos EQUAL 0)) + message(SEND_ERROR + "Possible issue with TBB detection - TBBROOT is set, " + "but library/include path is not inside it:\n " + "TBBROOT: $ENV{TBBROOT}\n " + "(absolute): ${_root}\n " + "INCLUDE: ${_inc}\n " + "LIBRARY: ${_lib}\n") endif() - link_directories(${TBB_LIBRARY_DIRS}) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${TBB_LIBRARIES}) endif() -endif() +endfunction() -if(NOT HAVE_TBB) - set(TBB_DEFAULT_INCLUDE_DIRS - "/opt/intel/tbb/include" "/usr/local/include" "/usr/include" - "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB" - "C:/Program Files/tbb/include" - "C:/Program Files (x86)/tbb/include" - "${CMAKE_INSTALL_PREFIX}/include") +function(ocv_tbb_env_guess _found) + find_path(TBB_ENV_INCLUDE NAMES "tbb/tbb.h" PATHS ENV CPATH NO_DEFAULT_PATH) + find_path(TBB_ENV_INCLUDE NAMES "tbb/tbb.h") + find_library(TBB_ENV_LIB NAMES "tbb" PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH NO_DEFAULT_PATH) + find_library(TBB_ENV_LIB NAMES "tbb") + find_library(TBB_ENV_LIB_DEBUG NAMES "tbb_debug" PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH NO_DEFAULT_PATH) + find_library(TBB_ENV_LIB_DEBUG NAMES "tbb_debug") + if (TBB_ENV_INCLUDE AND TBB_ENV_LIB) + ocv_tbb_verify() + ocv_tbb_read_version("${TBB_ENV_INCLUDE}") + add_library(tbb UNKNOWN IMPORTED) + set_target_properties(tbb PROPERTIES + IMPORTED_LOCATION "${TBB_ENV_LIB}" + IMPORTED_LOCATION_DEBUG "${TBB_ENV_LIB_DEBUG}" + INTERFACE_INCLUDE_DIRECTORIES "${TBB_ENV_INCLUDE}" + ) + message(STATUS "Found TBB: ${TBB_ENV_LIB}") + set(${_found} TRUE PARENT_SCOPE) + endif() +endfunction() - find_path(TBB_INCLUDE_DIRS "tbb/tbb.h" PATHS ${TBB_INCLUDE_DIR} ${TBB_DEFAULT_INCLUDE_DIRS} DOC "The path to TBB headers") - if(TBB_INCLUDE_DIRS) - if(UNIX) - set(TBB_LIB_DIR "${TBB_INCLUDE_DIRS}/../lib" CACHE PATH "Full path of TBB library directory") - link_directories("${TBB_LIB_DIR}") - endif() - if(APPLE) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} libtbb.dylib) - elseif(ANDROID) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb) - add_definitions(-DTBB_USE_GCC_BUILTINS) - elseif (UNIX) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb) - elseif (WIN32) - if(CMAKE_COMPILER_IS_GNUCXX) - set(TBB_LIB_DIR "${TBB_INCLUDE_DIRS}/../lib" CACHE PATH "Full path of TBB library directory") - link_directories("${TBB_LIB_DIR}") - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb) - else() - get_filename_component(_TBB_LIB_PATH "${TBB_INCLUDE_DIRS}/../lib" ABSOLUTE) +function(ocv_tbb_read_version _path) + find_file(TBB_VER_FILE tbb/tbb_stddef.h "${_path}" NO_DEFAULT_PATH CMAKE_FIND_ROOT_PATH_BOTH) + ocv_parse_header("${TBB_VER_FILE}" TBB_VERSION_LINES TBB_VERSION_MAJOR TBB_VERSION_MINOR TBB_INTERFACE_VERSION CACHE) +endfunction() - if(CMAKE_SYSTEM_PROCESSOR MATCHES amd64*|x86_64* OR MSVC64) - set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/intel64") - else() - set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/ia32") - endif() +#===================================================================== - if(MSVC80) - set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc8") - elseif(MSVC90) - set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc9") - elseif(MSVC10) - set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc10") - elseif(MSVC11) - set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc11") - elseif(MSVC12) - set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc12") - elseif(MSVC14) - set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc14") - endif() - set(TBB_LIB_DIR "${_TBB_LIB_PATH}" CACHE PATH "Full path of TBB library directory") - link_directories("${TBB_LIB_DIR}") - endif() - endif() +if(BUILD_TBB) + add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/tbb") + message(STATUS "Found TBB: build") + set(HAVE_TBB TRUE) +endif() - set(HAVE_TBB 1) - if(NOT "${TBB_INCLUDE_DIRS}" STREQUAL "") - ocv_include_directories("${TBB_INCLUDE_DIRS}") - endif() - endif(TBB_INCLUDE_DIRS) -endif(NOT HAVE_TBB) +if(NOT HAVE_TBB) + ocv_tbb_env_guess(HAVE_TBB) +endif() -# get TBB version -if(HAVE_TBB) - find_file(TBB_STDDEF_PATH tbb/tbb_stddef.h "${TBB_INCLUDE_DIRS}") - mark_as_advanced(TBB _STDDEF_PATH) +if(TBB_INTERFACE_VERSION LESS 6000) # drop support of versions < 4.0 + set(HAVE_TBB FALSE) endif() -if(HAVE_TBB AND TBB_STDDEF_PATH) - ocv_parse_header("${TBB_STDDEF_PATH}" TBB_VERSION_LINES TBB_VERSION_MAJOR TBB_VERSION_MINOR TBB_INTERFACE_VERSION) -else() - unset(TBB_VERSION_MAJOR) - unset(TBB_VERSION_MINOR) - unset(TBB_INTERFACE_VERSION) + +if(HAVE_TBB) + list(APPEND OPENCV_LINKER_LIBS tbb) endif() diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 34b4565..b63a99b 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -687,9 +687,9 @@ macro(ocv_parse_header FILENAME FILE_VAR) set(__parnet_scope OFF) set(__add_cache OFF) foreach(name ${ARGN}) - if("${name}" STREQUAL "PARENT_SCOPE") + if(${name} STREQUAL "PARENT_SCOPE") set(__parnet_scope ON) - elseif("${name}" STREQUAL "CACHE") + elseif(${name} STREQUAL "CACHE") set(__add_cache ON) elseif(vars_regex) set(vars_regex "${vars_regex}|${name}") @@ -703,7 +703,7 @@ macro(ocv_parse_header FILENAME FILE_VAR) unset(${FILE_VAR}) endif() foreach(name ${ARGN}) - if(NOT "${name}" STREQUAL "PARENT_SCOPE" AND NOT "${name}" STREQUAL "CACHE") + if(NOT ${name} STREQUAL "PARENT_SCOPE" AND NOT ${name} STREQUAL "CACHE") if(${FILE_VAR}) if(${FILE_VAR} MATCHES ".+[ \t]${name}[ \t]+([0-9]+).*") string(REGEX REPLACE ".+[ \t]${name}[ \t]+([0-9]+).*" "\\1" ${name} "${${FILE_VAR}}") diff --git a/modules/core/include/opencv2/core/private.hpp b/modules/core/include/opencv2/core/private.hpp index 4e5ba78..e428ecf 100644 --- a/modules/core/include/opencv2/core/private.hpp +++ b/modules/core/include/opencv2/core/private.hpp @@ -60,15 +60,10 @@ #endif #ifdef HAVE_TBB -# include "tbb/tbb_stddef.h" -# if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202 -# include "tbb/tbb.h" -# include "tbb/task.h" -# undef min -# undef max -# else -# undef HAVE_TBB -# endif +# include "tbb/tbb.h" +# include "tbb/task.h" +# undef min +# undef max #endif #if defined HAVE_FP16 && (defined __F16C__ || (defined _MSC_VER && _MSC_VER >= 1700)) diff --git a/modules/core/src/parallel.cpp b/modules/core/src/parallel.cpp index ebf3907..71ac94e 100644 --- a/modules/core/src/parallel.cpp +++ b/modules/core/src/parallel.cpp @@ -84,37 +84,30 @@ */ #if defined HAVE_TBB + #include "tbb/tbb.h" + #include "tbb/task.h" #include "tbb/tbb_stddef.h" - #if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202 - #include "tbb/tbb.h" - #include "tbb/task.h" - #if TBB_INTERFACE_VERSION >= 6100 - #include "tbb/task_arena.h" - #endif - #undef min - #undef max - #else - #undef HAVE_TBB - #endif // end TBB version -#endif - -#ifndef HAVE_TBB - #if defined HAVE_CSTRIPES - #include "C=.h" - #undef shared - #elif defined HAVE_OPENMP - #include - #elif defined HAVE_GCD - #include - #include - #elif defined WINRT && _MSC_VER < 1900 - #include - #elif defined HAVE_CONCURRENCY - #include + #if TBB_INTERFACE_VERSION >= 8000 + #include "tbb/task_arena.h" #endif + #undef min + #undef max +#elif defined HAVE_CSTRIPES + #include "C=.h" + #undef shared +#elif defined HAVE_OPENMP + #include +#elif defined HAVE_GCD + #include + #include +#elif defined WINRT && _MSC_VER < 1900 + #include +#elif defined HAVE_CONCURRENCY + #include #endif -#if defined HAVE_TBB && TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202 + +#if defined HAVE_TBB # define CV_PARALLEL_FRAMEWORK "tbb" #elif defined HAVE_CSTRIPES # define CV_PARALLEL_FRAMEWORK "cstripes" @@ -491,8 +484,10 @@ void cv::setNumThreads( int threads ) int cv::getThreadNum(void) { #if defined HAVE_TBB - #if TBB_INTERFACE_VERSION >= 6100 && defined TBB_PREVIEW_TASK_ARENA && TBB_PREVIEW_TASK_ARENA - return tbb::task_arena::current_slot(); + #if TBB_INTERFACE_VERSION >= 9100 + return tbb::this_task_arena::current_thread_index(); + #elif TBB_INTERFACE_VERSION >= 8000 + return tbb::task_arena::current_thread_index(); #else return 0; #endif diff --git a/modules/videoio/src/cap_openni.cpp b/modules/videoio/src/cap_openni.cpp index 6c91df9..50cab02 100644 --- a/modules/videoio/src/cap_openni.cpp +++ b/modules/videoio/src/cap_openni.cpp @@ -44,10 +44,6 @@ #ifdef HAVE_OPENNI -#if defined TBB_INTERFACE_VERSION && TBB_INTERFACE_VERSION < 5000 -# undef HAVE_TBB -#endif - #include #ifndef i386 diff --git a/modules/videoio/src/cap_openni2.cpp b/modules/videoio/src/cap_openni2.cpp index 775038e..c9a8dba 100644 --- a/modules/videoio/src/cap_openni2.cpp +++ b/modules/videoio/src/cap_openni2.cpp @@ -44,10 +44,6 @@ #ifdef HAVE_OPENNI2 -#if defined TBB_INTERFACE_VERSION && TBB_INTERFACE_VERSION < 5000 -# undef HAVE_TBB -#endif - #include #ifndef i386 diff --git a/samples/gpu/driver_api_multi.cpp b/samples/gpu/driver_api_multi.cpp index 933368a..6d49ee9 100644 --- a/samples/gpu/driver_api_multi.cpp +++ b/samples/gpu/driver_api_multi.cpp @@ -12,15 +12,10 @@ #include "opencv2/cudaarithm.hpp" #ifdef HAVE_TBB -# include "tbb/tbb_stddef.h" -# if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202 -# include "tbb/tbb.h" -# include "tbb/task.h" -# undef min -# undef max -# else -# undef HAVE_TBB -# endif +# include "tbb/tbb.h" +# include "tbb/task.h" +# undef min +# undef max #endif #if !defined(HAVE_CUDA) || !defined(HAVE_TBB) || defined(__arm__) diff --git a/samples/gpu/driver_api_stereo_multi.cpp b/samples/gpu/driver_api_stereo_multi.cpp index 7cb0f5d..e487c31 100644 --- a/samples/gpu/driver_api_stereo_multi.cpp +++ b/samples/gpu/driver_api_stereo_multi.cpp @@ -14,15 +14,10 @@ #include "opencv2/cudastereo.hpp" #ifdef HAVE_TBB -# include "tbb/tbb_stddef.h" -# if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202 -# include "tbb/tbb.h" -# include "tbb/task.h" -# undef min -# undef max -# else -# undef HAVE_TBB -# endif +# include "tbb/tbb.h" +# include "tbb/task.h" +# undef min +# undef max #endif #if !defined(HAVE_CUDA) || !defined(HAVE_TBB) || defined(__arm__) diff --git a/samples/gpu/multi.cpp b/samples/gpu/multi.cpp index 11e33b3..9c0e15f 100644 --- a/samples/gpu/multi.cpp +++ b/samples/gpu/multi.cpp @@ -12,15 +12,10 @@ #include "opencv2/cudaarithm.hpp" #ifdef HAVE_TBB -# include "tbb/tbb_stddef.h" -# if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202 -# include "tbb/tbb.h" -# include "tbb/task.h" -# undef min -# undef max -# else -# undef HAVE_TBB -# endif +# include "tbb/tbb.h" +# include "tbb/task.h" +# undef min +# undef max #endif #if !defined(HAVE_CUDA) || !defined(HAVE_TBB)