Skip to content

Commit

Permalink
Include product instance name for the data product copied implicitly …
Browse files Browse the repository at this point in the history
…to host
  • Loading branch information
makortel committed Feb 17, 2023
1 parent 150d6d1 commit 36d6142
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
12 changes: 7 additions & 5 deletions HeterogeneousCore/AlpakaCore/interface/alpaka/ProducerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
// can think of it later if really needed
template <typename TProduct, typename TToken, edm::Transition Tr>
edm::EDPutTokenT<TToken> deviceProduces(std::string instanceName) {
edm::EDPutTokenT<TToken> token = Base::template produces<TToken, Tr>(std::move(instanceName));

if constexpr (not detail::useProductDirectly<TProduct>) {
if constexpr (detail::useProductDirectly<TProduct>) {
return Base::template produces<TToken, Tr>(std::move(instanceName));
} else {
edm::EDPutTokenT<TToken> token = Base::template produces<TToken, Tr>(instanceName);
this->registerTransformAsync(
token,
[](TToken const& deviceProduct, edm::WaitingTaskWithArenaHolder holder) {
Expand All @@ -100,9 +101,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
// Wrap possibly move-only type into a copyable type
return std::make_shared<TplType>(std::move(productOnHost), sentry.finish());
},
[](auto tplPtr) { return std::move(std::get<0>(*tplPtr)); });
[](auto tplPtr) { return std::move(std::get<0>(*tplPtr)); },
std::move(instanceName));
return token;
}
return token;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
* This class demonstrates a stream EDProducer that
* - consumes a host EDProduct
* - consumes a device ESProduct
* - produces a device EDProduct (that can get transferred to host automatically)
* - produces a device EDProduct (that gets transferred to host automatically if needed)
* - optionally uses a product instance label
*/
class TestAlpakaStreamProducer : public stream::EDProducer<> {
public:
Expand All @@ -27,7 +28,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE))} {
getToken_ = consumes(config.getParameter<edm::InputTag>("source"));
esToken_ = esConsumes();
devicePutToken_ = produces();
devicePutToken_ = produces(config.getParameter<std::string>("productInstanceName"));
}

void produce(device::Event& iEvent, device::EventSetup const& iSetup) override {
Expand All @@ -45,6 +46,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("source");
desc.add<std::string>("productInstanceName", "");

edm::ParameterSetDescription psetSize;
psetSize.add<int32_t>("alpaka_serial_sync");
Expand Down
17 changes: 16 additions & 1 deletion HeterogeneousCore/AlpakaTest/test/testAlpakaModules_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@
alpaka_cuda_async = cms.int32(25)
)
)
process.alpakaStreamInstanceProducer = cms.EDProducer("TestAlpakaStreamProducer@alpaka",
source = cms.InputTag("intProduct"),
productInstanceName = cms.string("testInstance"),
size = cms.PSet(
alpaka_serial_sync = cms.int32(6),
alpaka_cuda_async = cms.int32(36)
)
)
process.alpakaStreamSynchronizingProducer = cms.EDProducer("TestAlpakaStreamSynchronizingProducer@alpaka",
source = cms.InputTag("alpakaGlobalProducer")
)
Expand All @@ -83,19 +91,24 @@
source = cms.InputTag("alpakaStreamProducer"),
expectSize = cms.int32(5)
)
process.alpakaStreamInstanceConsumer = cms.EDAnalyzer("TestAlpakaAnalyzer",
source = cms.InputTag("alpakaStreamInstanceProducer", "testInstance"),
expectSize = cms.int32(6)
)
process.alpakaStreamSynchronizingConsumer = cms.EDAnalyzer("TestAlpakaAnalyzer",
source = cms.InputTag("alpakaStreamSynchronizingProducer"),
expectSize = cms.int32(10)
)

if args.moduleBackend != "":
for name in ["ESProducerA", "ESProducerB", "ESProducerC", "ESProducerD",
"GlobalProducer", "StreamProducer", "StreamSynchronizingProducer"]:
"GlobalProducer", "StreamProducer", "StreamInstanceProducer", "StreamSynchronizingProducer"]:
mod = getattr(process, "alpaka"+name)
mod.alpaka = cms.untracked.PSet(backend = cms.untracked.string(args.moduleBackend))
if args.expectBackend == "cuda_async":
process.alpakaGlobalConsumer.expectSize = 20
process.alpakaStreamConsumer.expectSize = 25
process.alpakaStreamInstanceConsumer.expectSize = 36
process.alpakaStreamSynchronizingConsumer.expectSize = 20

process.output = cms.OutputModule('PoolOutputModule',
Expand All @@ -112,11 +125,13 @@
process.intProduct,
process.alpakaGlobalProducer,
process.alpakaStreamProducer,
process.alpakaStreamInstanceProducer,
process.alpakaStreamSynchronizingProducer
)
process.p = cms.Path(
process.alpakaGlobalConsumer+
process.alpakaStreamConsumer+
process.alpakaStreamInstanceConsumer+
process.alpakaStreamSynchronizingConsumer,
process.t
)
Expand Down

0 comments on commit 36d6142

Please sign in to comment.