Skip to content

Commit 808bebc

Browse files
committed
feat(build): TBB 发现增加 multiarch 回退探测,并行 STL 接入系统 TBB
- apt 安装 libtbb-dev 后,conda cmake 仍找不到 TBBConfig.cmake (不搜索 /usr/lib/x86_64-linux-gnu/cmake):顶层 find_package(TBB) 未命中时回退 find_file 探测 Debian multiarch cmake 目录并设置 TBB_DIR - parallel_stl 消费 TBB 头文件沿用 numa 的 shim 模式:TBB::tbb 携带的 /usr/include 在 sysroot 工具链下会被 CMake 剥掉、强加则遮蔽工具链 自身头文件,故将 tbb/ 与 oneapi/ 子树软链到 build/tbb-headers - 实测(8M floats,16 核):par 4.42x / par_unseq 4.54x vs plain loop; conda gcc 15 与系统 g++ 13 两条工具链均验证,109 项测试全通过
1 parent 4e59689 commit 808bebc

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ endif()
5858
# libstdc++. Without it the parallel STL example still builds and covers
5959
# seq/unseq; par policies are compiled in only when TBB is present.
6060
find_package(TBB QUIET)
61+
if(NOT TBB_FOUND)
62+
# Fallback probe: conda-distributed CMake does not search the Debian
63+
# multiarch cmake-config directory where apt installs TBBConfig.cmake.
64+
find_file(HPC_TBB_CONFIG_FILE TBBConfig.cmake PATHS
65+
/usr/lib/x86_64-linux-gnu/cmake/TBB
66+
/usr/lib64/cmake/TBB
67+
/usr/lib/cmake/TBB)
68+
if(HPC_TBB_CONFIG_FILE)
69+
get_filename_component(TBB_DIR "${HPC_TBB_CONFIG_FILE}" DIRECTORY)
70+
find_package(TBB QUIET)
71+
endif()
72+
endif()
6173
if(TBB_FOUND)
6274
message(STATUS "TBB found: parallel STL example includes par/par_unseq")
6375
endif()

examples/03-modern-cpp/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,30 @@ hpc_add_example(
3030
# Parallel STL execution policies. seq/unseq always build; par/par_unseq
3131
# require Intel TBB (GCC libstdc++ implements them on top of it).
3232
if(TBB_FOUND)
33+
# TBB headers reach the targets through a shim directory, mirroring the
34+
# numa pattern: TBB::tbb's /usr/include is silently dropped by CMake on
35+
# sysroot toolchains (conda) and would shadow the toolchain's own
36+
# headers if forced. Symlinking only the tbb/ and oneapi/ subtrees keeps
37+
# the rest of the include resolution untouched.
38+
get_target_property(_hpc_tbb_includes TBB::tbb INTERFACE_INCLUDE_DIRECTORIES)
39+
set(_hpc_tbb_shim "${CMAKE_BINARY_DIR}/tbb-headers")
40+
file(MAKE_DIRECTORY "${_hpc_tbb_shim}")
41+
foreach(_hpc_tbb_inc ${_hpc_tbb_includes})
42+
foreach(_hpc_tbb_sub tbb oneapi)
43+
if(EXISTS "${_hpc_tbb_inc}/${_hpc_tbb_sub}"
44+
AND NOT EXISTS "${_hpc_tbb_shim}/${_hpc_tbb_sub}")
45+
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
46+
"${_hpc_tbb_inc}/${_hpc_tbb_sub}"
47+
"${_hpc_tbb_shim}/${_hpc_tbb_sub}")
48+
endif()
49+
endforeach()
50+
endforeach()
51+
3352
hpc_add_example(
3453
NAME parallel_stl
3554
SOURCES src/parallel_stl.cpp
3655
BENCHMARK_SOURCES bench/parallel_stl_bench.cpp
56+
INCLUDE_DIRS ${_hpc_tbb_shim}
3757
LIBRARIES TBB::tbb
3858
)
3959
target_compile_definitions(parallel_stl PRIVATE HPC_HAS_TBB)

0 commit comments

Comments
 (0)