Skip to content

Commit

Permalink
Merge pull request cms-sw#18 from jsamudio/tmp_FllorMerge
Browse files Browse the repository at this point in the history
Merge Florian's latest stable branch
  • Loading branch information
jsamudio authored Jun 23, 2023
2 parents e4b3841 + 966f832 commit 9cbe385
Show file tree
Hide file tree
Showing 18 changed files with 335 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "DataFormats/Portable/interface/PortableHostCollection.h"
#include "DataFormats/ParticleFlowReco_Alpaka/interface/CaloRecHitSoA.h"

using CaloRecHitHostCollection = PortableHostCollection<CaloRecHitSoA>;
namespace reco {
using CaloRecHitHostCollection = PortableHostCollection<CaloRecHitSoA>;
}

#endif
15 changes: 9 additions & 6 deletions DataFormats/ParticleFlowReco_Alpaka/interface/CaloRecHitSoA.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
#include "DataFormats/SoATemplate/interface/SoALayout.h"
#include "DataFormats/SoATemplate/interface/SoAView.h"

GENERATE_SOA_LAYOUT(CaloRecHitSoALayout,
SOA_COLUMN(uint32_t, detId),
SOA_COLUMN(float, energy),
SOA_COLUMN(float, time)
)
namespace reco {

using CaloRecHitSoA = CaloRecHitSoALayout<>;
GENERATE_SOA_LAYOUT(CaloRecHitSoALayout,
SOA_COLUMN(uint32_t, detId),
SOA_COLUMN(float, energy),
SOA_COLUMN(float, time)
)

using CaloRecHitSoA = CaloRecHitSoALayout<>;
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "DataFormats/ParticleFlowReco_Alpaka/interface/PFRecHitSoA.h"
#include "DataFormats/Portable/interface/PortableHostCollection.h"

using PFRecHitHostCollection = PortableHostCollection<PFRecHitSoA>;
namespace reco {
using PFRecHitHostCollection = PortableHostCollection<PFRecHitSoA>;
}

#endif
29 changes: 18 additions & 11 deletions DataFormats/ParticleFlowReco_Alpaka/interface/PFRecHitSoA.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,24 @@

#include "DataFormats/ParticleFlowReco/interface/PFLayer.h"

using Vec8 = Eigen::Matrix<uint32_t, 8, 1>;
GENERATE_SOA_LAYOUT(PFRecHitSoALayout,
SOA_COLUMN(uint32_t, detId),
SOA_COLUMN(float, energy),
SOA_COLUMN(float, time),
SOA_COLUMN(int, depth),
SOA_COLUMN(PFLayer::Layer, layer),
SOA_EIGEN_COLUMN(Vec8, neighbours),
SOA_SCALAR(uint32_t, size)
)
namespace reco {

using PFRecHitsNeighbours = Eigen::Matrix<uint32_t, 8, 1>;
GENERATE_SOA_LAYOUT(PFRecHitSoALayout,
SOA_COLUMN(uint32_t, detId),
SOA_COLUMN(float, energy),
SOA_COLUMN(float, time),
SOA_COLUMN(int, depth),
SOA_COLUMN(PFLayer::Layer, layer),
SOA_COLUMN(uint32_t, num_neighbours),
SOA_EIGEN_COLUMN(PFRecHitsNeighbours, neighbours),
SOA_COLUMN(float, x),
SOA_COLUMN(float, y),
SOA_COLUMN(float, z),
SOA_SCALAR(uint32_t, size)
)

using PFRecHitSoA = PFRecHitSoALayout<>;
using PFRecHitSoA = PFRecHitSoALayout<>;
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {
using CaloRecHitDeviceCollection = PortableCollection<CaloRecHitSoA>;
using CaloRecHitDeviceCollection = PortableCollection<reco::CaloRecHitSoA>;
} // namespace ALPAKA_ACCELERATOR_NAMESPACE

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "DataFormats/ParticleFlowReco_Alpaka/interface/PFRecHitSoA.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {
using PFRecHitDeviceCollection = PortableCollection<PFRecHitSoA>;
using PFRecHitDeviceCollection = PortableCollection<reco::PFRecHitSoA>;
} // namespace ALPAKA_ACCELERATOR_NAMESPACE

#endif
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<lcgdict>
<class name="CaloRecHitHostCollection"/>
<class name="reco::CaloRecHitHostCollection"/>
<read
sourceClass="CaloRecHitHostCollection"
targetClass="CaloRecHitHostCollection"
sourceClass="reco::CaloRecHitHostCollection"
targetClass="reco::CaloRecHitHostCollection"
version="[1-]"
source="CaloRecHitSoA layout_;"
source="reco::CaloRecHitSoA layout_;"
target="buffer_,layout_,view_"
embed="false">
<![CDATA[
CaloRecHitHostCollection::ROOTReadStreamer(newObj, onfile.layout_);
reco::CaloRecHitHostCollection::ROOTReadStreamer(newObj, onfile.layout_);
]]>
</read>
<class name="edm::Wrapper<CaloRecHitHostCollection>" splitLevel="0"/>
<class name="edm::Wrapper<reco::CaloRecHitHostCollection>" splitLevel="0"/>

<class name="PFRecHitHostCollection"/>
<class name="reco::PFRecHitHostCollection"/>
<read
sourceClass="PFRecHitHostCollection"
targetClass="PFRecHitHostCollection"
sourceClass="reco::PFRecHitHostCollection"
targetClass="reco::PFRecHitHostCollection"
version="[1-]"
source="PFRecHitSoA layout_;"
source="reco::PFRecHitSoA layout_;"
target="buffer_,layout_,view_"
embed="false">
<![CDATA[
PFRecHitHostCollection::ROOTReadStreamer(newObj, onfile.layout_);
reco::PFRecHitHostCollection::ROOTReadStreamer(newObj, onfile.layout_);
]]>
</read>
<class name="edm::Wrapper<PFRecHitHostCollection>" splitLevel="0"/>
<class name="edm::Wrapper<reco::PFRecHitHostCollection>" splitLevel="0"/>
</lcgdict>
8 changes: 4 additions & 4 deletions DataFormats/ParticleFlowReco_Alpaka/src/classes_def.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<lcgdict>
<selection>
<class name="CaloRecHitSoA"/>
<class name="CaloRecHitSoA::View"/>
<class name="PFRecHitSoA"/>
<class name="PFRecHitSoA::View"/>
<class name="reco::CaloRecHitSoA"/>
<class name="reco::CaloRecHitSoA::View"/>
<class name="reco::PFRecHitSoA"/>
<class name="reco::PFRecHitSoA::View"/>
</selection>
</lcgdict>

1 change: 1 addition & 0 deletions RecoParticleFlow/PFRecHitProducer/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<use name="eigen"/>
<use name="FWCore/Framework"/>
<use name="FWCore/Utilities"/>
<use name="DataFormats/Portable"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
#ifndef RecoParticleFlow_PFRecHitProducer_interface_PFRecHitHBHETopologyAlpakaESDataSoA_h
#define RecoParticleFlow_PFRecHitProducer_interface_PFRecHitHBHETopologyAlpakaESDataSoA_h

#include <Eigen/Core>
#include <Eigen/Dense>

#include "DataFormats/SoATemplate/interface/SoACommon.h"
#include "DataFormats/SoATemplate/interface/SoALayout.h"
#include "DataFormats/SoATemplate/interface/SoAView.h"

namespace reco {

using PFRecHitsTopologyNeighbours = Eigen::Matrix<uint32_t, 8, 1>;
GENERATE_SOA_LAYOUT(PFRecHitHBHETopologyAlpakaESDataSoALayout,
SOA_COLUMN(float, positionX),
SOA_COLUMN(float, positionY),
SOA_COLUMN(float, positionZ),
SOA_COLUMN(int32_t, neighbour0),
SOA_COLUMN(int32_t, neighbour1),
SOA_COLUMN(int32_t, neighbour2),
SOA_COLUMN(int32_t, neighbour3),
SOA_COLUMN(int32_t, neighbour4),
SOA_COLUMN(int32_t, neighbour5),
SOA_COLUMN(int32_t, neighbour6),
SOA_COLUMN(int32_t, neighbour7))
SOA_EIGEN_COLUMN(PFRecHitsTopologyNeighbours, neighbours),
SOA_SCALAR(uint32_t, denseId_min),
SOA_SCALAR(uint32_t, denseId_max))

using PFRecHitHBHETopologyAlpakaESDataSoA = PFRecHitHBHETopologyAlpakaESDataSoALayout<>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@

#include "DataFormats/ParticleFlowReco_Alpaka/interface/alpaka/PFRecHitDeviceCollection.h"
#include "DataFormats/ParticleFlowReco_Alpaka/interface/alpaka/CaloRecHitDeviceCollection.h"
#include "RecoParticleFlow/PFRecHitProducer/interface/alpaka/PFRecHitHBHEParamsAlpakaESData.h"
#include "RecoParticleFlow/PFRecHitProducer/interface/alpaka/PFRecHitHBHETopologyAlpakaESData.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {

class PFRecHitProducerKernel {
public:
void execute(Queue& queue, const CaloRecHitDeviceCollection& recHits, PFRecHitDeviceCollection& collection) const;
void execute(const Device& device, Queue& queue,
const PFRecHitHBHEParamsAlpakaESDataDevice& params,
const PFRecHitHBHETopologyAlpakaESDataDevice& topology,
const CaloRecHitDeviceCollection& recHits,
PFRecHitDeviceCollection& collection) const;
};

} // namespace ALPAKA_ACCELERATOR_NAMESPACE
Expand Down
77 changes: 60 additions & 17 deletions RecoParticleFlow/PFRecHitProducer/plugins/PFRecHitProducerTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class PFRecHitProducerTest : public DQMEDAnalyzer {
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
void DumpEvent(const reco::PFRecHitCollection& pfRecHitsCPU, const PFRecHitHostCollection::ConstView& pfRecHitsAlpaka);
void DumpEvent(const reco::PFRecHitCollection& pfRecHitsCPU, const reco::PFRecHitHostCollection::ConstView& pfRecHitsAlpaka);

edm::EDGetTokenT<edm::SortedCollection<HBHERecHit>> recHitsToken;
edm::EDGetTokenT<reco::PFRecHitCollection> pfRecHitsTokenCPU;
edm::EDGetTokenT<PFRecHitHostCollection> pfRecHitsTokenAlpaka;
edm::EDGetTokenT<reco::PFRecHitHostCollection> pfRecHitsTokenAlpaka;
int32_t num_events = 0, num_errors = 0;
};

