CMS 3D CMS Logo

NoThreadPool.h
Go to the documentation of this file.
1 /*
2  * Custom TensorFlow thread pool implementation that does no threading at all,
3  * but schedules all tasks in the caller thread.
4  * Based on TensorFlow 2.1.
5  * For more info, see https://gitlab.cern.ch/mrieger/CMSSW-DNN.
6  *
7  * Author: Marcel Rieger
8  */
9 
10 #ifndef PHYSICSTOOLS_TENSORFLOW_NOTHREADPOOL_H
11 #define PHYSICSTOOLS_TENSORFLOW_NOTHREADPOOL_H
12 
14 
15 #include "tensorflow/core/lib/core/threadpool.h"
16 #include "tensorflow/core/lib/core/threadpool_options.h"
17 
18 namespace tensorflow {
19 
20  class NoThreadPool : public tensorflow::thread::ThreadPoolInterface {
21  public:
22  static NoThreadPool& instance() {
24  return pool;
25  }
26 
27  explicit NoThreadPool() : numScheduleCalled_(0) {}
28 
29  void Schedule(std::function<void()> fn) override {
30  numScheduleCalled_ += 1;
31  fn();
32  }
33 
34  void ScheduleWithHint(std::function<void()> fn, int start, int end) override { Schedule(fn); }
35 
36  void Cancel() override {}
37 
38  int NumThreads() const override { return 1; }
39 
40  int CurrentThreadId() const override { return -1; }
41 
43 
44  private:
45  std::atomic<int> numScheduleCalled_;
46  };
47 
48 } // namespace tensorflow
49 
50 #endif // PHYSICSTOOLS_TENSORFLOW_NOTHREADPOOL_H
tensorflow::NoThreadPool
Definition: NoThreadPool.h:20
start
Definition: start.py:1
tensorflow::NoThreadPool::GetNumScheduleCalled
int GetNumScheduleCalled()
Definition: NoThreadPool.h:42
tensorflow::NoThreadPool::NumThreads
int NumThreads() const override
Definition: NoThreadPool.h:38
tensorflow::NoThreadPool::instance
static NoThreadPool & instance()
Definition: NoThreadPool.h:22
tensorflow::NoThreadPool::numScheduleCalled_
std::atomic< int > numScheduleCalled_
Definition: NoThreadPool.h:45
mps_fire.end
end
Definition: mps_fire.py:242
tensorflow::NoThreadPool::Cancel
void Cancel() override
Definition: NoThreadPool.h:36
CMS_THREAD_SAFE
#define CMS_THREAD_SAFE
Definition: thread_safety_macros.h:4
tensorflow::NoThreadPool::ScheduleWithHint
void ScheduleWithHint(std::function< void()> fn, int start, int end) override
Definition: NoThreadPool.h:34
tensorflow::NoThreadPool::NoThreadPool
NoThreadPool()
Definition: NoThreadPool.h:27
thread_safety_macros.h
tensorflow::NoThreadPool::CurrentThreadId
int CurrentThreadId() const override
Definition: NoThreadPool.h:40
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
personalPlayback.fn
fn
Definition: personalPlayback.py:515
tensorflow
Definition: NoThreadPool.h:18
tensorflow::NoThreadPool::Schedule
void Schedule(std::function< void()> fn) override
Definition: NoThreadPool.h:29
submitPVResolutionJobs.pool
pool
Definition: submitPVResolutionJobs.py:351