CMS 3D CMS Logo

EDMetadata.cc
Go to the documentation of this file.
3 
5 #ifndef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
7  // Make sure that the production of the product in the GPU is
8  // complete before destructing the product. This is to make sure
9  // that the EDM stream does not move to the next event before all
10  // asynchronous processing of the current is complete.
11 
12  // TODO: a callback notifying a WaitingTaskHolder (or similar)
13  // would avoid blocking the CPU, but would also require more work.
14 
15  if (event_) {
16  // Must not throw in a destructor, and if there were an
17  // exception could not really propagate it anyway.
18  CMS_SA_ALLOW try { alpaka::wait(*event_); } catch (...) {
19  }
20  }
21  }
22 
24  alpaka::enqueue(*queue_, alpaka::HostOnlyTask([holder = std::move(holder)]() {
25  // The functor is required to be const, but the original waitingTaskHolder_
26  // needs to be notified...
27  const_cast<edm::WaitingTaskWithArenaHolder&>(holder).doneWaiting(nullptr);
28  }));
29  }
30 
31  void EDMetadata::synchronize(EDMetadata& consumer, bool tryReuseQueue) const {
32  if (*queue_ == *consumer.queue_) {
33  return;
34  }
35 
36  if (tryReuseQueue) {
37  if (auto queue = tryReuseQueue_()) {
38  consumer.queue_ = queue_;
39  return;
40  }
41  }
42 
43  // TODO: how necessary this check is?
44  if (alpaka::getDev(*queue_) != alpaka::getDev(*consumer.queue_)) {
45  throw edm::Exception(edm::errors::LogicError) << "Handling data from multiple devices is not yet supported";
46  }
47 
48  if (not alpaka::isComplete(*event_)) {
49  // Event not yet occurred, so need to add synchronization
50  // here. Sychronization is done by making the queue to wait
51  // for an event, so all subsequent work in the queue will run
52  // only after the event has "occurred" (i.e. data product
53  // became available).
54  alpaka::wait(*consumer.queue_, *event_);
55  }
56  }
57 
58  std::shared_ptr<Queue> EDMetadata::tryReuseQueue_() const {
59  bool expected = true;
60  if (mayReuseQueue_.compare_exchange_strong(expected, false)) {
61  // If the current thread is the one flipping the flag, it may
62  // reuse the queue.
63  return queue_;
64  }
65  return nullptr;
66  }
67 #endif
68 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
#define CMS_SA_ALLOW
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
def move(src, dest)
Definition: eostools.py:511