Skip to content

Commit 2a2b9df

Browse files
authored
Enforce TBB threading for DNN library (#220)
- Use TBB threading by default. 1. since vendored TBB is available in our project 2. macOS does not have proper defaults sometimes that could make the build failed - Use custom `cmake/FindTBB.cmake` to force using vendored TBB
1 parent 4d83114 commit 2a2b9df

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

3rdparty/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
add_subdirectory(googletest)
22

3+
set(DNNL_CPU_RUNTIME "TBB" CACHE STRING "oneDNN CPU threading runtime")
4+
35
add_subdirectory(oneDNN)
46

57
# Unified TBB Configuration

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ enable_testing()
2626

2727
include_directories("include")
2828

29+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
30+
2931
add_subdirectory(3rdparty)
3032

3133
include(cmake/opencv_config.cmake)

cmake/FindTBB.cmake

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Lightweight FindTBB to reuse vendored TBB target from this project
2+
3+
if(TARGET TBB::tbb)
4+
set(_vendor_tbb_include "${CMAKE_SOURCE_DIR}/3rdparty/TBB/include")
5+
if(EXISTS "${_vendor_tbb_include}/oneapi/tbb/version.h")
6+
# TBB::tbb is an ALIAS; set properties on the real target 'tbb'
7+
if(TARGET tbb)
8+
set_target_properties(tbb PROPERTIES
9+
INTERFACE_INCLUDE_DIRECTORIES "${_vendor_tbb_include}")
10+
endif()
11+
endif()
12+
set(TBB_FOUND TRUE)
13+
# Provide minimal compatibility variables
14+
set(TBB_IMPORTED_TARGETS TBB::tbb)
15+
mark_as_advanced(TBB_FOUND)
16+
unset(_vendor_tbb_include)
17+
return()
18+
endif()
19+
20+
# Create an imported INTERFACE target that links to our vendored TBB build target
21+
add_library(TBB::tbb INTERFACE IMPORTED)
22+
set_target_properties(TBB::tbb PROPERTIES
23+
INTERFACE_LINK_LIBRARIES tbb
24+
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/3rdparty/TBB/include"
25+
)
26+
set(TBB_FOUND TRUE)
27+
set(TBB_IMPORTED_TARGETS TBB::tbb)

0 commit comments

Comments
 (0)