CMS 3D CMS Logo

EDMetadata.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_AlpakaCore_interface_alpaka_EDMetadata_h
2 #define HeterogeneousCore_AlpakaCore_interface_alpaka_EDMetadata_h
3 
4 #include <atomic>
5 #include <memory>
6 
7 #include <alpaka/alpaka.hpp>
8 
11 
36 #ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
37  // Host backends with a synchronous queue
38 
39  class EDMetadata {
40  public:
41  EDMetadata(std::shared_ptr<Queue> queue) : queue_(std::move(queue)) {}
42 
43  Device device() const { return alpaka::getDev(*queue_); }
44 
45  // Alpaka operations do not accept a temporary as an argument
46  // TODO: Returning non-const reference here is BAD
47  Queue& queue() const { return *queue_; }
48 
49  void recordEvent() {}
50  void discardEvent() {}
51 
52  private:
53  std::shared_ptr<Queue> queue_;
54  };
55 
56  // TODO: else if device backends with a synchronous queue
57 
58 #else
59  // All backends with an asynchronous queue
60 
61  class EDMetadata {
62  public:
63  EDMetadata(std::shared_ptr<Queue> queue, std::shared_ptr<Event> event)
64  : queue_(std::move(queue)), event_(std::move(event)) {}
65  ~EDMetadata();
66 
67  Device device() const { return alpaka::getDev(*queue_); }
68 
69  // Alpaka operations do not accept a temporary as an argument
70  // TODO: Returning non-const reference here is BAD
71  Queue& queue() const { return *queue_; }
72 
74 
75  void recordEvent() { alpaka::enqueue(*queue_, *event_); }
76  void discardEvent() { event_.reset(); }
77 
81  void synchronize(EDMetadata& consumer, bool tryReuseQueue) const;
82 
83  private:
88  std::shared_ptr<Queue> tryReuseQueue_() const;
89 
90  std::shared_ptr<Queue> queue_;
91  std::shared_ptr<Event> event_;
92  // This flag tells whether the Queue may be reused by a
93  // consumer or not. The goal is to have a "chain" of modules to
94  // queue their work to the same queue.
95  mutable std::atomic<bool> mayReuseQueue_ = true;
96  // Cache to potentially reduce alpaka::wait() calls
97  mutable std::atomic<bool> eventComplete_ = false;
98  };
99 #endif
100 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
101 
102 #endif
std::shared_ptr< Event > event_
Definition: EDMetadata.h:91
void enqueueCallback(edm::WaitingTaskWithArenaHolder holder)
Definition: EDMetadata.cc:34
std::shared_ptr< Queue > queue_
Definition: EDMetadata.h:90
void synchronize(EDMetadata &consumer, bool tryReuseQueue) const
Definition: EDMetadata.cc:43
std::shared_ptr< Queue > tryReuseQueue_() const
Definition: EDMetadata.cc:83
EDMetadata(std::shared_ptr< Queue > queue, std::shared_ptr< Event > event)
Definition: EDMetadata.h:63
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1