Skip to content

Commit

Permalink
Link tbbbind against static HWLOC instead of HWLOC 1.11
Browse files Browse the repository at this point in the history
Signed-off-by: Isaev, Ilya <[email protected]>
  • Loading branch information
isaevil committed Feb 10, 2025
1 parent d3ad09c commit b02dba6
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 33 deletions.
16 changes: 13 additions & 3 deletions cmake/hwloc_detection.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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})
Expand Down
7 changes: 3 additions & 4 deletions src/tbb/governor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/tbbbind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

3 changes: 3 additions & 0 deletions src/tbbbind/def/lin32-tbbbind.def
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*;
};
3 changes: 3 additions & 0 deletions src/tbbbind/def/lin64-tbbbind.def
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*;
};
57 changes: 34 additions & 23 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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 $<$<BOOL:UNIX>:-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(
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)

0 comments on commit b02dba6

Please sign in to comment.