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 : tbb::task_scheduler_init::default_num_threads()), numScheduleCalled_(0) {
31  // when nThreads is zero or smaller, use the default value determined by tbb
32  }

Member Function Documentation

◆ Cancel()

void tensorflow::TBBThreadPool::Cancel ( )
inlineoverride

Definition at line 57 of file TBBThreadPool.h.

57 {}

◆ CurrentThreadId()

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

Definition at line 61 of file TBBThreadPool.h.

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

References triggerObjects_cff::id.

◆ GetNumScheduleCalled()

int tensorflow::TBBThreadPool::GetNumScheduleCalled ( )
inline

Definition at line 67 of file TBBThreadPool.h.

67 { return numScheduleCalled_; }

References numScheduleCalled_.

◆ instance()

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

Definition at line 24 of file TBBThreadPool.h.

24  {
26  return pool;
27  }

References CMS_THREAD_SAFE, runTheMatrix::nThreads, and submitPVResolutionJobs::pool.

Referenced by tensorflow::run().

◆ NumThreads()

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

Definition at line 59 of file TBBThreadPool.h.

59 { return nThreads_; }

References nThreads_.

◆ Schedule()

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

Definition at line 34 of file TBBThreadPool.h.

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

References personalPlayback::fn, and numScheduleCalled_.

Referenced by ScheduleWithHint().

◆ ScheduleWithHint()

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

Definition at line 55 of file TBBThreadPool.h.

55 { Schedule(fn); }

References personalPlayback::fn, and Schedule().

Member Data Documentation

◆ nThreads_

const int tensorflow::TBBThreadPool::nThreads_
private

Definition at line 70 of file TBBThreadPool.h.

Referenced by NumThreads().

◆ numScheduleCalled_

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

Definition at line 71 of file TBBThreadPool.h.

Referenced by GetNumScheduleCalled(), and Schedule().

tensorflow::TBBThreadPool::TBBThreadPool
TBBThreadPool(int nThreads=-1)
Definition: TBBThreadPool.h:29
CMS_THREAD_SAFE
#define CMS_THREAD_SAFE
Definition: thread_safety_macros.h:4
runTheMatrix.nThreads
nThreads
Definition: runTheMatrix.py:361
cms::cuda::device::unique_ptr
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
Definition: device_unique_ptr.h:33
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
tensorflow::TBBThreadPool::nThreads_
const int nThreads_
Definition: TBBThreadPool.h:70
personalPlayback.fn
fn
Definition: personalPlayback.py:515
tensorflow::TBBThreadPool::Schedule
void Schedule(std::function< void()> fn) override
Definition: TBBThreadPool.h:34
tensorflow::TBBThreadPool::numScheduleCalled_
std::atomic< int > numScheduleCalled_
Definition: TBBThreadPool.h:71
submitPVResolutionJobs.pool
pool
Definition: submitPVResolutionJobs.py:351