core, gapi: supported build with oneTBB 2021

This commit is contained in:
Maksim Shabunin 2021-01-24 04:12:40 +03:00
parent 900051cd04
commit 694fe3e7d2
6 changed files with 24 additions and 11 deletions

View File

@ -170,4 +170,4 @@ ocv_install_target(tbb EXPORT OpenCVModules
ocv_install_3rdparty_licenses(tbb "${tbb_src_dir}/LICENSE" "${tbb_src_dir}/README") ocv_install_3rdparty_licenses(tbb "${tbb_src_dir}/LICENSE" "${tbb_src_dir}/README")
ocv_tbb_read_version("${tbb_src_dir}/include") ocv_tbb_read_version("${tbb_src_dir}/include" tbb)

View File

@ -19,7 +19,7 @@
# - "tbb" target exists and added to OPENCV_LINKER_LIBS # - "tbb" target exists and added to OPENCV_LINKER_LIBS
function(ocv_tbb_cmake_guess _found) function(ocv_tbb_cmake_guess _found)
find_package(TBB QUIET COMPONENTS tbb PATHS "$ENV{TBBROOT}/cmake") find_package(TBB QUIET COMPONENTS tbb PATHS "$ENV{TBBROOT}/cmake" "$ENV{TBBROOT}/lib/cmake/tbb")
if(TBB_FOUND) if(TBB_FOUND)
if(NOT TARGET TBB::tbb) if(NOT TARGET TBB::tbb)
message(WARNING "No TBB::tbb target found!") message(WARNING "No TBB::tbb target found!")
@ -28,11 +28,11 @@ function(ocv_tbb_cmake_guess _found)
get_target_property(_lib TBB::tbb IMPORTED_LOCATION_RELEASE) get_target_property(_lib TBB::tbb IMPORTED_LOCATION_RELEASE)
message(STATUS "Found TBB (cmake): ${_lib}") message(STATUS "Found TBB (cmake): ${_lib}")
get_target_property(_inc TBB::tbb INTERFACE_INCLUDE_DIRECTORIES) get_target_property(_inc TBB::tbb INTERFACE_INCLUDE_DIRECTORIES)
ocv_tbb_read_version("${_inc}")
add_library(tbb INTERFACE IMPORTED) add_library(tbb INTERFACE IMPORTED)
set_target_properties(tbb PROPERTIES set_target_properties(tbb PROPERTIES
INTERFACE_LINK_LIBRARIES TBB::tbb INTERFACE_LINK_LIBRARIES TBB::tbb
) )
ocv_tbb_read_version("${_inc}" tbb)
set(${_found} TRUE PARENT_SCOPE) set(${_found} TRUE PARENT_SCOPE)
endif() endif()
endfunction() endfunction()
@ -66,7 +66,6 @@ function(ocv_tbb_env_guess _found)
find_library(TBB_ENV_LIB_DEBUG NAMES "tbb_debug") find_library(TBB_ENV_LIB_DEBUG NAMES "tbb_debug")
if (TBB_ENV_INCLUDE AND (TBB_ENV_LIB OR TBB_ENV_LIB_DEBUG)) if (TBB_ENV_INCLUDE AND (TBB_ENV_LIB OR TBB_ENV_LIB_DEBUG))
ocv_tbb_env_verify() ocv_tbb_env_verify()
ocv_tbb_read_version("${TBB_ENV_INCLUDE}")
add_library(tbb UNKNOWN IMPORTED) add_library(tbb UNKNOWN IMPORTED)
set_target_properties(tbb PROPERTIES set_target_properties(tbb PROPERTIES
IMPORTED_LOCATION "${TBB_ENV_LIB}" IMPORTED_LOCATION "${TBB_ENV_LIB}"
@ -82,12 +81,14 @@ function(ocv_tbb_env_guess _found)
get_filename_component(_dir "${TBB_ENV_LIB}" DIRECTORY) get_filename_component(_dir "${TBB_ENV_LIB}" DIRECTORY)
set_target_properties(tbb PROPERTIES INTERFACE_LINK_LIBRARIES "-L${_dir}") set_target_properties(tbb PROPERTIES INTERFACE_LINK_LIBRARIES "-L${_dir}")
endif() endif()
ocv_tbb_read_version("${TBB_ENV_INCLUDE}" tbb)
message(STATUS "Found TBB (env): ${TBB_ENV_LIB}") message(STATUS "Found TBB (env): ${TBB_ENV_LIB}")
set(${_found} TRUE PARENT_SCOPE) set(${_found} TRUE PARENT_SCOPE)
endif() endif()
endfunction() endfunction()
function(ocv_tbb_read_version _path) function(ocv_tbb_read_version _path _tgt)
find_file(TBB_VER_FILE oneapi/tbb/version.h "${_path}" NO_DEFAULT_PATH CMAKE_FIND_ROOT_PATH_BOTH)
find_file(TBB_VER_FILE tbb/tbb_stddef.h "${_path}" NO_DEFAULT_PATH CMAKE_FIND_ROOT_PATH_BOTH) 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) ocv_parse_header("${TBB_VER_FILE}" TBB_VERSION_LINES TBB_VERSION_MAJOR TBB_VERSION_MINOR TBB_INTERFACE_VERSION CACHE)
endfunction() endfunction()

View File

@ -103,7 +103,6 @@
#endif #endif
#include "tbb/tbb.h" #include "tbb/tbb.h"
#include "tbb/task.h" #include "tbb/task.h"
#include "tbb/tbb_stddef.h"
#if TBB_INTERFACE_VERSION >= 8000 #if TBB_INTERFACE_VERSION >= 8000
#include "tbb/task_arena.h" #include "tbb/task_arena.h"
#endif #endif

View File

@ -6,7 +6,9 @@
#include "gtbbexecutor.hpp" #include "gtbbexecutor.hpp"
#if defined(HAVE_TBB) #if defined(HAVE_TBB) && (TBB_INTERFACE_VERSION < 12000)
// TODO: TBB task API has been deprecated and removed in 12000
#include "gapi_itt.hpp" #include "gapi_itt.hpp"
#include <opencv2/gapi/own/assert.hpp> #include <opencv2/gapi/own/assert.hpp>
@ -442,4 +444,4 @@ std::ostream& cv::gimpl::parallel::operator<<(std::ostream& o, tile_node const&
return o; return o;
} }
#endif // HAVE_TBB #endif // HAVE_TBB && TBB_INTERFACE_VERSION

View File

@ -11,7 +11,11 @@
#include <opencv2/cvconfig.h> #include <opencv2/cvconfig.h>
#endif #endif
#if defined(HAVE_TBB) #ifdef HAVE_TBB
#include <tbb/tbb.h>
#include <tbb/task.h>
#if TBB_INTERFACE_VERSION < 12000
// TODO: TBB task API has been deprecated and removed in 12000
#include <atomic> #include <atomic>
#include <vector> #include <vector>
@ -98,6 +102,7 @@ void execute(prio_items_queue_t& q, tbb::task_arena& arena);
}}} // namespace cv::gimpl::parallel }}} // namespace cv::gimpl::parallel
#endif // TBB_INTERFACE_VERSION
#endif // HAVE_TBB #endif // HAVE_TBB
#endif // OPENCV_GAPI_TBB_EXECUTOR_HPP #endif // OPENCV_GAPI_TBB_EXECUTOR_HPP

View File

@ -7,10 +7,14 @@
// Deliberately include .cpp file instead of header as we use non exported function (execute) // Deliberately include .cpp file instead of header as we use non exported function (execute)
#include <executor/gtbbexecutor.cpp> #include <executor/gtbbexecutor.cpp>
#if defined(HAVE_TBB) #ifdef HAVE_TBB
#include <tbb/tbb.h>
#include <tbb/task.h>
#if TBB_INTERFACE_VERSION < 12000
#include <tbb/task_arena.h>
#include "../test_precomp.hpp" #include "../test_precomp.hpp"
#include <tbb/task_arena.h>
#include <thread> #include <thread>
namespace { namespace {
@ -169,4 +173,6 @@ TEST(TBBExecutor, Dependencies) {
} }
} }
} // namespace opencv_test } // namespace opencv_test
#endif //TBB_INTERFACE_VERSION
#endif //HAVE_TBB #endif //HAVE_TBB