More accurate hwloc finding in case of dynamic tbbbind (#16488)

This commit is contained in:
Ilya Lavrenov 2023-03-24 22:42:20 +04:00 committed by GitHub
parent 81b4666632
commit 18df64c135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,10 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
if(NOT ANDROID)
find_package(PkgConfig QUIET)
endif()
function(_ov_get_tbb_location tbb_target _tbb_lib_location_var) function(_ov_get_tbb_location tbb_target _tbb_lib_location_var)
if(NOT TBB_FOUND) if(NOT TBB_FOUND)
return() return()
@ -63,48 +67,45 @@ macro(ov_find_package_tbb)
unset(TBB_DIR) unset(TBB_DIR)
# try tbb.pc from system # try tbb.pc from system
if(NOT ANDROID AND ENABLE_SYSTEM_TBB) if(ENABLE_SYSTEM_TBB AND PkgConfig_FOUND)
find_package(PkgConfig QUIET) macro(_ov_pkg_config_tbb_unset)
if(PkgConfig_FOUND) # unset since it affects OpenVINOConfig.cmake.in
macro(_ov_pkg_config_tbb_unset) unset(tbb_FOUND)
# unset since it affects OpenVINOConfig.cmake.in unset(tbb_FOUND CACHE)
unset(tbb_FOUND) endmacro()
unset(tbb_FOUND CACHE) pkg_search_module(tbb QUIET
endmacro() IMPORTED_TARGET GLOBAL
pkg_search_module(tbb QUIET tbb)
IMPORTED_TARGET GLOBAL if(tbb_FOUND)
tbb) # parse version
if(tbb_FOUND) string(REGEX REPLACE "~.*" "" tbb_VERSION_PATCHED "${tbb_VERSION}")
# parse version if(tbb_VERSION_PATCHED AND tbb_VERSION_PATCHED VERSION_LESS _ov_minimal_tbb_version)
string(REGEX REPLACE "~.*" "" tbb_VERSION_PATCHED "${tbb_VERSION}") _ov_pkg_config_tbb_unset()
if(tbb_VERSION_PATCHED AND tbb_VERSION_PATCHED VERSION_LESS _ov_minimal_tbb_version) message(WARNING "Found TBB ${tbb_VERSION} via ${PKG_CONFIG_EXECUTABLE} while OpenVINO requies ${_ov_minimal_tbb_version} at least")
_ov_pkg_config_tbb_unset() elseif(TARGET PkgConfig::tbb)
message(WARNING "Found TBB ${tbb_VERSION} via ${PKG_CONFIG_EXECUTABLE} while OpenVINO requies ${_ov_minimal_tbb_version} at least") add_library(TBB::tbb ALIAS PkgConfig::tbb)
elseif(TARGET PkgConfig::tbb) set(TBB_VERSION ${tbb_VERSION})
add_library(TBB::tbb ALIAS PkgConfig::tbb) set(TBB_FOUND ${tbb_FOUND})
set(TBB_VERSION ${tbb_VERSION})
set(TBB_FOUND ${tbb_FOUND})
# note: for python wheels we need to find and install tbbmalloc as well # note: for python wheels we need to find and install tbbmalloc as well
_ov_get_tbb_location(PkgConfig::tbb tbb_loc) _ov_get_tbb_location(PkgConfig::tbb tbb_loc)
string(REPLACE "tbb" "tbbmalloc" tbbmalloc_loc "${tbb_loc}") string(REPLACE "tbb" "tbbmalloc" tbbmalloc_loc "${tbb_loc}")
if(EXISTS "${tbbmalloc_loc}") if(EXISTS "${tbbmalloc_loc}")
add_library(TBB::tbbmalloc SHARED IMPORTED) add_library(TBB::tbbmalloc SHARED IMPORTED)
set_target_properties(TBB::tbbmalloc PROPERTIES IMPORTED_LOCATION ${tbbmalloc_loc}) set_target_properties(TBB::tbbmalloc PROPERTIES IMPORTED_LOCATION ${tbbmalloc_loc})
endif()
message(STATUS "${PKG_CONFIG_EXECUTABLE}: tbb (${tbb_VERSION}) is found at ${tbb_PREFIX}")
else()
_ov_pkg_config_tbb_unset()
if(CPACK_GENERATOR STREQUAL "^(DEB|RPM|CONDA-FORGE|BREW)$")
# package managers require system TBB
set(message_type FATAL_ERROR)
else()
set(message_type WARNING)
endif()
message(${message_type} "cmake v${CMAKE_VERSION} contains bug in function 'pkg_search_module', need to update to at least v3.16.0 version")
endif() endif()
message(STATUS "${PKG_CONFIG_EXECUTABLE}: tbb (${tbb_VERSION}) is found at ${tbb_PREFIX}")
else()
_ov_pkg_config_tbb_unset()
if(CPACK_GENERATOR STREQUAL "^(DEB|RPM|CONDA-FORGE|BREW)$")
# package managers require system TBB
set(message_type FATAL_ERROR)
else()
set(message_type WARNING)
endif()
message(${message_type} "cmake v${CMAKE_VERSION} contains bug in function 'pkg_search_module', need to update to at least v3.16.0 version")
endif() endif()
endif() endif()
endif() endif()
@ -124,7 +125,7 @@ macro(ov_find_package_tbb)
endif() endif()
# try to find one more time # try to find one more time
find_package(TBB QUIET COMPONENTS tbb tbbmalloc find_package(TBB ${_ov_minimal_tbb_version} QUIET COMPONENTS tbb tbbmalloc
# TBB_DIR can be provided by ov_download_tbb # TBB_DIR can be provided by ov_download_tbb
HINTS ${TBB_DIR} HINTS ${TBB_DIR}
${_tbb_paths} ${_tbb_paths}
@ -143,20 +144,38 @@ macro(ov_find_package_tbb)
endforeach() endforeach()
if(WIN32 AND TARGET TBB::tbbbind_2_5) if(WIN32 AND TARGET TBB::tbbbind_2_5)
# Add HWLOC::hwloc_2_5 target to check via Apivalidator # some package managers provide hwloc.pc file within installation package
get_target_property(TBB_location TBB::tbb IMPORTED_LOCATION_RELEASE) # let's try it first
get_filename_component(TBB_dir "${TBB_location}" DIRECTORY) if(PkgConfig_FOUND)
set(hwloc_dll_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwloc${CMAKE_SHARED_LIBRARY_SUFFIX}") pkg_search_module(HWLOC QUIET
find_file(HWLOC_DLL NAMES ${hwloc_dll_name} PATHS "${TBB_dir}" DOC "Path to hwloc.dll") IMPORTED_TARGET GLOBAL
hwloc)
if(NOT HWLOC_DLL)
message(FATAL_ERROR "Failed to find ${hwloc_dll_name} in ${TBB_dir}")
endif() endif()
add_library(HWLOC::hwloc_2_5 SHARED IMPORTED) if(TARGET PkgConfig::HWLOC)
set_property(TARGET HWLOC::hwloc_2_5 APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) # dependency is satisfied
set_target_properties(HWLOC::hwloc_2_5 PROPERTIES else()
IMPORTED_LOCATION_RELEASE "${HWLOC_DLL}") # Add HWLOC::hwloc_2_5 target to check via ApiValidator
get_target_property(imported_configs TBB::tbbbind_2_5 IMPORTED_CONFIGURATIONS)
foreach(imported_config RELEASE RELWITHDEBINFO DEBUG)
if(imported_config IN_LIST imported_configs)
get_target_property(TBBbind_location TBB::tbbbind_2_5 IMPORTED_LOCATION_${imported_config})
get_filename_component(TBB_dir "${TBBbind_location}" DIRECTORY)
break()
endif()
endforeach()
set(hwloc_dll_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwloc${CMAKE_SHARED_LIBRARY_SUFFIX}")
find_file(HWLOC_DLL NAMES ${hwloc_dll_name} PATHS "${TBB_dir}" DOC "Path to hwloc.dll")
if(NOT HWLOC_DLL)
message(FATAL_ERROR "Failed to find ${hwloc_dll_name} in ${TBB_dir}")
endif()
add_library(HWLOC::hwloc_2_5 SHARED IMPORTED)
set_property(TARGET HWLOC::hwloc_2_5 APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(HWLOC::hwloc_2_5 PROPERTIES IMPORTED_LOCATION_RELEASE "${HWLOC_DLL}")
endif()
endif() endif()
endif() endif()