Skip to content

Commit

Permalink
Rename variables and adjust allocation syntax
Browse files Browse the repository at this point in the history
Adjust formatting

Rename data member and remove unnecessary include
  • Loading branch information
jsamudio committed Oct 4, 2024
1 parent 41a87e8 commit 36f2bb0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
inputPFRecHitSoA_Token_{consumes(config.getParameter<edm::InputTag>("pfRecHits"))},
outputPFClusterSoA_Token_{produces()},
outputPFRHFractionSoA_Token_{produces()},
num_rhf_{cms::alpakatools::make_host_buffer<uint32_t, Platform>()},
numRHF_{cms::alpakatools::make_host_buffer<uint32_t, Platform>()},
synchronise_(config.getParameter<bool>("synchronise")) {}

void acquire(device::Event const& event, device::EventSetup const& setup) override {
Expand All @@ -35,22 +35,22 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
if (pfRecHits->metadata().size() != 0)
nRH = pfRecHits->size();

pfClusteringVars_ = std::make_optional<reco::PFClusteringVarsDeviceCollection>(nRH, event.queue());
pfClusteringEdgeVars_ = std::make_optional<reco::PFClusteringEdgeVarsDeviceCollection>(nRH * 8, event.queue());
pfClusters_ = std::make_optional<reco::PFClusterDeviceCollection>(nRH, event.queue());
pfClusteringVars_.emplace(nRH, event.queue());
pfClusteringEdgeVars_.emplace(nRH * 8, event.queue());
pfClusters_.emplace(nRH, event.queue());

*num_rhf_ = 0;
*numRHF_ = 0;

if (nRH != 0) {
PFClusterProducerKernel kernel(event.queue(), pfRecHits);
kernel.step1(event.queue(),
params,
topology,
*pfClusteringVars_,
*pfClusteringEdgeVars_,
pfRecHits,
*pfClusters_,
num_rhf_.data());
kernel.seedTopoAndContract(event.queue(),
params,
topology,
*pfClusteringVars_,
*pfClusteringEdgeVars_,
pfRecHits,
*pfClusters_,
numRHF_.data());
}
}

Expand All @@ -59,29 +59,32 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
const reco::PFRecHitHCALTopologyDeviceCollection& topology = setup.getData(topologyToken_);
const reco::PFRecHitHostCollection& pfRecHits = event.get(inputPFRecHitSoA_Token_);
int nRH = 0;

std::optional<reco::PFRecHitFractionDeviceCollection> pfrhFractions;

if (pfRecHits->metadata().size() != 0)
nRH = pfRecHits->size();

if (nRH != 0) {
pfrhFractions_ = std::make_optional<reco::PFRecHitFractionDeviceCollection>(*num_rhf_.data(), event.queue());
pfrhFractions.emplace(*numRHF_.data(), event.queue());
PFClusterProducerKernel kernel(event.queue(), pfRecHits);
kernel.step2(event.queue(),
params,
topology,
*pfClusteringVars_,
*pfClusteringEdgeVars_,
pfRecHits,
*pfClusters_,
*pfrhFractions_);
kernel.cluster(event.queue(),
params,
topology,
*pfClusteringVars_,
*pfClusteringEdgeVars_,
pfRecHits,
*pfClusters_,
*pfrhFractions);
} else {
pfrhFractions_ = std::make_optional<reco::PFRecHitFractionDeviceCollection>(0, event.queue());
pfrhFractions.emplace(0, event.queue());
}

if (synchronise_)
alpaka::wait(event.queue());

event.emplace(outputPFClusterSoA_Token_, std::move(*pfClusters_));
event.emplace(outputPFRHFractionSoA_Token_, std::move(*pfrhFractions_));
event.emplace(outputPFRHFractionSoA_Token_, std::move(*pfrhFractions));
}

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
Expand All @@ -99,11 +102,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
const edm::EDGetTokenT<reco::PFRecHitHostCollection> inputPFRecHitSoA_Token_;
const device::EDPutToken<reco::PFClusterDeviceCollection> outputPFClusterSoA_Token_;
const device::EDPutToken<reco::PFRecHitFractionDeviceCollection> outputPFRHFractionSoA_Token_;
cms::alpakatools::host_buffer<uint32_t> num_rhf_;
cms::alpakatools::host_buffer<uint32_t> numRHF_;
std::optional<reco::PFClusteringVarsDeviceCollection> pfClusteringVars_;
std::optional<reco::PFClusteringEdgeVarsDeviceCollection> pfClusteringEdgeVars_;
std::optional<reco::PFClusterDeviceCollection> pfClusters_;
std::optional<reco::PFRecHitFractionDeviceCollection> pfrhFractions_;
const bool synchronise_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
reco::PFClusteringVarsDeviceCollection::View pfClusteringVars,
reco::PFClusterDeviceCollection::View clusterView,
uint32_t* __restrict__ nSeeds,
uint32_t* __restrict__ num_rhf_) const {
uint32_t* __restrict__ nRHF) const {
const int nRH = pfRecHits.size();
int& totalSeedOffset = alpaka::declareSharedVar<int, __COUNTER__>(acc);
int& totalSeedFracOffset = alpaka::declareSharedVar<int, __COUNTER__>(acc);
Expand Down Expand Up @@ -1302,7 +1302,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
pfClusteringVars.pcrhFracSize() = totalSeedFracOffset;
pfClusteringVars.nRHFracs() = totalSeedFracOffset;
clusterView.nRHFracs() = totalSeedFracOffset;
*num_rhf_ = totalSeedFracOffset;
*nRHF = totalSeedFracOffset;
clusterView.nSeeds() = *nSeeds;
clusterView.nTopos() = pfClusteringVars.nTopos();

Expand Down Expand Up @@ -1468,14 +1468,14 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
alpaka::memset(queue, nSeeds, 0x00); // Reset nSeeds
}

