Skip to content

Commit

Permalink
Fix PFClusterSoAProducer to read a device collection
Browse files Browse the repository at this point in the history
  • Loading branch information
fwyzard committed Nov 30, 2024
1 parent 48600da commit c0252e9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 36 deletions.
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,6 +16,7 @@
#include "RecoParticleFlow/PFRecHitProducer/interface/PFRecHitTopologyRecord.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {

class PFClusterSoAProducer : public stream::SynchronizingEDProducer<> {
public:
PFClusterSoAProducer(edm::ParameterSet const& config)
Expand All @@ -30,7 +31,7 @@ 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_);
const reco::PFRecHitDeviceCollection& pfRecHits = event.get(inputPFRecHitSoA_Token_);
int nRH = 0;
if (pfRecHits->metadata().size() != 0)
nRH = pfRecHits->size();
Expand All @@ -42,7 +43,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
*numRHF_ = 0;

if (nRH != 0) {
PFClusterProducerKernel kernel(event.queue(), pfRecHits);
PFClusterProducerKernel kernel(event.queue());
kernel.seedTopoAndContract(event.queue(),
params,
topology,
Expand All @@ -57,7 +58,7 @@ 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_);
const reco::PFRecHitDeviceCollection& pfRecHits = event.get(inputPFRecHitSoA_Token_);
int nRH = 0;

std::optional<reco::PFRecHitFractionDeviceCollection> pfrhFractions;
Expand All @@ -67,7 +68,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {

if (nRH != 0) {
pfrhFractions.emplace(*numRHF_.data(), event.queue());
PFClusterProducerKernel kernel(event.queue(), pfRecHits);
PFClusterProducerKernel kernel(event.queue());
kernel.cluster(event.queue(),
params,
topology,
Expand Down Expand Up @@ -99,7 +100,7 @@ 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 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,7 +1472,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
const reco::PFRecHitHCALTopologyDeviceCollection& topology,
reco::PFClusteringVarsDeviceCollection& pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection& pfClusteringEdgeVars,
const reco::PFRecHitHostCollection& pfRecHits,
const reco::PFRecHitDeviceCollection& pfRecHits,
reco::PFClusterDeviceCollection& pfClusters,
uint32_t* __restrict__ nRHF) {
const int nRH = pfRecHits->size();
Expand Down Expand Up @@ -1533,7 +1532,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
const reco::PFRecHitHCALTopologyDeviceCollection& topology,
reco::PFClusteringVarsDeviceCollection& pfClusteringVars,
reco::PFClusteringEdgeVarsDeviceCollection& pfClusteringEdgeVars,
const reco::PFRecHitHostCollection& pfRecHits,
const reco::PFRecHitDeviceCollection& pfRecHits,
reco::PFClusterDeviceCollection& pfClusters,
reco::PFRecHitFractionDeviceCollection& pfrhFractions) {
const int nRH = pfRecHits->size();
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,14 @@ 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,
reco::PFClusterDeviceCollection& pfClusters,
uint32_t* __restrict__ nRHF);

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

Expand Down

0 comments on commit c0252e9

Please sign in to comment.