9 #ifndef PHYSICSTOOLS_TENSORFLOW_TBBTHREADPOOL_H
10 #define PHYSICSTOOLS_TENSORFLOW_TBBTHREADPOOL_H
14 #include "tensorflow/core/lib/core/threadpool.h"
16 #include "tbb/task_arena.h"
17 #include "tbb/task_group.h"
18 #include "tbb/global_control.h"
20 namespace tensorflow {
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
uint16_t *__restrict__ id
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