From 4fcc18c00eb5186c9850fd3f725722d6198a7545 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Sat, 2 Apr 2022 11:11:13 +0300 Subject: [PATCH] Tbb 2018 and older usage (#11411) * fixed TBB * Fixed compilation with old TBBs * Fixed installation for custom provided TBB --- cmake/dependencies.cmake | 2 +- cmake/developer_package/TBBConfig.cmake | 3 ++ src/cmake/ie_parallel.cmake | 4 +- src/cmake/install_tbb.cmake | 46 ++++++++----------- .../src/threading/ie_tbb_streams_executor.cpp | 3 ++ 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index a297d9684e0..8881b1c9bd7 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -146,7 +146,7 @@ if(THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO" AND NOT ENABLE_SYST # custom downloaded or user provided TBB update_deps_cache(TBB_DIR "${TBBROOT}/cmake" "Path to TBB cmake folder") else() - message(FATAL_ERROR "Failed to find TBBConfig.cmake in ${TBBROOT} tree") + message(WARNING "Failed to find TBBConfig.cmake in ${TBBROOT} tree. Custom TBBConfig.cmake will be used") endif() debug_message(STATUS "tbb=" ${TBB}) diff --git a/cmake/developer_package/TBBConfig.cmake b/cmake/developer_package/TBBConfig.cmake index 908125a8faf..20ae8d35456 100644 --- a/cmake/developer_package/TBBConfig.cmake +++ b/cmake/developer_package/TBBConfig.cmake @@ -23,6 +23,9 @@ else() unset(IE_OWN_TBB_CONFIG) endif() +unset(TBB_DIR) +unset(TBB_DIR CACHE) + find_package(TBB CONFIG PATHS ${TBBROOT}/cmake diff --git a/src/cmake/ie_parallel.cmake b/src/cmake/ie_parallel.cmake index b52d593a9ea..6a751499879 100644 --- a/src/cmake/ie_parallel.cmake +++ b/src/cmake/ie_parallel.cmake @@ -4,7 +4,7 @@ macro(ov_find_tbb) if(THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO" AND NOT TBB_FOUND) - find_package(TBB COMPONENTS tbb tbbmalloc) + find_package(TBB QUIET COMPONENTS tbb tbbmalloc) # try to find TBB via custom scripts if have not found by default if(NOT TBB_FOUND AND IEDevScripts_DIR) @@ -19,6 +19,8 @@ macro(ov_find_tbb) PATHS ${IEDevScripts_DIR} NO_CMAKE_FIND_ROOT_PATH NO_DEFAULT_PATH) + else() + message(STATUS "TBB (${TBB_VERSION}) is found at ${TBB_DIR}") endif() # WA for oneTBB: it does not define TBB_IMPORTED_TARGETS diff --git a/src/cmake/install_tbb.cmake b/src/cmake/install_tbb.cmake index 511470e7ff1..565e8dda6ee 100644 --- a/src/cmake/install_tbb.cmake +++ b/src/cmake/install_tbb.cmake @@ -51,18 +51,11 @@ if(THREADING MATCHES "^(TBB|TBB_AUTO)$" AND if(TBB MATCHES ${TEMP}) set(tbb_downloaded ON) - elseif(DEFINED ENV{TBB}) + elseif(DEFINED ENV{TBBROOT}) set(tbb_custom ON) endif() - if(tbb_custom OR ENABLE_SYSTEM_TBB) - # since the setup.py for pip installs tbb component - # explicitly, it's OK to put EXCLUDE_FROM_ALL to such component - # to ignore from IRC distribution - set(exclude_from_all EXCLUDE_FROM_ALL) - endif() - - if(ENABLE_SYSTEM_TBB) + if(ENABLE_SYSTEM_TBB OR tbb_custom) # need to take locations of actual libraries and install them foreach(tbb_lib IN LISTS TBB_IMPORTED_TARGETS) get_target_property(tbb_loc ${tbb_lib} IMPORTED_LOCATION_RELEASE) @@ -73,40 +66,40 @@ if(THREADING MATCHES "^(TBB|TBB_AUTO)$" AND # We need to install such files get_filename_component(name_we "${tbb_loc}" NAME_WE) get_filename_component(dir "${tbb_loc}" DIRECTORY) + # grab all tbb files matching pattern file(GLOB tbb_files "${dir}/${name_we}.*") foreach(tbb_file IN LISTS tbb_files) if(tbb_file MATCHES "^.*\.${CMAKE_SHARED_LIBRARY_SUFFIX}(\.[0-9]+)*$") + # since the setup.py for pip installs tbb component + # explicitly, it's OK to put EXCLUDE_FROM_ALL to such component + # to ignore from IRC / apt / yum distribution; + # but they will be present in .wheel install(FILES "${tbb_file}" DESTINATION runtime/3rdparty/tbb/lib - COMPONENT tbb ${exclude_from_all}) + COMPONENT tbb EXCLUDE_FROM_ALL) endif() endforeach() endforeach() - else() + elseif(tbb_downloaded) if(WIN32) install(DIRECTORY "${TBB}/bin" DESTINATION runtime/3rdparty/tbb - COMPONENT tbb ${exclude_from_all}) - elseif(tbb_custom OR tbb_downloaded) + COMPONENT tbb) + else() install(DIRECTORY "${TBB}/lib" DESTINATION runtime/3rdparty/tbb - COMPONENT tbb ${exclude_from_all} - FILES_MATCHING - # install only versioned shared libraries - REGEX "^.*\.${CMAKE_SHARED_LIBRARY_SUFFIX}(\.[0-9]+)*$") + COMPONENT tbb) endif() - endif() - - # development files are needed only for 'tbb_downloaded' case - # which we are going to distribute - if(tbb_downloaded) - ie_cpack_add_component(tbb_dev REQUIRED) - list(APPEND core_dev_components tbb_dev) install(FILES "${TBB}/LICENSE" DESTINATION runtime/3rdparty/tbb COMPONENT tbb) + # install development files + + ie_cpack_add_component(tbb_dev REQUIRED) + list(APPEND core_dev_components tbb_dev) + set(IE_TBB_DIR_INSTALL "3rdparty/tbb/cmake") install(FILES "${TBB}/cmake/TBBConfig.cmake" "${TBB}/cmake/TBBConfigVersion.cmake" @@ -120,13 +113,14 @@ if(THREADING MATCHES "^(TBB|TBB_AUTO)$" AND # .lib files are needed only for Windows install(DIRECTORY "${TBB}/lib" DESTINATION runtime/3rdparty/tbb - COMPONENT tbb) + COMPONENT tbb_dev) endif() + else() + message(WARNING "TBB of unknown origin. TBB files are not installed") endif() unset(tbb_downloaded) unset(tbb_custom) - unset(exclude_from_all) endif() # install tbbbind for static OpenVINO case diff --git a/src/inference/src/threading/ie_tbb_streams_executor.cpp b/src/inference/src/threading/ie_tbb_streams_executor.cpp index 58205b32245..f255a374697 100644 --- a/src/inference/src/threading/ie_tbb_streams_executor.cpp +++ b/src/inference/src/threading/ie_tbb_streams_executor.cpp @@ -21,6 +21,9 @@ #if ((IE_THREAD == IE_THREAD_TBB) || (IE_THREAD == IE_THREAD_TBB_AUTO)) # include # include +# ifndef TBB_PREVIEW_GLOBAL_CONTROL +# define TBB_PREVIEW_GLOBAL_CONTROL 1 +# endif # include # include # include