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

Migrate BeamSpotDeviceProducer and HcalDigisSoAProducer to rely on implicit host-to-device copy #47226

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
27 changes: 6 additions & 21 deletions EventFilter/HcalRawToDigi/plugins/alpaka/HcalDigisSoAProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
using HostCollectionPhase1 = hcal::Phase1DigiHostCollection;
using HostCollectionPhase0 = hcal::Phase0DigiHostCollection;

using DeviceCollectionPhase1 = hcal::Phase1DigiDeviceCollection;
using DeviceCollectionPhase0 = hcal::Phase0DigiDeviceCollection;

// output product tokens
device::EDPutToken<DeviceCollectionPhase1> digisF01HEToken_;
device::EDPutToken<DeviceCollectionPhase0> digisF5HBToken_;
device::EDPutToken<DeviceCollectionPhase1> digisF3HBToken_;
edm::EDPutTokenT<HostCollectionPhase1> digisF01HEToken_;
edm::EDPutTokenT<HostCollectionPhase0> digisF5HBToken_;
edm::EDPutTokenT<HostCollectionPhase1> digisF3HBToken_;

struct ConfigParameters {
uint32_t maxChannelsF01HE, maxChannelsF5HB, maxChannelsF3HB;
Expand Down Expand Up @@ -86,9 +83,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
// stack host memory in the queue
HostCollectionPhase0 hf5_(size, event.queue());

// device product
DeviceCollectionPhase0 df5_(size, event.queue());

// set SoA_Scalar;
hf5_.view().stride() = stride;
hf5_.view().size() = hbheDigis.size();
Expand All @@ -111,9 +105,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
hf5_vi.data()[i + 1] = sample;
}
}
// copy hf5 to df5
alpaka::memcpy(event.queue(), df5_.buffer(), hf5_.const_buffer());
event.emplace(digisF5HBToken_, std::move(df5_));
event.emplace(digisF5HBToken_, std::move(hf5_));

if (qie11Digis.empty()) {
event.emplace(digisF01HEToken_, 0, event.queue());
Expand Down Expand Up @@ -144,10 +136,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
HostCollectionPhase1 hf1_(size_f1, event.queue());
HostCollectionPhase1 hf3_(size_f3, event.queue());

// device product
DeviceCollectionPhase1 df1_(size_f1, event.queue());
DeviceCollectionPhase1 df3_(size_f3, event.queue());

// set SoA_Scalar;
hf1_.view().stride() = stride01;
hf3_.view().stride() = stride01;
Expand Down Expand Up @@ -186,11 +174,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
hf1_.view().size() = size_f1;
hf3_.view().size() = size_f3;

alpaka::memcpy(event.queue(), df1_.buffer(), hf1_.const_buffer());
alpaka::memcpy(event.queue(), df3_.buffer(), hf3_.const_buffer());

event.emplace(digisF01HEToken_, std::move(df1_));
event.emplace(digisF3HBToken_, std::move(df3_));
event.emplace(digisF01HEToken_, std::move(hf1_));
event.emplace(digisF3HBToken_, std::move(hf3_));
}
}
} // namespace ALPAKA_ACCELERATOR_NAMESPACE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
class BeamSpotDeviceProducer : public global::EDProducer<> {
public:
BeamSpotDeviceProducer(edm::ParameterSet const& config)
: legacyToken_{consumes(config.getParameter<edm::InputTag>("src"))}, deviceToken_{produces()} {}
: legacyToken_{consumes(config.getParameter<edm::InputTag>("src"))}, podToken_{produces()} {}

void produce(edm::StreamID, device::Event& event, device::EventSetup const& setup) const override {
reco::BeamSpot const& beamspot = event.get(legacyToken_);
Expand All @@ -33,13 +33,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
hostProduct->emittanceY = beamspot.emittanceY();
hostProduct->betaStar = beamspot.betaStar();

if constexpr (std::is_same_v<Device, alpaka::DevCpu>) {
event.emplace(deviceToken_, std::move(hostProduct));
} else {
BeamSpotDevice deviceProduct{event.queue()};
alpaka::memcpy(event.queue(), deviceProduct.buffer(), hostProduct.const_buffer());
event.emplace(deviceToken_, std::move(deviceProduct));
}
event.emplace(podToken_, std::move(hostProduct));
}

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
Expand All @@ -50,7 +44,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {

private:
const edm::EDGetTokenT<reco::BeamSpot> legacyToken_;
const device::EDPutToken<BeamSpotDevice> deviceToken_;
const edm::EDPutTokenT<BeamSpotHost> podToken_;
};

} // namespace ALPAKA_ACCELERATOR_NAMESPACE
Expand Down