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  void discardEvent() {}
52 
53  private:
54  std::shared_ptr<Queue> queue_;
55  };
56 
57  // TODO: else if device backends with a synchronous queue
58 
59 #else
60  // All backends with an asynchronous queue
61 
62  class EDMetadata {
63  public:
64  EDMetadata(std::shared_ptr<Queue> queue, std::shared_ptr<Event> event)
65  : queue_(std::move(queue)), event_(std::move(event)) {}
66  ~EDMetadata();
67 
68  Device device() const { return alpaka::getDev(*queue_); }
69 
70  // Alpaka operations do not accept a temporary as an argument
71  // TODO: Returning non-const reference here is BAD
72  Queue& queue() const { return *queue_; }
73 
75 
76  void recordEvent() { alpaka::enqueue(*queue_, *event_); }
77  void discardEvent() { event_.reset(); }
78 
82  void synchronize(EDMetadata& consumer, bool tryReuseQueue) const;
83 
84  private:
89  std::shared_ptr<Queue> tryReuseQueue_() const;
90 
91  std::shared_ptr<Queue> queue_;
92  std::shared_ptr<Event> event_;
93  // This flag tells whether the Queue may be reused by a
94  // consumer or not. The goal is to have a "chain" of modules to
95  // queue their work to the same queue.
96  mutable std::atomic<bool> mayReuseQueue_ = true;
97  // Cache to potentially reduce alpaka::wait() calls
98  mutable std::atomic<bool> eventComplete_ = false;
99  };
100 #endif
101 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
102 
103 #endif
std::shared_ptr< Event > event_
Definition: EDMetadata.h:92
void enqueueCallback(edm::WaitingTaskWithArenaHolder holder)
Definition: EDMetadata.cc:32
std::shared_ptr< Queue > queue_
Definition: EDMetadata.h:91
void synchronize(EDMetadata &consumer, bool tryReuseQueue) const
Definition: EDMetadata.cc:40
std::shared_ptr< Queue > tryReuseQueue_() const
Definition: EDMetadata.cc:80
EDMetadata(std::shared_ptr< Queue > queue, std::shared_ptr< Event > event)
Definition: EDMetadata.h:64
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1