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

Fix PFClusterSoAProducer to read a device collection #46887

Merged
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
18 changes: 8 additions & 10 deletions RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFClusterECLCC.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#ifndef RecoParticleFlow_PFClusterProducer_plugins_alpaka_PFClusterECLCC_h
#define RecoParticleFlow_PFClusterProducer_plugins_alpaka_PFClusterECLCC_h

#include "DataFormats/ParticleFlowReco/interface/alpaka/PFRecHitDeviceCollection.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h"
#include "RecoParticleFlow/PFClusterProducer/interface/alpaka/PFClusteringVarsDeviceCollection.h"
#include "RecoParticleFlow/PFClusterProducer/interface/alpaka/PFClusteringEdgeVarsDeviceCollection.h"
#include "RecoParticleFlow/PFClusterProducer/interface/alpaka/PFClusteringVarsDeviceCollection.h"

// The following comment block is required in using the ECL-CC algorithm for topological clustering

Expand Down Expand Up @@ -79,9 +80,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
// Initial step of ECL-CC. Uses ID of first neighbour in edgeList with a smaller ID
class ECLCCInit {
public:
template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
ALPAKA_FN_ACC void operator()(const TAcc& acc,
reco::PFRecHitHostCollection::ConstView pfRecHits,
ALPAKA_FN_ACC void operator()(Acc1D const& acc,
reco::PFRecHitDeviceCollection::ConstView pfRecHits,
reco::PFClusteringVarsDeviceCollection::View pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection::View pfClusteringEdgeVars) const {
const int nRH = pfRecHits.size();
Expand All @@ -103,9 +103,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
// Processes vertices
class ECLCCCompute1 {
public:
template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
ALPAKA_FN_ACC void operator()(const TAcc& acc,
reco::PFRecHitHostCollection::ConstView pfRecHits,
ALPAKA_FN_ACC void operator()(Acc1D const& acc,
reco::PFRecHitDeviceCollection::ConstView pfRecHits,
reco::PFClusteringVarsDeviceCollection::View pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection::View pfClusteringEdgeVars) const {
const int nRH = pfRecHits.size();
Expand Down Expand Up @@ -148,9 +147,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
/* link all vertices to sink */
class ECLCCFlatten {
public:
template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
ALPAKA_FN_ACC void operator()(const TAcc& acc,
reco::PFRecHitHostCollection::ConstView pfRecHits,
ALPAKA_FN_ACC void operator()(Acc1D const& acc,
reco::PFRecHitDeviceCollection::ConstView pfRecHits,
reco::PFClusteringVarsDeviceCollection::View pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection::View pfClusteringEdgeVars) const {
const int nRH = pfRecHits.size();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <Eigen/Core>
#include <Eigen/Dense>

#include "DataFormats/ParticleFlowReco/interface/PFRecHitHostCollection.h"
#include "DataFormats/ParticleFlowReco/interface/alpaka/PFRecHitDeviceCollection.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
Expand All @@ -16,12 +16,14 @@
#include "RecoParticleFlow/PFRecHitProducer/interface/PFRecHitTopologyRecord.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {

class PFClusterSoAProducer : public stream::SynchronizingEDProducer<> {
public:
PFClusterSoAProducer(edm::ParameterSet const& config)
: pfClusParamsToken(esConsumes(config.getParameter<edm::ESInputTag>("pfClusterParams"))),
topologyToken_(esConsumes(config.getParameter<edm::ESInputTag>("topology"))),
inputPFRecHitSoA_Token_{consumes(config.getParameter<edm::InputTag>("pfRecHits"))},
inputPFRecHitNum_Token_{consumes(config.getParameter<edm::InputTag>("pfRecHits"))},
outputPFClusterSoA_Token_{produces()},
outputPFRHFractionSoA_Token_{produces()},
numRHF_{cms::alpakatools::make_host_buffer<uint32_t, Platform>()},
Expand All @@ -30,10 +32,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
void acquire(device::Event const& event, device::EventSetup const& setup) override {
const reco::PFClusterParamsDeviceCollection& params = setup.getData(pfClusParamsToken);
const reco::PFRecHitHCALTopologyDeviceCollection& topology = setup.getData(topologyToken_);
const reco::PFRecHitHostCollection& pfRecHits = event.get(inputPFRecHitSoA_Token_);
int nRH = 0;
if (pfRecHits->metadata().size() != 0)
nRH = pfRecHits->size();
const reco::PFRecHitDeviceCollection& pfRecHits = event.get(inputPFRecHitSoA_Token_);
int nRH = event.get(inputPFRecHitNum_Token_);

pfClusteringVars_.emplace(nRH, event.queue());
pfClusteringEdgeVars_.emplace(nRH * 8, event.queue());
Expand All @@ -42,13 +42,14 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
*numRHF_ = 0;

if (nRH != 0) {
PFClusterProducerKernel kernel(event.queue(), pfRecHits);
PFClusterProducerKernel kernel(event.queue());
kernel.seedTopoAndContract(event.queue(),
params,
topology,
*pfClusteringVars_,
*pfClusteringEdgeVars_,
pfRecHits,
nRH,
*pfClusters_,
numRHF_.data());
}
Expand All @@ -57,23 +58,21 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
void produce(device::Event& event, device::EventSetup const& setup) override {
const reco::PFClusterParamsDeviceCollection& params = setup.getData(pfClusParamsToken);
const reco::PFRecHitHCALTopologyDeviceCollection& topology = setup.getData(topologyToken_);
const reco::PFRecHitHostCollection& pfRecHits = event.get(inputPFRecHitSoA_Token_);
int nRH = 0;
const reco::PFRecHitDeviceCollection& pfRecHits = event.get(inputPFRecHitSoA_Token_);

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

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

int nRH = event.get(inputPFRecHitNum_Token_);
if (nRH != 0) {
pfrhFractions.emplace(*numRHF_.data(), event.queue());
PFClusterProducerKernel kernel(event.queue(), pfRecHits);
pfrhFractions.emplace(*numRHF_, event.queue());
PFClusterProducerKernel kernel(event.queue());
kernel.cluster(event.queue(),
params,
topology,
*pfClusteringVars_,
*pfClusteringEdgeVars_,
pfRecHits,
nRH,
*pfClusters_,
*pfrhFractions);
} else {
Expand All @@ -99,7 +98,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
private:
const device::ESGetToken<reco::PFClusterParamsDeviceCollection, JobConfigurationGPURecord> pfClusParamsToken;
const device::ESGetToken<reco::PFRecHitHCALTopologyDeviceCollection, PFRecHitHCALTopologyRecord> topologyToken_;
const edm::EDGetTokenT<reco::PFRecHitHostCollection> inputPFRecHitSoA_Token_;
const device::EDGetToken<reco::PFRecHitDeviceCollection> inputPFRecHitSoA_Token_;
const edm::EDGetTokenT<cms_uint32_t> inputPFRecHitNum_Token_;
const device::EDPutToken<reco::PFClusterDeviceCollection> outputPFClusterSoA_Token_;
const device::EDPutToken<reco::PFRecHitFractionDeviceCollection> outputPFRHFractionSoA_Token_;
cms::alpakatools::host_buffer<uint32_t> numRHF_;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include <alpaka/alpaka.hpp>

#include "DataFormats/ParticleFlowReco/interface/PFLayer.h"
#include "FWCore/Utilities/interface/bit_cast.h"
#include "HeterogeneousCore/AlpakaInterface/interface/atomicMaxF.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h"
#include "HeterogeneousCore/AlpakaInterface/interface/atomicMaxF.h"

#include "DataFormats/ParticleFlowReco/interface/PFLayer.h"
#include "RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFClusterSoAProducerKernel.h"
#include "RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFClusterECLCC.h"
#include "RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFClusterSoAProducerKernel.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {

Expand Down Expand Up @@ -1088,7 +1087,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
reco::PFClusteringVarsDeviceCollection::View pfClusteringVars,
const reco::PFClusterParamsDeviceCollection::ConstView pfClusParams,
const reco::PFRecHitHCALTopologyDeviceCollection::ConstView topology,
const reco::PFRecHitHostCollection::ConstView pfRecHits,
const reco::PFRecHitDeviceCollection::ConstView pfRecHits,
reco::PFClusterDeviceCollection::View clusterView,
uint32_t* __restrict__ nSeeds) const {
const int nRH = pfRecHits.size();
Expand Down Expand Up @@ -1165,7 +1164,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
public:
template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
ALPAKA_FN_ACC void operator()(const TAcc& acc,
const reco::PFRecHitHostCollection::ConstView pfRecHits,
const reco::PFRecHitDeviceCollection::ConstView pfRecHits,
reco::PFClusteringVarsDeviceCollection::View pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection::View pfClusteringEdgeVars,
uint32_t* __restrict__ nSeeds) const {
Expand Down Expand Up @@ -1195,7 +1194,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
public:
template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
ALPAKA_FN_ACC void operator()(const TAcc& acc,
const reco::PFRecHitHostCollection::ConstView pfRecHits,
const reco::PFRecHitDeviceCollection::ConstView pfRecHits,
reco::PFClusteringVarsDeviceCollection::View pfClusteringVars,
reco::PFClusterDeviceCollection::View clusterView,
uint32_t* __restrict__ nSeeds,
Expand Down Expand Up @@ -1319,7 +1318,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
public:
template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
ALPAKA_FN_ACC void operator()(const TAcc& acc,
const reco::PFRecHitHostCollection::ConstView pfRecHits,
const reco::PFRecHitDeviceCollection::ConstView pfRecHits,
reco::PFClusteringVarsDeviceCollection::View pfClusteringVars,
reco::PFRecHitFractionDeviceCollection::View fracView) const {
const int nRH = pfRecHits.size();
Expand Down Expand Up @@ -1350,7 +1349,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
public:
template <bool debug = false, typename TAcc, typename = std::enable_if<!std::is_same_v<Device, alpaka::DevCpu>>>
ALPAKA_FN_ACC void operator()(const TAcc& acc,
const reco::PFRecHitHostCollection::ConstView pfRecHits,
const reco::PFRecHitDeviceCollection::ConstView pfRecHits,
const reco::PFClusterParamsDeviceCollection::ConstView pfClusParams,
const reco::PFRecHitHCALTopologyDeviceCollection::ConstView topology,
reco::PFClusteringVarsDeviceCollection::View pfClusteringVars,
Expand Down Expand Up @@ -1412,7 +1411,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
public:
template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
ALPAKA_FN_ACC void operator()(const TAcc& acc,
const reco::PFRecHitHostCollection::ConstView pfRecHits,
const reco::PFRecHitDeviceCollection::ConstView pfRecHits,
const reco::PFClusterParamsDeviceCollection::ConstView pfClusParams,
const reco::PFRecHitHCALTopologyDeviceCollection::ConstView topology,
reco::PFClusteringVarsDeviceCollection::View pfClusteringVars,
Expand Down Expand Up @@ -1454,7 +1453,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
}
};

PFClusterProducerKernel::PFClusterProducerKernel(Queue& queue, const reco::PFRecHitHostCollection& pfRecHits)
PFClusterProducerKernel::PFClusterProducerKernel(Queue& queue)
: nSeeds(cms::alpakatools::make_device_buffer<uint32_t>(queue)),
globalClusterPos(
cms::alpakatools::make_device_buffer<Position4[]>(queue, blocksForExoticClusters * maxTopoInput)),
Expand All @@ -1473,10 +1472,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
const reco::PFRecHitHCALTopologyDeviceCollection& topology,
reco::PFClusteringVarsDeviceCollection& pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection& pfClusteringEdgeVars,
const reco::PFRecHitHostCollection& pfRecHits,
const reco::PFRecHitDeviceCollection& pfRecHits,
int nRH,
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 @@ -1533,11 +1532,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
const reco::PFRecHitHCALTopologyDeviceCollection& topology,
reco::PFClusteringVarsDeviceCollection& pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection& pfClusteringEdgeVars,
const reco::PFRecHitHostCollection& pfRecHits,
const reco::PFRecHitDeviceCollection& pfRecHits,
int nRH,
reco::PFClusterDeviceCollection& pfClusters,
reco::PFRecHitFractionDeviceCollection& pfrhFractions) {
const int nRH = pfRecHits->size();

// fillRhfIndex
alpaka::exec<Acc2D>(queue,
make_workdiv<Acc2D>({divide_up_by(nRH, 32), divide_up_by(nRH, 32)}, {32, 32}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#ifndef RecoParticleFlow_PFClusterProducer_PFClusterProducerAlpakaKernel_h
#define RecoParticleFlow_PFClusterProducer_PFClusterProducerAlpakaKernel_h

#include "DataFormats/ParticleFlowReco/interface/alpaka/PFRecHitDeviceCollection.h"
#include "DataFormats/ParticleFlowReco/interface/PFRecHitHostCollection.h"
#include "DataFormats/ParticleFlowReco/interface/alpaka/PFClusterDeviceCollection.h"
#include "DataFormats/ParticleFlowReco/interface/alpaka/PFRecHitDeviceCollection.h"
#include "DataFormats/ParticleFlowReco/interface/alpaka/PFRecHitFractionDeviceCollection.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "RecoParticleFlow/PFClusterProducer/interface/alpaka/PFClusterParamsDeviceCollection.h"
#include "RecoParticleFlow/PFClusterProducer/interface/alpaka/PFClusteringVarsDeviceCollection.h"
#include "RecoParticleFlow/PFClusterProducer/interface/alpaka/PFClusteringEdgeVarsDeviceCollection.h"
#include "RecoParticleFlow/PFClusterProducer/interface/alpaka/PFClusteringVarsDeviceCollection.h"
#include "RecoParticleFlow/PFRecHitProducer/interface/alpaka/PFRecHitTopologyDeviceCollection.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {

Expand Down Expand Up @@ -37,14 +36,15 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {

class PFClusterProducerKernel {
public:
PFClusterProducerKernel(Queue& queue, const reco::PFRecHitHostCollection& pfRecHits);
explicit PFClusterProducerKernel(Queue& queue);

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

Expand All @@ -53,7 +53,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
const reco::PFRecHitHCALTopologyDeviceCollection& topology,
reco::PFClusteringVarsDeviceCollection& pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection& pfClusteringEdgeVars,
const reco::PFRecHitHostCollection& pfRecHits,
const reco::PFRecHitDeviceCollection& pfRecHits,
int nRH,
reco::PFClusterDeviceCollection& pfClusters,
reco::PFRecHitFractionDeviceCollection& pfrhFractions);

Expand Down
Loading