Skip to content

Commit

Permalink
Merge pull request #40818 from makortel/fixAlpakaInstanceName
Browse files Browse the repository at this point in the history
[13_0_X] Include product instance name for the data product copied implicitly to host in Alpaka EDProducers
  • Loading branch information
cmsbuild authored Feb 20, 2023
2 parents 43423c3 + 6dead51 commit 574e102
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 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 @@ -16,16 +16,19 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
* Alpaka buffer that is then moved into an object of a class that
* is templated over the device type, and implicitly transfers the
* data product to device
*
* This class also tests the explicit label for ESProducts works
*/
class TestAlpakaESProducerB : public ESProducer {
public:
TestAlpakaESProducerB(edm::ParameterSet const& iConfig) {
auto cc = setWhatProduced(this);
auto cc = setWhatProduced(this, iConfig.getParameter<std::string>("explicitLabel"));
token_ = cc.consumes();
}

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add("explicitLabel", std::string{});
descriptions.addWithDefaultLabel(desc);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "FWCore/Framework/interface/ESTransientHandle.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/ESGetToken.h"
#include "FWCore/Utilities/interface/ESInputTag.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESGetToken.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESProducer.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/ModuleFactory.h"
Expand All @@ -23,12 +24,14 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
public:
TestAlpakaESProducerD(edm::ParameterSet const& iConfig) {
auto cc = setWhatProduced(this);
tokenA_ = cc.consumes();
tokenB_ = cc.consumes();
tokenA_ = cc.consumes(iConfig.getParameter<edm::ESInputTag>("srcA"));
tokenB_ = cc.consumes(iConfig.getParameter<edm::ESInputTag>("srcB"));
}

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add("srcA", edm::ESInputTag{});
desc.add("srcB", edm::ESInputTag{});
descriptions.addWithDefaultLabel(desc);
}

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
24 changes: 22 additions & 2 deletions HeterogeneousCore/AlpakaTest/test/testAlpakaModules_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@

from HeterogeneousCore.AlpakaTest.testAlpakaESProducerA_cfi import testAlpakaESProducerA
process.alpakaESProducerA = testAlpakaESProducerA.clone()
process.alpakaESProducerAdataLabel = process.alpakaESProducerA.clone(appendToDataLabel = cms.string("appendedLabel"))
process.alpakaESProducerB = cms.ESProducer("TestAlpakaESProducerB@alpaka")
process.alpakaESProducerBexplicitLabel = process.alpakaESProducerB.clone(explicitLabel = cms.string("explicitLabel"))
process.alpakaESProducerC = cms.ESProducer("TestAlpakaESProducerC@alpaka")
process.alpakaESProducerD = cms.ESProducer("TestAlpakaESProducerD@alpaka")
process.alpakaESProducerD = cms.ESProducer("TestAlpakaESProducerD@alpaka",
srcA = cms.ESInputTag("", "appendedLabel"),
srcB = cms.ESInputTag("", "explicitLabel"),
)

process.intProduct = cms.EDProducer("IntProducer", ivalue = cms.int32(42))

Expand All @@ -71,6 +76,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 +96,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 +130,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 574e102

Please sign in to comment.