Skip to content

Commit

Permalink
Restore compilaltion with tbb 2017u7 (#3007) (#3426)
Browse files Browse the repository at this point in the history
* Restore compilaltion with tbb 2017u7

Signed-off-by: Alexander Peskov <[email protected]>

* Fix unsupported arg for tbb deterministic_reduce

Signed-off-by: Alexander Peskov <[email protected]>

Co-authored-by: Alexander Zhogov <[email protected]>

Co-authored-by: Alexander Peskov <[email protected]>
Co-authored-by: Alexander Zhogov <[email protected]>
  • Loading branch information
3 people authored Dec 2, 2020
1 parent 422127e commit f730bf9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions inference-engine/cmake/ie_parallel.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function(set_ie_threading_interface_for TARGET_NAME)
find_package(TBB COMPONENTS tbb tbbmalloc)
set("TBB_FOUND" ${TBB_FOUND} PARENT_SCOPE)
set("TBB_IMPORTED_TARGETS" ${TBB_IMPORTED_TARGETS} PARENT_SCOPE)
set("TBB_VERSION" ${TBB_VERSION} PARENT_SCOPE)
if (TBB_FOUND)
if (TBB_VERSION VERSION_LESS 2020)
ext_message(WARNING "TBB version is less than OpenVINO recommends to use.\
Expand Down
15 changes: 12 additions & 3 deletions inference-engine/include/ie_parallel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ inline int parallel_get_env_threads() {
}
#if IE_THREAD == IE_THREAD_TBB
#define PARTITIONING , tbb::static_partitioner()

// The TBB version less than 2018u1 has no static_partitioner argument for
// tbb::parallel_deterministic_reduce. So will fallback to non deterministic version.
#if (TBB_INTERFACE_VERSION >= 10001)
#define _TBB_REDUCE_FUNC tbb::parallel_deterministic_reduce
#else
#define _TBB_REDUCE_FUNC tbb::parallel_reduce
#endif

#else
#define PARTITIONING
#endif
Expand Down Expand Up @@ -186,7 +195,7 @@ void parallel_sort(I begin, I end, const F& comparator) {
template <typename T0, typename R, typename F>
R parallel_sum(const T0& D0, const R& input, const F& func) {
#if (IE_THREAD == IE_THREAD_TBB || IE_THREAD == IE_THREAD_TBB_AUTO)
return tbb::parallel_deterministic_reduce(
return _TBB_REDUCE_FUNC(
tbb::blocked_range<T0>(0, D0), input,
[&](const tbb::blocked_range<T0>& r, R init) -> R {
R sum = init;
Expand Down Expand Up @@ -218,7 +227,7 @@ R parallel_sum(const T0& D0, const R& input, const F& func) {
template <typename T0, typename T1, typename R, typename F>
R parallel_sum2d(const T0& D0, const T1& D1, const R& input, const F& func) {
#if (IE_THREAD == IE_THREAD_TBB || IE_THREAD == IE_THREAD_TBB_AUTO)
return tbb::parallel_deterministic_reduce(
return _TBB_REDUCE_FUNC(
tbb::blocked_range2d<T0, T1>(0, D0, 0, D1), input,
[&](const tbb::blocked_range2d<T0, T1>& r, R init) -> R {
R sum = init;
Expand Down Expand Up @@ -257,7 +266,7 @@ R parallel_sum2d(const T0& D0, const T1& D1, const R& input, const F& func) {
template <typename T0, typename T1, typename T2, typename R, typename F>
R parallel_sum3d(const T0& D0, const T1& D1, const T2& D2, const R& input, const F& func) {
#if (IE_THREAD == IE_THREAD_TBB || IE_THREAD == IE_THREAD_TBB_AUTO)
return tbb::parallel_deterministic_reduce(
return _TBB_REDUCE_FUNC(
tbb::blocked_range3d<T0, T1, T2>(0, D0, 0, D1, 0, D2), input,
[&](const tbb::blocked_range3d<T0, T1, T2>& r, R init) -> R {
R sum = init;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ function(ie_headers_compilation_with_custom_flags)
# To include TBB headers as system
set_ie_threading_interface_for(${target_name})

# To avoid further TBB find_package action in next call of this function. Some version of TBB
# has an issue with cmake config which lead to fail in case of multiple call of find_package
# from one cmake script file.
set("TBB_FOUND" ${TBB_FOUND} PARENT_SCOPE)
set("TBB_IMPORTED_TARGETS" ${TBB_IMPORTED_TARGETS} PARENT_SCOPE)
set("TBB_VERSION" ${TBB_VERSION} PARENT_SCOPE)

set_target_properties(${target_name} PROPERTIES
CXX_STANDARD ${IE_TEST_CXX_STANDARD}
CXX_STANDARD_REQUIRED OFF)
Expand Down

0 comments on commit f730bf9

Please sign in to comment.