Expand All @@ -44,7 +44,7 @@ PFRecHitProducerTest::PFRecHitProducerTest(const edm::ParameterSet& conf)
pfRecHitsTokenCPU(
consumes<reco::PFRecHitCollection>(conf.getUntrackedParameter<edm::InputTag>("pfRecHitsSourceCPU"))),
pfRecHitsTokenAlpaka(
consumes<PFRecHitHostCollection>(conf.getUntrackedParameter<edm::InputTag>("pfRecHitsSourceAlpaka")))
consumes<reco::PFRecHitHostCollection>(conf.getUntrackedParameter<edm::InputTag>("pfRecHitsSourceAlpaka")))
{}

PFRecHitProducerTest::~PFRecHitProducerTest() {
Expand All @@ -62,12 +62,12 @@ void PFRecHitProducerTest::analyze(edm::Event const& event, edm::EventSetup cons

// PF Rec Hits
edm::Handle<reco::PFRecHitCollection> pfRecHitsCPUlegacy;
edm::Handle<PFRecHitHostCollection> pfRecHitsAlpakaSoA;
edm::Handle<reco::PFRecHitHostCollection> pfRecHitsAlpakaSoA;
event.getByToken(pfRecHitsTokenCPU, pfRecHitsCPUlegacy);
event.getByToken(pfRecHitsTokenAlpaka, pfRecHitsAlpakaSoA);

const reco::PFRecHitCollection& pfRecHitsCPU = *pfRecHitsCPUlegacy;
const PFRecHitHostCollection::ConstView& pfRecHitsAlpaka = pfRecHitsAlpakaSoA->const_view();
const reco::PFRecHitHostCollection::ConstView& pfRecHitsAlpaka = pfRecHitsAlpakaSoA->const_view();

bool error = false;
if(pfRecHitsCPU.size() != pfRecHitsAlpaka.size())
Expand All @@ -88,15 +88,41 @@ void PFRecHitProducerTest::analyze(edm::Event const& event, edm::EventSetup cons
if(pfRecHitsCPU[i].depth() != pfRecHitsAlpaka[j].depth()
|| pfRecHitsCPU[i].layer() != pfRecHitsAlpaka[j].layer()
|| pfRecHitsCPU[i].time() != pfRecHitsAlpaka[j].time()
|| pfRecHitsCPU[i].energy() != pfRecHitsAlpaka[j].energy())
|| pfRecHitsCPU[i].energy() != pfRecHitsAlpaka[j].energy()
|| pfRecHitsCPU[i].position().x() != pfRecHitsAlpaka[i].x()
|| pfRecHitsCPU[i].position().y() != pfRecHitsAlpaka[i].y()
|| pfRecHitsCPU[i].position().z() != pfRecHitsAlpaka[i].z()
)
error = true;
else
{
// check neighbours
reco::PFRecHit::Neighbours pfRecHitNeighbours = pfRecHitsCPU[i].neighbours();
std::vector<uint32_t> neighbours_cpu(pfRecHitNeighbours.begin(), pfRecHitNeighbours.end());
std::sort(neighbours_cpu.begin(), neighbours_cpu.end());

std::vector<uint32_t> neighbours_alpaka(pfRecHitsAlpaka[j].num_neighbours());
for(size_t k = 0; k < pfRecHitsAlpaka[j].num_neighbours(); k++)
neighbours_alpaka[k] = pfRecHitsAlpaka[i].neighbours()(k);
std::sort(neighbours_alpaka.begin(), neighbours_alpaka.end());

if(neighbours_cpu.size() != neighbours_alpaka.size())
error = true;
else
for(size_t k = 0; k < neighbours_cpu.size(); k++)
if(neighbours_cpu[k] != neighbours_alpaka[k])
error = true;
}
}
}
if(!detId_found)
error = true;
}
}

