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 
12 
37 #ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
38  // Host backends with a synchronous queue
39 
40  class EDMetadata {
41  public:
42  EDMetadata(std::shared_ptr<Queue> queue) : queue_(std::move(queue)) {}
43 
44  Device device() const { return alpaka::getDev(*queue_); }
45 
46  // Alpaka operations do not accept a temporary as an argument
47  // TODO: Returning non-const reference here is BAD
48  Queue& queue() const { return *queue_; }
49 
50  void recordEvent() {}
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 
80  void synchronize(EDMetadata& consumer, bool tryReuseQueue) const;
81 
82  private:
87  std::shared_ptr<Queue> tryReuseQueue_() const;
88 
89  std::shared_ptr<Queue> queue_;
90  std::shared_ptr<Event> event_;
91  // This flag tells whether the Queue may be reused by a
92  // consumer or not. The goal is to have a "chain" of modules to
93  // queue their work to the same queue.
94  mutable std::atomic<bool> mayReuseQueue_ = true;
95  };
96 #endif
97 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
98 
99 #endif
std::shared_ptr< Event > event_
Definition: EDMetadata.h:90
void enqueueCallback(edm::WaitingTaskWithArenaHolder holder)
Definition: EDMetadata.cc:23
std::shared_ptr< Queue > queue_
Definition: EDMetadata.h:89
void synchronize(EDMetadata &consumer, bool tryReuseQueue) const
Definition: EDMetadata.cc:31
std::shared_ptr< Queue > tryReuseQueue_() const
Definition: EDMetadata.cc:58
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