CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
tensorflow::TBBThreadPool Class Reference

#include <TBBThreadPool.h>

Inheritance diagram for tensorflow::TBBThreadPool:

Public Member Functions

void Cancel () override
 
int CurrentThreadId () const override
 
int GetNumScheduleCalled ()
 
int NumThreads () const override
 
void Schedule (std::function< void()> fn) override
 
void ScheduleWithHint (std::function< void()> fn, int start, int end) override
 
 TBBThreadPool (int nThreads=-1)
 

Static Public Member Functions

static TBBThreadPoolinstance (int nThreads=-1)
 

Private Attributes

const int nThreads_
 
std::atomic< int > numScheduleCalled_
 

Detailed Description

Definition at line 22 of file TBBThreadPool.h.

Constructor & Destructor Documentation

◆ TBBThreadPool()

tensorflow::TBBThreadPool::TBBThreadPool ( int  nThreads = -1)
inlineexplicit

Definition at line 29 of file TBBThreadPool.h.

30  : nThreads_(nThreads > 0 ? nThreads
31  : tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)),
33  // when nThreads is zero or smaller, use the default value determined by tbb
34  }
std::atomic< int > numScheduleCalled_
Definition: TBBThreadPool.h:73

Member Function Documentation

◆ Cancel()

void tensorflow::TBBThreadPool::Cancel ( )
inlineoverride

Definition at line 59 of file TBBThreadPool.h.

59 {}

◆ CurrentThreadId()

int tensorflow::TBBThreadPool::CurrentThreadId ( ) const
inlineoverride

Definition at line 63 of file TBBThreadPool.h.

References triggerObjects_cff::id.

63  {
64  static std::atomic<int> idCounter{0};
65  thread_local const int id = idCounter++;
66  return id;
67  }

◆ GetNumScheduleCalled()

int tensorflow::TBBThreadPool::GetNumScheduleCalled ( )
inline

Definition at line 69 of file TBBThreadPool.h.

References numScheduleCalled_.

69 { return numScheduleCalled_; }
std::atomic< int > numScheduleCalled_
Definition: TBBThreadPool.h:73

◆ instance()

static TBBThreadPool& tensorflow::TBBThreadPool::instance ( int  nThreads = -1)
inlinestatic

Definition at line 24 of file TBBThreadPool.h.

References CMS_THREAD_SAFE, and submitPVResolutionJobs::pool.

Referenced by tensorflow::run().

24  {
25  CMS_THREAD_SAFE static TBBThreadPool pool(nThreads);
26  return pool;
27  }
TBBThreadPool(int nThreads=-1)
Definition: TBBThreadPool.h:29
#define CMS_THREAD_SAFE

◆ NumThreads()

int tensorflow::TBBThreadPool::NumThreads ( ) const
inlineoverride

Definition at line 61 of file TBBThreadPool.h.

References nThreads_.

61 { return nThreads_; }

◆ Schedule()

void tensorflow::TBBThreadPool::Schedule ( std::function< void()>  fn)
inlineoverride

Definition at line 36 of file TBBThreadPool.h.

References personalPlayback::fn, and numScheduleCalled_.

Referenced by ScheduleWithHint().

36  {
37  numScheduleCalled_ += 1;
38 
39  // use a task arena to avoid having unrelated tasks start
40  // running on this thread, which could potentially start deadlocks
41  tbb::task_arena taskArena;
42  tbb::task_group taskGroup;
43 
44  // we are required to always call wait before destructor
45  auto doneWithTaskGroup = [&taskArena, &taskGroup](void*) {
46  taskArena.execute([&taskGroup]() { taskGroup.wait(); });
47  };
48  std::unique_ptr<tbb::task_group, decltype(doneWithTaskGroup)> taskGuard(&taskGroup, doneWithTaskGroup);
49 
50  // schedule the task
51  taskArena.execute([&taskGroup, &fn] { taskGroup.run(fn); });
52 
53  // reset the task guard which will call wait
54  taskGuard.reset();
55  }
std::atomic< int > numScheduleCalled_
Definition: TBBThreadPool.h:73

◆ ScheduleWithHint()

void tensorflow::TBBThreadPool::ScheduleWithHint ( std::function< void()>  fn,
int  start,
int  end 
)
inlineoverride

Definition at line 57 of file TBBThreadPool.h.

References personalPlayback::fn, and Schedule().

57 { Schedule(fn); }
void Schedule(std::function< void()> fn) override
Definition: TBBThreadPool.h:36

Member Data Documentation

◆ nThreads_

const int tensorflow::TBBThreadPool::nThreads_
private

Definition at line 72 of file TBBThreadPool.h.

Referenced by NumThreads().

◆ numScheduleCalled_

std::atomic<int> tensorflow::TBBThreadPool::numScheduleCalled_
private

Definition at line 73 of file TBBThreadPool.h.

Referenced by GetNumScheduleCalled(), and Schedule().