//if(num_events == 0)
// DumpEvent(pfRecHitsCPU, pfRecHitsAlpaka);

if(error)
{
// When enabling this, need to set number of threads to 1 to get useful output
Expand All @@ -107,34 +133,51 @@ void PFRecHitProducerTest::analyze(edm::Event const& event, edm::EventSetup cons
num_events++;
}

void PFRecHitProducerTest::DumpEvent(const reco::PFRecHitCollection& pfRecHitsCPU, const PFRecHitHostCollection::ConstView& pfRecHitsAlpaka) {
void PFRecHitProducerTest::DumpEvent(const reco::PFRecHitCollection& pfRecHitsCPU, const reco::PFRecHitHostCollection::ConstView& pfRecHitsAlpaka) {
printf("Found %zd/%d pfRecHits with CPU/Alpaka\n", pfRecHitsCPU.size(), pfRecHitsAlpaka.size());
for (size_t i = 0; i < pfRecHitsCPU.size(); i++)
printf("CPU %4lu %u %d %d %u : %f %f (%f,%f,%f)\n",
{
reco::PFRecHit::Neighbours pfRecHitNeighbours = pfRecHitsCPU[i].neighbours();
std::vector<uint32_t> neighbours(pfRecHitNeighbours.begin(), pfRecHitNeighbours.end());
std::sort(neighbours.begin(), neighbours.end());
printf("CPU %4lu detId:%u depth:%d layer:%d time:%f energy:%f pos:%f,%f,%f neighbours:%lu(",
i,
pfRecHitsCPU[i].detId(),
pfRecHitsCPU[i].depth(),
pfRecHitsCPU[i].layer(),
pfRecHitsCPU[i].neighbours().size(),
pfRecHitsCPU[i].time(),
pfRecHitsCPU[i].energy(),
0., //pfRecHitsCPU[i].position().x(),
0., //pfRecHitsCPU[i].position().y(),
0. //pfRecHitsCPU[i].position().z()
pfRecHitsCPU[i].position().x(),
pfRecHitsCPU[i].position().y(),
pfRecHitsCPU[i].position().z(),
neighbours.size()
);
for(uint32_t j = 0; j < neighbours.size(); j++)
printf("%s%u", (j == 0) ? "" : ",", neighbours[j]);
printf(")\n");
}
for (size_t i = 0; i < pfRecHitsAlpaka.size(); i++)
printf("Alpaka %4lu %u %d %d %u : %f %f (%f,%f,%f)\n",
{
std::vector<uint32_t> neighbours(pfRecHitsAlpaka[i].num_neighbours());
for(size_t k = 0; k < pfRecHitsAlpaka[i].num_neighbours(); k++)
neighbours[k] = pfRecHitsAlpaka[i].neighbours()(k);
std::sort(neighbours.begin(), neighbours.end());
printf("Alpaka %4lu detId:%u depth:%d layer:%d time:%f energy:%f pos:%f,%f,%f neighbours:%lu(",
i,
pfRecHitsAlpaka[i].detId(),
pfRecHitsAlpaka[i].depth(),
pfRecHitsAlpaka[i].layer(),
-1,//pfRecHitsAlpaka[i].neighbours().size(),
pfRecHitsAlpaka[i].time(),
pfRecHitsAlpaka[i].energy(),
0., //pfRecHitsGPU->at(i).position().x(),
0., //pfRecHitsGPU->at(i).position().y(),
0. //pfRecHitsGPU->at(i).position().z()
pfRecHitsAlpaka[i].x(),
pfRecHitsAlpaka[i].y(),
pfRecHitsAlpaka[i].z(),
neighbours.size()
);
for(uint32_t j = 0; j < neighbours.size(); j++)
printf("%s%u", (j == 0) ? "" : ",", neighbours[j]);
printf(")\n");
}
}

void PFRecHitProducerTest::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
if(DEBUG)
printf("Found %d recHits\n", num_recHits);

CaloRecHitHostCollection hostProduct{num_recHits, event.queue()};
reco::CaloRecHitHostCollection hostProduct{num_recHits, event.queue()};
auto& view = hostProduct.view();

for(int i = 0; i < num_recHits; i++)
Expand Down
Loading

0 comments on commit 9cbe385

Please sign in to comment.