common: dnnl_thread: workaround for Wundef hits in TBB

This commit is contained in:
Dmitrii Zarukin
2025-04-25 16:38:54 -07:00
committed by Dmitry Zarukin
parent 7edc35c37c
commit fb8f7dacc8
3 changed files with 45 additions and 4 deletions

View File

@ -76,8 +76,9 @@ inline void dnnl_thr_barrier() {
}
#elif DNNL_CPU_THREADING_RUNTIME == DNNL_RUNTIME_TBB
#include "tbb/parallel_for.h"
#include "tbb/task_arena.h"
#include "common/dnnl_thread_tbb_proxy.hpp"
#define DNNL_THR_SYNC 0
inline int dnnl_get_max_threads() {
return tbb::this_task_arena::max_concurrency();

View File

@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright 2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
#ifndef COMMON_DNNL_THREAD_TBB_PROXY_HPP
#define COMMON_DNNL_THREAD_TBB_PROXY_HPP
// The purpose of the proxy header file is exactly to enable system_header
// diagnostics for TBB headers because they have multiple Wundef hits.
// Treating **this** file as system allows to avoid those warning hits.
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC system_header
#elif defined(__clang__)
#pragma clang system_header
#endif
#include "tbb/parallel_for.h"
#include "tbb/task_arena.h"
// API to do explicit finalization was introduced in 2021.6.
// Used in tests/test_thread.hpp. Keep all include files in a single place.
#if defined(TBB_INTERFACE_VERSION) && (TBB_INTERFACE_VERSION >= 12060)
#include "tbb/global_control.h"
#endif
#endif
// vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2020-2022 Intel Corporation
* Copyright 2020-2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -325,8 +325,8 @@ auto execute_in_thr_ctx(const thr_ctx_t &ctx, F &&f, Args_t &...args)
// limitation that can be worked around by doing explicit finalization.
// The API to do that was introduced in 2021.6.0. When using an older TBB
// runtime the crash may still happen.
// Appropriate header lives in a `src/common/dnnl_thread_tbb_proxy.hpp`.
#if DNNL_TBB_NEED_EXPLICIT_FINALIZE
#include "tbb/global_control.h"
inline void finalize_tbb() {
oneapi::tbb::task_scheduler_handle handle
= oneapi::tbb::task_scheduler_handle {oneapi::tbb::attach {}};