From 36d61420f9390d7b619b4c421a9a0c30d80f3c37 Mon Sep 17 00:00:00 2001 From: Matti Kortelainen Date: Fri, 17 Feb 2023 17:29:52 +0100 Subject: [PATCH] Include product instance name for the data product copied implicitly to host --- .../AlpakaCore/interface/alpaka/ProducerBase.h | 12 +++++++----- .../plugins/alpaka/TestAlpakaStreamProducer.cc | 6 ++++-- .../AlpakaTest/test/testAlpakaModules_cfg.py | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/HeterogeneousCore/AlpakaCore/interface/alpaka/ProducerBase.h b/HeterogeneousCore/AlpakaCore/interface/alpaka/ProducerBase.h index 1cfd7a1361dce..e3983cdecd89b 100644 --- a/HeterogeneousCore/AlpakaCore/interface/alpaka/ProducerBase.h +++ b/HeterogeneousCore/AlpakaCore/interface/alpaka/ProducerBase.h @@ -78,9 +78,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { // can think of it later if really needed template edm::EDPutTokenT deviceProduces(std::string instanceName) { - edm::EDPutTokenT token = Base::template produces(std::move(instanceName)); - - if constexpr (not detail::useProductDirectly) { + if constexpr (detail::useProductDirectly) { + return Base::template produces(std::move(instanceName)); + } else { + edm::EDPutTokenT token = Base::template produces(instanceName); this->registerTransformAsync( token, [](TToken const& deviceProduct, edm::WaitingTaskWithArenaHolder holder) { @@ -100,9 +101,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { // Wrap possibly move-only type into a copyable type return std::make_shared(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; } }; diff --git a/HeterogeneousCore/AlpakaTest/plugins/alpaka/TestAlpakaStreamProducer.cc b/HeterogeneousCore/AlpakaTest/plugins/alpaka/TestAlpakaStreamProducer.cc index 3d83f637647c3..e543a53b0aa0c 100644 --- a/HeterogeneousCore/AlpakaTest/plugins/alpaka/TestAlpakaStreamProducer.cc +++ b/HeterogeneousCore/AlpakaTest/plugins/alpaka/TestAlpakaStreamProducer.cc @@ -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: @@ -27,7 +28,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE))} { getToken_ = consumes(config.getParameter("source")); esToken_ = esConsumes(); - devicePutToken_ = produces(); + devicePutToken_ = produces(config.getParameter("productInstanceName")); } void produce(device::Event& iEvent, device::EventSetup const& iSetup) override { @@ -45,6 +46,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.add("source"); + desc.add("productInstanceName", ""); edm::ParameterSetDescription psetSize; psetSize.add("alpaka_serial_sync"); diff --git a/HeterogeneousCore/AlpakaTest/test/testAlpakaModules_cfg.py b/HeterogeneousCore/AlpakaTest/test/testAlpakaModules_cfg.py index f0ac99500d2b7..1ab68cf9337fc 100644 --- a/HeterogeneousCore/AlpakaTest/test/testAlpakaModules_cfg.py +++ b/HeterogeneousCore/AlpakaTest/test/testAlpakaModules_cfg.py @@ -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") ) @@ -83,6 +91,10 @@ 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) @@ -90,12 +102,13 @@ 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', @@ -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 )