From b02dba6bbec39f6a55b24dd33f9d210577e8bc26 Mon Sep 17 00:00:00 2001 From: "Isaev, Ilya" Date: Tue, 29 Nov 2022 11:14:18 +0100 Subject: [PATCH] Link tbbbind against static HWLOC instead of HWLOC 1.11 Signed-off-by: Isaev, Ilya --- cmake/hwloc_detection.cmake | 16 +++++++-- src/tbb/governor.cpp | 7 ++-- src/tbbbind/CMakeLists.txt | 6 ++-- src/tbbbind/def/lin32-tbbbind.def | 3 ++ src/tbbbind/def/lin64-tbbbind.def | 3 ++ test/CMakeLists.txt | 57 ++++++++++++++++++------------- 6 files changed, 59 insertions(+), 33 deletions(-) diff --git a/cmake/hwloc_detection.cmake b/cmake/hwloc_detection.cmake index aaca5a599c..73782cbeae 100644 --- a/cmake/hwloc_detection.cmake +++ b/cmake/hwloc_detection.cmake @@ -12,20 +12,29 @@ # See the License for the specific language governing permissions and # limitations under the License. -list(APPEND HWLOC_REQUIRED_VERSIONS 1_11 2 2_5) +list(APPEND HWLOC_REQUIRED_VERSIONS static 2 2_5) foreach(hwloc_version ${HWLOC_REQUIRED_VERSIONS}) + set(HWLOC_TARGET_NAME HWLOC::hwloc_${hwloc_version}) + + string(TOUPPER ${hwloc_version} hwloc_version) + if (NOT WIN32) set(CMAKE_HWLOC_${hwloc_version}_DLL_PATH STUB) endif() - set(HWLOC_TARGET_NAME HWLOC::hwloc_${hwloc_version}) if (NOT TARGET ${HWLOC_TARGET_NAME} AND CMAKE_HWLOC_${hwloc_version}_LIBRARY_PATH AND CMAKE_HWLOC_${hwloc_version}_DLL_PATH AND CMAKE_HWLOC_${hwloc_version}_INCLUDE_PATH ) - add_library(${HWLOC_TARGET_NAME} SHARED IMPORTED) + if (HWLOC_TARGET_NAME MATCHES "static") + set(_hwloc_library_type "STATIC") + else() + set(_hwloc_library_type "SHARED") + endif() + add_library(${HWLOC_TARGET_NAME} ${_hwloc_library_type} IMPORTED) + set_target_properties(${HWLOC_TARGET_NAME} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_HWLOC_${hwloc_version}_INCLUDE_PATH}") if (WIN32) @@ -36,6 +45,7 @@ foreach(hwloc_version ${HWLOC_REQUIRED_VERSIONS}) set_target_properties(${HWLOC_TARGET_NAME} PROPERTIES IMPORTED_LOCATION "${CMAKE_HWLOC_${hwloc_version}_LIBRARY_PATH}") endif() + unset(_hwloc_library_type) endif() if (TARGET ${HWLOC_TARGET_NAME}) diff --git a/src/tbb/governor.cpp b/src/tbb/governor.cpp index 4b417b4043..a90517f39e 100644 --- a/src/tbb/governor.cpp +++ b/src/tbb/governor.cpp @@ -426,10 +426,9 @@ static const unsigned LinkTableSize = sizeof(TbbBindLinkTable) / sizeof(dynamic_ #define LIBRARY_PREFIX "lib" #endif /* __unix__ */ -#define TBBBIND_NAME LIBRARY_PREFIX "tbbbind" DEBUG_SUFFIX LIBRARY_EXTENSION -#define TBBBIND_2_0_NAME LIBRARY_PREFIX "tbbbind_2_0" DEBUG_SUFFIX LIBRARY_EXTENSION - -#define TBBBIND_2_5_NAME LIBRARY_PREFIX "tbbbind_2_5" DEBUG_SUFFIX LIBRARY_EXTENSION +#define TBBBIND_NAME LIBRARY_PREFIX "tbbbind" DEBUG_SUFFIX LIBRARY_EXTENSION +#define TBBBIND_2_0_NAME LIBRARY_PREFIX "tbbbind_2_0" DEBUG_SUFFIX LIBRARY_EXTENSION +#define TBBBIND_2_5_NAME LIBRARY_PREFIX "tbbbind_2_5" DEBUG_SUFFIX LIBRARY_EXTENSION #endif /* _WIN32 || _WIN64 || __unix__ */ // Representation of system hardware topology information on the TBB side. diff --git a/src/tbbbind/CMakeLists.txt b/src/tbbbind/CMakeLists.txt index 993dc8b859..3bf074f421 100644 --- a/src/tbbbind/CMakeLists.txt +++ b/src/tbbbind/CMakeLists.txt @@ -98,8 +98,8 @@ if (NOT DEFINED HWLOC_TARGET_EXPLICITLY_DEFINED AND TARGET PkgConfig::HWLOC) message(STATUS "The ${TBBBIND_LIBRARY_NAME} target will be configured using the HWLOC ${HWLOC_VERSION}") tbbbind_build(${TBBBIND_LIBRARY_NAME} PkgConfig::HWLOC) else() - tbbbind_build(tbbbind HWLOC::hwloc_1_11) - tbbbind_build(tbbbind_2_0 HWLOC::hwloc_2 ) - tbbbind_build(tbbbind_2_5 HWLOC::hwloc_2_5 ) + tbbbind_build(tbbbind HWLOC::hwloc_static) + tbbbind_build(tbbbind_2_0 HWLOC::hwloc_2 ) + tbbbind_build(tbbbind_2_5 HWLOC::hwloc_2_5 ) endif() diff --git a/src/tbbbind/def/lin32-tbbbind.def b/src/tbbbind/def/lin32-tbbbind.def index 221dc84678..5da197d0cd 100644 --- a/src/tbbbind/def/lin32-tbbbind.def +++ b/src/tbbbind/def/lin32-tbbbind.def @@ -23,4 +23,7 @@ __TBB_internal_allocate_binding_handler; __TBB_internal_deallocate_binding_handler; __TBB_internal_get_default_concurrency; __TBB_internal_destroy_system_topology; + +local: +*; }; diff --git a/src/tbbbind/def/lin64-tbbbind.def b/src/tbbbind/def/lin64-tbbbind.def index 221dc84678..5da197d0cd 100644 --- a/src/tbbbind/def/lin64-tbbbind.def +++ b/src/tbbbind/def/lin64-tbbbind.def @@ -23,4 +23,7 @@ __TBB_internal_allocate_binding_handler; __TBB_internal_deallocate_binding_handler; __TBB_internal_get_default_concurrency; __TBB_internal_destroy_system_topology; + +local: +*; }; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 63383b6d79..d3fc518a23 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -195,7 +195,11 @@ function(_tbb_get_hwloc_runtime_vars) foreach(HWLOC_VERSION ${_runtime_vars_HWLOC_VERSION_LIST}) get_target_property(HWLOC_LOCATION HWLOC::${HWLOC_VERSION} IMPORTED_LOCATION) - get_filename_component(HWLOC_LOCATION_PATH ${HWLOC_LOCATION} DIRECTORY) + if (NOT HWLOC_LOCATION) + get_target_property(HWLOC_LOCATION_PATH HWLOC::${HWLOC_VERSION} LIBRARY_OUTPUT_DIRECTORY) + else() + get_filename_component(HWLOC_LOCATION_PATH ${HWLOC_LOCATION} DIRECTORY) + endif() list(APPEND LIBRARIES_PATH ${HWLOC_LOCATION_PATH}) endforeach() @@ -296,10 +300,23 @@ function(tbb_add_tbbbind_test) ) endif() - set_tests_properties(${_tbbbind_test_NAME} PROPERTIES - PASS_REGULAR_EXPRESSION "oneTBB: TBBBIND.*UNAVAILABLE" - FAIL_REGULAR_EXPRESSION "Status:.*FAILURE" - ) + if (TARGET HWLOC::hwloc_static) + # TBBBind is statically linked with HWLOC is available, + # so in the environment without HWLOC, it should be found. + set_tests_properties(${_tbbbind_test_NAME} PROPERTIES + PASS_REGULAR_EXPRESSION "oneTBB: TBBBIND.*tbbbind" + FAIL_REGULAR_EXPRESSION "Status: FAILURE!" + ) + # Don't export symbols from HWLOC archive library + target_link_options(${_tbbbind_test_NAME} PRIVATE $<$:-Wl,--exclude-libs,ALL>) + target_link_libraries(${_tbbbind_test_NAME} PRIVATE HWLOC::hwloc_static) + target_compile_definitions(${_tbbbind_test_NAME} PRIVATE __TBB_HWLOC_VALID_ENVIRONMENT) + else() + set_tests_properties(${_tbbbind_test_NAME} PROPERTIES + PASS_REGULAR_EXPRESSION "oneTBB: TBBBIND.*UNAVAILABLE" + FAIL_REGULAR_EXPRESSION "Status:.*FAILURE" + ) + endif() if (TARGET HWLOC::hwloc_stub) _tbb_get_hwloc_runtime_vars( @@ -321,32 +338,26 @@ function(tbb_add_tbbbind_test) set(HWLOC_2_TESTS_STATUS_SHOWN TRUE PARENT_SCOPE) endif() - if (TARGET HWLOC::hwloc_1_11 AND NOT HWLOC_1_11_TESTS_STATUS_SHOWN) - message(STATUS "HWLOC 1.11 dependent tests were enabled.") - set(HWLOC_1_11_TESTS_STATUS_SHOWN TRUE PARENT_SCOPE) + if (TARGET HWLOC::hwloc_static AND NOT HWLOC_STATIC_TESTS_STATUS_SHOWN) + message(STATUS "Portable TBBBind tests were enabled.") + set(HWLOC_STATIC_TESTS_STATUS_SHOWN TRUE PARENT_SCOPE) endif() list(APPEND HWLOC_TEST_CASES hwloc_2_5 hwloc_2 - hwloc_1_11 hwloc_2_5_hwloc_2 - hwloc_2_5_hwloc_1_11 - hwloc_2_hwloc_1_11 - hwloc_2_5_hwloc_2_hwloc_1_11 - incompatible_hwlocs_1_11_vs_2_5 - incompatible_hwlocs_1_11_vs_2 + hwloc_2_5_hwloc_static + hwloc_2_hwloc_static + hwloc_2_5_hwloc_2_hwloc_static ) list(APPEND HWLOC_TEST_CASE_0_VARS tbbbind_2_5 "hwloc_2_5") list(APPEND HWLOC_TEST_CASE_1_VARS tbbbind_2 "hwloc_2") - list(APPEND HWLOC_TEST_CASE_2_VARS tbbbind "hwloc_1_11") - list(APPEND HWLOC_TEST_CASE_3_VARS tbbbind_2_5 "hwloc_2_5,hwloc_2") - list(APPEND HWLOC_TEST_CASE_4_VARS tbbbind_2_5 "hwloc_2_5,hwloc_1_11") - list(APPEND HWLOC_TEST_CASE_5_VARS tbbbind_2 "hwloc_2,hwloc_1_11") - list(APPEND HWLOC_TEST_CASE_6_VARS tbbbind_2_5 "hwloc_2_5,hwloc_2,hwloc_1_11") - list(APPEND HWLOC_TEST_CASE_7_VARS tbbbind_2_5 "hwloc_1_11,hwloc_2_5") - list(APPEND HWLOC_TEST_CASE_8_VARS tbbbind_2 "hwloc_1_11,hwloc_2") + list(APPEND HWLOC_TEST_CASE_2_VARS tbbbind_2_5 "hwloc_2_5,hwloc_2") + list(APPEND HWLOC_TEST_CASE_3_VARS tbbbind_2_5 "hwloc_2_5,hwloc_static") + list(APPEND HWLOC_TEST_CASE_4_VARS tbbbind_2 "hwloc_2,hwloc_static") + list(APPEND HWLOC_TEST_CASE_5_VARS tbbbind_2_5 "hwloc_2_5,hwloc_2,hwloc_static") foreach(TEST_CASE ${HWLOC_TEST_CASES}) list(FIND HWLOC_TEST_CASES ${TEST_CASE} TEST_CASE_INDEX) @@ -367,7 +378,7 @@ endfunction() # Copy libraries to test folder to make it visible during tests execution if external TBB is tested. # TODO: check and update for multi-config generators. if (TBB_FOUND) - list(APPEND _tbb_test_components tbb tbbmalloc tbbmalloc_proxy tbbbind tbbbind_2_0 tbbbind_2_5) + list(APPEND _tbb_test_components tbb tbbmalloc tbbmalloc_proxy tbbbind tbbbind_2_0 tbbbind_2_5 tbbbind_standalone) foreach(_component ${_tbb_test_components}) if (TARGET TBB::${_component}) get_property(${_component}_lib_file_location TARGET TBB::${_component} PROPERTY LOCATION) @@ -712,4 +723,4 @@ endif() unset(HWLOC_2_5_TESTS_STATUS_SHOWN) unset(HWLOC_2_TESTS_STATUS_SHOWN) -unset(HWLOC_1_11_TESTS_STATUS_SHOWN) +unset(HWLOC_STATIC_TESTS_STATUS_SHOWN)