HeterogeneousCore
AlpakaCore
src
alpaka
EDMetadata.cc
Go to the documentation of this file.
1
#include "
FWCore/Utilities/interface/EDMException.h
"
2
#include "
HeterogeneousCore/AlpakaCore/interface/alpaka/EDMetadata.h
"
3
4
namespace
ALPAKA_ACCELERATOR_NAMESPACE
{
5
#ifndef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
6
EDMetadata::~EDMetadata
() {
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
23
void
EDMetadata::enqueueCallback
(
edm::WaitingTaskWithArenaHolder
holder) {
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
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:90
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata
Definition:
EDMetadata.h:61
alpaka::HostOnlyTask
Definition:
HostOnlyTask.h:15
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata::enqueueCallback
void enqueueCallback(edm::WaitingTaskWithArenaHolder holder)
Definition:
EDMetadata.cc:23
edm::WaitingTaskWithArenaHolder
Definition:
WaitingTaskWithArenaHolder.h:34
ALPAKA_ACCELERATOR_NAMESPACE
Definition:
PortableCollection.h:14
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata::queue_
std::shared_ptr< Queue > queue_
Definition:
EDMetadata.h:89
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata::queue
Queue & queue() const
Definition:
EDMetadata.h:71
EDMException.h
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata::synchronize
void synchronize(EDMetadata &consumer, bool tryReuseQueue) const
Definition:
EDMetadata.cc:31
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata::tryReuseQueue_
std::shared_ptr< Queue > tryReuseQueue_() const
Definition:
EDMetadata.cc:58
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata::mayReuseQueue_
std::atomic< bool > mayReuseQueue_
Definition:
EDMetadata.h:94
EDMetadata.h
ALPAKA_ACCELERATOR_NAMESPACE::EDMetadata::~EDMetadata
~EDMetadata()
Definition:
EDMetadata.cc:6
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