void PFClusterProducerKernel::step1(Queue& queue,
const reco::PFClusterParamsDeviceCollection& params,
const reco::PFRecHitHCALTopologyDeviceCollection& topology,
reco::PFClusteringVarsDeviceCollection& pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection& pfClusteringEdgeVars,
const reco::PFRecHitHostCollection& pfRecHits,
reco::PFClusterDeviceCollection& pfClusters,
uint32_t* __restrict__ num_rhf_) {
void PFClusterProducerKernel::seedTopoAndContract(Queue& queue,
const reco::PFClusterParamsDeviceCollection& params,
const reco::PFRecHitHCALTopologyDeviceCollection& topology,
reco::PFClusteringVarsDeviceCollection& pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection& pfClusteringEdgeVars,
const reco::PFRecHitHostCollection& pfRecHits,
reco::PFClusterDeviceCollection& pfClusters,
uint32_t* __restrict__ nRHF) {
const int nRH = pfRecHits->size();
const int threadsPerBlock = 256;
const int blocks = divide_up_by(nRH, threadsPerBlock);
Expand Down Expand Up @@ -1525,17 +1525,17 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
pfClusteringVars.view(),
pfClusters.view(),
nSeeds.data(),
num_rhf_);
nRHF);
}

void PFClusterProducerKernel::step2(Queue& queue,
const reco::PFClusterParamsDeviceCollection& params,
const reco::PFRecHitHCALTopologyDeviceCollection& topology,
reco::PFClusteringVarsDeviceCollection& pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection& pfClusteringEdgeVars,
const reco::PFRecHitHostCollection& pfRecHits,
reco::PFClusterDeviceCollection& pfClusters,
reco::PFRecHitFractionDeviceCollection& pfrhFractions) {
void PFClusterProducerKernel::cluster(Queue& queue,
const reco::PFClusterParamsDeviceCollection& params,
const reco::PFRecHitHCALTopologyDeviceCollection& topology,
reco::PFClusteringVarsDeviceCollection& pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection& pfClusteringEdgeVars,
const reco::PFRecHitHostCollection& pfRecHits,
reco::PFClusterDeviceCollection& pfClusters,
reco::PFRecHitFractionDeviceCollection& pfrhFractions) {
const int nRH = pfRecHits->size();

// fillRhfIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "DataFormats/ParticleFlowReco/interface/alpaka/PFRecHitDeviceCollection.h"
#include "DataFormats/ParticleFlowReco/interface/PFRecHitHostCollection.h"
#include "DataFormats/ParticleFlowReco/interface/alpaka/PFClusterDeviceCollection.h"
#include "DataFormats/ParticleFlowReco/interface/PFClusterHostCollection.h"
#include "DataFormats/ParticleFlowReco/interface/alpaka/PFRecHitFractionDeviceCollection.h"
#include "RecoParticleFlow/PFClusterProducer/interface/alpaka/PFClusterParamsDeviceCollection.h"
#include "RecoParticleFlow/PFClusterProducer/interface/alpaka/PFClusteringVarsDeviceCollection.h"
Expand Down Expand Up @@ -40,23 +39,23 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
public:
PFClusterProducerKernel(Queue& queue, const reco::PFRecHitHostCollection& pfRecHits);

void step1(Queue& queue,
const reco::PFClusterParamsDeviceCollection& params,
const reco::PFRecHitHCALTopologyDeviceCollection& topology,
reco::PFClusteringVarsDeviceCollection& pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection& pfClusteringEdgeVars,
const reco::PFRecHitHostCollection& pfRecHits,
reco::PFClusterDeviceCollection& pfClusters,
uint32_t* __restrict__ num_rhf_);
void seedTopoAndContract(Queue& queue,
const reco::PFClusterParamsDeviceCollection& params,
const reco::PFRecHitHCALTopologyDeviceCollection& topology,
reco::PFClusteringVarsDeviceCollection& pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection& pfClusteringEdgeVars,
const reco::PFRecHitHostCollection& pfRecHits,
reco::PFClusterDeviceCollection& pfClusters,
uint32_t* __restrict__ nRHF);

void step2(Queue& queue,
const reco::PFClusterParamsDeviceCollection& params,
const reco::PFRecHitHCALTopologyDeviceCollection& topology,
reco::PFClusteringVarsDeviceCollection& pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection& pfClusteringEdgeVars,
const reco::PFRecHitHostCollection& pfRecHits,
reco::PFClusterDeviceCollection& pfClusters,
reco::PFRecHitFractionDeviceCollection& pfrhFractions);
void cluster(Queue& queue,
const reco::PFClusterParamsDeviceCollection& params,
const reco::PFRecHitHCALTopologyDeviceCollection& topology,
reco::PFClusteringVarsDeviceCollection& pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection& pfClusteringEdgeVars,
const reco::PFRecHitHostCollection& pfRecHits,
reco::PFClusterDeviceCollection& pfClusters,
reco::PFRecHitFractionDeviceCollection& pfrhFractions);

private:
cms::alpakatools::device_buffer<Device, uint32_t> nSeeds;
Expand Down

0 comments on commit 36f2bb0

Please sign in to comment.