src
HeterogeneousCore
AlpakaCore
src
alpaka
EDMetadata.cc
Go to the documentation of this file.
1
#include <alpaka/alpaka.hpp>
2
3
#include "
FWCore/Utilities/interface/EDMException.h
"
4
#include "
HeterogeneousCore/AlpakaCore/interface/alpaka/EDMetadata.h
"
5
6
namespace
ALPAKA_ACCELERATOR_NAMESPACE
{
7
#ifndef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
8
EDMetadata::~EDMetadata
() {
9
// Make sure that the production of the product in the GPU is
10
// complete before destructing the product. This is to make sure
11
// that the EDM stream does not move to the next event before all
12
// asynchronous processing of the current is complete.
13
14
// TODO: a callback notifying a WaitingTaskHolder (or similar)
15
// would avoid blocking the CPU, but would also require more work.
16
17
// If event_ is null, the EDMetadata was either
18
// default-constructed, or fully synchronized before leaving the
19
// produce() call, so no synchronization is needed.
20
// If the queue was re-used, then some other EDMetadata object in
21
// the same edm::Event records the event_ (in the same queue) and
22
// calls alpaka::wait(), and therefore this wait() call can be
23
// skipped).
24
if
(
event_
and not
eventComplete_
and
mayReuseQueue_
) {
25
// Must not throw in a destructor, and if there were an
26
// exception could not really propagate it anyway.
27
CMS_SA_ALLOW
try
{
alpaka::wait
(*
event_
); }
catch
(...) {
28
}
29
}
30
}
31
32
void
EDMetadata::enqueueCallback
(
edm::WaitingTaskWithArenaHolder
holder) {
33
alpaka::enqueue(*
queue_
,
alpaka::HostOnlyTask
([holder =
std::move
(holder)](std::exception_ptr eptr) {
34
// The functor is required to be const, but the original waitingTaskHolder_
35
// needs to be notified...
36
const_cast<
edm::WaitingTaskWithArenaHolder
&
>
(holder).doneWaiting(eptr);
37
}));
38
}
39
40
void
EDMetadata::synchronize
(
EDMetadata
&
consumer
,
bool
tryReuseQueue)
const
{
41
if
(*
queue_
== *
consumer
.queue_) {
42
return
;
43
}
44
45
if
(tryReuseQueue) {
46
if
(
auto
queue
=
tryReuseQueue_
()) {
47
consumer
.queue_ =
queue_
;
48
return
;
49
}
50
}
51
52
if
(
eventComplete_
) {
53
return
;
54
}
55
56
// TODO: how necessary this check is?
57
if
(alpaka::getDev(*
queue_
) != alpaka::getDev(*
consumer
.queue_)) {
58
throw
edm::Exception
(
edm::errors::LogicError
) <<
"Handling data from multiple devices is not yet supported"
;
59
}
60
61
// If the event has been discarded, the produce() function that
62
// constructed this EDMetadata object did not launch any
63
// asynchronous work.
64
if
(not
event_
) {
65
return
;
66
}
67
68
if
(alpaka::isComplete(*
event_
)) {
69
eventComplete_
=
true
;
70
}
else
{
71
// Event not yet occurred, so need to add synchronization
72
// here. Sychronization is done by making the queue to wait
73
// for an event, so all subsequent work in the queue will run
74
// only after the event has "occurred" (i.e. data product
75
// became available).
76
alpaka::wait
(*
consumer
.queue_, *
event_
);
77
}
78
}
79
80
std::shared_ptr<Queue>
EDMetadata::tryReuseQueue_
()
const
{
81
bool
expected =
true
;
82
if
(
mayReuseQueue_
.compare_exchange_strong(expected,
false
)) {
83
// If the current thread is the one flipping the flag, it may
84
// reuse the queue.
85
return
queue_
;
86
}
87
return
nullptr
;
88
}
89
#endif
90
}
// namespace ALPAKA_ACCELERATOR_NAMESPACE
SequenceTypes.wait
def wait(seq)
Definition:
SequenceTypes.py:645
CMS_SA_ALLOW
#define CMS_SA_ALLOW
Exception
Definition:
hltDiff.cc:245
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata::event_
std::shared_ptr< Event > event_
Definition:
EDMetadata.h:92
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata
Definition:
EDMetadata.h:62
alpaka::HostOnlyTask
Definition:
HostOnlyTask.h:17
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata::enqueueCallback
void enqueueCallback(edm::WaitingTaskWithArenaHolder holder)
Definition:
EDMetadata.cc:32
edm::WaitingTaskWithArenaHolder
Definition:
WaitingTaskWithArenaHolder.h:34
ALPAKA_ACCELERATOR_NAMESPACE
Definition:
SiPixelCablingSoAESProducer.cc:21
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata::queue_
std::shared_ptr< Queue > queue_
Definition:
EDMetadata.h:91
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata::queue
Queue & queue() const
Definition:
EDMetadata.h:72
EDMException.h
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata::synchronize
void synchronize(EDMetadata &consumer, bool tryReuseQueue) const
Definition:
EDMetadata.cc:40
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata::eventComplete_
std::atomic< bool > eventComplete_
Definition:
EDMetadata.h:98
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata::tryReuseQueue_
std::shared_ptr< Queue > tryReuseQueue_() const
Definition:
EDMetadata.cc:80
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata::mayReuseQueue_
std::atomic< bool > mayReuseQueue_
Definition:
EDMetadata.h:96
EDMetadata.h
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata::~EDMetadata
~EDMetadata()
Definition:
EDMetadata.cc:8
eostools.move
def move(src, dest)
Definition:
eostools.py:511
OfflineOutput_cfi.consumer
consumer
Definition:
OfflineOutput_cfi.py:3
edm::errors::LogicError
Definition:
EDMException.h:37
Generated for CMSSW Reference Manual by
1.8.14