Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[13_0_X] Allow access to const edm::{Event,EventSetup} from device::{Event,EventSetup} #40935

Merged
merged 1 commit into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HeterogeneousCore/AlpakaCore/interface/alpaka/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::device {
auto streamID() const { return constEvent_.streamID(); }
auto id() const { return constEvent_.id(); }

// To be able to interact with non-Alpaka helper code that needs
// to access edm::Event
operator edm::Event const &() const { return constEvent_; }

Device device() const { return metadata_->device(); }

// Alpaka operations do not accept a temporary as an argument
Expand Down
4 changes: 4 additions & 0 deletions HeterogeneousCore/AlpakaCore/interface/alpaka/EventSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::device {
public:
EventSetup(edm::EventSetup const& iSetup, Device const& dev) : setup_(iSetup), device_(dev) {}

// To be able to interact with non-Alpaka helper code that needs
// to access edm::EventSetup
operator edm::EventSetup const &() const { return setup_; }

// getData()

template <typename T, typename R>
Expand Down
29 changes: 29 additions & 0 deletions HeterogeneousCore/AlpakaTest/interface/TestHostOnlyHelperClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef HeterogeneousCore_AlpakaTest_interface_TestHostOnlyHelperClass_h
#define HeterogeneousCore_AlpakaTest_interface_TestHostOnlyHelperClass_h

#include "DataFormats/TestObjects/interface/ToyProducts.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/ESGetToken.h"
#include "HeterogeneousCore/AlpakaTest/interface/AlpakaESTestRecords.h"
#include "HeterogeneousCore/AlpakaTest/interface/ESTestData.h"

namespace cms::alpakatest {
class TestHostOnlyHelperClass {
public:
TestHostOnlyHelperClass(edm::ParameterSet const& iConfig, edm::ConsumesCollector iC);

static void fillPSetDescription(edm::ParameterSetDescription& iDesc);

int run(edm::Event const& iEvent, edm::EventSetup const& iSetup) const;

private:
edm::EDGetTokenT<edmtest::IntProduct> const edToken_;
edm::ESGetToken<cms::alpakatest::ESTestDataA, AlpakaESTestRecordA> const esToken_;
};
} // namespace cms::alpakatest

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "FWCore/Utilities/interface/InputTag.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/stream/SynchronizingEDProducer.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaTest/interface/TestHostOnlyHelperClass.h"

#include "TestHelperClass.h"

Expand All @@ -13,6 +14,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
* - consumes a device EDProduct
* - consumes a host ESProduct
* - consumes a device ESProduct
* - uses a non-Alpaka-aware helper class (need to use edm::ConsumesCollector), that
* - consumes a host EDProduct
* - consumes a host ESProduct
* - consumes a device ESProduct
* - produces a host EDProduct
* - synchronizes in a non-blocking way with the ExternalWork module
Expand All @@ -21,11 +25,20 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
class TestAlpakaStreamSynchronizingProducer : public stream::SynchronizingEDProducer<> {
public:
TestAlpakaStreamSynchronizingProducer(edm::ParameterSet const& iConfig)
: esTokenDevice_(esConsumes()), putToken_{produces()}, helper_{iConfig, consumesCollector()} {}
: esTokenDevice_(esConsumes()),
putToken_{produces()},
helper_{iConfig, consumesCollector()},
hostHelper_{iConfig, consumesCollector()},
expectedInt_{iConfig.getParameter<int>("expectedInt")} {}

void acquire(device::Event const& iEvent, device::EventSetup const& iSetup) override {
[[maybe_unused]] auto const& esData = iSetup.getData(esTokenDevice_);

int const value = hostHelper_.run(iEvent, iSetup);
if (value != expectedInt_) {
throw cms::Exception("Assert") << "Expected value " << expectedInt_ << ", but got " << value;
}

helper_.makeAsync(iEvent, iSetup);
}

Expand All @@ -35,7 +48,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("source");
TestHelperClass::fillPSetDescription(desc);
cms::alpakatest::TestHostOnlyHelperClass::fillPSetDescription(desc);
desc.add<int>("expectedInt");
descriptions.addWithDefaultLabel(desc);
}

Expand All @@ -44,6 +59,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
const edm::EDPutTokenT<portabletest::TestHostCollection> putToken_;

TestHelperClass helper_;
cms::alpakatest::TestHostOnlyHelperClass const hostHelper_;
int const expectedInt_;
};

} // namespace ALPAKA_ACCELERATOR_NAMESPACE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

#include "TestHelperClass.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {
Expand All @@ -6,6 +8,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
esTokenHost_(iC.esConsumes()),
esTokenDevice_(iC.esConsumes()) {}

void TestHelperClass::fillPSetDescription(edm::ParameterSetDescription& iDesc) { iDesc.add<edm::InputTag>("source"); }

void TestHelperClass::makeAsync(device::Event const& iEvent, device::EventSetup const& iSetup) {
[[maybe_unused]] auto esDataHostHandle = iSetup.getHandle(esTokenHost_);
[[maybe_unused]] auto const& esDataDevice = iSetup.getData(esTokenDevice_);
Expand Down
2 changes: 2 additions & 0 deletions HeterogeneousCore/AlpakaTest/plugins/alpaka/TestHelperClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
public:
TestHelperClass(edm::ParameterSet const& iConfig, edm::ConsumesCollector iC);

static void fillPSetDescription(edm::ParameterSetDescription& iDesc);

void makeAsync(device::Event const& iEvent, device::EventSetup const& iSetup);

portabletest::TestHostCollection moveFrom() { return std::move(hostProduct_); }
Expand Down
18 changes: 18 additions & 0 deletions HeterogeneousCore/AlpakaTest/src/TestHostOnlyHelperClass.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "HeterogeneousCore/AlpakaTest/interface/TestHostOnlyHelperClass.h"

namespace cms::alpakatest {
TestHostOnlyHelperClass::TestHostOnlyHelperClass(edm::ParameterSet const& iConfig, edm::ConsumesCollector iC)
: edToken_(iC.consumes(iConfig.getParameter<edm::InputTag>("intSource"))), esToken_(iC.esConsumes()) {}

void TestHostOnlyHelperClass::fillPSetDescription(edm::ParameterSetDescription& iDesc) {
iDesc.add<edm::InputTag>("intSource");
}

int TestHostOnlyHelperClass::run(edm::Event const& iEvent, edm::EventSetup const& iSetup) const {
auto const& ed = iEvent.get(edToken_);
auto const& es = iSetup.getData(esToken_);

return ed.value + es.value();
}
} // namespace cms::alpakatest
4 changes: 3 additions & 1 deletion HeterogeneousCore/AlpakaTest/test/testAlpakaModules_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@
)
)
process.alpakaStreamSynchronizingProducer = cms.EDProducer("TestAlpakaStreamSynchronizingProducer@alpaka",
source = cms.InputTag("alpakaGlobalProducer")
source = cms.InputTag("alpakaGlobalProducer"),
intSource = cms.InputTag("intProduct"),
expectedInt = cms.int32(84) # sum of intProduct and esProducerA
)

process.alpakaGlobalConsumer = cms.EDAnalyzer("TestAlpakaAnalyzer",
Expand Down