9 #ifndef PHYSICSTOOLS_TENSORFLOW_TBBTHREADPOOL_H 10 #define PHYSICSTOOLS_TENSORFLOW_TBBTHREADPOOL_H 14 #include "tensorflow/core/lib/core/threadpool.h" 16 #include "oneapi/tbb/task_arena.h" 17 #include "oneapi/tbb/task_group.h" 18 #include "oneapi/tbb/global_control.h" 31 : tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)),
41 tbb::task_arena taskArena;
42 tbb::task_group taskGroup;
45 auto doneWithTaskGroup = [&taskArena, &taskGroup](
void*) {
46 taskArena.execute([&taskGroup]() { taskGroup.wait(); });
48 std::unique_ptr<tbb::task_group, decltype(doneWithTaskGroup)> taskGuard(&taskGroup, doneWithTaskGroup);
51 taskArena.execute([&taskGroup, &
fn] { taskGroup.run(
fn); });
64 static std::atomic<int> idCounter{0};
65 thread_local
const int id = idCounter++;
78 #endif // PHYSICSTOOLS_TENSORFLOW_TBBTHREADPOOL_H
void ScheduleWithHint(std::function< void()> fn, int start, int end) override
std::atomic< int > numScheduleCalled_
TBBThreadPool(int nThreads=-1)
int CurrentThreadId() const override
static TBBThreadPool & instance(int nThreads=-1)
int GetNumScheduleCalled()
int NumThreads() const override
void Schedule(std::function< void()> fn) override