From 5cddb20ef6204bcbd8468800c956ce1e2be4be56 Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Tue, 20 May 2025 15:41:42 +0200 Subject: [PATCH 01/40] First compiling version of P modules in OT barrel SoA. --- .../plugins/BuildFile.xml | 11 ++ .../alpaka/Phase2OTRecHitsSoAConverter.cc | 181 ++++++++++++++++++ 2 files changed, 192 insertions(+) create mode 100644 RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc diff --git a/RecoLocalTracker/Phase2TrackerRecHits/plugins/BuildFile.xml b/RecoLocalTracker/Phase2TrackerRecHits/plugins/BuildFile.xml index 5ec8e56667ecf..5addf06f89d9b 100644 --- a/RecoLocalTracker/Phase2TrackerRecHits/plugins/BuildFile.xml +++ b/RecoLocalTracker/Phase2TrackerRecHits/plugins/BuildFile.xml @@ -6,3 +6,14 @@ + + + + + + + + + + + diff --git a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc new file mode 100644 index 0000000000000..36982e5272df1 --- /dev/null +++ b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc @@ -0,0 +1,181 @@ +#include +#include +#include +#include "DataFormats/BeamSpot/interface/BeamSpot.h" +#include "DataFormats/GeometryVector/interface/GlobalPoint.h" +#include "DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsSoA.h" +#include "DataFormats/TrackingRecHitSoA/interface/alpaka/TrackingRecHitsSoACollection.h" +#include "HeterogeneousCore/AlpakaCore/interface/alpaka/Event.h" +#include "HeterogeneousCore/AlpakaInterface/interface/config.h" + +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "FWCore/Utilities/interface/InputTag.h" + +#include "DataFormats/Common/interface/DetSetVectorNew.h" +#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/TrackerRecHit2D/interface/Phase2TrackerRecHit1D.h" +#include "DataFormats/Math/interface/approx_atan2.h" + +#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" + +#include "HeterogeneousCore/AlpakaCore/interface/alpaka/stream/EDProducer.h" + +#include "DataFormats/TrackerCommon/interface/TrackerTopology.h" + +#include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h" + +#include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h" + + +#define TBD 1 + +namespace ALPAKA_ACCELERATOR_NAMESPACE { + +class Phase2OTRecHitsSoAConverter : public stream::EDProducer<> { + + using Hits = reco::TrackingRecHitsSoACollection; + using HitsHost = ::reco::TrackingRecHitHost; + using HMSstorage = typename std::vector; + +public: + explicit Phase2OTRecHitsSoAConverter(const edm::ParameterSet& iConfig); + ~Phase2OTRecHitsSoAConverter() override = default; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + void produce(device::Event& iEvent, const device::EventSetup& es) override; + + const edm::ESGetToken geomToken_; + const edm::EDGetTokenT recHitToken_; + const edm::EDGetTokenT<::reco::BeamSpot> beamSpotToken_; + + const device::EDPutToken stripSoADevice_; + const edm::EDPutTokenT hitModuleStart_; +}; + + +Phase2OTRecHitsSoAConverter::Phase2OTRecHitsSoAConverter(const edm::ParameterSet& iConfig) + : stream::EDProducer<>(iConfig), + geomToken_(esConsumes()), + recHitToken_{consumes(iConfig.getParameter("stripRecHitSource"))}, + beamSpotToken_(consumes<::reco::BeamSpot>(iConfig.getParameter("beamSpot"))), + stripSoADevice_{produces()}, + hitModuleStart_{produces()} { } + + +void Phase2OTRecHitsSoAConverter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + + desc.add("pixelRecHitSoASource", edm::InputTag("siPixelRecHitsPreSplittingAlpaka")); + desc.add("stripRecHitSource", edm::InputTag("siStripMatchedRecHits", "matchedRecHit")); + desc.add("beamSpot", edm::InputTag("offlineBeamSpot")); + desc.add("caGeometry", std::string("caGeometry")); + + descriptions.addWithDefaultLabel(desc); + +} + +//https://github.com/cms-sw/cmssw/blob/3f06ef32d66bd2a7fa04e411fa4db4845193bd3c/RecoTracker/MkFit/plugins/convertHits.h + +void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSetup const& iSetup) { + + auto queue = iEvent.queue(); + auto& bs = iEvent.get(beamSpotToken_); + const auto &trackerGeometry = &iSetup.getData(geomToken_); + auto const& stripHits = iEvent.get(recHitToken_); + + // Count strip hits and active strip modules + const int nStripHits = stripHits.data().size(); + const int activeStripModules = stripHits.size(); + + auto isPinPSinOTBarrel = [&](DetId detId) { + // Select only P-hits from the OT barrel + return (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP && + detId.subdetId() == GeomDetEnumerators::P2OTB); + }; + + auto const& detUnits = trackerGeometry->detUnits(); + std::map detIdToIndex; + std::set p_modulesInPSInOTBarrel; + for (auto& detUnit : detUnits) + { + auto detId = detUnit->geographicalId(); + detIdToIndex[detUnit->geographicalId()] = detUnit->index(); + std::cout << detUnit->geographicalId() << " - " << detUnit->index() << std::endl; + if (isPinPSinOTBarrel(detId)) + p_modulesInPSInOTBarrel.insert(detUnit->index()); + } + std::cout << "Tot number of p_modulesInPSInOTBarrel: " << p_modulesInPSInOTBarrel.size() << std::endl; + std::cout << "Number of strip (active) modules: " << activeStripModules << std::endl; + std::cout << "Number of strip hits: " << nStripHits << std::endl; + + HitsHost stripHitsHost(queue, nStripHits, p_modulesInPSInOTBarrel.size()); + auto& stripHitsModuleView = stripHitsHost.view<::reco::HitModuleSoA>(); + + int n_hits = 0; + assert(p_modulesInPSInOTBarrel.size()); + int offset_modules = *p_modulesInPSInOTBarrel.begin(); + for (const auto& detSet : stripHits) { + + auto firstHit = detSet.begin(); + auto detId = firstHit->rawId(); + auto det = trackerGeometry->idToDet(detId); + auto index = detIdToIndex[detId]; + stripHitsModuleView[detIdToIndex[detId] - offset_modules].moduleStart() = n_hits; + + for (const auto& recHit : detSet) { + + // Select only P-hits from the OT barrel + if (isPinPSinOTBarrel(DetId(detId))) { + stripHitsHost.view()[n_hits].xLocal() = recHit.localPosition().x(); + stripHitsHost.view()[n_hits].yLocal() = recHit.localPosition().y(); + stripHitsHost.view()[n_hits].xerrLocal() = recHit.localPositionError().xx(); + stripHitsHost.view()[n_hits].yerrLocal() = recHit.localPositionError().yy(); + auto globalPosition = det->toGlobal(recHit.localPosition()); + double gx = globalPosition.x() - bs.x0(); + double gy = globalPosition.y() - bs.y0(); + double gz = globalPosition.z() - bs.z0(); + std::cout << gx << std::endl; + stripHitsHost.view()[n_hits].xGlobal() = gx; + stripHitsHost.view()[n_hits].yGlobal() = gy; + stripHitsHost.view()[n_hits].zGlobal() = gz; + stripHitsHost.view()[n_hits].rGlobal() = sqrt(gx * gx + gy * gy); + stripHitsHost.view()[n_hits].iphi() = unsafe_atan2s<7>(gy, gx); + stripHitsHost.view()[n_hits].chargeAndStatus().charge = 0; + stripHitsHost.view()[n_hits].chargeAndStatus().status = {0, 0, 0, 0, 0}; + stripHitsHost.view()[n_hits].clusterSizeX() = -1; + stripHitsHost.view()[n_hits].clusterSizeY() = -1; + stripHitsHost.view()[n_hits].detectorIndex() = index; + n_hits++; + } + } + } + + auto moduleStartView = cms::alpakatools::make_host_view(stripHitsModuleView.moduleStart(), stripHitsModuleView.metadata().size()); + HMSstorage moduleStartVec(stripHitsModuleView.metadata().size()); + + // Put in the event the hit module start vector. + // Now, this could be avoided having the Host Hit SoA + // consumed by the downstream module (converters to legacy formats). + // But this is the common practice at the moment + // also for legacy data formats. + alpaka::memcpy(queue, moduleStartVec, moduleStartView); + iEvent.emplace(hitModuleStart_, std::move(moduleStartVec)); + + Hits stripHitsDevice(queue, stripHitsHost.view().metadata().size(), stripHitsModuleView.metadata().size()); + alpaka::memcpy(queue, stripHitsDevice.buffer(), stripHitsHost.buffer()); + stripHitsDevice.updateFromDevice(queue); + + // Would be useful to have a way to prompt a special CopyToDevice for EDProducers + iEvent.emplace(stripSoADevice_, std::move(stripHitsDevice)); + +} + +} + +#include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h" +DEFINE_FWK_ALPAKA_MODULE(Phase2OTRecHitsSoAConverter); From a9adb7d7f76539577dc20a0d7cd04d2414a9e060 Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Tue, 20 May 2025 19:23:31 +0200 Subject: [PATCH 02/40] WIP. --- .../sequences/HLTOtLocalRecoSequence_cfi.py | 10 ++++ .../alpaka/Phase2OTRecHitsSoAConverter.cc | 46 ++++++++++++++----- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTOtLocalRecoSequence_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTOtLocalRecoSequence_cfi.py index 74591b451f439..45e954fc55109 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTOtLocalRecoSequence_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTOtLocalRecoSequence_cfi.py @@ -1,5 +1,15 @@ import FWCore.ParameterSet.Config as cms from ..modules.hltMeasurementTrackerEvent_cfi import * +from ..modules.hltSiPhase2RecHits_cfi import * +from RecoLocalTracker.Phase2TrackerRecHits.phase2OTRecHitsSoAConverter_cfi import * + +from Configuration.ProcessModifiers.alpaka_cff import alpaka HLTOtLocalRecoSequence = cms.Sequence(hltMeasurementTrackerEvent) + +HLTOtLocalRecoSequenceWithHits_ = cms.Sequence(hltMeasurementTrackerEvent + +hltSiPhase2RecHits + +phase2OTRecHitsSoAConverter) + +#alpaka.toReplaceWith(HLTOtLocalRecoSequence, HLTOtLocalRecoSequenceWithHits_) diff --git a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc index 36982e5272df1..faeaadefac62c 100644 --- a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc +++ b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc @@ -15,6 +15,7 @@ #include "DataFormats/Common/interface/DetSetVectorNew.h" #include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/SiStripDetId/interface/StripSubdetector.h" #include "DataFormats/TrackerRecHit2D/interface/Phase2TrackerRecHit1D.h" #include "DataFormats/Math/interface/approx_atan2.h" @@ -61,7 +62,7 @@ class Phase2OTRecHitsSoAConverter : public stream::EDProducer<> { Phase2OTRecHitsSoAConverter::Phase2OTRecHitsSoAConverter(const edm::ParameterSet& iConfig) : stream::EDProducer<>(iConfig), geomToken_(esConsumes()), - recHitToken_{consumes(iConfig.getParameter("stripRecHitSource"))}, + recHitToken_{consumes(iConfig.getParameter("otRecHitSource"))}, beamSpotToken_(consumes<::reco::BeamSpot>(iConfig.getParameter("beamSpot"))), stripSoADevice_{produces()}, hitModuleStart_{produces()} { } @@ -70,10 +71,8 @@ Phase2OTRecHitsSoAConverter::Phase2OTRecHitsSoAConverter(const edm::ParameterSet void Phase2OTRecHitsSoAConverter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.add("pixelRecHitSoASource", edm::InputTag("siPixelRecHitsPreSplittingAlpaka")); - desc.add("stripRecHitSource", edm::InputTag("siStripMatchedRecHits", "matchedRecHit")); - desc.add("beamSpot", edm::InputTag("offlineBeamSpot")); - desc.add("caGeometry", std::string("caGeometry")); + desc.add("otRecHitSource", edm::InputTag("hltSiPhase2RecHits")); + desc.add("beamSpot", edm::InputTag("hltOnlineBeamSpot")); descriptions.addWithDefaultLabel(desc); @@ -93,9 +92,11 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe const int activeStripModules = stripHits.size(); auto isPinPSinOTBarrel = [&](DetId detId) { +// std::cout << (int)trackerGeometry->getDetectorType(detId) << " " << (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP) << "\n"; +// std::cout << (int)detId.subdetId() << " " << (detId.subdetId() == StripSubdetector::TOB) << std::endl; // Select only P-hits from the OT barrel return (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP && - detId.subdetId() == GeomDetEnumerators::P2OTB); + detId.subdetId() == StripSubdetector::TOB); }; auto const& detUnits = trackerGeometry->detUnits(); @@ -103,34 +104,53 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe std::set p_modulesInPSInOTBarrel; for (auto& detUnit : detUnits) { - auto detId = detUnit->geographicalId(); + DetId detId(detUnit->geographicalId()); detIdToIndex[detUnit->geographicalId()] = detUnit->index(); - std::cout << detUnit->geographicalId() << " - " << detUnit->index() << std::endl; - if (isPinPSinOTBarrel(detId)) + if (isPinPSinOTBarrel(detId)) { p_modulesInPSInOTBarrel.insert(detUnit->index()); + std::cout << "Inserted " << detUnit->index() << " " << p_modulesInPSInOTBarrel.size() << std::endl; + } + } + // Count the number of P hits in the OT to dimension the SoA + int PHitsInOTBarrel = 0; + for (const auto& detSet : stripHits) { + for (const auto& recHit : detSet) { + DetId detId(recHit.geographicalId()); + if (isPinPSinOTBarrel(detId)) + PHitsInOTBarrel++; + } } std::cout << "Tot number of p_modulesInPSInOTBarrel: " << p_modulesInPSInOTBarrel.size() << std::endl; std::cout << "Number of strip (active) modules: " << activeStripModules << std::endl; std::cout << "Number of strip hits: " << nStripHits << std::endl; + std::cout << "Total hits of PinOTBarrel: " << PHitsInOTBarrel << std::endl; - HitsHost stripHitsHost(queue, nStripHits, p_modulesInPSInOTBarrel.size()); + HitsHost stripHitsHost(queue, PHitsInOTBarrel, p_modulesInPSInOTBarrel.size()); auto& stripHitsModuleView = stripHitsHost.view<::reco::HitModuleSoA>(); int n_hits = 0; assert(p_modulesInPSInOTBarrel.size()); - int offset_modules = *p_modulesInPSInOTBarrel.begin(); for (const auto& detSet : stripHits) { auto firstHit = detSet.begin(); auto detId = firstHit->rawId(); auto det = trackerGeometry->idToDet(detId); auto index = detIdToIndex[detId]; - stripHitsModuleView[detIdToIndex[detId] - offset_modules].moduleStart() = n_hits; + if (isPinPSinOTBarrel(DetId(detId))) { + auto it = p_modulesInPSInOTBarrel.find(index); + if (it != p_modulesInPSInOTBarrel.end()) { + int offset = std::distance(p_modulesInPSInOTBarrel.begin(), it); + stripHitsModuleView[offset].moduleStart() = n_hits; + } else { + assert(0); + } + } for (const auto& recHit : detSet) { // Select only P-hits from the OT barrel if (isPinPSinOTBarrel(DetId(detId))) { + assert(n_hits < PHitsInOTBarrel); stripHitsHost.view()[n_hits].xLocal() = recHit.localPosition().x(); stripHitsHost.view()[n_hits].yLocal() = recHit.localPosition().y(); stripHitsHost.view()[n_hits].xerrLocal() = recHit.localPositionError().xx(); @@ -155,6 +175,8 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe } } + std::cout << "DONE" << std::endl; + auto moduleStartView = cms::alpakatools::make_host_view(stripHitsModuleView.moduleStart(), stripHitsModuleView.metadata().size()); HMSstorage moduleStartVec(stripHitsModuleView.metadata().size()); From dd315307dad8709013c434f4ecb4252d09467d23 Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Wed, 21 May 2025 11:57:07 +0200 Subject: [PATCH 03/40] Enable OT SoA producers, increase SoA size for pixelTracks. --- .../python/HLT_75e33/sequences/HLTOtLocalRecoSequence_cfi.py | 2 +- .../plugins/alpaka/Phase2OTRecHitsSoAConverter.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTOtLocalRecoSequence_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTOtLocalRecoSequence_cfi.py index 45e954fc55109..7364f49abf106 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTOtLocalRecoSequence_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTOtLocalRecoSequence_cfi.py @@ -12,4 +12,4 @@ +hltSiPhase2RecHits +phase2OTRecHitsSoAConverter) -#alpaka.toReplaceWith(HLTOtLocalRecoSequence, HLTOtLocalRecoSequenceWithHits_) +alpaka.toReplaceWith(HLTOtLocalRecoSequence, HLTOtLocalRecoSequenceWithHits_) diff --git a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc index faeaadefac62c..a6946c07ce144 100644 --- a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc +++ b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc @@ -108,7 +108,7 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe detIdToIndex[detUnit->geographicalId()] = detUnit->index(); if (isPinPSinOTBarrel(detId)) { p_modulesInPSInOTBarrel.insert(detUnit->index()); - std::cout << "Inserted " << detUnit->index() << " " << p_modulesInPSInOTBarrel.size() << std::endl; +// std::cout << "Inserted " << detUnit->index() << " " << p_modulesInPSInOTBarrel.size() << std::endl; } } // Count the number of P hits in the OT to dimension the SoA @@ -159,7 +159,7 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe double gx = globalPosition.x() - bs.x0(); double gy = globalPosition.y() - bs.y0(); double gz = globalPosition.z() - bs.z0(); - std::cout << gx << std::endl; +// std::cout << gx << std::endl; stripHitsHost.view()[n_hits].xGlobal() = gx; stripHitsHost.view()[n_hits].yGlobal() = gy; stripHitsHost.view()[n_hits].zGlobal() = gz; From a88507bf59010cc0943b7ccc822c5e26e091196b Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Wed, 21 May 2025 16:32:55 +0200 Subject: [PATCH 04/40] Update CAHitNtuplet to support Phase2 OT CA extension. Update also the configuration parameters to include the 3 additional barrel layers from the OT. Added 6 more double connections. --- .../modules/hltPhase2PixelTracksSoA_cfi.py | 16 +- .../plugins/alpaka/CAHitNtuplet.cc | 293 +++++++++++------- 2 files changed, 186 insertions(+), 123 deletions(-) diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py index 6baca6635d7b8..3315867748069 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py @@ -34,14 +34,14 @@ maxZip = cms.double(12.), ), geometry = cms.PSet( - caDCACuts = cms.vdouble(0.15, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25), - caThetaCuts = cms.vdouble(0.002, 0.002, 0.002, 0.002, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003), - startingPairs = cms.vuint32(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32), - pairGraph = cms.vuint32(0, 1, 0, 4, 0, 16, 1, 2, 1, 4, 1, 16, 2, 3, 2, 4, 2, 16, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 0, 2, 0, 5, 0, 17, 0, 6, 0, 18, 1, 3, 1, 5, 1, 17, 1, 6, 1, 18, 11, 12, 12, 13, 13, 14, 14, 15, 23, 24, 24, 25, 25, 26, 26, 27, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 16, 18, 17, 19, 18, 20, 19, 21, 20, 22, 21, 23, 22, 24), - phiCuts = cms.vint32(522, 522, 522, 626, 730, 730, 626, 730, 730, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 522, 522, 522, 522, 522, 522, 522, 522), - minZ = cms.vdouble(-16, 4, -22, -17, 6, -22, -18, 11, -22, 23, 30, 39, 50, 65, 82, 109, -28, -35, -44, -55, -70, -87, -113, -16, 7, -22, 11, -22, -17, 9, -22, 13, -22, 137, 173, 199, 229, -142, -177, -203, -233, 23, 30, 39, 50, 65, 82, 109, -28, -35, -44, -55, -70, -87, -113), - maxZ = cms.vdouble(17, 22, -4, 17, 22, -6, 18, 22, -11, 28, 35, 44, 55, 70, 87, 113, -23, -30, -39, -50, -65, -82, -109, 17, 22, -7, 22, -10, 17, 22, -9, 22, -13, 142, 177, 203, 233, -137, -173, -199, -229, 28, 35, 44, 55, 70, 87, 113, -23, -30, -39, -50, -65, -82, -109), - maxR = cms.vdouble(5, 5, 5, 7, 8, 8, 7, 7, 7, 6, 6, 6, 6, 5, 6, 5, 6, 6, 6, 6, 5, 6, 5, 5, 5, 5, 5, 5, 5, 8, 8, 8, 8, 6, 5, 5, 5, 6, 5, 5, 5, 9, 9, 9, 8, 8, 8, 11, 9, 9, 9, 8, 8, 8, 11) + caDCACuts = cms.vdouble(0.15, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25), + caThetaCuts = cms.vdouble(0.002, 0.002, 0.002, 0.002, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003), + startingPairs = cms.vint32(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32), + pairGraph = cms.vint32(0, 1, 0, 4, 0, 16, 1, 2, 1, 4, 1, 16, 2, 3, 2, 4, 2, 16, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 0, 2, 0, 5, 0, 17, 0, 6, 0, 18, 1, 3, 1, 5, 1, 17, 1, 6, 1, 18, 11, 12, 12, 13, 13, 14, 14, 15, 23, 24, 24, 25, 25, 26, 26, 27, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 16, 18, 17, 19, 18, 20, 19, 21, 20, 22, 21, 23, 22, 24, 2, 28, 3, 28, 3, 29, 28, 29, 28, 30, 29, 30), + phiCuts = cms.vint32(522, 522, 522, 626, 730, 730, 626, 730, 730, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522), + minZ = cms.vdouble(-16, 4, -22, -17, 6, -22, -18, 11, -22, 23, 30, 39, 50, 65, 82, 109, -28, -35, -44, -55, -70, -87, -113, -16, 7, -22, 11, -22, -17, 9, -22, 13, -22, 137, 173, 199, 229, -142, -177, -203, -233, 23, 30, 39, 50, 65, 82, 109, -28, -35, -44, -55, -70, -87, -113, -1000, -1000, -1000, -1000, -1000, -1000), + maxZ = cms.vdouble(17, 22, -4, 17, 22, -6, 18, 22, -11, 28, 35, 44, 55, 70, 87, 113, -23, -30, -39, -50, -65, -82, -109, 17, 22, -7, 22, -10, 17, 22, -9, 22, -13, 142, 177, 203, 233, -137, -173, -199, -229, 28, 35, 44, 55, 70, 87, 113, -23, -30, -39, -50, -65, -82, -109, 1000, 1000, 1000, 1000, 1000, 1000), + maxR = cms.vdouble(5, 5, 5, 7, 8, 8, 7, 7, 7, 6, 6, 6, 6, 5, 6, 5, 6, 6, 6, 6, 5, 6, 5, 5, 5, 5, 5, 5, 5, 8, 8, 8, 8, 6, 5, 5, 5, 6, 5, 5, 5, 9, 9, 9, 8, 8, 8, 11, 9, 9, 9, 8, 8, 8, 11, 60, 60, 60, 60, 60, 60) ), # autoselect the alpaka backend alpaka = cms.untracked.PSet(backend = cms.untracked.string('')) diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc index 59a8c19a0390f..330f455feb033 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc @@ -35,6 +35,7 @@ #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" #include "DataFormats/TrackerCommon/interface/TrackerTopology.h" #include "RecoTracker/PixelSeeding/interface/CAGeometrySoA.h" +#include "DataFormats/SiStripDetId/interface/StripSubdetector.h" // #define GPU_DEBUG @@ -73,21 +74,21 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { template class CAHitNtupletAlpaka - : public stream::EDProducer, - edm::RunCache>> { + : public stream::EDProducer, + edm::RunCache>> { using HitsConstView = ::reco::TrackingRecHitConstView; using HitsOnDevice = reco::TrackingRecHitsSoACollection; using HitsOnHost = ::reco::TrackingRecHitHost; using TkSoAHost = ::reco::TracksHost; using TkSoADevice = reco::TracksSoACollection; - + using Algo = CAHitNtupletGenerator; - + using CAGeometryCache = cms::alpakatools::MoveToDeviceCache; using Rotation = SOARotation; using Frame = SOAFrame; - + public: explicit CAHitNtupletAlpaka(const edm::ParameterSet& iConfig, const ::reco::CAGeometryParams* iCache); ~CAHitNtupletAlpaka() override = default; @@ -100,53 +101,100 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { RunContext const* iContext) { /* Do nothing */ }; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - + static std::shared_ptr globalBeginRun(edm::Run const& iRun, - edm::EventSetup const& iSetup, - GlobalCache const* iCache) { - assert(iCache->minZ_.size() == iCache->maxZ_.size()); - assert(iCache->minZ_.size() == iCache->maxR_.size()); - assert(iCache->minZ_.size() == iCache->phiCuts_.size()); - - assert(iCache->caThetaCuts_.size() == iCache->caDCACuts_.size()); - - int n_layers = iCache->caThetaCuts_.size(); - int n_pairs = iCache->pairGraph_.size() / 2; - int n_modules = 0; - + edm::EventSetup const& iSetup, + GlobalCache const* iCache) { + assert(iCache->minZ_.size() == iCache->maxZ_.size()); + assert(iCache->minZ_.size() == iCache->maxR_.size()); + assert(iCache->minZ_.size() == iCache->phiCuts_.size()); + + assert(iCache->caThetaCuts_.size() == iCache->caDCACuts_.size()); + + int n_layers = iCache->caThetaCuts_.size(); + int n_pairs = iCache->pairGraph_.size() / 2; + int n_modules = 0; + #ifdef GPU_DEBUG - std::cout << "No. Layers to be used = " << n_layers << std::endl; - std::cout << "No. Pairs to be used = " << n_pairs << std::endl; + std::cout << "No. Layers to be used = " << n_layers << std::endl; + std::cout << "No. Pairs to be used = " << n_pairs << std::endl; #endif + + assert(int(n_pairs) == int(iCache->minZ_.size())); + assert(int(*std::max_element(iCache->startingPairs_.begin(), iCache->startingPairs_.end())) <= n_pairs); + assert(int(*std::max_element(iCache->pairGraph_.begin(), iCache->pairGraph_.end())) < n_layers); - assert(int(n_pairs) == int(iCache->minZ_.size())); - assert(int(*std::max_element(iCache->startingPairs_.begin(), iCache->startingPairs_.end())) <= n_pairs); - assert(int(*std::max_element(iCache->pairGraph_.begin(), iCache->pairGraph_.end())) < n_layers); - - const auto& trackerGeometry = iSetup.getData(iCache->tokenGeometry_); - const auto& trackerTopology = iSetup.getData(iCache->tokenTopology_); - auto const& dets = trackerGeometry.dets(); + const auto& trackerGeometry = iSetup.getData(iCache->tokenGeometry_); + const auto& trackerTopology = iSetup.getData(iCache->tokenTopology_); + auto const& dets = trackerGeometry.dets(); #ifdef GPU_DEBUG - auto subSystem = 1; - auto subSystemName = GeomDetEnumerators::tkDetEnum[subSystem]; - auto subSystemOffset = trackerGeometry.offsetDU(subSystemName); - std::cout - << "=========================================================================================================" - << std::endl; - std::cout << " ===================== Subsystem: " << subSystemName << std::endl; - subSystemName = GeomDetEnumerators::tkDetEnum[++subSystem]; - subSystemOffset = trackerGeometry.offsetDU(subSystemName); + auto subSystem = 1; + auto subSystemName = GeomDetEnumerators::tkDetEnum[subSystem]; + auto subSystemOffset = trackerGeometry.offsetDU(subSystemName); + std::cout + << "=========================================================================================================" + << std::endl; + std::cout << " ===================== Subsystem: " << subSystemName << std::endl; + subSystemName = GeomDetEnumerators::tkDetEnum[++subSystem]; + subSystemOffset = trackerGeometry.offsetDU(subSystemName); #endif - auto oldLayer = 0u; - auto layerCount = 0; - - std::vector layerStarts(n_layers + 1); - //^ why n_layers + 1? This is a cumulative sum of the number - // of modules each layer has. And we need the extra spot - // at the end to hold the total number of modules. - + auto oldLayer = 0u; + auto layerCount = 0; + + std::vector layerStarts(n_layers + 1); + std::vector moduleToindexInDets; + + auto isPinPSinOTBarrel = [&](DetId detId) { + // std::cout << (int)trackerGeometry->getDetectorType(detId) << " " << (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP) << "\n"; + // std::cout << (int)detId.subdetId() << " " << (detId.subdetId() == StripSubdetector::TOB) << std::endl; + // Select only P-hits from the OT barrel + return (trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP && + detId.subdetId() == StripSubdetector::TOB); + }; + auto isPh2Pixel = [&](DetId detId) { + return (trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXB + || trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF); + }; + if constexpr (std::is_base_of_v) { + int counter = 0; + for (auto& det : dets) { + DetId detid = det->geographicalId(); + auto layer = trackerTopology.layer(detid); + // Logic: + // - if we are not inside pixels, we need to ignore anything **but** the OT. + // - for the time being, this is assuming that the CA extension will + // only cover the OT barrel part, and will ignore the OT forward. + if (isPh2Pixel(detid)) { + if (layer != oldLayer) { + layerStarts[layerCount++] = n_modules; + if (layerCount > n_layers + 1) + break; + oldLayer = layer; + } + moduleToindexInDets.push_back(counter); + n_modules++; + } else { + auto const & detUnits = det->components(); + for (auto& detUnit : detUnits) + { + DetId unitDetId(detUnit->geographicalId()); + if (isPinPSinOTBarrel(unitDetId)) { + if (layer != oldLayer) { + layerStarts[layerCount++] = n_modules; + if (layerCount > n_layers + 1) + break; + oldLayer = layer; + } + moduleToindexInDets.push_back(counter); + n_modules++; + } + } + } + counter++; + } + } else { for (auto& det : dets) { DetId detid = det->geographicalId(); #ifdef GPU_DEBUG @@ -173,15 +221,18 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { n_modules++; } + } - reco::CAGeometryHost product{{{n_layers + 1, n_pairs, n_modules}}, cms::alpakatools::host()}; + reco::CAGeometryHost product{{{n_layers + 1, n_pairs, n_modules}}, cms::alpakatools::host()}; - auto layerSoA = product.view(); - auto cellSoA = product.view<::reco::CAGraphSoA>(); - auto modulesSoA = product.view<::reco::CAModulesSoA>(); + auto layerSoA = product.view(); + auto cellSoA = product.view<::reco::CAGraphSoA>(); + auto modulesSoA = product.view<::reco::CAModulesSoA>(); + if constexpr (std::is_base_of_v) { for (int i = 0; i < n_modules; ++i) { - auto det = dets[i]; + auto idx = moduleToindexInDets[i]; + auto det = dets[idx]; auto vv = det->surface().position(); auto rr = Rotation(det->surface().rotation()); modulesSoA[i].detFrame() = Frame(vv.x(), vv.y(), vv.z(), rr); @@ -192,83 +243,95 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { layerSoA.caThetaCut()[i] = iCache->caThetaCuts_[i]; layerSoA.caDCACut()[i] = iCache->caDCACuts_[i]; } - - layerSoA.layerStarts()[n_layers] = layerStarts[n_layers]; - - for (int i = 0; i < n_pairs; ++i) { - cellSoA.graph()[i] = {{uint32_t(iCache->pairGraph_[2 * i]), uint32_t(iCache->pairGraph_[2 * i + 1])}}; - cellSoA.phiCuts()[i] = iCache->phiCuts_[i]; - cellSoA.minz()[i] = iCache->minZ_[i]; - cellSoA.maxz()[i] = iCache->maxZ_[i]; - cellSoA.maxr()[i] = iCache->maxR_[i]; - cellSoA.startingPair()[i] = false; + } else { + for (int i = 0; i < n_modules; ++i) { + auto det = dets[i]; + auto vv = det->surface().position(); + auto rr = Rotation(det->surface().rotation()); + modulesSoA[i].detFrame() = Frame(vv.x(), vv.y(), vv.z(), rr); } - for (const unsigned int& i : iCache->startingPairs_) - cellSoA.startingPair()[i] = true; - - return std::make_shared(std::move(product)); - } - - static std::unique_ptr<::reco::CAGeometryParams> initializeGlobalCache(edm::ParameterSet const& iConfig) { - return std::make_unique<::reco::CAGeometryParams>(iConfig.getParameterSet("geometry")); + for (int i = 0; i < n_layers; ++i) { + layerSoA.layerStarts()[i] = layerStarts[i]; + layerSoA.caThetaCut()[i] = iCache->caThetaCuts_[i]; + layerSoA.caDCACut()[i] = iCache->caDCACuts_[i]; + } } - private: - const edm::ESGetToken tokenField_; - const device::EDGetToken tokenHit_; - const device::EDPutToken tokenTrack_; - - const ::reco::FormulaEvaluator maxNumberOfDoublets_; - const ::reco::FormulaEvaluator maxNumberOfTuples_; - - Algo deviceAlgo_; - }; - - template - CAHitNtupletAlpaka::CAHitNtupletAlpaka(const edm::ParameterSet& iConfig, - const ::reco::CAGeometryParams* iCache) - : EDProducer(iConfig), - tokenField_(esConsumes()), - tokenHit_(consumes(iConfig.getParameter("pixelRecHitSrc"))), - tokenTrack_(produces()), - maxNumberOfDoublets_(iConfig.getParameter("maxNumberOfDoublets")), - maxNumberOfTuples_(iConfig.getParameter("maxNumberOfTuples")), - deviceAlgo_(iConfig) { - iCache->tokenGeometry_ = esConsumes(); - iCache->tokenTopology_ = esConsumes(); - } + layerSoA.layerStarts()[n_layers] = layerStarts[n_layers]; - template - void CAHitNtupletAlpaka::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - edm::ParameterSetDescription desc; + for (int i = 0; i < n_pairs; ++i) { + cellSoA.graph()[i] = {{uint32_t(iCache->pairGraph_[2 * i]), uint32_t(iCache->pairGraph_[2 * i + 1])}}; + cellSoA.phiCuts()[i] = iCache->phiCuts_[i]; + cellSoA.minz()[i] = iCache->minZ_[i]; + cellSoA.maxz()[i] = iCache->maxZ_[i]; + cellSoA.maxr()[i] = iCache->maxR_[i]; + cellSoA.startingPair()[i] = false; + } - desc.add("pixelRecHitSrc", edm::InputTag("siPixelRecHitsPreSplittingAlpaka")); + for (const int& i : iCache->startingPairs_) + cellSoA.startingPair()[i] = true; - Algo::fillPSetDescription(desc); - descriptions.addWithDefaultLabel(desc); + return std::make_shared(std::move(product)); } - template - void CAHitNtupletAlpaka::produce(device::Event& iEvent, const device::EventSetup& es) { - auto bf = 1. / es.getData(tokenField_).inverseBzAtOriginInGeV(); - - auto const& geometry = runCache()->get(iEvent.queue()); - auto const& hits = iEvent.get(tokenHit_); - - std::array nHitsV = {{double(hits.nHits())}}; - std::array emptyV; - - uint32_t const maxTuples = maxNumberOfTuples_.evaluate(nHitsV, emptyV); - uint32_t const maxDoublets = maxNumberOfDoublets_.evaluate(nHitsV, emptyV); - - iEvent.emplace(tokenTrack_, - deviceAlgo_.makeTuplesAsync(hits, geometry, bf, maxDoublets, maxTuples, iEvent.queue())); + static std::unique_ptr<::reco::CAGeoemtryParams> initializeGlobalCache(edm::ParameterSet const& iConfig) { + return std::make_unique<::reco::CAGeoemtryParams>(iConfig.getParameterSet("geometry")); } - using CAHitNtupletAlpakaPhase1 = CAHitNtupletAlpaka; - using CAHitNtupletAlpakaHIonPhase1 = CAHitNtupletAlpaka; - using CAHitNtupletAlpakaPhase2 = CAHitNtupletAlpaka; +private: + const edm::ESGetToken tokenField_; + const device::EDGetToken tokenHit_; + const device::EDPutToken tokenTrack_; + + const TFormula maxNumberOfDoublets_; + const TFormula maxNumberOfTuples_; + Algo deviceAlgo_; +}; + +template +CAHitNtupletAlpaka::CAHitNtupletAlpaka(const edm::ParameterSet& iConfig, + const ::reco::CAGeoemtryParams* iCache) + : EDProducer(iConfig), + tokenField_(esConsumes()), + tokenHit_(consumes(iConfig.getParameter("pixelRecHitSrc"))), + tokenTrack_(produces()), + maxNumberOfDoublets_( + TFormula("doubletsHitsDependecy", iConfig.getParameter("maxNumberOfDoublets").data())), + maxNumberOfTuples_( + TFormula("tracksHitsDependency", iConfig.getParameter("maxNumberOfTuples").data())), + deviceAlgo_(iConfig) { + iCache->tokenGeometry_ = esConsumes(); + iCache->tokenTopology_ = esConsumes(); +} + +template +void CAHitNtupletAlpaka::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + + desc.add("pixelRecHitSrc", edm::InputTag("siPixelRecHitsPreSplittingAlpaka")); + + Algo::fillPSetDescription(desc); + descriptions.addWithDefaultLabel(desc); +} + +template +void CAHitNtupletAlpaka::produce(device::Event& iEvent, const device::EventSetup& es) { + auto bf = 1. / es.getData(tokenField_).inverseBzAtOriginInGeV(); + + auto const& geometry = runCache()->get(iEvent.queue()); + auto const& hits = iEvent.get(tokenHit_); + + uint32_t const maxTuples = maxNumberOfTuples_.Eval(hits.nHits()); + uint32_t const maxDoublets = maxNumberOfDoublets_.Eval(hits.nHits()); + + iEvent.emplace(tokenTrack_, + deviceAlgo_.makeTuplesAsync(hits, geometry, bf, maxDoublets, maxTuples, iEvent.queue())); +} + +using CAHitNtupletAlpakaPhase1 = CAHitNtupletAlpaka; +using CAHitNtupletAlpakaHIonPhase1 = CAHitNtupletAlpaka; +using CAHitNtupletAlpakaPhase2 = CAHitNtupletAlpaka; } // namespace ALPAKA_ACCELERATOR_NAMESPACE #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h" From 8bdee0a6094cccc2cc4e3c823a4a2ac97ed65ec0 Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Wed, 21 May 2025 17:36:56 +0200 Subject: [PATCH 05/40] Correctly compute the index used to address rotations. The index in the SiStipHitSoA to address the proper rotation of the module is now correctly computed by couting all the preceeding pixel modules and simply incrementing that number by one, for every new P-module in the OT barrel. The code and logic is extremely fragile and relies on a couple of assumptions: - all pixel modules will be used in the CA, not matter what. - the order of modules in Phase2OTRecHitsSoAConverter and in CAHitNtuplet is the same. --- .../alpaka/Phase2OTRecHitsSoAConverter.cc | 18 +++++++++++++++--- .../plugins/alpaka/CAHitNtuplet.cc | 4 +++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc index a6946c07ce144..ff131e51f5ac5 100644 --- a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc +++ b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc @@ -31,8 +31,6 @@ #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h" -#define TBD 1 - namespace ALPAKA_ACCELERATOR_NAMESPACE { class Phase2OTRecHitsSoAConverter : public stream::EDProducer<> { @@ -98,13 +96,26 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe return (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP && detId.subdetId() == StripSubdetector::TOB); }; + auto isPh2Pixel = [&](DetId detId) { + return (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXB + || trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXB3D + || trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF + || trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF3D); + }; auto const& detUnits = trackerGeometry->detUnits(); std::map detIdToIndex; std::set p_modulesInPSInOTBarrel; + int modulesInPixel = 0; +// auto subSystem = GeomDetEnumerators::P2OTEC; +// auto subSystemName = GeomDetEnumerators::tkDetEnum[subSystem]; +// modulesInPixel += trackerGeometry->offsetDU(subSystemName); + for (auto& detUnit : detUnits) { DetId detId(detUnit->geographicalId()); + if (isPh2Pixel(detId)) + modulesInPixel++; detIdToIndex[detUnit->geographicalId()] = detUnit->index(); if (isPinPSinOTBarrel(detId)) { p_modulesInPSInOTBarrel.insert(detUnit->index()); @@ -120,6 +131,7 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe PHitsInOTBarrel++; } } + std::cout << "Tot number of modules in Pixels " << modulesInPixel << std::endl; std::cout << "Tot number of p_modulesInPSInOTBarrel: " << p_modulesInPSInOTBarrel.size() << std::endl; std::cout << "Number of strip (active) modules: " << activeStripModules << std::endl; std::cout << "Number of strip hits: " << nStripHits << std::endl; @@ -169,7 +181,7 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe stripHitsHost.view()[n_hits].chargeAndStatus().status = {0, 0, 0, 0, 0}; stripHitsHost.view()[n_hits].clusterSizeX() = -1; stripHitsHost.view()[n_hits].clusterSizeY() = -1; - stripHitsHost.view()[n_hits].detectorIndex() = index; + stripHitsHost.view()[n_hits].detectorIndex() = modulesInPixel++; n_hits++; } } diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc index 330f455feb033..d520173d02723 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc @@ -155,7 +155,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { }; auto isPh2Pixel = [&](DetId detId) { return (trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXB - || trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF); + || trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF + || trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF + || trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF3D); }; if constexpr (std::is_base_of_v) { int counter = 0; From a098506fb3785de914c8bbfe4a77e5807ec53e11 Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Wed, 21 May 2025 18:40:39 +0200 Subject: [PATCH 06/40] Fix counting of pixel modules. --- RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc index d520173d02723..632cf6bd0ab39 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc @@ -155,7 +155,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { }; auto isPh2Pixel = [&](DetId detId) { return (trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXB - || trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF + || trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXB3D || trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF || trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF3D); }; From b1a837a31c080477f2964fa24930dae88be9ca04 Mon Sep 17 00:00:00 2001 From: Luca Ferragina Date: Wed, 21 May 2025 18:45:18 +0200 Subject: [PATCH 07/40] Add producer to merge Pixel and tracker recHits --- .../hltPhase2PixelRecHitsExtendedSoA_cfi.py | 5 + .../modules/hltPhase2PixelTracksSoA_cfi.py | 2 +- .../HLTPhase2PixelTracksSequence_cfi.py | 2 + .../alpaka/SiPixelRecHitExtendedAlpaka.cc | 258 ++++++++++++++++++ 4 files changed, 266 insertions(+), 1 deletion(-) create mode 100644 HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelRecHitsExtendedSoA_cfi.py create mode 100644 RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelRecHitsExtendedSoA_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelRecHitsExtendedSoA_cfi.py new file mode 100644 index 0000000000000..ddb2d7e54b458 --- /dev/null +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelRecHitsExtendedSoA_cfi.py @@ -0,0 +1,5 @@ +import FWCore.ParameterSet.Config as cms + +from RecoLocalTracker.SiPixelRecHits.SiPixelRecHitExtendedAlpakaPhase2_alpaka import SiPixelRecHitExtendedAlpakaPhase2_alpaka as _SiPixelRecHitExtendedAlpakaPhase2_alpaka + +hltPhase2PixelRecHitsExtendedSoA = _SiPixelRecHitExtendedAlpakaPhase2_alpaka() \ No newline at end of file diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py index 3315867748069..ff41cfd60cfb5 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py @@ -1,7 +1,7 @@ import FWCore.ParameterSet.Config as cms hltPhase2PixelTracksSoA = cms.EDProducer('CAHitNtupletAlpakaPhase2@alpaka', - pixelRecHitSrc = cms.InputTag('hltPhase2SiPixelRecHitsSoA'), + pixelRecHitSrc = cms.InputTag('hltPhase2PixelRecHitsExtendedSoA'), ptmin = cms.double(0.9), hardCurvCut = cms.double(0.0328407225), earlyFishbone = cms.bool(True), diff --git a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTPhase2PixelTracksSequence_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTPhase2PixelTracksSequence_cfi.py index 9277f2dadeace..3c7be640aa694 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTPhase2PixelTracksSequence_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTPhase2PixelTracksSequence_cfi.py @@ -7,6 +7,7 @@ from ..modules.hltPhase2PixelTracksHitDoublets_cfi import * from ..modules.hltPhase2PixelTracksHitSeeds_cfi import * from ..modules.hltPhase2PixelTracksSeedLayers_cfi import * +from ..modules.hltPhase2PixelRecHitsExtendedSoA_cfi import * HLTPhase2PixelTracksSequence = cms.Sequence(hltPhase2PixelTracksSeedLayers+hltPhase2PixelTracksAndHighPtStepTrackingRegions+hltPhase2PixelTracksHitDoublets+hltPhase2PixelTracksHitSeeds+hltPhase2PixelFitterByHelixProjections+hltPhase2PixelTrackFilterByKinematics+hltPhase2PixelTracks) from ..sequences.HLTBeamSpotSequence_cfi import HLTBeamSpotSequence @@ -16,6 +17,7 @@ +hltPhase2PixelTracksAndHighPtStepTrackingRegions # needed by highPtTripletStep iteration +hltPhase2PixelFitterByHelixProjections # needed by tracker muons +hltPhase2PixelTrackFilterByKinematics # needed by tracker muons + +hltPhase2PixelRecHitsExtendedSoA +hltPhase2PixelTracksSoA +hltPhase2PixelTracks ) diff --git a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc new file mode 100644 index 0000000000000..55de5ed7d606c --- /dev/null +++ b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc @@ -0,0 +1,258 @@ +#include "DataFormats/BeamSpot/interface/BeamSpotPOD.h" +#include "DataFormats/BeamSpot/interface/alpaka/BeamSpotDevice.h" +#include "DataFormats/SiPixelClusterSoA/interface/SiPixelClustersDevice.h" +#include "DataFormats/SiPixelClusterSoA/interface/alpaka/SiPixelClustersSoACollection.h" +#include "DataFormats/SiPixelDigiSoA/interface/SiPixelDigisDevice.h" +#include "DataFormats/SiPixelDigiSoA/interface/alpaka/SiPixelDigisSoACollection.h" +#include "DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsDevice.h" +#include "DataFormats/TrackingRecHitSoA/interface/alpaka/TrackingRecHitsSoACollection.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "FWCore/Utilities/interface/InputTag.h" +#include "Geometry/CommonTopologies/interface/SimplePixelTopology.h" +#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "HeterogeneousCore/AlpakaCore/interface/alpaka/Event.h" +#include "HeterogeneousCore/AlpakaCore/interface/alpaka/EventSetup.h" +#include "HeterogeneousCore/AlpakaCore/interface/alpaka/global/EDProducer.h" +#include "HeterogeneousCore/AlpakaInterface/interface/config.h" +#include "HeterogeneousCore/AlpakaInterface/interface/memory.h" + +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "FWCore/Utilities/interface/InputTag.h" +#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "RecoLocalTracker/Records/interface/PixelCPEFastParamsRecord.h" + +#include "RecoLocalTracker/SiPixelRecHits/interface/PixelCPEBase.h" +#include "RecoLocalTracker/SiPixelRecHits/interface/pixelCPEforDevice.h" +#include "RecoLocalTracker/SiPixelRecHits/interface/alpaka/PixelCPEFastParamsCollection.h" + +#include "PixelRecHitKernel.h" + +#include + +namespace ALPAKA_ACCELERATOR_NAMESPACE { + template + class SiPixelRecHitExtendedAlpaka : public global::EDProducer<> { + public: + explicit SiPixelRecHitExtendedAlpaka(const edm::ParameterSet& iConfig); + ~SiPixelRecHitExtendedAlpaka() override = default; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + void produce(edm::StreamID streamID, device::Event& iEvent, const device::EventSetup& iSetup) const override; + + const device::EDGetToken pixelRecHitToken_; + const device::EDGetToken trackerRecHitToken_; + + const device::EDPutToken outputRecHitsSoAToken_; + }; + + template + SiPixelRecHitExtendedAlpaka::SiPixelRecHitExtendedAlpaka(const edm::ParameterSet& iConfig) + : EDProducer(iConfig), + pixelRecHitToken_(consumes(iConfig.getParameter("pixelRecHitsSoA"))), + trackerRecHitToken_(consumes(iConfig.getParameter("trackerRecHitsSoA"))), + outputRecHitsSoAToken_(produces()) {} + + template + void SiPixelRecHitExtendedAlpaka::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + + desc.add("pixelRecHitsSoA", edm::InputTag("hltPhase2SiPixelRecHitsSoA")); + desc.add("trackerRecHitsSoA", edm::InputTag("phase2OTRecHitsSoAConverter")); + + descriptions.addWithDefaultLabel(desc); + } + + template + void SiPixelRecHitExtendedAlpaka::produce(edm::StreamID streamID, + device::Event& iEvent, + const device::EventSetup& es) const { + // get both Pixel and Tracker recHits + const auto& pixelRecHitsSoA = iEvent.get(pixelRecHitToken_); + const auto& otRecHitsSoA = iEvent.get(trackerRecHitToken_); + std::cout << "----------------- Merging Pixel and Tracker RecHits -----------------" << std::endl; + const int nPixelHits = pixelRecHitsSoA.nHits(); + std::cout << "Number of Pixel recHits: " << nPixelHits << std::endl; + const int nTrackerHits = otRecHitsSoA.nHits(); + std::cout << "Number of Tracker recHits: " << nTrackerHits << std::endl; + const int nTotHits = nPixelHits + nTrackerHits; + std::cout << "Number of Pixel modules: " << pixelRecHitsSoA.nModules() << std::endl; + std::cout << "Number of Tracker modules: " << otRecHitsSoA.nModules() << std::endl; + const int nTotModules = pixelRecHitsSoA.nModules() + otRecHitsSoA.nModules(); + + auto outputSoA = reco::TrackingRecHitsSoACollection(iEvent.queue(), nTotHits, nTotModules); + std::cout << "Total number of recHits: " << outputSoA.nHits() << std::endl; + + // copy all columns from pixelRecHitsSoA and otRecHitsSoA to outputSoA + // xLocal + auto xLocalOutputPixel = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xLocal(), nPixelHits); + auto xLocalOutputTracker = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xLocal() + nPixelHits, nTrackerHits); + auto xLocalPixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().xLocal(), nPixelHits); + auto xLocalTracker = cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().xLocal(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), xLocalOutputPixel, xLocalPixel); + alpaka::memcpy(iEvent.queue(), xLocalOutputTracker, xLocalTracker); + + // yLocal + auto yLocalOutputPixel = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yLocal(), nPixelHits); + auto yLocalOutputTracker = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yLocal() + nPixelHits, nTrackerHits); + auto yLocalPixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().yLocal(), nPixelHits); + auto yLocalTracker = cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().yLocal(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), yLocalOutputPixel, yLocalPixel); + alpaka::memcpy(iEvent.queue(), yLocalOutputTracker, yLocalTracker); + + // xerrLocal + auto xerrLocalOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xerrLocal(), nPixelHits); + auto xerrLocalOutputTracker = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xerrLocal() + nPixelHits, nTrackerHits); + auto xerrLocalPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().xerrLocal(), nPixelHits); + auto xerrLocalTracker = + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().xerrLocal(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), xerrLocalOutputPixel, xerrLocalPixel); + alpaka::memcpy(iEvent.queue(), xerrLocalOutputTracker, xerrLocalTracker); + + // yerrLocal + auto yerrLocalOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yerrLocal(), nPixelHits); + auto yerrLocalOutputTracker = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yerrLocal() + nPixelHits, nTrackerHits); + auto yerrLocalPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().yerrLocal(), nPixelHits); + auto yerrLocalTracker = + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().yerrLocal(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), yerrLocalOutputPixel, yerrLocalPixel); + alpaka::memcpy(iEvent.queue(), yerrLocalOutputTracker, yerrLocalTracker); + + // xGlobal + auto xGlobalOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xGlobal(), nPixelHits); + auto xGlobalOutputTracker = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xGlobal() + nPixelHits, nTrackerHits); + auto xGlobalPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().xGlobal(), nPixelHits); + auto xGlobalTracker = + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().xGlobal(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), xGlobalOutputPixel, xGlobalPixel); + alpaka::memcpy(iEvent.queue(), xGlobalOutputTracker, xGlobalTracker); + + // yGlobal + auto yGlobalOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yGlobal(), nPixelHits); + auto yGlobalOutputTracker = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yGlobal() + nPixelHits, nTrackerHits); + auto yGlobalPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().yGlobal(), nPixelHits); + auto yGlobalTracker = + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().yGlobal(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), yGlobalOutputPixel, yGlobalPixel); + alpaka::memcpy(iEvent.queue(), yGlobalOutputTracker, yGlobalTracker); + + // zGlobal + auto zGlobalOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().zGlobal(), nPixelHits); + auto zGlobalOutputTracker = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().zGlobal() + nPixelHits, nTrackerHits); + auto zGlobalPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().zGlobal(), nPixelHits); + auto zGlobalTracker = + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().zGlobal(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), zGlobalOutputPixel, zGlobalPixel); + alpaka::memcpy(iEvent.queue(), zGlobalOutputTracker, zGlobalTracker); + + // rGlobal + auto rGlobalOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().rGlobal(), nPixelHits); + auto rGlobalOutputTracker = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().rGlobal() + nPixelHits, nTrackerHits); + auto rGlobalPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().rGlobal(), nPixelHits); + auto rGlobalTracker = + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().rGlobal(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), rGlobalOutputPixel, rGlobalPixel); + alpaka::memcpy(iEvent.queue(), rGlobalOutputTracker, rGlobalTracker); + + // iphi + auto iphiOutputPixel = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().iphi(), nPixelHits); + auto iphiOutputTracker = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().iphi() + nPixelHits, nTrackerHits); + auto iphiPixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().iphi(), nPixelHits); + auto iphiTracker = cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().iphi(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), iphiOutputPixel, iphiPixel); + alpaka::memcpy(iEvent.queue(), iphiOutputTracker, iphiTracker); + + // chargeAndStatus + auto chargeAndStatusOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().chargeAndStatus(), nPixelHits); + auto chargeAndStatusOutputTracker = cms::alpakatools::make_device_view( + iEvent.queue(), outputSoA.view().chargeAndStatus() + nPixelHits, nTrackerHits); + auto chargeAndStatusPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().chargeAndStatus(), nPixelHits); + auto chargeAndStatusTracker = + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().chargeAndStatus(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), chargeAndStatusOutputPixel, chargeAndStatusPixel); + alpaka::memcpy(iEvent.queue(), chargeAndStatusOutputTracker, chargeAndStatusTracker); + + // clusterSizeX + auto clusterSizeXOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().clusterSizeX(), nPixelHits); + auto clusterSizeXOutputTracker = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().clusterSizeX() + nPixelHits, nTrackerHits); + auto clusterSizeXPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().clusterSizeX(), nPixelHits); + auto clusterSizeXTracker = + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().clusterSizeX(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), clusterSizeXOutputPixel, clusterSizeXPixel); + alpaka::memcpy(iEvent.queue(), clusterSizeXOutputTracker, clusterSizeXTracker); + + // clusterSizeY + auto clusterSizeYOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().clusterSizeY(), nPixelHits); + auto clusterSizeYOutputTracker = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().clusterSizeY() + nPixelHits, nTrackerHits); + auto clusterSizeYPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().clusterSizeY(), nPixelHits); + auto clusterSizeYTracker = + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().clusterSizeY(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), clusterSizeYOutputPixel, clusterSizeYPixel); + alpaka::memcpy(iEvent.queue(), clusterSizeYOutputTracker, clusterSizeYTracker); + + // detectorIndex + auto detectorIndexOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().detectorIndex(), nPixelHits); + auto detectorIndexOutputTracker = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().detectorIndex() + nPixelHits, nTrackerHits); + auto detectorIndexPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().detectorIndex(), nPixelHits); + auto detectorIndexTracker = + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().detectorIndex(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), detectorIndexOutputPixel, detectorIndexPixel); + alpaka::memcpy(iEvent.queue(), detectorIndexOutputTracker, detectorIndexTracker); + + auto offsetBPIX2Output = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().offsetBPIX2()); + auto offsetBPIX2Pixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().offsetBPIX2()); + alpaka::memcpy(iEvent.queue(), offsetBPIX2Output, offsetBPIX2Pixel); + + // emplace the merged hits in the event + iEvent.emplace(outputRecHitsSoAToken_, std::move(outputSoA)); + } + using SiPixelRecHitExtendedAlpakaPhase1 = SiPixelRecHitExtendedAlpaka; + using SiPixelRecHitExtendedAlpakaHIonPhase1 = SiPixelRecHitExtendedAlpaka; + using SiPixelRecHitExtendedAlpakaPhase2 = SiPixelRecHitExtendedAlpaka; +} // namespace ALPAKA_ACCELERATOR_NAMESPACE + +#include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h" +DEFINE_FWK_ALPAKA_MODULE(SiPixelRecHitExtendedAlpakaPhase1); +DEFINE_FWK_ALPAKA_MODULE(SiPixelRecHitExtendedAlpakaHIonPhase1); +DEFINE_FWK_ALPAKA_MODULE(SiPixelRecHitExtendedAlpakaPhase2); From 3588964e00eda89e3d1c74c24a103f41d97622a9 Mon Sep 17 00:00:00 2001 From: "Jan Schulz (LXPLUS)" Date: Wed, 21 May 2025 18:48:44 +0200 Subject: [PATCH 08/40] Modify PixelTrack converter (SoA -> legacy) to be able to handle the extension to OT in Phase-2 --- .../PixelTrackProducerFromSoAAlpaka.cc | 108 ++++++++++++++---- 1 file changed, 88 insertions(+), 20 deletions(-) diff --git a/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc b/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc index acb780850b638..e54773d8e942e 100644 --- a/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc +++ b/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc @@ -17,6 +17,7 @@ #include "DataFormats/TrackSoA/interface/alpaka/TrackUtilities.h" #include "DataFormats/TrackerCommon/interface/TrackerTopology.h" #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h" +#include "DataFormats/TrackerRecHit2D/interface/Phase2TrackerRecHit1D.h" #include "DataFormats/TrajectoryState/interface/LocalTrajectoryParameters.h" #include "FWCore/Framework/interface/ConsumesCollector.h" #include "FWCore/Framework/interface/Event.h" @@ -29,8 +30,10 @@ #include "FWCore/Utilities/interface/InputTag.h" #include "Geometry/CommonTopologies/interface/SimplePixelTopology.h" #include "Geometry/Records/interface/TrackerTopologyRcd.h" +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" #include "RecoTracker/PixelTrackFitting/interface/alpaka/FitUtils.h" +#include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h" #include "TrackingTools/AnalyticalJacobians/interface/JacobianLocalToCurvilinear.h" #include "TrackingTools/TrajectoryParametrization/interface/CurvilinearTrajectoryError.h" #include "TrackingTools/TrajectoryParametrization/interface/GlobalTrajectoryParameters.h" @@ -60,27 +63,33 @@ class PixelTrackProducerFromSoAAlpaka : public edm::global::EDProducer<> { void produce(edm::StreamID streamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override; // Event Data tokens - const edm::EDGetTokenT tBeamSpot_; - const edm::EDGetTokenT tokenTrack_; - const edm::EDGetTokenT cpuHits_; + const edm::EDGetTokenT beamSpotToken_; + const edm::EDGetTokenT trackSoAToken_; + const edm::EDGetTokenT pixelRecHitsToken_; + edm::EDGetTokenT otRecHitsToken_; const edm::EDGetTokenT hmsToken_; // Event Setup tokens const edm::ESGetToken idealMagneticFieldToken_; - const edm::ESGetToken ttTopoToken_; + const edm::ESGetToken trackerTopologyToken_; + const edm::ESGetToken trackerGeometryToken_; int32_t const minNumberOfHits_; pixelTrack::Quality const minQuality_; + const bool useOTExtension_; }; PixelTrackProducerFromSoAAlpaka::PixelTrackProducerFromSoAAlpaka(const edm::ParameterSet &iConfig) - : tBeamSpot_(consumes(iConfig.getParameter("beamSpot"))), - tokenTrack_(consumes(iConfig.getParameter("trackSrc"))), - cpuHits_(consumes(iConfig.getParameter("pixelRecHitLegacySrc"))), + : beamSpotToken_(consumes(iConfig.getParameter("beamSpot"))), + trackSoAToken_(consumes(iConfig.getParameter("trackSrc"))), + pixelRecHitsToken_( + consumes(iConfig.getParameter("pixelRecHitLegacySrc"))), hmsToken_(consumes(iConfig.getParameter("pixelRecHitLegacySrc"))), idealMagneticFieldToken_(esConsumes()), - ttTopoToken_(esConsumes()), + trackerTopologyToken_(esConsumes()), + trackerGeometryToken_(esConsumes()), minNumberOfHits_(iConfig.getParameter("minNumberOfHits")), - minQuality_(pixelTrack::qualityByName(iConfig.getParameter("minQuality"))) { + minQuality_(pixelTrack::qualityByName(iConfig.getParameter("minQuality"))), + useOTExtension_(iConfig.getParameter("useOTExtension")) { if (minQuality_ == pixelTrack::Quality::notQuality) { throw cms::Exception("PixelTrackConfiguration") << iConfig.getParameter("minQuality") + " is not a pixelTrack::Quality"; @@ -96,6 +105,12 @@ PixelTrackProducerFromSoAAlpaka::PixelTrackProducerFromSoAAlpaka(const edm::Para // around a rare race condition in framework scheduling produces(); produces(); + + // if useOTExtension consume the OT RecHits + if (useOTExtension_) { + otRecHitsToken_ = + consumes(iConfig.getParameter("outerTrackerRecHitSrc")); + } } void PixelTrackProducerFromSoAAlpaka::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { @@ -103,8 +118,10 @@ void PixelTrackProducerFromSoAAlpaka::fillDescriptions(edm::ConfigurationDescrip desc.add("beamSpot", edm::InputTag("offlineBeamSpot")); desc.add("trackSrc", edm::InputTag("pixelTracksAlpaka")); desc.add("pixelRecHitLegacySrc", edm::InputTag("siPixelRecHitsPreSplittingLegacy")); + desc.add("outerTrackerRecHitSrc", edm::InputTag("hltSiPhase2RecHits")); desc.add("minNumberOfHits", 0); desc.add("minQuality", "loose"); + desc.add("useOTExtension", false); descriptions.addWithDefaultLabel(desc); } @@ -125,33 +142,56 @@ void PixelTrackProducerFromSoAAlpaka::produce(edm::StreamID streamID, std::cout << "Converting soa helix in reco tracks" << std::endl; #endif + // index map: trackId(in SoA) -> trackId(in legacy edm) auto indToEdmP = std::make_unique(); auto &indToEdm = *indToEdmP; auto const &idealField = iSetup.getData(idealMagneticFieldToken_); + // prepare container for legacy tracks pixeltrackfitting::TracksWithRecHits tracks; - auto const &httopo = iSetup.getData(ttTopoToken_); + // get trackerTopology and trackerGeometry + auto const &trackerTopology = iSetup.getData(trackerTopologyToken_); + const auto &trackerGeometry = &iSetup.getData(trackerGeometryToken_); - const auto &bsh = iEvent.get(tBeamSpot_); + // get beamspot + const auto &bsh = iEvent.get(beamSpotToken_); GlobalPoint bs(bsh.x0(), bsh.y0(), bsh.z0()); - auto const &pixelRecHitsDSV = iEvent.get(cpuHits_); - std::vector hitmap; + // get the module's starting indices in the hit collection + auto const &hitsModuleStart = iEvent.get(hmsToken_); + + // get Pixel RecHits + auto const &pixelRecHitsDSV = iEvent.get(pixelRecHitsToken_); auto const &pixelRecHits = pixelRecHitsDSV.data(); auto const nPixelHits = pixelRecHits.size(); - auto const &hitsModuleStart = iEvent.get(hmsToken_); + // get OT RecHits if needed + size_t nOTHits = 0; + const Phase2TrackerRecHit1DCollectionNew *otRecHitsDSV = nullptr; + if (useOTExtension_) { + otRecHitsDSV = &iEvent.get(otRecHitsToken_); + nOTHits = otRecHitsDSV->dataSize(); + } - hitmap.resize(nPixelHits, nullptr); + size_t nHits = nPixelHits + nOTHits; + + // hitmap to go from a unique RecHit identifier to the RecHit in the legacy collection + // (unique hit identifier is equivalent to the position of the hit in the RecHit SoA) + std::vector hitmap; + hitmap.resize(nHits, nullptr); + // loop over pixel RecHits to fill the hitmap for (auto const &pixelHit : pixelRecHits) { auto const &thit = static_cast(pixelHit); auto const detI = thit.det()->index(); auto const &clus = thit.firstClusterRef(); assert(clus.isPixel()); + + // get hit identifier as (hit offset of the module) + (hit index in this module) auto const idx = hitsModuleStart[detI] + clus.pixelCluster().originalId(); + if (idx >= hitmap.size()) hitmap.resize(idx + 256, nullptr); // only in case of hit overflow in one module @@ -159,10 +199,31 @@ void PixelTrackProducerFromSoAAlpaka::produce(edm::StreamID streamID, hitmap[idx] = &pixelHit; } + // function to select only P-hits from the OT barrel + auto isPinPSinOTBarrel = [&](DetId detId) { + return (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP && + detId.subdetId() == StripSubdetector::TOB); + }; + + // if OT RecHits are used in PixelTracks, fill the hitmap also with those + if (useOTExtension_) { + // perform the exact same loop of how the SoA is initially filled with OT hits + // and get the index by counting the hits (starting from nPixelHits) + for (int idx = nPixelHits; auto const &detSet : *otRecHitsDSV) { + auto detId = detSet.detId(); + if (isPinPSinOTBarrel(DetId(detId))) { + for (auto const &recHit : detSet) { + hitmap[idx] = &recHit; + idx++; + } + } + } + } + std::vector hits; hits.reserve(5); //TODO move to a configurable parameter? - auto const &tsoa = iEvent.get(tokenTrack_); + auto const &tsoa = iEvent.get(trackSoAToken_); auto const *quality = tsoa.view().quality(); auto const *hitOffs = tsoa.view().hitOffsets(); auto const *hitIdxs = tsoa.template view().id(); @@ -184,17 +245,24 @@ void PixelTrackProducerFromSoAAlpaka::produce(edm::StreamID streamID, return quality[i1] > quality[i2]; }); - //store the index of the SoA: indToEdm[index_SoAtrack] -> index_edmTrack (if it exists) - indToEdm.resize(sortIdxs.size(), -1); + indToEdm.resize(nTracks, -1); + + // loop over (sorted) tracks for (const auto &it : sortIdxs) { auto nHits = reco::nHits(tsoa.view(), it); assert(nHits >= 3); auto q = quality[it]; + // apply cuts on quality and number of hits if (q < minQuality_) - continue; + // since the tracks are sorted according to quality, + // we can break after the first track with low quality + break; if (nHits < minNumberOfHits_) //move to nLayers? continue; + + //store the index of the SoA: + // indToEdm[index_SoAtrack] -> index_edmTrack (if it exists) indToEdm[it] = nt; ++nt; @@ -267,7 +335,7 @@ void PixelTrackProducerFromSoAAlpaka::produce(edm::StreamID streamID, #endif // store tracks - storeTracks(iEvent, tracks, httopo); + storeTracks(iEvent, tracks, trackerTopology); iEvent.put(std::move(indToEdmP)); } From 683a91497ddf7531c202d8d16abf4f20ccf174b9 Mon Sep 17 00:00:00 2001 From: "Jan Schulz (LXPLUS)" Date: Wed, 21 May 2025 18:49:02 +0200 Subject: [PATCH 09/40] Modify hltPhase2PixelTracks to enable OT extension by default in alpaka Phase2 --- .../python/HLT_75e33/modules/hltPhase2PixelTracks_cfi.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracks_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracks_cfi.py index b06d6b0fcdf9d..dbe639e7492c1 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracks_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracks_cfi.py @@ -15,6 +15,8 @@ minNumberOfHits = cms.int32(0), minQuality = cms.string('tight'), pixelRecHitLegacySrc = cms.InputTag("hltSiPixelRecHits"), - trackSrc = cms.InputTag("hltPhase2PixelTracksSoA") + trackSrc = cms.InputTag("hltPhase2PixelTracksSoA"), + outerTrackerRecHitSrc = cms.InputTag("hltSiPhase2RecHits"), + useOTExtension = cms.bool(True) ) alpaka.toReplaceWith(hltPhase2PixelTracks, _hltPhase2PixelTracks) From bd6622618b78c28c8f70449f1e438d3fc4b33aa4 Mon Sep 17 00:00:00 2001 From: Luca Ferragina Date: Wed, 21 May 2025 19:17:36 +0200 Subject: [PATCH 10/40] Add missing moduleStart SoA to merged recHits collection --- .../alpaka/SiPixelRecHitExtendedAlpaka.cc | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc index 55de5ed7d606c..9e5d5ea5c9616 100644 --- a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc +++ b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc @@ -89,8 +89,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { auto outputSoA = reco::TrackingRecHitsSoACollection(iEvent.queue(), nTotHits, nTotModules); std::cout << "Total number of recHits: " << outputSoA.nHits() << std::endl; - - // copy all columns from pixelRecHitsSoA and otRecHitsSoA to outputSoA + + // copy all columns from pixelRecHitsSoA and otRecHitsSoA to outputSoA // xLocal auto xLocalOutputPixel = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xLocal(), nPixelHits); auto xLocalOutputTracker = @@ -238,12 +238,21 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { alpaka::memcpy(iEvent.queue(), detectorIndexOutputPixel, detectorIndexPixel); alpaka::memcpy(iEvent.queue(), detectorIndexOutputTracker, detectorIndexTracker); - auto offsetBPIX2Output = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().offsetBPIX2()); - auto offsetBPIX2Pixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().offsetBPIX2()); + auto offsetBPIX2Output = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().offsetBPIX2()); + auto offsetBPIX2Pixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().offsetBPIX2()); alpaka::memcpy(iEvent.queue(), offsetBPIX2Output, offsetBPIX2Pixel); + auto hitModuleStartPixel = cms::alpakatools::make_device_view( + iEvent.queue(), pixelRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelHits); + auto hitModuleStartTracker = cms::alpakatools::make_device_view( + iEvent.queue(), otRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nTrackerHits); + auto hitModuleStartPixelOutput = cms::alpakatools::make_device_view( + iEvent.queue(), outputSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelHits); + auto hitModuleStartTrackerOutput = cms::alpakatools::make_device_view( + iEvent.queue(), outputSoA.view<::reco::HitModuleSoA>().moduleStart() + nPixelHits, nTrackerHits); + alpaka::memcpy(iEvent.queue(), hitModuleStartPixelOutput, hitModuleStartPixel); + alpaka::memcpy(iEvent.queue(), hitModuleStartTrackerOutput, hitModuleStartTracker); + // emplace the merged hits in the event iEvent.emplace(outputRecHitsSoAToken_, std::move(outputSoA)); } From 62b1b3283b864e087348622e5af07794e1a465f8 Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Wed, 21 May 2025 20:00:43 +0200 Subject: [PATCH 11/40] WIP --- .../HLT_75e33/sequences/HLTOtLocalRecoSequence_cfi.py | 3 +-- .../sequences/HLTPhase2PixelTracksSequence_cfi.py | 2 ++ .../plugins/alpaka/Phase2OTRecHitsSoAConverter.cc | 8 +++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTOtLocalRecoSequence_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTOtLocalRecoSequence_cfi.py index 7364f49abf106..ce93aee2f2de7 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTOtLocalRecoSequence_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTOtLocalRecoSequence_cfi.py @@ -2,7 +2,6 @@ from ..modules.hltMeasurementTrackerEvent_cfi import * from ..modules.hltSiPhase2RecHits_cfi import * -from RecoLocalTracker.Phase2TrackerRecHits.phase2OTRecHitsSoAConverter_cfi import * from Configuration.ProcessModifiers.alpaka_cff import alpaka @@ -10,6 +9,6 @@ HLTOtLocalRecoSequenceWithHits_ = cms.Sequence(hltMeasurementTrackerEvent +hltSiPhase2RecHits - +phase2OTRecHitsSoAConverter) + ) alpaka.toReplaceWith(HLTOtLocalRecoSequence, HLTOtLocalRecoSequenceWithHits_) diff --git a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTPhase2PixelTracksSequence_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTPhase2PixelTracksSequence_cfi.py index 3c7be640aa694..987cd92fc7a99 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTPhase2PixelTracksSequence_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTPhase2PixelTracksSequence_cfi.py @@ -8,6 +8,7 @@ from ..modules.hltPhase2PixelTracksHitSeeds_cfi import * from ..modules.hltPhase2PixelTracksSeedLayers_cfi import * from ..modules.hltPhase2PixelRecHitsExtendedSoA_cfi import * +from RecoLocalTracker.Phase2TrackerRecHits.phase2OTRecHitsSoAConverter_cfi import * HLTPhase2PixelTracksSequence = cms.Sequence(hltPhase2PixelTracksSeedLayers+hltPhase2PixelTracksAndHighPtStepTrackingRegions+hltPhase2PixelTracksHitDoublets+hltPhase2PixelTracksHitSeeds+hltPhase2PixelFitterByHelixProjections+hltPhase2PixelTrackFilterByKinematics+hltPhase2PixelTracks) from ..sequences.HLTBeamSpotSequence_cfi import HLTBeamSpotSequence @@ -17,6 +18,7 @@ +hltPhase2PixelTracksAndHighPtStepTrackingRegions # needed by highPtTripletStep iteration +hltPhase2PixelFitterByHelixProjections # needed by tracker muons +hltPhase2PixelTrackFilterByKinematics # needed by tracker muons + +phase2OTRecHitsSoAConverter +hltPhase2PixelRecHitsExtendedSoA +hltPhase2PixelTracksSoA +hltPhase2PixelTracks diff --git a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc index ff131e51f5ac5..eab6a5c914ece 100644 --- a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc +++ b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc @@ -51,6 +51,7 @@ class Phase2OTRecHitsSoAConverter : public stream::EDProducer<> { const edm::ESGetToken geomToken_; const edm::EDGetTokenT recHitToken_; const edm::EDGetTokenT<::reco::BeamSpot> beamSpotToken_; + const edm::EDGetTokenT pixelHitsSoA_; const device::EDPutToken stripSoADevice_; const edm::EDPutTokenT hitModuleStart_; @@ -62,6 +63,7 @@ Phase2OTRecHitsSoAConverter::Phase2OTRecHitsSoAConverter(const edm::ParameterSet geomToken_(esConsumes()), recHitToken_{consumes(iConfig.getParameter("otRecHitSource"))}, beamSpotToken_(consumes<::reco::BeamSpot>(iConfig.getParameter("beamSpot"))), + pixelHitsSoA_{consumes(iConfig.getParameter("pixelRecHitSoASource"))}, stripSoADevice_{produces()}, hitModuleStart_{produces()} { } @@ -69,6 +71,7 @@ Phase2OTRecHitsSoAConverter::Phase2OTRecHitsSoAConverter(const edm::ParameterSet void Phase2OTRecHitsSoAConverter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; + desc.add("pixelRecHitSoASource", edm::InputTag("hltPhase2SiPixelRecHitsSoA")); desc.add("otRecHitSource", edm::InputTag("hltSiPhase2RecHits")); desc.add("beamSpot", edm::InputTag("hltOnlineBeamSpot")); @@ -85,6 +88,9 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe const auto &trackerGeometry = &iSetup.getData(geomToken_); auto const& stripHits = iEvent.get(recHitToken_); + auto const& pixelHitsHost = iEvent.get(pixelHitsSoA_); + int nPixelHits = pixelHitsHost.view().metadata().size(); + // Count strip hits and active strip modules const int nStripHits = stripHits.data().size(); const int activeStripModules = stripHits.size(); @@ -152,7 +158,7 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe auto it = p_modulesInPSInOTBarrel.find(index); if (it != p_modulesInPSInOTBarrel.end()) { int offset = std::distance(p_modulesInPSInOTBarrel.begin(), it); - stripHitsModuleView[offset].moduleStart() = n_hits; + stripHitsModuleView[offset].moduleStart() = n_hits + nPixelHits; } else { assert(0); } From 35837cf380feaefa243b0f6c7873603966268e68 Mon Sep 17 00:00:00 2001 From: Luca Ferragina Date: Thu, 22 May 2025 10:30:14 +0200 Subject: [PATCH 12/40] Fix illegal memory access in RecHits merger --- .../alpaka/SiPixelRecHitExtendedAlpaka.cc | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc index 9e5d5ea5c9616..4f7c45c1ccc0e 100644 --- a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc +++ b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc @@ -242,18 +242,24 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { auto offsetBPIX2Pixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().offsetBPIX2()); alpaka::memcpy(iEvent.queue(), offsetBPIX2Output, offsetBPIX2Pixel); - auto hitModuleStartPixel = cms::alpakatools::make_device_view( - iEvent.queue(), pixelRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelHits); - auto hitModuleStartTracker = cms::alpakatools::make_device_view( - iEvent.queue(), otRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nTrackerHits); - auto hitModuleStartPixelOutput = cms::alpakatools::make_device_view( - iEvent.queue(), outputSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelHits); - auto hitModuleStartTrackerOutput = cms::alpakatools::make_device_view( - iEvent.queue(), outputSoA.view<::reco::HitModuleSoA>().moduleStart() + nPixelHits, nTrackerHits); - alpaka::memcpy(iEvent.queue(), hitModuleStartPixelOutput, hitModuleStartPixel); - alpaka::memcpy(iEvent.queue(), hitModuleStartTrackerOutput, hitModuleStartTracker); - - // emplace the merged hits in the event + // copy the moduleStart from pixelRecHitsSoA and otRecHitsSoA to outputSoA + const int nPixelModules = pixelRecHitsSoA.nModules(); + const int nTrackerModules = otRecHitsSoA.nModules(); + + auto hitModuleStartOutputPixel = cms::alpakatools::make_device_view( + iEvent.queue(), outputSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); + auto hitModuleStartOutputTracker = cms::alpakatools::make_device_view( + iEvent.queue(), outputSoA.view<::reco::HitModuleSoA>().moduleStart() + nPixelModules, nTrackerModules); + + const auto hitModuleStartPixel = cms::alpakatools::make_device_view( + iEvent.queue(), pixelRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); + const auto hitModuleStartTracker = cms::alpakatools::make_device_view( + iEvent.queue(), otRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nTrackerModules); + + alpaka::memcpy(iEvent.queue(), hitModuleStartOutputPixel, hitModuleStartPixel); + alpaka::memcpy(iEvent.queue(), hitModuleStartOutputTracker, hitModuleStartTracker); + + // emplace the merged SoA in the event iEvent.emplace(outputRecHitsSoAToken_, std::move(outputSoA)); } using SiPixelRecHitExtendedAlpakaPhase1 = SiPixelRecHitExtendedAlpaka; From 6f8293fc614559542e91a21a4aac54c3dccb96aa Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Thu, 22 May 2025 13:56:06 +0200 Subject: [PATCH 13/40] Add plus one for the last layer. --- .../interface/alpaka/TrackingRecHitsSoACollection.h | 2 +- .../plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DataFormats/TrackingRecHitSoA/interface/alpaka/TrackingRecHitsSoACollection.h b/DataFormats/TrackingRecHitSoA/interface/alpaka/TrackingRecHitsSoACollection.h index 6750a42334bcb..5370a9411505b 100644 --- a/DataFormats/TrackingRecHitSoA/interface/alpaka/TrackingRecHitsSoACollection.h +++ b/DataFormats/TrackingRecHitSoA/interface/alpaka/TrackingRecHitsSoACollection.h @@ -63,7 +63,7 @@ namespace cms::alpakatools { auto nHits = hostData.nHits(); - reco::TrackingRecHitDevice deviceData(queue, nHits, hostData.nModules()); + reco::TrackingRecHitDevice deviceData(queue, nHits, hostData.nModules() + 1); if (nHits == 0) { std::memset( diff --git a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc index 4f7c45c1ccc0e..b8f2b1105be24 100644 --- a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc +++ b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc @@ -87,7 +87,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { std::cout << "Number of Tracker modules: " << otRecHitsSoA.nModules() << std::endl; const int nTotModules = pixelRecHitsSoA.nModules() + otRecHitsSoA.nModules(); - auto outputSoA = reco::TrackingRecHitsSoACollection(iEvent.queue(), nTotHits, nTotModules); + auto outputSoA = reco::TrackingRecHitsSoACollection(iEvent.queue(), nTotHits, nTotModules + 1); std::cout << "Total number of recHits: " << outputSoA.nHits() << std::endl; // copy all columns from pixelRecHitsSoA and otRecHitsSoA to outputSoA @@ -244,7 +244,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { // copy the moduleStart from pixelRecHitsSoA and otRecHitsSoA to outputSoA const int nPixelModules = pixelRecHitsSoA.nModules(); - const int nTrackerModules = otRecHitsSoA.nModules(); + const int nTrackerModules = otRecHitsSoA.nModules() + 1; auto hitModuleStartOutputPixel = cms::alpakatools::make_device_view( iEvent.queue(), outputSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); From 26f1dd9cbe8ac2b01b8da8b915e7136ede183910 Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Thu, 22 May 2025 13:56:48 +0200 Subject: [PATCH 14/40] Update hard-coded constants to be able to run CA+Extension. --- DataFormats/SiPixelClusterSoA/interface/ClusteringConstants.h | 2 +- Geometry/CommonTopologies/interface/SimplePixelTopology.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DataFormats/SiPixelClusterSoA/interface/ClusteringConstants.h b/DataFormats/SiPixelClusterSoA/interface/ClusteringConstants.h index 810b58042557f..da219c63919e6 100644 --- a/DataFormats/SiPixelClusterSoA/interface/ClusteringConstants.h +++ b/DataFormats/SiPixelClusterSoA/interface/ClusteringConstants.h @@ -23,7 +23,7 @@ namespace pixelClustering { constexpr uint16_t clusterThresholdPhase2OtherLayers = 4000; constexpr uint32_t maxNumDigis = 3 * 256 * 1024; // @PU=200 µ=530k σ=50k this is >4σ away - constexpr uint16_t maxNumModules = 5000; // This is an upperlimit taking into account D110 has 4000 modules + constexpr uint16_t maxNumModules = 5000 + 2872; // This is an upperlimit taking into account D110 has 4000 modules + 3 layer of OT for CA Extension constexpr int32_t maxNumClustersPerModules = maxHitsInModule(); constexpr uint16_t invalidModuleId = std::numeric_limits::max() - 1; diff --git a/Geometry/CommonTopologies/interface/SimplePixelTopology.h b/Geometry/CommonTopologies/interface/SimplePixelTopology.h index d775302a993f5..ebd3ba00f1b54 100644 --- a/Geometry/CommonTopologies/interface/SimplePixelTopology.h +++ b/Geometry/CommonTopologies/interface/SimplePixelTopology.h @@ -9,7 +9,7 @@ namespace pixelTopology { constexpr auto maxNumberOfLadders = 160; - constexpr uint8_t maxLayers = 28; + constexpr uint8_t maxLayers = 28 + 3; // CA Extension to 3 OT barrel layers constexpr uint8_t maxPairs = 64; // TODO @@ -216,7 +216,7 @@ namespace phase2PixelTopology { using pixelTopology::phi0p07; using pixelTopology::phi0p09; - constexpr uint32_t numberOfLayers = 28; + constexpr uint32_t numberOfLayers = 28 + 3; // CA Extension with 3 barrel layers from OT constexpr int nPairs = 23 + 6 + 14 + 8 + 4; // include far forward layer pairs constexpr uint16_t numberOfModules = 4000; From dba8905972d92747b64482d74e583d230a269d78 Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Thu, 22 May 2025 13:57:23 +0200 Subject: [PATCH 15/40] Add last layer with cumulative number of modules. --- .../alpaka/Phase2OTRecHitsSoAConverter.cc | 115 +++++++++++++----- .../plugins/alpaka/CAHitNtuplet.cc | 4 + 2 files changed, 86 insertions(+), 33 deletions(-) diff --git a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc index eab6a5c914ece..2bf4e9dc73c30 100644 --- a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc +++ b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc @@ -122,10 +122,10 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe DetId detId(detUnit->geographicalId()); if (isPh2Pixel(detId)) modulesInPixel++; - detIdToIndex[detUnit->geographicalId()] = detUnit->index(); if (isPinPSinOTBarrel(detId)) { + detIdToIndex[detUnit->geographicalId()] = detUnit->index(); p_modulesInPSInOTBarrel.insert(detUnit->index()); -// std::cout << "Inserted " << detUnit->index() << " " << p_modulesInPSInOTBarrel.size() << std::endl; + std::cout << "Inserted " << detUnit->index() << " " << p_modulesInPSInOTBarrel.size() << " on layer " << int((detId.rawId() >> 20) & 0xF) << std::endl; } } // Count the number of P hits in the OT to dimension the SoA @@ -143,57 +143,106 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe std::cout << "Number of strip hits: " << nStripHits << std::endl; std::cout << "Total hits of PinOTBarrel: " << PHitsInOTBarrel << std::endl; - HitsHost stripHitsHost(queue, PHitsInOTBarrel, p_modulesInPSInOTBarrel.size()); + HitsHost stripHitsHost(queue, PHitsInOTBarrel, p_modulesInPSInOTBarrel.size() + 1); auto& stripHitsModuleView = stripHitsHost.view<::reco::HitModuleSoA>(); - int n_hits = 0; + std::vector counterOfHitsPerModule(p_modulesInPSInOTBarrel.size(), 0); assert(p_modulesInPSInOTBarrel.size()); for (const auto& detSet : stripHits) { - auto firstHit = detSet.begin(); auto detId = firstHit->rawId(); - auto det = trackerGeometry->idToDet(detId); auto index = detIdToIndex[detId]; + int offset = 0; if (isPinPSinOTBarrel(DetId(detId))) { auto it = p_modulesInPSInOTBarrel.find(index); if (it != p_modulesInPSInOTBarrel.end()) { - int offset = std::distance(p_modulesInPSInOTBarrel.begin(), it); - stripHitsModuleView[offset].moduleStart() = n_hits + nPixelHits; + offset = std::distance(p_modulesInPSInOTBarrel.begin(), it); } else { assert(0); } + for (const auto& recHit : detSet) { + counterOfHitsPerModule[offset]++; + } } + } +#if 1 + int modId = 0; + for (auto c : counterOfHitsPerModule) { + std::cout << "On module " << modId << " we have " << c << " hits." << std::endl; + modId++; + } +#endif + + std::vector cumulativeHitPerModule(counterOfHitsPerModule.size()); + std::partial_sum(counterOfHitsPerModule.begin(), counterOfHitsPerModule.end(), cumulativeHitPerModule.begin()); + // Create new vector with first element as 0, then shifted contents from counterOfHitsPerModule + std::vector shifted(cumulativeHitPerModule.size(), 0); + stripHitsModuleView[0].moduleStart() = nPixelHits; + std::cout << "Module start: 0 with hits: " << stripHitsModuleView[0].moduleStart() << std::endl; + for (size_t i = 1; i < cumulativeHitPerModule.size(); ++i) { + shifted[i] = cumulativeHitPerModule[i - 1]; + stripHitsModuleView[i].moduleStart() = cumulativeHitPerModule[i-1] + nPixelHits; + std::cout << "Module start: " << i << " with hits: " << stripHitsModuleView[i].moduleStart() << std::endl; + } - for (const auto& recHit : detSet) { - - // Select only P-hits from the OT barrel - if (isPinPSinOTBarrel(DetId(detId))) { - assert(n_hits < PHitsInOTBarrel); - stripHitsHost.view()[n_hits].xLocal() = recHit.localPosition().x(); - stripHitsHost.view()[n_hits].yLocal() = recHit.localPosition().y(); - stripHitsHost.view()[n_hits].xerrLocal() = recHit.localPositionError().xx(); - stripHitsHost.view()[n_hits].yerrLocal() = recHit.localPositionError().yy(); - auto globalPosition = det->toGlobal(recHit.localPosition()); - double gx = globalPosition.x() - bs.x0(); - double gy = globalPosition.y() - bs.y0(); - double gz = globalPosition.z() - bs.z0(); -// std::cout << gx << std::endl; - stripHitsHost.view()[n_hits].xGlobal() = gx; - stripHitsHost.view()[n_hits].yGlobal() = gy; - stripHitsHost.view()[n_hits].zGlobal() = gz; - stripHitsHost.view()[n_hits].rGlobal() = sqrt(gx * gx + gy * gy); - stripHitsHost.view()[n_hits].iphi() = unsafe_atan2s<7>(gy, gx); - stripHitsHost.view()[n_hits].chargeAndStatus().charge = 0; - stripHitsHost.view()[n_hits].chargeAndStatus().status = {0, 0, 0, 0, 0}; - stripHitsHost.view()[n_hits].clusterSizeX() = -1; - stripHitsHost.view()[n_hits].clusterSizeY() = -1; - stripHitsHost.view()[n_hits].detectorIndex() = modulesInPixel++; - n_hits++; + for (const auto& detSet : stripHits) { + auto firstHit = detSet.begin(); + auto detId = firstHit->rawId(); + auto det = trackerGeometry->idToDet(detId); + auto index = detIdToIndex[detId]; + int offset = 0; + if (isPinPSinOTBarrel(DetId(detId))) { + auto it = p_modulesInPSInOTBarrel.find(index); + if (it != p_modulesInPSInOTBarrel.end()) { + offset = std::distance(p_modulesInPSInOTBarrel.begin(), it); +// stripHitsModuleView[offset].moduleStart() = cumulativeHitPerModule[offset] + nPixelHits; +// std::cout << "Module start: " << offset << " " << index << " with hits: " << stripHitsModuleView[offset].moduleStart() << std::endl; + } else { + assert(0); + } + for (const auto& recHit : detSet) { + // Select only P-hits from the OT barrel + if (isPinPSinOTBarrel(DetId(detId))) { + int idx = shifted[offset]++; + assert(idx < PHitsInOTBarrel); + stripHitsHost.view()[idx].xLocal() = recHit.localPosition().x(); + stripHitsHost.view()[idx].yLocal() = recHit.localPosition().y(); + stripHitsHost.view()[idx].xerrLocal() = recHit.localPositionError().xx(); + stripHitsHost.view()[idx].yerrLocal() = recHit.localPositionError().yy(); + auto globalPosition = det->toGlobal(recHit.localPosition()); + double gx = globalPosition.x() - bs.x0(); + double gy = globalPosition.y() - bs.y0(); + double gz = globalPosition.z() - bs.z0(); + // std::cout << gx << std::endl; + stripHitsHost.view()[idx].xGlobal() = gx; + stripHitsHost.view()[idx].yGlobal() = gy; + stripHitsHost.view()[idx].zGlobal() = gz; + stripHitsHost.view()[idx].rGlobal() = sqrt(gx * gx + gy * gy); + stripHitsHost.view()[idx].iphi() = unsafe_atan2s<7>(gy, gx); + stripHitsHost.view()[idx].chargeAndStatus().charge = 0; + stripHitsHost.view()[idx].chargeAndStatus().status = {0, 0, 0, 0, 0}; + stripHitsHost.view()[idx].clusterSizeX() = -1; + stripHitsHost.view()[idx].clusterSizeY() = -1; + stripHitsHost.view()[idx].detectorIndex() = modulesInPixel + offset; + } } } } + stripHitsModuleView[p_modulesInPSInOTBarrel.size()].moduleStart() = cumulativeHitPerModule[p_modulesInPSInOTBarrel.size()-1]+nPixelHits; std::cout << "DONE" << std::endl; +#if 1 + int current = 0; + for (int h = 0; h < stripHitsHost.view().metadata().size(); ++h) { + auto idx = stripHitsHost.view()[h].detectorIndex(); + std::cout << h << " detectorIndexInSoA: " << idx << std::endl; + assert(idx>=current); + current = idx; + } + for (int h = 0; h < stripHitsModuleView.metadata().size(); ++h) { + std::cout << h << " -> " << stripHitsModuleView[h].moduleStart() << std::endl; + } +#endif auto moduleStartView = cms::alpakatools::make_host_view(stripHitsModuleView.moduleStart(), stripHitsModuleView.metadata().size()); HMSstorage moduleStartVec(stripHitsModuleView.metadata().size()); diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc index 632cf6bd0ab39..20085d13516e0 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc @@ -170,6 +170,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { // only cover the OT barrel part, and will ignore the OT forward. if (isPh2Pixel(detid)) { if (layer != oldLayer) { + std::cout << "Pixel LayerStart: " << layerCount << " has " << n_modules << " modules." << std::endl; layerStarts[layerCount++] = n_modules; if (layerCount > n_layers + 1) break; @@ -184,6 +185,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { DetId unitDetId(detUnit->geographicalId()); if (isPinPSinOTBarrel(unitDetId)) { if (layer != oldLayer) { + std::cout << "OT LayerStart: " << layerCount << " has " << n_modules << " modules." << std::endl; layerStarts[layerCount++] = n_modules; if (layerCount > n_layers + 1) break; @@ -196,6 +198,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { } counter++; } + layerStarts[n_layers] = n_modules; + std::cout << "OT LayerStart: " << n_layers << " has " << n_modules << " modules." << std::endl; } else { for (auto& det : dets) { DetId detid = det->geographicalId(); From 9211aa3f2d0922d26f915000c96808dfe4dda3b3 Mon Sep 17 00:00:00 2001 From: "Jan Schulz (LXPLUS)" Date: Thu, 22 May 2025 14:16:54 +0200 Subject: [PATCH 16/40] Correct PixelTrack converter (SoA -> legacy) for new ordering of OT RecHits in SoA --- .../PixelTrackProducerFromSoAAlpaka.cc | 65 ++++++++++++++++++- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc b/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc index e54773d8e942e..5a081bfb51464 100644 --- a/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc +++ b/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc @@ -207,12 +207,71 @@ void PixelTrackProducerFromSoAAlpaka::produce(edm::StreamID streamID, // if OT RecHits are used in PixelTracks, fill the hitmap also with those if (useOTExtension_) { + // The RecHits in the SoA are ordered according to the detUnit->index() + // of the respective OT module. For this reason, in order to infer the + // hit position in the SoA, we need to know which modules are there and + // how many hits each module has. + // We use: + // - detIdToIndex: map the detId to detUnit->index() + // (NOTE: technically, we wouldn't need the detUnit at all if the order + // of detIds and detUnit->index is identical, to be checked) + // - p_modulesInPSInOTBarrel: set of detUnit->index() of considered modules + // (used for finding the "moduleIdOT", position of the module in the SoA) + // - moduleStartOT: map from moduleIdOT to position of first RecHit of that + // layer in the RecHit SoA + + auto const &detUnits = trackerGeometry->detUnits(); + std::map detIdToIndex; + std::set p_modulesInPSInOTBarrel; + + // fill detIdToIndex map and p_modulesInPSInOTBarrel set of modules + for (auto &detUnit : detUnits) { + DetId detId(detUnit->geographicalId()); + if (isPinPSinOTBarrel(detId)) { + detIdToIndex[detUnit->geographicalId()] = detUnit->index(); + p_modulesInPSInOTBarrel.insert(detUnit->index()); + } + } + + // function to get the "moduleId" of the OT modules + // (NOT a general CMSSW Id but just the index of the OT module in moduleStartOT) + auto getModuleIdOT = [&](DetId detId) { + int index = detIdToIndex[detId]; + auto it = p_modulesInPSInOTBarrel.find(index); + if (it != p_modulesInPSInOTBarrel.end()) { + return std::distance(p_modulesInPSInOTBarrel.begin(), it); + } else { + return -1L; + } + }; + + // count hits in all considered OT modules and fill them in moduleStartOT + // at the position of the subsequent module + std::vector moduleStartOT; + moduleStartOT.resize(p_modulesInPSInOTBarrel.size() + 1, 0); + for (auto const &detSet : *otRecHitsDSV) { + auto detId = detSet.detId(); + if (isPinPSinOTBarrel(DetId(detId))) { + int moduleId = getModuleIdOT(detId); + if (moduleId != -1) { + moduleStartOT[moduleId + 1] = detSet.size(); + } else { + assert(0); + } + } + } + + // accumulate the number of hits starting from the number of pixel hits + // to finalize the actual positions of the layers in the RecHit SoA + moduleStartOT[0] = nPixelHits; + std::partial_sum(moduleStartOT.cbegin(), moduleStartOT.cend(), moduleStartOT.begin()); + // perform the exact same loop of how the SoA is initially filled with OT hits // and get the index by counting the hits (starting from nPixelHits) - for (int idx = nPixelHits; auto const &detSet : *otRecHitsDSV) { + for (auto const &detSet : *otRecHitsDSV) { auto detId = detSet.detId(); if (isPinPSinOTBarrel(DetId(detId))) { - for (auto const &recHit : detSet) { + for (int idx = moduleStartOT[getModuleIdOT(detId)]; auto const &recHit : detSet) { hitmap[idx] = &recHit; idx++; } @@ -261,7 +320,7 @@ void PixelTrackProducerFromSoAAlpaka::produce(edm::StreamID streamID, if (nHits < minNumberOfHits_) //move to nLayers? continue; - //store the index of the SoA: + //store the index of the SoA: // indToEdm[index_SoAtrack] -> index_edmTrack (if it exists) indToEdm[it] = nt; ++nt; From 3e29ae7f1ea3cb83d57aa85dd181846ab80c9d79 Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Thu, 22 May 2025 16:13:41 +0200 Subject: [PATCH 17/40] Fix topology for CA Extension. --- Geometry/CommonTopologies/interface/SimplePixelTopology.h | 2 +- .../plugins/alpaka/Phase2OTRecHitsSoAConverter.cc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Geometry/CommonTopologies/interface/SimplePixelTopology.h b/Geometry/CommonTopologies/interface/SimplePixelTopology.h index ebd3ba00f1b54..e019b4f1d0bfa 100644 --- a/Geometry/CommonTopologies/interface/SimplePixelTopology.h +++ b/Geometry/CommonTopologies/interface/SimplePixelTopology.h @@ -365,7 +365,7 @@ namespace pixelTopology { static constexpr uint32_t maxNumOfActiveDoublets = maxNumberOfDoublets / 8; static constexpr uint32_t maxNumberOfQuadruplets = maxNumberOfTuples; static constexpr uint32_t maxDepth = 12; - static constexpr uint32_t numberOfLayers = 28; + static constexpr uint32_t numberOfLayers = 28 + 3; static constexpr uint32_t maxSizeCluster = 2047; diff --git a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc index 2bf4e9dc73c30..7b2fd568b79ec 100644 --- a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc +++ b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc @@ -125,7 +125,7 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe if (isPinPSinOTBarrel(detId)) { detIdToIndex[detUnit->geographicalId()] = detUnit->index(); p_modulesInPSInOTBarrel.insert(detUnit->index()); - std::cout << "Inserted " << detUnit->index() << " " << p_modulesInPSInOTBarrel.size() << " on layer " << int((detId.rawId() >> 20) & 0xF) << std::endl; +// std::cout << "Inserted " << detUnit->index() << " " << p_modulesInPSInOTBarrel.size() << " on layer " << int((detId.rawId() >> 20) & 0xF) << std::endl; } } // Count the number of P hits in the OT to dimension the SoA @@ -165,7 +165,7 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe } } } -#if 1 +#if 0 int modId = 0; for (auto c : counterOfHitsPerModule) { std::cout << "On module " << modId << " we have " << c << " hits." << std::endl; @@ -231,7 +231,7 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe stripHitsModuleView[p_modulesInPSInOTBarrel.size()].moduleStart() = cumulativeHitPerModule[p_modulesInPSInOTBarrel.size()-1]+nPixelHits; std::cout << "DONE" << std::endl; -#if 1 +#if 0 int current = 0; for (int h = 0; h < stripHitsHost.view().metadata().size(); ++h) { auto idx = stripHitsHost.view()[h].detectorIndex(); From 0dadd78cacc4ae225bc95d8fb4d976bf3dcd44ee Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Fri, 23 May 2025 10:36:08 +0200 Subject: [PATCH 18/40] Improve debugging printouts. --- .../modules/hltPhase2PixelTracksSoA_cfi.py | 12 ++- .../alpaka/Phase2OTRecHitsSoAConverter.cc | 4 +- .../CAHitNtupletGeneratorKernels.dev.cc | 24 ++++-- .../alpaka/CAHitNtupletGeneratorKernelsImpl.h | 79 ++++++++++--------- 4 files changed, 72 insertions(+), 47 deletions(-) diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py index ff41cfd60cfb5..bdedf2d4da823 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py @@ -6,7 +6,7 @@ hardCurvCut = cms.double(0.0328407225), earlyFishbone = cms.bool(True), lateFishbone = cms.bool(False), - fillStatistics = cms.bool(False), + fillStatistics = cms.bool(True), minHitsPerNtuplet = cms.uint32(4), maxNumberOfDoublets = cms.string(str(5*512*1024)), maxNumberOfTuples = cms.string(str(32*1024)), @@ -33,6 +33,16 @@ maxTip = cms.double(0.3), maxZip = cms.double(12.), ), + # geometry = cms.PSet( + # caDCACuts = cms.vdouble(0.15, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25), + # caThetaCuts = cms.vdouble(0.002, 0.002, 0.002, 0.002, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003), + # startingPairs = cms.vint32(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32), + # pairGraph = cms.vint32(0, 1, 0, 4, 0, 16, 1, 2, 1, 4, 1, 16, 2, 3, 2, 4, 2, 16, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 0, 2, 0, 5, 0, 17, 0, 6, 0, 18, 1, 3, 1, 5, 1, 17, 1, 6, 1, 18, 11, 12, 12, 13, 13, 14, 14, 15, 23, 24, 24, 25, 25, 26, 26, 27, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 16, 18, 17, 19, 18, 20, 19, 21, 20, 22, 21, 23, 22, 24, 2, 28, 3, 28, 3, 29, 28, 29, 28, 30, 29, 30), + # phiCuts = cms.vint32(522, 522, 522, 626, 730, 730, 626, 730, 730, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 650, 522, 522, 522, 522, 522, 522, 650, 1200, 900, 2000, 1200, 1500, 1500), + # minZ = cms.vdouble(-16.0, 4.0, -22.0, -17.0, 6.0, -22.0, -18.0, 11.0, -22.0, 23.0, 30.0, 39.0, 50.0, 65.0, 82.0, 109.0, -28.0, -35.0, -44.0, -55.0, -70.0, -87.0, -113.0, -16.0, 7.0, -22.0, 11.0, -22.0, -17.0, 9.0, -22.0, 13.0, -22.0, 137.0, 173.0, 199.0, 229.0, -142.0, -177.0, -203.0, -233.0, 23.0, 30.0, 39.0, 50.0, 65.0, 82.0, 109.0, -28.0, -35.0, -44.0, -55.0, -70.0, -87.0, -113.0, -1000, -1000, -1000, -1000, -1000, -1000), + # maxZ = cms.vdouble(17.0, 22.0, -4.0, 17.0, 22.0, -6.0, 18.0, 22.0, -11.0, 28.0, 35.0, 44.0, 55.0, 70.0, 87.0, 113.0, -23.0, -30.0, -39.0, -50.0, -65.0, -82.0, -109.0, 17.0, 22.0, -7.0, 22.0, -10.0, 17.0, 22.0, -9.0, 22.0, -13.0, 142.0, 177.0, 203.0, 233.0, -137.0, -173.0, -199.0, -229.0, 28.0, 35.0, 44.0, 55.0, 70.0, 87.0, 113.0, -23.0, -30.0, -39.0, -50.0, -65.0, -82.0, -109.0, 1000, 1000, 1000, 1000, 1000, 1000), + # maxR = cms.vdouble(5.0, 10.0, 10.0, 7.0, 8.0, 8.0, 7.0, 7.0, 7.0, 6.0, 6.0, 6.0, 6.0, 5.0, 6.0, 5.0, 6.0, 6.0, 6.0, 6.0, 5.0, 6.0, 5.0, 10.0, 5.0, 5.0, 5.0, 5.0, 10.0, 10.0, 10.0, 8.0, 8.0, 6.0, 5.0, 5.0, 5.0, 6.0, 5.0, 5.0, 5.0, 9.0, 9.0, 9.0, 8.0, 8.0, 8.0, 11.0, 9.0, 9.0, 9.0, 8.0, 8.0, 8.0, 11.0, 60, 60, 60, 60, 60, 60) + #) geometry = cms.PSet( caDCACuts = cms.vdouble(0.15, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25), caThetaCuts = cms.vdouble(0.002, 0.002, 0.002, 0.002, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003), diff --git a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc index 7b2fd568b79ec..9692b8ce18c78 100644 --- a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc +++ b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc @@ -178,11 +178,11 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe // Create new vector with first element as 0, then shifted contents from counterOfHitsPerModule std::vector shifted(cumulativeHitPerModule.size(), 0); stripHitsModuleView[0].moduleStart() = nPixelHits; - std::cout << "Module start: 0 with hits: " << stripHitsModuleView[0].moduleStart() << std::endl; +// std::cout << "Module start: 0 with hits: " << stripHitsModuleView[0].moduleStart() << std::endl; for (size_t i = 1; i < cumulativeHitPerModule.size(); ++i) { shifted[i] = cumulativeHitPerModule[i - 1]; stripHitsModuleView[i].moduleStart() = cumulativeHitPerModule[i-1] + nPixelHits; - std::cout << "Module start: " << i << " with hits: " << stripHitsModuleView[i].moduleStart() << std::endl; + // std::cout << "Module start: " << i << " with hits: " << stripHitsModuleView[i].moduleStart() << std::endl; } for (const auto& detSet : stripHits) { diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc index c7558009fe5b2..4ac15e57f0358 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc @@ -744,12 +744,26 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { workDiv1D, Kernel_doStatsForTracks{}, tracks_view, - this->device_hitContainer_->data(), - this->counters_->data()); + this->device_hitContainer_.data(), + this->counters_.data()); - auto workDiv1D = cms::alpakatools::make_workdiv(1, 1); - alpaka::exec(queue, workDiv1D, Kernel_printCounters{}, this->counters_->data()); - } + workDiv1D = cms::alpakatools::make_workdiv(1,1); + alpaka::exec(queue, workDiv1D, Kernel_printCounters{}, this->counters_.data()); + alpaka::wait(queue); + + workDiv1D = cms::alpakatools::make_workdiv(1,1); + alpaka::exec(queue, + workDiv1D, + Kernel_print_found_ntuplets{}, + hh, + tracks_view, + this->device_hitContainer_.data(), + this->device_hitToTuple_.data(), + 0, + 100, + 0); + alpaka::wait(queue); + } #ifdef GPU_DEBUG alpaka::wait(queue); #endif diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h index ca6e3eefc83d9..b1ec09be5f85a 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h @@ -1060,31 +1060,31 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { int iev) const { constexpr auto loose = Quality::loose; + // Print header + printf("TK: %10s %3s %3s %3s %6s %9s %8s %8s %9s %9s %9s %9s %9s\n", + "ID", "Q", "nH", "nL", "Qchg", "pT", "Eta", "Phi", "Tip", "Zip", "Chi2", "z1", "z2"); for (auto i : cms::alpakatools::uniform_elements(acc, firstPrint, std::min(lastPrint, foundNtuplets->nOnes()))) { auto nh = foundNtuplets->size(i); if (nh < 3) continue; if (tracks_view[i].quality() < loose) continue; - printf("TK: %d %d %d %d %f %f %f %f %f %f %f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n", - 10000 * iev + i, - int(tracks_view[i].quality()), - nh, - tracks_view[i].nLayers(), - reco::charge(tracks_view, i), - tracks_view[i].pt(), - tracks_view[i].eta(), - reco::phi(tracks_view, i), - reco::tip(tracks_view, i), - reco::zip(tracks_view, i), - tracks_view[i].chi2(), - hh[*foundNtuplets->begin(i)].zGlobal(), - hh[*(foundNtuplets->begin(i) + 1)].zGlobal(), - hh[*(foundNtuplets->begin(i) + 2)].zGlobal(), - nh > 3 ? hh[int(*(foundNtuplets->begin(i) + 3))].zGlobal() : 0, - nh > 4 ? hh[int(*(foundNtuplets->begin(i) + 4))].zGlobal() : 0, - nh > 5 ? hh[int(*(foundNtuplets->begin(i) + 5))].zGlobal() : 0, - nh > 6 ? hh[int(*(foundNtuplets->begin(i) + nh - 1))].zGlobal() : 0); + + printf("TK: %10d %3d %3d %3d %6.1f %9.3f %8.3f %8.3f %9.3f %9.3f %9.3f %9.3f %9.3f\n", + 10000 * iev + i, // ID + int(tracks_view[i].quality()), // Quality + nh, // Number of hits + tracks_view[i].nLayers(), // Number of layers + reco::charge(tracks_view, i), // Charge + tracks_view[i].pt(), // Pt + tracks_view[i].eta(), // Eta + reco::phi(tracks_view, i), // Phi + reco::tip(tracks_view, i), // Tip + reco::zip(tracks_view, i), // Zip + tracks_view[i].chi2(), // Chi2 + hh[*foundNtuplets->begin(i)].zGlobal(), // z1 + hh[*(foundNtuplets->begin(i) + 1)].zGlobal()// z2 + ); } } }; @@ -1093,10 +1093,12 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { public: ALPAKA_FN_ACC void operator()(Acc1D const &acc, Counters const *counters) const { auto const &c = *counters; - printf( - "||Counters | nEvents | nHits | nCells | nTuples | nFitTacks | nLooseTracks | nGoodTracks | nUsedHits | " - "nDupHits | nFishCells | nKilledCells | nUsedCells | nZeroTrackCells ||\n"); - printf("Counters Raw %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld\n", + printf("||%-15s|%10s|%10s|%10s|%10s|%14s|%16s|%14s|%11s|%10s|%13s|%15s|%12s|%17s||\n", + "Counters", "nEvents", "nHits", "nCells", "nTuples", "nFitTracks", + "nLooseTracks", "nGoodTracks", "nUsedHits", "nDupHits", "nFishCells", + "nKilledCells", "nUsedCells", "nZeroTrackCells"); + printf("||%-15s|%10lld|%10lld|%10lld|%10lld|%14lld|%16lld|%14lld|%11lld|%10lld|%13lld|%15lld|%12lld|%17lld||\n", + "Raw", c.nEvents, c.nHits, c.nCells, @@ -1110,22 +1112,21 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { c.nKilledCells, c.nEmptyCells, c.nZeroTrackCells); - printf( - "Counters Norm %lld || %.1f| %.1f| %.1f| %.1f| %.1f| %.1f| %.1f| %.1f| %.3f| %.3f| %.3f| " - "%.3f||\n", - c.nEvents, - c.nHits / double(c.nEvents), - c.nCells / double(c.nEvents), - c.nTuples / double(c.nEvents), - c.nFitTracks / double(c.nEvents), - c.nLooseTracks / double(c.nEvents), - c.nGoodTracks / double(c.nEvents), - c.nUsedHits / double(c.nEvents), - c.nDupHits / double(c.nEvents), - c.nFishCells / double(c.nCells), - c.nKilledCells / double(c.nCells), - c.nEmptyCells / double(c.nCells), - c.nZeroTrackCells / double(c.nCells)); + printf("||%-15s|%10lld|%10.1f|%10.1f|%10.1f|%14.1f|%16.1f|%14.1f|%11.1f|%10.3f|%13.3f|%15.3f|%12.3f|%17.3f||\n", + "Norm", + c.nEvents, + c.nHits / double(c.nEvents), + c.nCells / double(c.nEvents), + c.nTuples / double(c.nEvents), + c.nFitTracks / double(c.nEvents), + c.nLooseTracks / double(c.nEvents), + c.nGoodTracks / double(c.nEvents), + c.nUsedHits / double(c.nEvents), + c.nDupHits / double(c.nEvents), + c.nFishCells / double(c.nCells), + c.nKilledCells / double(c.nCells), + c.nEmptyCells / double(c.nCells), + c.nZeroTrackCells / double(c.nCells)); } }; From e98c85ae163b92354949da15eb1ad9c77e825fc0 Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Sat, 24 May 2025 14:51:03 +0200 Subject: [PATCH 19/40] Fix size of allocated buffer. --- .../CAHitNtupletGeneratorKernels.dev.cc | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc index 4ac15e57f0358..bd5bccb7d363f 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc @@ -54,6 +54,69 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { int nCellsToCells = std::max(int(maxDoublets * algoParams.avgCellsPerCell_), 1); int nCellsToTracks = std::max(int(maxDoublets * algoParams.avgTracksPerCell_), 1); + // Cell -> Neighbor Cells + device_cellToNeighbors_{cms::alpakatools::make_device_buffer(queue)}, + device_cellToNeighborsStorage_{cms::alpakatools::make_device_buffer( + queue, int(maxDoublets * m_params.algoParams_.avgCellsPerCell_) + 1)}, + device_cellToNeighborsOffsets_{ + cms::alpakatools::make_device_buffer(queue, maxDoublets + 1)}, + device_cellToNeighborsView_{device_cellToNeighbors_.data(), + device_cellToNeighborsOffsets_.data(), + device_cellToNeighborsStorage_.data(), + int(maxDoublets + 1), + int(maxDoublets * m_params.algoParams_.avgCellsPerCell_)}, + + // Cell -> Tracks + device_cellToTracks_{cms::alpakatools::make_device_buffer(queue)}, + device_cellToTracksStorage_{cms::alpakatools::make_device_buffer( + queue, int(maxDoublets * m_params.algoParams_.avgTracksPerCell_) + 1)}, + device_cellToTracksOffsets_{ + cms::alpakatools::make_device_buffer(queue, maxDoublets + 1)}, + device_cellToTracksView_{device_cellToTracks_.data(), + device_cellToTracksOffsets_.data(), + device_cellToTracksStorage_.data(), + int(maxDoublets + 1), + int(maxDoublets * m_params.algoParams_.avgTracksPerCell_) + 1}, + + // Tracks -> Hits + device_hitContainer_{cms::alpakatools::make_device_buffer(queue)}, + device_hitContainerStorage_{cms::alpakatools::make_device_buffer( + queue, int(m_params.algoParams_.avgHitsPerTrack_ * maxTuples) + 1)}, + device_hitContainerOffsets_{ + cms::alpakatools::make_device_buffer(queue, maxTuples + 1)}, + device_hitContainerView_{device_hitContainer_.data(), + device_hitContainerOffsets_.data(), + device_hitContainerStorage_.data(), + int(maxTuples + 1), + int(m_params.algoParams_.avgHitsPerTrack_ * maxTuples) + 1}, + + // No.Hits -> Track (Multiplicity) + device_tupleMultiplicity_{cms::alpakatools::make_device_buffer(queue)}, + device_tupleMultiplicityStorage_{ + cms::alpakatools::make_device_buffer(queue, maxTuples)}, + device_tupleMultiplicityOffsets_{ + cms::alpakatools::make_device_buffer(queue, TrackerTraits::maxHitsOnTrack + 1)}, + device_tupleMultiplicityView_{device_tupleMultiplicity_.data(), + device_tupleMultiplicityOffsets_.data(), + device_tupleMultiplicityStorage_.data(), + int(TrackerTraits::maxHitsOnTrack + 1), + int(maxTuples)}, + + // Structures and Counters Storage + device_simpleCells_{cms::alpakatools::make_device_buffer(queue, maxDoublets)}, + device_extraStorage_{ + cms::alpakatools::make_device_buffer(queue, 5u)}, + device_hitTuple_apc_{reinterpret_cast(device_extraStorage_.data())}, + device_nCells_{ + cms::alpakatools::make_device_view(queue, *reinterpret_cast(device_extraStorage_.data() + 2))}, + device_nTriplets_{ + cms::alpakatools::make_device_view(queue, *reinterpret_cast(device_extraStorage_.data() + 3))}, + device_nCellTracks_{ + cms::alpakatools::make_device_view(queue, *reinterpret_cast(device_extraStorage_.data() + 4))}, + deviceTriplets_{CACoupleSoACollection(maxDoublets * m_params.algoParams_.avgCellsPerCell_, queue)}, + deviceTracksCells_{ + CACoupleSoACollection(int(maxDoublets * m_params.algoParams_.avgTracksPerCell_) + 1, queue)} { + #ifdef GPU_DEBUG std::cout << "Allocation for tuple building with: " << std::endl; std::cout << "- nHits = " << nHits << std::endl; From 11e2539d17750111ef882be65c63091d58c5ba77 Mon Sep 17 00:00:00 2001 From: Bruno Alves Date: Mon, 30 Jun 2025 09:23:06 +0200 Subject: [PATCH 20/40] Resolve conflicts. --- .../interface/TrackingRecHitsDevice.h | 1 + .../modules/hltPhase2PixelTracksSoA_cfi.py | 10 - .../python/customizeHLTforCMSSW.py | 20 ++ .../PixelSeeding/plugins/alpaka/CAFishbone.h | 189 +++++++++--------- .../plugins/alpaka/CAHitNtuplet.cc | 9 +- .../CAHitNtupletGeneratorKernels.dev.cc | 6 +- .../alpaka/CAHitNtupletGeneratorKernelsImpl.h | 2 +- .../plugins/alpaka/CAPixelDoubletsAlgos.h | 24 ++- .../PixelTrackProducerFromSoAAlpaka.cc | 2 +- 9 files changed, 138 insertions(+), 125 deletions(-) diff --git a/DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsDevice.h b/DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsDevice.h index 96455bf938a87..d2dfc4a314141 100644 --- a/DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsDevice.h +++ b/DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsDevice.h @@ -33,6 +33,7 @@ namespace reco { : HitPortableCollectionDevice({{int(nHits), int(nModules + 1)}}, queue) {} // N.B. why this + 1? Because the HitModulesLayout is holding the + // N.B. why this + 1? Because the HitModulesLayout is holding the // moduleStart vector that is a cumulative sum of all the hits // in each module. The extra element of the array (the last one) // is used to hold the total number of hits. We are "hiding" this diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py index bdedf2d4da823..476034c677644 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py @@ -33,16 +33,6 @@ maxTip = cms.double(0.3), maxZip = cms.double(12.), ), - # geometry = cms.PSet( - # caDCACuts = cms.vdouble(0.15, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25), - # caThetaCuts = cms.vdouble(0.002, 0.002, 0.002, 0.002, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003), - # startingPairs = cms.vint32(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32), - # pairGraph = cms.vint32(0, 1, 0, 4, 0, 16, 1, 2, 1, 4, 1, 16, 2, 3, 2, 4, 2, 16, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 0, 2, 0, 5, 0, 17, 0, 6, 0, 18, 1, 3, 1, 5, 1, 17, 1, 6, 1, 18, 11, 12, 12, 13, 13, 14, 14, 15, 23, 24, 24, 25, 25, 26, 26, 27, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 16, 18, 17, 19, 18, 20, 19, 21, 20, 22, 21, 23, 22, 24, 2, 28, 3, 28, 3, 29, 28, 29, 28, 30, 29, 30), - # phiCuts = cms.vint32(522, 522, 522, 626, 730, 730, 626, 730, 730, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 650, 522, 522, 522, 522, 522, 522, 650, 1200, 900, 2000, 1200, 1500, 1500), - # minZ = cms.vdouble(-16.0, 4.0, -22.0, -17.0, 6.0, -22.0, -18.0, 11.0, -22.0, 23.0, 30.0, 39.0, 50.0, 65.0, 82.0, 109.0, -28.0, -35.0, -44.0, -55.0, -70.0, -87.0, -113.0, -16.0, 7.0, -22.0, 11.0, -22.0, -17.0, 9.0, -22.0, 13.0, -22.0, 137.0, 173.0, 199.0, 229.0, -142.0, -177.0, -203.0, -233.0, 23.0, 30.0, 39.0, 50.0, 65.0, 82.0, 109.0, -28.0, -35.0, -44.0, -55.0, -70.0, -87.0, -113.0, -1000, -1000, -1000, -1000, -1000, -1000), - # maxZ = cms.vdouble(17.0, 22.0, -4.0, 17.0, 22.0, -6.0, 18.0, 22.0, -11.0, 28.0, 35.0, 44.0, 55.0, 70.0, 87.0, 113.0, -23.0, -30.0, -39.0, -50.0, -65.0, -82.0, -109.0, 17.0, 22.0, -7.0, 22.0, -10.0, 17.0, 22.0, -9.0, 22.0, -13.0, 142.0, 177.0, 203.0, 233.0, -137.0, -173.0, -199.0, -229.0, 28.0, 35.0, 44.0, 55.0, 70.0, 87.0, 113.0, -23.0, -30.0, -39.0, -50.0, -65.0, -82.0, -109.0, 1000, 1000, 1000, 1000, 1000, 1000), - # maxR = cms.vdouble(5.0, 10.0, 10.0, 7.0, 8.0, 8.0, 7.0, 7.0, 7.0, 6.0, 6.0, 6.0, 6.0, 5.0, 6.0, 5.0, 6.0, 6.0, 6.0, 6.0, 5.0, 6.0, 5.0, 10.0, 5.0, 5.0, 5.0, 5.0, 10.0, 10.0, 10.0, 8.0, 8.0, 6.0, 5.0, 5.0, 5.0, 6.0, 5.0, 5.0, 5.0, 9.0, 9.0, 9.0, 8.0, 8.0, 8.0, 11.0, 9.0, 9.0, 9.0, 8.0, 8.0, 8.0, 11.0, 60, 60, 60, 60, 60, 60) - #) geometry = cms.PSet( caDCACuts = cms.vdouble(0.15, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25), caThetaCuts = cms.vdouble(0.002, 0.002, 0.002, 0.002, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003), diff --git a/HLTrigger/Configuration/python/customizeHLTforCMSSW.py b/HLTrigger/Configuration/python/customizeHLTforCMSSW.py index 884840d6ef234..e4a64ca25e152 100644 --- a/HLTrigger/Configuration/python/customizeHLTforCMSSW.py +++ b/HLTrigger/Configuration/python/customizeHLTforCMSSW.py @@ -182,6 +182,26 @@ def customizeHLTfor47611(process): return process +def customizeHLTfor47630(process): + attributes_to_remove = [ + 'connectionRetrialPeriod', + 'connectionRetrialTimeOut', + 'connectionTimeOut', + 'enableConnectionSharing', + 'enablePoolAutomaticCleanUp', + 'enableReadOnlySessionOnUpdateConnection', + 'idleConnectionCleanupPeriod' + ] + + for mod in modules_by_type(process, "PoolDBESSource"): + if hasattr(mod, 'DBParameters'): + pset = getattr(mod,'DBParameters') + for attr in attributes_to_remove: + if hasattr(pset, attr): + delattr(mod.DBParameters, attr) + + return process + # CMSSW version specific customizations def customizeHLTforCMSSW(process, menuType="GRun"): diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAFishbone.h b/RecoTracker/PixelSeeding/plugins/alpaka/CAFishbone.h index 96924f76932ec..2a2523c26baec 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAFishbone.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAFishbone.h @@ -17,10 +17,20 @@ #include "CACell.h" #include "CAStructures.h" -//#define GPU_DEBUG - namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { + using namespace ::caStructures; + template + using CellNeighbors = caStructures::CellNeighborsT; + template + using CellTracks = caStructures::CellTracksT; + template + using CellNeighborsVector = caStructures::CellNeighborsVectorT; + template + using CellTracksVector = caStructures::CellTracksVectorT; + template + using OuterHitOfCell = caStructures::OuterHitOfCellT; + using HitToCell = caStructures::GenericContainer; using CellToTracks = caStructures::GenericContainer; @@ -31,18 +41,35 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { HitsConstView hh, CACell* cells, uint32_t const* __restrict__ nCells, + // OuterHitOfCell const* isOuterHitOfCellWrap, HitToCell const* __restrict__ outerHitHisto, CellToTracks const* __restrict__ cellTracksHisto, uint32_t outerHits, bool checkTrack) const { + constexpr auto maxCellsPerHit = TrackerTraits::maxCellsPerHit; + + // auto const isOuterHitOfCell = isOuterHitOfCellWrap->container; + + float x[maxCellsPerHit], y[maxCellsPerHit], z[maxCellsPerHit], n[maxCellsPerHit]; + uint32_t cc[maxCellsPerHit]; + uint16_t d[maxCellsPerHit]; + uint8_t l[maxCellsPerHit]; + // outermost parallel loop, using all grid elements along the slower dimension (Y or 0 in a 2D grid) for (uint32_t idy : cms::alpakatools::uniform_elements_y(acc, outerHits)) { - uint32_t size = outerHitHisto->size(idy); + // auto const& vc = isOuterHitOfCell[idy]; + uint32_t size = outerHitHisto->size(idy); //TODO have this offset in the histo building directly +// #ifdef GPU_DEBUG +// printf("hist %d histSize %d \n",idy,size); +// #endif + // printf("fishbone ---> outerhit %d size %d - ",idy,size); if (size < 2) continue; - + auto const* __restrict__ bin = outerHitHisto->begin(idy); + auto const* __restrict__ end = outerHitHisto->end(idy); + auto const nInBin = end - bin; // if alligned kill one of the two. // in principle one could try to relax the cut (only in r-z?) for jumping-doublets @@ -50,88 +77,71 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { auto xo = c0.outer_x(hh); auto yo = c0.outer_y(hh); auto zo = c0.outer_z(hh); - - for (uint32_t ic : cms::alpakatools::independent_group_elements_x(acc, size)) { - unsigned int otherCell = bin[ic]; - auto& ci = cells[otherCell]; - + auto sg = 0; + //printf("first cell %d x0 %.2f y0 %.2f z0 %.2f - ",bin[0],c0.outer_x(hh),c0.outer_y(hh),c0.outer_z(hh)); + + // this could be moved below + // precomputing these here has + // the advantage we then loop on less + // entries but we can anyway skip them below and avoid having + // the arrays above + +// #ifdef GPU_DEBUG +// for (auto idx = 0u; idx < size; idx++) { +// unsigned int otherCell = bin[idx]; +// printf("vc[0] %d idx %d vc[idx] %d otherCell %d \n",vc[0],idx,vc[idx],otherCell); +// } +// #endif + for (auto idx = 0u; idx < nInBin; idx++) { + // for (int32_t ic = 0; ic < size; ++ic) { + // for (auto ic = 0u; ic < size; ic++) { + unsigned int otherCell = bin[idx]; + auto& ci = cells[otherCell];//vc[ic]]; + // unsigned int otherCell = bin[ic] - nHitsBPix1; + // auto& ci = cells[otherCell]; if (ci.unused()) continue; // for triplets equivalent to next - if (checkTrack && cellTracksHisto->size(otherCell) == 0) + if (checkTrack && cellTracksHisto->size(otherCell) == 0)//ci.tracks().empty()) continue; + cc[sg] = otherCell;//vc[ic]; + l[sg] = ci.layerPairId(); + d[sg] = ci.inner_detIndex(hh); + x[sg] = ci.inner_x(hh) - xo; + y[sg] = ci.inner_y(hh) - yo; + z[sg] = ci.inner_z(hh) - zo; + n[sg] = x[sg] * x[sg] + y[sg] * y[sg] + z[sg] * z[sg]; + ++sg; + //printf("sg %d idx %d cell %d x %.2f y %.2f z %.2f - ",sg,idx,otherCell,x[sg],y[sg],z[sg]); + } + //printf("\n"); + if (sg < 2) + continue; - float x1 = (ci.inner_x(hh) - xo); - float y1 = (ci.inner_y(hh) - yo); - float z1 = (ci.inner_z(hh) - zo); - float n1 = x1 * x1 + y1 * y1 + z1 * z1; - - for (auto jc = ic + 1; jc < size; ++jc) { - unsigned int nextCell = bin[jc]; - auto& cj = cells[nextCell]; - if (cj.unused()) - continue; - if (checkTrack && cellTracksHisto->size(nextCell) == 0) - continue; -#ifdef GPU_DEBUG - printf("xx = %.2f yo = %.2f zo = %.2f xi = %.2f yi = %.2f zi = %.2f xj = %.2f yj = %.2f zj = %.2f\n", - xo, - yo, - zo, - ci.inner_x(hh), - ci.inner_y(hh), - ci.inner_z(hh), - cj.inner_x(hh), - cj.inner_y(hh), - cj.inner_z(hh)); -#endif - - if (ci.inner_detIndex(hh) == cj.inner_detIndex(hh)) - continue; - - float x2 = (cj.inner_x(hh) - xo); - float y2 = (cj.inner_y(hh) - yo); - float z2 = (cj.inner_z(hh) - zo); - float n2 = x2 * x2 + y2 * y2 + z2 * z2; - - auto cos12 = x1 * x2 + y1 * y2 + z1 * z2; - - if (cos12 * cos12 >= 0.99999f * (n1 * n2)) { + // innermost parallel loop, using the block elements along the faster dimension (X or 1 in a 2D grid) + for (uint32_t ic : cms::alpakatools::independent_group_elements_x(acc, sg - 1)) { + auto& ci = cells[cc[ic]]; + for (auto jc = ic + 1; (int)jc < sg; ++jc) { + auto& cj = cells[cc[jc]]; + // must be different detectors (in the same layer) + // if (d[ic]==d[jc]) continue; + auto cos12 = x[ic] * x[jc] + y[ic] * y[jc] + z[ic] * z[jc]; + + // cos12 * cos12 could go after d[ic] != d[jc] + if (d[ic] != d[jc] && cos12 * cos12 >= 0.99999f * (n[ic] * n[jc])) { // alligned: kill farthest (prefer consecutive layers) // if same layer prefer farthest (longer level arm) and make space for intermediate hit - bool sameLayer = int(ci.layerPairId()) == int(cj.layerPairId()); - if (n1 > n2) { + bool sameLayer = l[ic] == l[jc]; + if (n[ic] > n[jc]) { if (sameLayer) { cj.kill(); // closest - ci.setFishbone(acc, cj.inner_hit_id(), cj.inner_z(hh), hh); #ifdef GPU_DEBUG - printf( - "n1>n2 lic = %d ljc = %d dic = %.2f djc = %.2f cell %d kill %d cos = %.7f n1 = %.3f n2 = %.3f " - "same\n", - int(ci.layerPairId()), - int(cj.layerPairId()), - ci.inner_detIndex(hh), - cj.inner_detIndex(hh), - bin[ic], - bin[jc], - cos12 * cos12 / (n1 * n2), - n1, - n2); +printf("hit %d same layer cell %d kill %d \n",idy,cc[ic],cc[jc]); #endif + ci.setFishbone(acc, cj.inner_hit_id(), cj.inner_z(hh), hh); } else { ci.kill(); // farthest #ifdef GPU_DEBUG - printf( - "n1>n2 lic = %d ljc = %d dic = %.2f djc = %.2f cell %d kill %d cos = %.7f n1 = %.3f n2 = %.3f " - "diff\n", - int(ci.layerPairId()), - int(cj.layerPairId()), - ci.inner_detIndex(hh), - cj.inner_detIndex(hh), - bin[jc], - bin[ic], - cos12 * cos12 / (n1 * n2), - n1, - n2); +printf("hit %d same layer cell %d kill %d \n",idy,cc[jc],cc[ic]); #endif // break; // removed to improve reproducibility, keep it for reference and tests } @@ -139,40 +149,18 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { if (!sameLayer) { cj.kill(); // farthest #ifdef GPU_DEBUG - printf( - "n2>n1 lic = %d ljc = %d dic = %.2f djc = %.2f cell %d kill %d cos = %.7f n1 = %.3f n2 = %.3f " - "diff\n", - int(ci.layerPairId()), - int(cj.layerPairId()), - ci.inner_detIndex(hh), - cj.inner_detIndex(hh), - bin[ic], - bin[jc], - cos12 * cos12 / (n1 * n2), - n1, - n2); -#endif +printf("hit %d diff layer cell %d kill %d \n",idy,cc[ic],cc[jc]); +#endif } else { ci.kill(); // closest - cj.setFishbone(acc, ci.inner_hit_id(), ci.inner_z(hh), hh); #ifdef GPU_DEBUG - printf( - "n2>n1 lic = %d ljc = %d dic = %.2f djc = %.2f cell %d kill %d cos = %.7f n1 = %.3f n2 = %.3f " - "same\n", - int(ci.layerPairId()), - int(cj.layerPairId()), - ci.inner_detIndex(hh), - cj.inner_detIndex(hh), - bin[jc], - bin[ic], - cos12 * cos12 / (n1 * n2), - n1, - n2); +printf("hit %d diff layer cell %d kill %d \n",idy,cc[jc],cc[ic]); #endif + cj.setFishbone(acc, ci.inner_hit_id(), ci.inner_z(hh), hh); // break; // removed to improve reproducibility, keep it for reference and tests } } - } // cos + } } // cj } // ci } // hits @@ -182,3 +170,4 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { } // namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets #endif // RecoTracker_PixelSeeding_plugins_alpaka_CAFishbone_h + diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc index 20085d13516e0..cd1546bc95677 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc @@ -144,8 +144,12 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { auto layerCount = 0; std::vector layerStarts(n_layers + 1); + //^ why n_layers + 1? This is a cumulative sum of the number + // of modules each layer has. And we need the extra spot + // at the end to hold the total number of modules. + std::vector moduleToindexInDets; - + auto isPinPSinOTBarrel = [&](DetId detId) { // std::cout << (int)trackerGeometry->getDetectorType(detId) << " " << (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP) << "\n"; // std::cout << (int)detId.subdetId() << " " << (detId.subdetId() == StripSubdetector::TOB) << std::endl; @@ -201,6 +205,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { layerStarts[n_layers] = n_modules; std::cout << "OT LayerStart: " << n_layers << " has " << n_modules << " modules." << std::endl; } else { + + for (auto& det : dets) { DetId detid = det->geographicalId(); #ifdef GPU_DEBUG @@ -338,6 +344,7 @@ void CAHitNtupletAlpaka::produce(device::Event& iEvent, const dev using CAHitNtupletAlpakaPhase1 = CAHitNtupletAlpaka; using CAHitNtupletAlpakaHIonPhase1 = CAHitNtupletAlpaka; using CAHitNtupletAlpakaPhase2 = CAHitNtupletAlpaka; +using CAHitNtupletAlpakaPhase2OT = CAHitNtupletAlpaka; } // namespace ALPAKA_ACCELERATOR_NAMESPACE #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h" diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc index bd5bccb7d363f..e42a185c0c46b 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc @@ -257,7 +257,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { using namespace caHitNtupletGeneratorKernels; const auto workDiv1D = cms::alpakatools::make_workdiv(1, ll.metadata().size() - 1); - alpaka::exec(queue, workDiv1D, SetHitsLayerStart{}, mm, ll, this->device_layerStarts_->data()); + alpaka::exec(queue, workDiv1D, SetHitsLayerStart{}, mm, ll, this->device_layerStarts_.data()); cms::alpakatools::fillManyFromVector(device_hitPhiHist_->data(), device_hitPhiView_, @@ -810,6 +810,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { this->device_hitContainer_.data(), this->counters_.data()); + workDiv1D = cms::alpakatools::make_workdiv(1,1); alpaka::exec(queue, workDiv1D, Kernel_printCounters{}, this->counters_.data()); alpaka::wait(queue); @@ -827,6 +828,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { 0); alpaka::wait(queue); } + + #ifdef GPU_DEBUG alpaka::wait(queue); #endif @@ -878,5 +881,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { template class CAHitNtupletGeneratorKernels; template class CAHitNtupletGeneratorKernels; template class CAHitNtupletGeneratorKernels; + template class CAHitNtupletGeneratorKernels; } // namespace ALPAKA_ACCELERATOR_NAMESPACE diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h index b1ec09be5f85a..a36421a23cd4e 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h @@ -389,7 +389,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { auto ro = thisCell.outer_r(hh); auto zo = thisCell.outer_z(hh); auto thetaCut = ll[thisCell.innerLayer()].caThetaCut(); - + // loop on inner cells for (uint32_t j : cms::alpakatools::independent_group_elements_x(acc, numberOfPossibleNeighbors)) { auto otherCell = outerHitCells[j]; diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoubletsAlgos.h b/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoubletsAlgos.h index 26b38ca1aa9fb..b63d6afab60bd 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoubletsAlgos.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoubletsAlgos.h @@ -129,17 +129,19 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { } template - ALPAKA_FN_ACC ALPAKA_FN_INLINE void doubletsFromHisto(const TAcc& acc, - uint32_t maxNumOfDoublets, - CACell* cells, - uint32_t* nCells, - HitsConstView hh, - ::reco::CAGraphSoAConstView cc, - ::reco::CALayersSoAConstView ll, - uint32_t const* __restrict__ offsets, - PhiBinner const* phiBinner, - HitToCell* outerHitHisto, - AlgoParams const& params) { + ALPAKA_FN_ACC ALPAKA_FN_INLINE void __attribute__((always_inline)) doubletsFromHisto( + const TAcc& acc, + uint32_t maxNumOfDoublets, + CASimpleCell* cells, + uint32_t* nCells, + HitsConstView hh, + ::reco::CAGraphSoAConstView cc, + ::reco::CALayersSoAConstView ll, + uint32_t const* __restrict__ offsets, + PhiBinner const* phiBinner, + HitToCell* outerHitHisto, + AlgoParams const& params) { + const bool doClusterCut = params.minYsizeB1_ > 0 or params.minYsizeB2_ > 0; const bool doZSizeCut = params.maxDYsize12_ > 0 or params.maxDYsize_ > 0 or params.maxDYPred_ > 0; diff --git a/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc b/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc index 5a081bfb51464..9f821d733c816 100644 --- a/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc +++ b/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc @@ -45,7 +45,7 @@ * objects from the output of SoA CA. */ -// #define GPU_DEBUG +#define GPU_DEBUG class PixelTrackProducerFromSoAAlpaka : public edm::global::EDProducer<> { using TrackSoAHost = reco::TracksHost; From 0266d5026e5dbaf7d95e51665f36ee9113b80f2e Mon Sep 17 00:00:00 2001 From: adriano Date: Sun, 25 May 2025 16:02:04 +0200 Subject: [PATCH 21/40] Simplified SiPixelRecHitExtendedAlpaka logic --- .../interface/SimplePixelTopology.h | 6 +- .../alpaka/SiPixelRecHitExtendedAlpaka.cc | 238 +++++++++--------- 2 files changed, 118 insertions(+), 126 deletions(-) diff --git a/Geometry/CommonTopologies/interface/SimplePixelTopology.h b/Geometry/CommonTopologies/interface/SimplePixelTopology.h index e019b4f1d0bfa..fb6d50eb8188c 100644 --- a/Geometry/CommonTopologies/interface/SimplePixelTopology.h +++ b/Geometry/CommonTopologies/interface/SimplePixelTopology.h @@ -365,7 +365,7 @@ namespace pixelTopology { static constexpr uint32_t maxNumOfActiveDoublets = maxNumberOfDoublets / 8; static constexpr uint32_t maxNumberOfQuadruplets = maxNumberOfTuples; static constexpr uint32_t maxDepth = 12; - static constexpr uint32_t numberOfLayers = 28 + 3; + static constexpr uint32_t numberOfLayers = 28; static constexpr uint32_t maxSizeCluster = 2047; @@ -440,6 +440,10 @@ namespace pixelTopology { static constexpr inline uint16_t localY(uint16_t py) { return py; } }; + struct Phase2OT : public Phase2 { + static constexpr uint32_t numberOfLayers = 28 + 3; //OT Barrel Extension + }; + struct Phase1 { // types using hindex_type = uint32_t; // FIXME from siPixelRecHitsHeterogeneousProduct diff --git a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc index b8f2b1105be24..652daac0a9c77 100644 --- a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc +++ b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc @@ -36,7 +36,7 @@ #include namespace ALPAKA_ACCELERATOR_NAMESPACE { - template + class SiPixelRecHitExtendedAlpaka : public global::EDProducer<> { public: explicit SiPixelRecHitExtendedAlpaka(const edm::ParameterSet& iConfig); @@ -53,15 +53,15 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { const device::EDPutToken outputRecHitsSoAToken_; }; - template - SiPixelRecHitExtendedAlpaka::SiPixelRecHitExtendedAlpaka(const edm::ParameterSet& iConfig) + + SiPixelRecHitExtendedAlpaka::SiPixelRecHitExtendedAlpaka(const edm::ParameterSet& iConfig) : EDProducer(iConfig), pixelRecHitToken_(consumes(iConfig.getParameter("pixelRecHitsSoA"))), trackerRecHitToken_(consumes(iConfig.getParameter("trackerRecHitsSoA"))), outputRecHitsSoAToken_(produces()) {} - template - void SiPixelRecHitExtendedAlpaka::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + + void SiPixelRecHitExtendedAlpaka::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.add("pixelRecHitsSoA", edm::InputTag("hltPhase2SiPixelRecHitsSoA")); @@ -70,10 +70,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { descriptions.addWithDefaultLabel(desc); } - template - void SiPixelRecHitExtendedAlpaka::produce(edm::StreamID streamID, + + void SiPixelRecHitExtendedAlpaka::produce(edm::StreamID streamID, device::Event& iEvent, const device::EventSetup& es) const { + auto queue = iEvent.queue(); // get both Pixel and Tracker recHits const auto& pixelRecHitsSoA = iEvent.get(pixelRecHitToken_); const auto& otRecHitsSoA = iEvent.get(trackerRecHitToken_); @@ -86,188 +87,175 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { std::cout << "Number of Pixel modules: " << pixelRecHitsSoA.nModules() << std::endl; std::cout << "Number of Tracker modules: " << otRecHitsSoA.nModules() << std::endl; const int nTotModules = pixelRecHitsSoA.nModules() + otRecHitsSoA.nModules(); - - auto outputSoA = reco::TrackingRecHitsSoACollection(iEvent.queue(), nTotHits, nTotModules + 1); + + auto outputSoA = reco::TrackingRecHitsSoACollection(queue, nTotHits, nTotModules); std::cout << "Total number of recHits: " << outputSoA.nHits() << std::endl; + + auto pixelBufferExtent = alpaka::getExtentProduct(pixelRecHitsSoA.buffer()); + alpaka::memcpy(queue, outputSoA.buffer(), pixelRecHitsSoA.buffer(), pixelBufferExtent); // copy all columns from pixelRecHitsSoA and otRecHitsSoA to outputSoA // xLocal - auto xLocalOutputPixel = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xLocal(), nPixelHits); + // auto xLocalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().xLocal(), nPixelHits); auto xLocalOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xLocal() + nPixelHits, nTrackerHits); - auto xLocalPixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().xLocal(), nPixelHits); - auto xLocalTracker = cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().xLocal(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), xLocalOutputPixel, xLocalPixel); - alpaka::memcpy(iEvent.queue(), xLocalOutputTracker, xLocalTracker); + cms::alpakatools::make_device_view(queue, outputSoA.view().xLocal() + nPixelHits, nTrackerHits); + // auto xLocalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().xLocal(), nPixelHits); + auto xLocalTracker = cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().xLocal(), nTrackerHits); + // alpaka::memcpy(queue, xLocalOutputPixel, xLocalPixel); + alpaka::memcpy(queue, xLocalOutputTracker, xLocalTracker); // yLocal - auto yLocalOutputPixel = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yLocal(), nPixelHits); + // auto yLocalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().yLocal(), nPixelHits); auto yLocalOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yLocal() + nPixelHits, nTrackerHits); - auto yLocalPixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().yLocal(), nPixelHits); - auto yLocalTracker = cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().yLocal(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), yLocalOutputPixel, yLocalPixel); - alpaka::memcpy(iEvent.queue(), yLocalOutputTracker, yLocalTracker); + cms::alpakatools::make_device_view(queue, outputSoA.view().yLocal() + nPixelHits, nTrackerHits); + // auto yLocalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().yLocal(), nPixelHits); + auto yLocalTracker = cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().yLocal(), nTrackerHits); + // alpaka::memcpy(queue, yLocalOutputPixel, yLocalPixel); + alpaka::memcpy(queue, yLocalOutputTracker, yLocalTracker); // xerrLocal - auto xerrLocalOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xerrLocal(), nPixelHits); + // auto xerrLocalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().xerrLocal(), nPixelHits); auto xerrLocalOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xerrLocal() + nPixelHits, nTrackerHits); - auto xerrLocalPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().xerrLocal(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().xerrLocal() + nPixelHits, nTrackerHits); + // auto xerrLocalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().xerrLocal(), nPixelHits); auto xerrLocalTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().xerrLocal(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), xerrLocalOutputPixel, xerrLocalPixel); - alpaka::memcpy(iEvent.queue(), xerrLocalOutputTracker, xerrLocalTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().xerrLocal(), nTrackerHits); + // alpaka::memcpy(queue, xerrLocalOutputPixel, xerrLocalPixel); + alpaka::memcpy(queue, xerrLocalOutputTracker, xerrLocalTracker); // yerrLocal - auto yerrLocalOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yerrLocal(), nPixelHits); + // auto yerrLocalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().yerrLocal(), nPixelHits); auto yerrLocalOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yerrLocal() + nPixelHits, nTrackerHits); - auto yerrLocalPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().yerrLocal(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().yerrLocal() + nPixelHits, nTrackerHits); + // auto yerrLocalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().yerrLocal(), nPixelHits); auto yerrLocalTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().yerrLocal(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), yerrLocalOutputPixel, yerrLocalPixel); - alpaka::memcpy(iEvent.queue(), yerrLocalOutputTracker, yerrLocalTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().yerrLocal(), nTrackerHits); + // alpaka::memcpy(queue, yerrLocalOutputPixel, yerrLocalPixel); + alpaka::memcpy(queue, yerrLocalOutputTracker, yerrLocalTracker); // xGlobal - auto xGlobalOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xGlobal(), nPixelHits); + // auto xGlobalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().xGlobal(), nPixelHits); auto xGlobalOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xGlobal() + nPixelHits, nTrackerHits); - auto xGlobalPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().xGlobal(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().xGlobal() + nPixelHits, nTrackerHits); + // auto xGlobalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().xGlobal(), nPixelHits); auto xGlobalTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().xGlobal(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), xGlobalOutputPixel, xGlobalPixel); - alpaka::memcpy(iEvent.queue(), xGlobalOutputTracker, xGlobalTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().xGlobal(), nTrackerHits); + // alpaka::memcpy(queue, xGlobalOutputPixel, xGlobalPixel); + alpaka::memcpy(queue, xGlobalOutputTracker, xGlobalTracker); // yGlobal - auto yGlobalOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yGlobal(), nPixelHits); + // auto yGlobalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().yGlobal(), nPixelHits); auto yGlobalOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yGlobal() + nPixelHits, nTrackerHits); - auto yGlobalPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().yGlobal(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().yGlobal() + nPixelHits, nTrackerHits); + // auto yGlobalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().yGlobal(), nPixelHits); auto yGlobalTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().yGlobal(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), yGlobalOutputPixel, yGlobalPixel); - alpaka::memcpy(iEvent.queue(), yGlobalOutputTracker, yGlobalTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().yGlobal(), nTrackerHits); + // alpaka::memcpy(queue, yGlobalOutputPixel, yGlobalPixel); + alpaka::memcpy(queue, yGlobalOutputTracker, yGlobalTracker); // zGlobal - auto zGlobalOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().zGlobal(), nPixelHits); + // auto zGlobalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().zGlobal(), nPixelHits); auto zGlobalOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().zGlobal() + nPixelHits, nTrackerHits); - auto zGlobalPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().zGlobal(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().zGlobal() + nPixelHits, nTrackerHits); + // auto zGlobalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().zGlobal(), nPixelHits); auto zGlobalTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().zGlobal(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), zGlobalOutputPixel, zGlobalPixel); - alpaka::memcpy(iEvent.queue(), zGlobalOutputTracker, zGlobalTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().zGlobal(), nTrackerHits); + // alpaka::memcpy(queue, zGlobalOutputPixel, zGlobalPixel); + alpaka::memcpy(queue, zGlobalOutputTracker, zGlobalTracker); // rGlobal - auto rGlobalOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().rGlobal(), nPixelHits); + // auto rGlobalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().rGlobal(), nPixelHits); auto rGlobalOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().rGlobal() + nPixelHits, nTrackerHits); - auto rGlobalPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().rGlobal(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().rGlobal() + nPixelHits, nTrackerHits); + // auto rGlobalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().rGlobal(), nPixelHits); auto rGlobalTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().rGlobal(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), rGlobalOutputPixel, rGlobalPixel); - alpaka::memcpy(iEvent.queue(), rGlobalOutputTracker, rGlobalTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().rGlobal(), nTrackerHits); + // alpaka::memcpy(queue, rGlobalOutputPixel, rGlobalPixel); + alpaka::memcpy(queue, rGlobalOutputTracker, rGlobalTracker); // iphi - auto iphiOutputPixel = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().iphi(), nPixelHits); + // auto iphiOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().iphi(), nPixelHits); auto iphiOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().iphi() + nPixelHits, nTrackerHits); - auto iphiPixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().iphi(), nPixelHits); - auto iphiTracker = cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().iphi(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), iphiOutputPixel, iphiPixel); - alpaka::memcpy(iEvent.queue(), iphiOutputTracker, iphiTracker); + cms::alpakatools::make_device_view(queue, outputSoA.view().iphi() + nPixelHits, nTrackerHits); + // auto iphiPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().iphi(), nPixelHits); + auto iphiTracker = cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().iphi(), nTrackerHits); + // alpaka::memcpy(queue, iphiOutputPixel, iphiPixel); + alpaka::memcpy(queue, iphiOutputTracker, iphiTracker); // chargeAndStatus - auto chargeAndStatusOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().chargeAndStatus(), nPixelHits); + // auto chargeAndStatusOutputPixel = + // cms::alpakatools::make_device_view(queue, outputSoA.view().chargeAndStatus(), nPixelHits); auto chargeAndStatusOutputTracker = cms::alpakatools::make_device_view( - iEvent.queue(), outputSoA.view().chargeAndStatus() + nPixelHits, nTrackerHits); - auto chargeAndStatusPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().chargeAndStatus(), nPixelHits); + queue, outputSoA.view().chargeAndStatus() + nPixelHits, nTrackerHits); + // auto chargeAndStatusPixel = + // cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().chargeAndStatus(), nPixelHits); auto chargeAndStatusTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().chargeAndStatus(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), chargeAndStatusOutputPixel, chargeAndStatusPixel); - alpaka::memcpy(iEvent.queue(), chargeAndStatusOutputTracker, chargeAndStatusTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().chargeAndStatus(), nTrackerHits); + // alpaka::memcpy(queue, chargeAndStatusOutputPixel, chargeAndStatusPixel); + alpaka::memcpy(queue, chargeAndStatusOutputTracker, chargeAndStatusTracker); // clusterSizeX - auto clusterSizeXOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().clusterSizeX(), nPixelHits); + // auto clusterSizeXOutputPixel = + // cms::alpakatools::make_device_view(queue, outputSoA.view().clusterSizeX(), nPixelHits); auto clusterSizeXOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().clusterSizeX() + nPixelHits, nTrackerHits); - auto clusterSizeXPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().clusterSizeX(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().clusterSizeX() + nPixelHits, nTrackerHits); + // auto clusterSizeXPixel = + // cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().clusterSizeX(), nPixelHits); auto clusterSizeXTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().clusterSizeX(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), clusterSizeXOutputPixel, clusterSizeXPixel); - alpaka::memcpy(iEvent.queue(), clusterSizeXOutputTracker, clusterSizeXTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().clusterSizeX(), nTrackerHits); + // alpaka::memcpy(queue, clusterSizeXOutputPixel, clusterSizeXPixel); + alpaka::memcpy(queue, clusterSizeXOutputTracker, clusterSizeXTracker); // clusterSizeY - auto clusterSizeYOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().clusterSizeY(), nPixelHits); + // auto clusterSizeYOutputPixel = + // cms::alpakatools::make_device_view(queue, outputSoA.view().clusterSizeY(), nPixelHits); auto clusterSizeYOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().clusterSizeY() + nPixelHits, nTrackerHits); - auto clusterSizeYPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().clusterSizeY(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().clusterSizeY() + nPixelHits, nTrackerHits); + // auto clusterSizeYPixel = + // cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().clusterSizeY(), nPixelHits); auto clusterSizeYTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().clusterSizeY(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), clusterSizeYOutputPixel, clusterSizeYPixel); - alpaka::memcpy(iEvent.queue(), clusterSizeYOutputTracker, clusterSizeYTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().clusterSizeY(), nTrackerHits); + // alpaka::memcpy(queue, clusterSizeYOutputPixel, clusterSizeYPixel); + alpaka::memcpy(queue, clusterSizeYOutputTracker, clusterSizeYTracker); // detectorIndex - auto detectorIndexOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().detectorIndex(), nPixelHits); + // auto detectorIndexOutputPixel = + // cms::alpakatools::make_device_view(queue, outputSoA.view().detectorIndex(), nPixelHits); auto detectorIndexOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().detectorIndex() + nPixelHits, nTrackerHits); - auto detectorIndexPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().detectorIndex(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().detectorIndex() + nPixelHits, nTrackerHits); + // auto detectorIndexPixel = + // cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().detectorIndex(), nPixelHits); auto detectorIndexTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().detectorIndex(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), detectorIndexOutputPixel, detectorIndexPixel); - alpaka::memcpy(iEvent.queue(), detectorIndexOutputTracker, detectorIndexTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().detectorIndex(), nTrackerHits); + // alpaka::memcpy(queue, detectorIndexOutputPixel, detectorIndexPixel); + alpaka::memcpy(queue, detectorIndexOutputTracker, detectorIndexTracker); - auto offsetBPIX2Output = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().offsetBPIX2()); - auto offsetBPIX2Pixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().offsetBPIX2()); - alpaka::memcpy(iEvent.queue(), offsetBPIX2Output, offsetBPIX2Pixel); + // auto offsetBPIX2Output = cms::alpakatools::make_device_view(queue, outputSoA.view().offsetBPIX2()); + // auto offsetBPIX2Pixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().offsetBPIX2()); + // alpaka::memcpy(queue, offsetBPIX2Output, offsetBPIX2Pixel); // copy the moduleStart from pixelRecHitsSoA and otRecHitsSoA to outputSoA const int nPixelModules = pixelRecHitsSoA.nModules(); - const int nTrackerModules = otRecHitsSoA.nModules() + 1; + const int nTrackerModules = otRecHitsSoA.nModules(); - auto hitModuleStartOutputPixel = cms::alpakatools::make_device_view( - iEvent.queue(), outputSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); + // auto hitModuleStartOutputPixel = cms::alpakatools::make_device_view( + // queue, outputSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); auto hitModuleStartOutputTracker = cms::alpakatools::make_device_view( - iEvent.queue(), outputSoA.view<::reco::HitModuleSoA>().moduleStart() + nPixelModules, nTrackerModules); + queue, outputSoA.view<::reco::HitModuleSoA>().moduleStart() + nPixelModules, nTrackerModules); - const auto hitModuleStartPixel = cms::alpakatools::make_device_view( - iEvent.queue(), pixelRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); + // const auto hitModuleStartPixel = cms::alpakatools::make_device_view( + // queue, pixelRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); const auto hitModuleStartTracker = cms::alpakatools::make_device_view( - iEvent.queue(), otRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nTrackerModules); + queue, otRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nTrackerModules); - alpaka::memcpy(iEvent.queue(), hitModuleStartOutputPixel, hitModuleStartPixel); - alpaka::memcpy(iEvent.queue(), hitModuleStartOutputTracker, hitModuleStartTracker); + // alpaka::memcpy(queue, hitModuleStartOutputPixel, hitModuleStartPixel); + alpaka::memcpy(queue, hitModuleStartOutputTracker, hitModuleStartTracker); // emplace the merged SoA in the event iEvent.emplace(outputRecHitsSoAToken_, std::move(outputSoA)); } - using SiPixelRecHitExtendedAlpakaPhase1 = SiPixelRecHitExtendedAlpaka; - using SiPixelRecHitExtendedAlpakaHIonPhase1 = SiPixelRecHitExtendedAlpaka; - using SiPixelRecHitExtendedAlpakaPhase2 = SiPixelRecHitExtendedAlpaka; + } // namespace ALPAKA_ACCELERATOR_NAMESPACE #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h" -DEFINE_FWK_ALPAKA_MODULE(SiPixelRecHitExtendedAlpakaPhase1); -DEFINE_FWK_ALPAKA_MODULE(SiPixelRecHitExtendedAlpakaHIonPhase1); -DEFINE_FWK_ALPAKA_MODULE(SiPixelRecHitExtendedAlpakaPhase2); +DEFINE_FWK_ALPAKA_MODULE(SiPixelRecHitExtendedAlpaka); From 2488fe246676b47f125bb4c5f3645a719387a3ff Mon Sep 17 00:00:00 2001 From: adriano Date: Mon, 26 May 2025 02:04:44 +0200 Subject: [PATCH 22/40] Add new TrackerTraits topology --- .../interface/SimplePixelTopology.h | 2 +- .../hltPhase2PixelRecHitsExtendedSoA_cfi.py | 4 +- .../modules/hltPhase2PixelTracksSoA_cfi.py | 12 +- .../alpaka/SiPixelRecHitExtendedAlpaka.cc | 221 +++++++++--------- .../plugins/alpaka/BrokenLineFit.dev.cc | 1 + .../PixelSeeding/plugins/alpaka/CAFishbone.h | 198 +++++++++------- .../plugins/alpaka/CAHitNtuplet.cc | 12 +- .../plugins/alpaka/CAHitNtupletGenerator.cc | 55 +++++ .../alpaka/CAHitNtupletGeneratorKernelsImpl.h | 2 +- .../PixelSeeding/plugins/alpaka/HelixFit.cc | 1 + .../plugins/alpaka/RiemannFit.dev.cc | 1 + 11 files changed, 297 insertions(+), 212 deletions(-) diff --git a/Geometry/CommonTopologies/interface/SimplePixelTopology.h b/Geometry/CommonTopologies/interface/SimplePixelTopology.h index fb6d50eb8188c..7e9816524e068 100644 --- a/Geometry/CommonTopologies/interface/SimplePixelTopology.h +++ b/Geometry/CommonTopologies/interface/SimplePixelTopology.h @@ -10,7 +10,7 @@ namespace pixelTopology { constexpr auto maxNumberOfLadders = 160; constexpr uint8_t maxLayers = 28 + 3; // CA Extension to 3 OT barrel layers - constexpr uint8_t maxPairs = 64; + constexpr uint8_t maxPairs = 64 + 64; // CA // TODO // Once CUDA is dropped this could be wrapped in #ifdef CA_TRIPLETS_HOLE diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelRecHitsExtendedSoA_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelRecHitsExtendedSoA_cfi.py index ddb2d7e54b458..d103e80b83597 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelRecHitsExtendedSoA_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelRecHitsExtendedSoA_cfi.py @@ -1,5 +1,5 @@ import FWCore.ParameterSet.Config as cms -from RecoLocalTracker.SiPixelRecHits.SiPixelRecHitExtendedAlpakaPhase2_alpaka import SiPixelRecHitExtendedAlpakaPhase2_alpaka as _SiPixelRecHitExtendedAlpakaPhase2_alpaka +from RecoLocalTracker.SiPixelRecHits.SiPixelRecHitExtendedAlpaka_alpaka import SiPixelRecHitExtendedAlpaka_alpaka as _SiPixelRecHitExtendedAlpaka_alpaka -hltPhase2PixelRecHitsExtendedSoA = _SiPixelRecHitExtendedAlpakaPhase2_alpaka() \ No newline at end of file +hltPhase2PixelRecHitsExtendedSoA = _SiPixelRecHitExtendedAlpaka_alpaka() diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py index 476034c677644..e0405af677071 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py @@ -1,6 +1,6 @@ import FWCore.ParameterSet.Config as cms -hltPhase2PixelTracksSoA = cms.EDProducer('CAHitNtupletAlpakaPhase2@alpaka', +hltPhase2PixelTracksSoA = cms.EDProducer('CAHitNtupletAlpakaPhase2OT@alpaka', pixelRecHitSrc = cms.InputTag('hltPhase2PixelRecHitsExtendedSoA'), ptmin = cms.double(0.9), hardCurvCut = cms.double(0.0328407225), @@ -9,7 +9,7 @@ fillStatistics = cms.bool(True), minHitsPerNtuplet = cms.uint32(4), maxNumberOfDoublets = cms.string(str(5*512*1024)), - maxNumberOfTuples = cms.string(str(32*1024)), + maxNumberOfTuples = cms.string(str(60*1024)), cellPtCut = cms.double(0.85), cellZ0Cut = cms.double(7.5), minYsizeB1 = cms.int32(25), @@ -17,10 +17,10 @@ maxDYsize12 = cms.int32(12), maxDYsize = cms.int32(10), maxDYPred = cms.int32(20), - avgHitsPerTrack = cms.double(7.0), - avgCellsPerHit = cms.double(6), - avgCellsPerCell = cms.double(0.151), - avgTracksPerCell = cms.double(0.040), + avgHitsPerTrack = cms.double(10.0), + avgCellsPerHit = cms.double(20), + avgCellsPerCell = cms.double(5), + avgTracksPerCell = cms.double(5), minHitsForSharingCut = cms.uint32(10), fitNas4 = cms.bool(False), useRiemannFit = cms.bool(False), diff --git a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc index 652daac0a9c77..302240cad441a 100644 --- a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc +++ b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc @@ -36,7 +36,7 @@ #include namespace ALPAKA_ACCELERATOR_NAMESPACE { - + class SiPixelRecHitExtendedAlpaka : public global::EDProducer<> { public: explicit SiPixelRecHitExtendedAlpaka(const edm::ParameterSet& iConfig); @@ -74,7 +74,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { void SiPixelRecHitExtendedAlpaka::produce(edm::StreamID streamID, device::Event& iEvent, const device::EventSetup& es) const { - auto queue = iEvent.queue(); // get both Pixel and Tracker recHits const auto& pixelRecHitsSoA = iEvent.get(pixelRecHitToken_); const auto& otRecHitsSoA = iEvent.get(trackerRecHitToken_); @@ -87,175 +86,183 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { std::cout << "Number of Pixel modules: " << pixelRecHitsSoA.nModules() << std::endl; std::cout << "Number of Tracker modules: " << otRecHitsSoA.nModules() << std::endl; const int nTotModules = pixelRecHitsSoA.nModules() + otRecHitsSoA.nModules(); - - auto outputSoA = reco::TrackingRecHitsSoACollection(queue, nTotHits, nTotModules); + + auto outputSoA = reco::TrackingRecHitsSoACollection(iEvent.queue(), nTotHits, nTotModules + 1); std::cout << "Total number of recHits: " << outputSoA.nHits() << std::endl; - - auto pixelBufferExtent = alpaka::getExtentProduct(pixelRecHitsSoA.buffer()); - alpaka::memcpy(queue, outputSoA.buffer(), pixelRecHitsSoA.buffer(), pixelBufferExtent); // copy all columns from pixelRecHitsSoA and otRecHitsSoA to outputSoA // xLocal - // auto xLocalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().xLocal(), nPixelHits); + auto xLocalOutputPixel = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xLocal(), nPixelHits); auto xLocalOutputTracker = - cms::alpakatools::make_device_view(queue, outputSoA.view().xLocal() + nPixelHits, nTrackerHits); - // auto xLocalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().xLocal(), nPixelHits); - auto xLocalTracker = cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().xLocal(), nTrackerHits); - // alpaka::memcpy(queue, xLocalOutputPixel, xLocalPixel); - alpaka::memcpy(queue, xLocalOutputTracker, xLocalTracker); + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xLocal() + nPixelHits, nTrackerHits); + auto xLocalPixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().xLocal(), nPixelHits); + auto xLocalTracker = cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().xLocal(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), xLocalOutputPixel, xLocalPixel); + alpaka::memcpy(iEvent.queue(), xLocalOutputTracker, xLocalTracker); // yLocal - // auto yLocalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().yLocal(), nPixelHits); + auto yLocalOutputPixel = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yLocal(), nPixelHits); auto yLocalOutputTracker = - cms::alpakatools::make_device_view(queue, outputSoA.view().yLocal() + nPixelHits, nTrackerHits); - // auto yLocalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().yLocal(), nPixelHits); - auto yLocalTracker = cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().yLocal(), nTrackerHits); - // alpaka::memcpy(queue, yLocalOutputPixel, yLocalPixel); - alpaka::memcpy(queue, yLocalOutputTracker, yLocalTracker); + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yLocal() + nPixelHits, nTrackerHits); + auto yLocalPixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().yLocal(), nPixelHits); + auto yLocalTracker = cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().yLocal(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), yLocalOutputPixel, yLocalPixel); + alpaka::memcpy(iEvent.queue(), yLocalOutputTracker, yLocalTracker); // xerrLocal - // auto xerrLocalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().xerrLocal(), nPixelHits); + auto xerrLocalOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xerrLocal(), nPixelHits); auto xerrLocalOutputTracker = - cms::alpakatools::make_device_view(queue, outputSoA.view().xerrLocal() + nPixelHits, nTrackerHits); - // auto xerrLocalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().xerrLocal(), nPixelHits); + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xerrLocal() + nPixelHits, nTrackerHits); + auto xerrLocalPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().xerrLocal(), nPixelHits); auto xerrLocalTracker = - cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().xerrLocal(), nTrackerHits); - // alpaka::memcpy(queue, xerrLocalOutputPixel, xerrLocalPixel); - alpaka::memcpy(queue, xerrLocalOutputTracker, xerrLocalTracker); + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().xerrLocal(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), xerrLocalOutputPixel, xerrLocalPixel); + alpaka::memcpy(iEvent.queue(), xerrLocalOutputTracker, xerrLocalTracker); // yerrLocal - // auto yerrLocalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().yerrLocal(), nPixelHits); + auto yerrLocalOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yerrLocal(), nPixelHits); auto yerrLocalOutputTracker = - cms::alpakatools::make_device_view(queue, outputSoA.view().yerrLocal() + nPixelHits, nTrackerHits); - // auto yerrLocalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().yerrLocal(), nPixelHits); + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yerrLocal() + nPixelHits, nTrackerHits); + auto yerrLocalPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().yerrLocal(), nPixelHits); auto yerrLocalTracker = - cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().yerrLocal(), nTrackerHits); - // alpaka::memcpy(queue, yerrLocalOutputPixel, yerrLocalPixel); - alpaka::memcpy(queue, yerrLocalOutputTracker, yerrLocalTracker); + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().yerrLocal(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), yerrLocalOutputPixel, yerrLocalPixel); + alpaka::memcpy(iEvent.queue(), yerrLocalOutputTracker, yerrLocalTracker); // xGlobal - // auto xGlobalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().xGlobal(), nPixelHits); + auto xGlobalOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xGlobal(), nPixelHits); auto xGlobalOutputTracker = - cms::alpakatools::make_device_view(queue, outputSoA.view().xGlobal() + nPixelHits, nTrackerHits); - // auto xGlobalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().xGlobal(), nPixelHits); + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xGlobal() + nPixelHits, nTrackerHits); + auto xGlobalPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().xGlobal(), nPixelHits); auto xGlobalTracker = - cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().xGlobal(), nTrackerHits); - // alpaka::memcpy(queue, xGlobalOutputPixel, xGlobalPixel); - alpaka::memcpy(queue, xGlobalOutputTracker, xGlobalTracker); + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().xGlobal(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), xGlobalOutputPixel, xGlobalPixel); + alpaka::memcpy(iEvent.queue(), xGlobalOutputTracker, xGlobalTracker); // yGlobal - // auto yGlobalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().yGlobal(), nPixelHits); + auto yGlobalOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yGlobal(), nPixelHits); auto yGlobalOutputTracker = - cms::alpakatools::make_device_view(queue, outputSoA.view().yGlobal() + nPixelHits, nTrackerHits); - // auto yGlobalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().yGlobal(), nPixelHits); + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yGlobal() + nPixelHits, nTrackerHits); + auto yGlobalPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().yGlobal(), nPixelHits); auto yGlobalTracker = - cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().yGlobal(), nTrackerHits); - // alpaka::memcpy(queue, yGlobalOutputPixel, yGlobalPixel); - alpaka::memcpy(queue, yGlobalOutputTracker, yGlobalTracker); + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().yGlobal(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), yGlobalOutputPixel, yGlobalPixel); + alpaka::memcpy(iEvent.queue(), yGlobalOutputTracker, yGlobalTracker); // zGlobal - // auto zGlobalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().zGlobal(), nPixelHits); + auto zGlobalOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().zGlobal(), nPixelHits); auto zGlobalOutputTracker = - cms::alpakatools::make_device_view(queue, outputSoA.view().zGlobal() + nPixelHits, nTrackerHits); - // auto zGlobalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().zGlobal(), nPixelHits); + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().zGlobal() + nPixelHits, nTrackerHits); + auto zGlobalPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().zGlobal(), nPixelHits); auto zGlobalTracker = - cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().zGlobal(), nTrackerHits); - // alpaka::memcpy(queue, zGlobalOutputPixel, zGlobalPixel); - alpaka::memcpy(queue, zGlobalOutputTracker, zGlobalTracker); + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().zGlobal(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), zGlobalOutputPixel, zGlobalPixel); + alpaka::memcpy(iEvent.queue(), zGlobalOutputTracker, zGlobalTracker); // rGlobal - // auto rGlobalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().rGlobal(), nPixelHits); + auto rGlobalOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().rGlobal(), nPixelHits); auto rGlobalOutputTracker = - cms::alpakatools::make_device_view(queue, outputSoA.view().rGlobal() + nPixelHits, nTrackerHits); - // auto rGlobalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().rGlobal(), nPixelHits); + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().rGlobal() + nPixelHits, nTrackerHits); + auto rGlobalPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().rGlobal(), nPixelHits); auto rGlobalTracker = - cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().rGlobal(), nTrackerHits); - // alpaka::memcpy(queue, rGlobalOutputPixel, rGlobalPixel); - alpaka::memcpy(queue, rGlobalOutputTracker, rGlobalTracker); + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().rGlobal(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), rGlobalOutputPixel, rGlobalPixel); + alpaka::memcpy(iEvent.queue(), rGlobalOutputTracker, rGlobalTracker); // iphi - // auto iphiOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().iphi(), nPixelHits); + auto iphiOutputPixel = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().iphi(), nPixelHits); auto iphiOutputTracker = - cms::alpakatools::make_device_view(queue, outputSoA.view().iphi() + nPixelHits, nTrackerHits); - // auto iphiPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().iphi(), nPixelHits); - auto iphiTracker = cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().iphi(), nTrackerHits); - // alpaka::memcpy(queue, iphiOutputPixel, iphiPixel); - alpaka::memcpy(queue, iphiOutputTracker, iphiTracker); + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().iphi() + nPixelHits, nTrackerHits); + auto iphiPixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().iphi(), nPixelHits); + auto iphiTracker = cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().iphi(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), iphiOutputPixel, iphiPixel); + alpaka::memcpy(iEvent.queue(), iphiOutputTracker, iphiTracker); // chargeAndStatus - // auto chargeAndStatusOutputPixel = - // cms::alpakatools::make_device_view(queue, outputSoA.view().chargeAndStatus(), nPixelHits); + auto chargeAndStatusOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().chargeAndStatus(), nPixelHits); auto chargeAndStatusOutputTracker = cms::alpakatools::make_device_view( - queue, outputSoA.view().chargeAndStatus() + nPixelHits, nTrackerHits); - // auto chargeAndStatusPixel = - // cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().chargeAndStatus(), nPixelHits); + iEvent.queue(), outputSoA.view().chargeAndStatus() + nPixelHits, nTrackerHits); + auto chargeAndStatusPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().chargeAndStatus(), nPixelHits); auto chargeAndStatusTracker = - cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().chargeAndStatus(), nTrackerHits); - // alpaka::memcpy(queue, chargeAndStatusOutputPixel, chargeAndStatusPixel); - alpaka::memcpy(queue, chargeAndStatusOutputTracker, chargeAndStatusTracker); + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().chargeAndStatus(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), chargeAndStatusOutputPixel, chargeAndStatusPixel); + alpaka::memcpy(iEvent.queue(), chargeAndStatusOutputTracker, chargeAndStatusTracker); // clusterSizeX - // auto clusterSizeXOutputPixel = - // cms::alpakatools::make_device_view(queue, outputSoA.view().clusterSizeX(), nPixelHits); + auto clusterSizeXOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().clusterSizeX(), nPixelHits); auto clusterSizeXOutputTracker = - cms::alpakatools::make_device_view(queue, outputSoA.view().clusterSizeX() + nPixelHits, nTrackerHits); - // auto clusterSizeXPixel = - // cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().clusterSizeX(), nPixelHits); + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().clusterSizeX() + nPixelHits, nTrackerHits); + auto clusterSizeXPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().clusterSizeX(), nPixelHits); auto clusterSizeXTracker = - cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().clusterSizeX(), nTrackerHits); - // alpaka::memcpy(queue, clusterSizeXOutputPixel, clusterSizeXPixel); - alpaka::memcpy(queue, clusterSizeXOutputTracker, clusterSizeXTracker); + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().clusterSizeX(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), clusterSizeXOutputPixel, clusterSizeXPixel); + alpaka::memcpy(iEvent.queue(), clusterSizeXOutputTracker, clusterSizeXTracker); // clusterSizeY - // auto clusterSizeYOutputPixel = - // cms::alpakatools::make_device_view(queue, outputSoA.view().clusterSizeY(), nPixelHits); + auto clusterSizeYOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().clusterSizeY(), nPixelHits); auto clusterSizeYOutputTracker = - cms::alpakatools::make_device_view(queue, outputSoA.view().clusterSizeY() + nPixelHits, nTrackerHits); - // auto clusterSizeYPixel = - // cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().clusterSizeY(), nPixelHits); + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().clusterSizeY() + nPixelHits, nTrackerHits); + auto clusterSizeYPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().clusterSizeY(), nPixelHits); auto clusterSizeYTracker = - cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().clusterSizeY(), nTrackerHits); - // alpaka::memcpy(queue, clusterSizeYOutputPixel, clusterSizeYPixel); - alpaka::memcpy(queue, clusterSizeYOutputTracker, clusterSizeYTracker); + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().clusterSizeY(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), clusterSizeYOutputPixel, clusterSizeYPixel); + alpaka::memcpy(iEvent.queue(), clusterSizeYOutputTracker, clusterSizeYTracker); // detectorIndex - // auto detectorIndexOutputPixel = - // cms::alpakatools::make_device_view(queue, outputSoA.view().detectorIndex(), nPixelHits); + auto detectorIndexOutputPixel = + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().detectorIndex(), nPixelHits); auto detectorIndexOutputTracker = - cms::alpakatools::make_device_view(queue, outputSoA.view().detectorIndex() + nPixelHits, nTrackerHits); - // auto detectorIndexPixel = - // cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().detectorIndex(), nPixelHits); + cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().detectorIndex() + nPixelHits, nTrackerHits); + auto detectorIndexPixel = + cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().detectorIndex(), nPixelHits); auto detectorIndexTracker = - cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().detectorIndex(), nTrackerHits); - // alpaka::memcpy(queue, detectorIndexOutputPixel, detectorIndexPixel); - alpaka::memcpy(queue, detectorIndexOutputTracker, detectorIndexTracker); + cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().detectorIndex(), nTrackerHits); + alpaka::memcpy(iEvent.queue(), detectorIndexOutputPixel, detectorIndexPixel); + alpaka::memcpy(iEvent.queue(), detectorIndexOutputTracker, detectorIndexTracker); - // auto offsetBPIX2Output = cms::alpakatools::make_device_view(queue, outputSoA.view().offsetBPIX2()); - // auto offsetBPIX2Pixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().offsetBPIX2()); - // alpaka::memcpy(queue, offsetBPIX2Output, offsetBPIX2Pixel); + auto offsetBPIX2Output = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().offsetBPIX2()); + auto offsetBPIX2Pixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().offsetBPIX2()); + alpaka::memcpy(iEvent.queue(), offsetBPIX2Output, offsetBPIX2Pixel); // copy the moduleStart from pixelRecHitsSoA and otRecHitsSoA to outputSoA const int nPixelModules = pixelRecHitsSoA.nModules(); - const int nTrackerModules = otRecHitsSoA.nModules(); + const int nTrackerModules = otRecHitsSoA.nModules() + 1; - // auto hitModuleStartOutputPixel = cms::alpakatools::make_device_view( - // queue, outputSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); + auto hitModuleStartOutputPixel = cms::alpakatools::make_device_view( + iEvent.queue(), outputSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); auto hitModuleStartOutputTracker = cms::alpakatools::make_device_view( - queue, outputSoA.view<::reco::HitModuleSoA>().moduleStart() + nPixelModules, nTrackerModules); + iEvent.queue(), outputSoA.view<::reco::HitModuleSoA>().moduleStart() + nPixelModules, nTrackerModules); - // const auto hitModuleStartPixel = cms::alpakatools::make_device_view( - // queue, pixelRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); + const auto hitModuleStartPixel = cms::alpakatools::make_device_view( + iEvent.queue(), pixelRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); const auto hitModuleStartTracker = cms::alpakatools::make_device_view( - queue, otRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nTrackerModules); + iEvent.queue(), otRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nTrackerModules); - // alpaka::memcpy(queue, hitModuleStartOutputPixel, hitModuleStartPixel); - alpaka::memcpy(queue, hitModuleStartOutputTracker, hitModuleStartTracker); + alpaka::memcpy(iEvent.queue(), hitModuleStartOutputPixel, hitModuleStartPixel); + alpaka::memcpy(iEvent.queue(), hitModuleStartOutputTracker, hitModuleStartTracker); // emplace the merged SoA in the event iEvent.emplace(outputRecHitsSoAToken_, std::move(outputSoA)); } - } // namespace ALPAKA_ACCELERATOR_NAMESPACE #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h" -DEFINE_FWK_ALPAKA_MODULE(SiPixelRecHitExtendedAlpaka); +DEFINE_FWK_ALPAKA_MODULE(SiPixelRecHitExtendedAlpaka); \ No newline at end of file diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/BrokenLineFit.dev.cc b/RecoTracker/PixelSeeding/plugins/alpaka/BrokenLineFit.dev.cc index 60317b3da3fd6..841ae7a74b6dd 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/BrokenLineFit.dev.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/BrokenLineFit.dev.cc @@ -418,6 +418,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { template class HelixFit; template class HelixFit; + template class HelixFit; template class HelixFit; } // namespace ALPAKA_ACCELERATOR_NAMESPACE diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAFishbone.h b/RecoTracker/PixelSeeding/plugins/alpaka/CAFishbone.h index 2a2523c26baec..e2fb9608014c9 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAFishbone.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAFishbone.h @@ -17,19 +17,9 @@ #include "CACell.h" #include "CAStructures.h" -namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { +//#define GPU_DEBUG - using namespace ::caStructures; - template - using CellNeighbors = caStructures::CellNeighborsT; - template - using CellTracks = caStructures::CellTracksT; - template - using CellNeighborsVector = caStructures::CellNeighborsVectorT; - template - using CellTracksVector = caStructures::CellTracksVectorT; - template - using OuterHitOfCell = caStructures::OuterHitOfCellT; +namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { using HitToCell = caStructures::GenericContainer; using CellToTracks = caStructures::GenericContainer; @@ -41,35 +31,19 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { HitsConstView hh, CACell* cells, uint32_t const* __restrict__ nCells, - // OuterHitOfCell const* isOuterHitOfCellWrap, HitToCell const* __restrict__ outerHitHisto, CellToTracks const* __restrict__ cellTracksHisto, uint32_t outerHits, bool checkTrack) const { - constexpr auto maxCellsPerHit = TrackerTraits::maxCellsPerHit; - - // auto const isOuterHitOfCell = isOuterHitOfCellWrap->container; - - float x[maxCellsPerHit], y[maxCellsPerHit], z[maxCellsPerHit], n[maxCellsPerHit]; - uint32_t cc[maxCellsPerHit]; - uint16_t d[maxCellsPerHit]; - uint8_t l[maxCellsPerHit]; - // outermost parallel loop, using all grid elements along the slower dimension (Y or 0 in a 2D grid) for (uint32_t idy : cms::alpakatools::uniform_elements_y(acc, outerHits)) { - // auto const& vc = isOuterHitOfCell[idy]; - uint32_t size = outerHitHisto->size(idy); //TODO have this offset in the histo building directly -// #ifdef GPU_DEBUG -// printf("hist %d histSize %d \n",idy,size); -// #endif - // printf("fishbone ---> outerhit %d size %d - ",idy,size); + uint32_t size = outerHitHisto->size(idy); + // printf("fishbone ---> outersize %d - ",idy,size); if (size < 2) continue; - + auto const* __restrict__ bin = outerHitHisto->begin(idy); - auto const* __restrict__ end = outerHitHisto->end(idy); - auto const nInBin = end - bin; // if alligned kill one of the two. // in principle one could try to relax the cut (only in r-z?) for jumping-doublets @@ -77,71 +51,96 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { auto xo = c0.outer_x(hh); auto yo = c0.outer_y(hh); auto zo = c0.outer_z(hh); - auto sg = 0; - //printf("first cell %d x0 %.2f y0 %.2f z0 %.2f - ",bin[0],c0.outer_x(hh),c0.outer_y(hh),c0.outer_z(hh)); - - // this could be moved below - // precomputing these here has - // the advantage we then loop on less - // entries but we can anyway skip them below and avoid having - // the arrays above - -// #ifdef GPU_DEBUG -// for (auto idx = 0u; idx < size; idx++) { -// unsigned int otherCell = bin[idx]; -// printf("vc[0] %d idx %d vc[idx] %d otherCell %d \n",vc[0],idx,vc[idx],otherCell); -// } -// #endif - for (auto idx = 0u; idx < nInBin; idx++) { - // for (int32_t ic = 0; ic < size; ++ic) { - // for (auto ic = 0u; ic < size; ic++) { - unsigned int otherCell = bin[idx]; - auto& ci = cells[otherCell];//vc[ic]]; - // unsigned int otherCell = bin[ic] - nHitsBPix1; - // auto& ci = cells[otherCell]; + //printf("first cell %d xo %.2f yo %.2f zo %.2f - ",bin[0],c0.outer_x(hh),c0.outer_y(hh),c0.outer_z(hh));ve + + // #ifdef GPU_DEBUG + // for (auto idx = 0u; idx < size; idx++) { + // unsigned int otherCell = bin[idx]; + // printf("vc[0] %d idx %d vc[idx] %d otherCell %d \n",vc[0],idx,vc[idx],otherCell); + // } + // #endif + for (uint32_t ic : cms::alpakatools::independent_group_elements_x(acc, size)) { + //printf("cell0 = %d ci = %d\n",bin[0],bin[ic]); + unsigned int otherCell = bin[ic]; + auto& ci = cells[otherCell]; + // printf("xo = %.2f yo = %.2f zo = %.2f xi = %.2f yi = %.2f zi = %.2f \n",xo,yo,zo,ci.inner_x(hh),ci.inner_y(hh),ci.inner_z(hh)); if (ci.unused()) continue; // for triplets equivalent to next - if (checkTrack && cellTracksHisto->size(otherCell) == 0)//ci.tracks().empty()) + if (checkTrack && cellTracksHisto->size(otherCell) == 0) continue; - cc[sg] = otherCell;//vc[ic]; - l[sg] = ci.layerPairId(); - d[sg] = ci.inner_detIndex(hh); - x[sg] = ci.inner_x(hh) - xo; - y[sg] = ci.inner_y(hh) - yo; - z[sg] = ci.inner_z(hh) - zo; - n[sg] = x[sg] * x[sg] + y[sg] * y[sg] + z[sg] * z[sg]; - ++sg; - //printf("sg %d idx %d cell %d x %.2f y %.2f z %.2f - ",sg,idx,otherCell,x[sg],y[sg],z[sg]); - } - //printf("\n"); - if (sg < 2) - continue; - // innermost parallel loop, using the block elements along the faster dimension (X or 1 in a 2D grid) - for (uint32_t ic : cms::alpakatools::independent_group_elements_x(acc, sg - 1)) { - auto& ci = cells[cc[ic]]; - for (auto jc = ic + 1; (int)jc < sg; ++jc) { - auto& cj = cells[cc[jc]]; - // must be different detectors (in the same layer) - // if (d[ic]==d[jc]) continue; - auto cos12 = x[ic] * x[jc] + y[ic] * y[jc] + z[ic] * z[jc]; - - // cos12 * cos12 could go after d[ic] != d[jc] - if (d[ic] != d[jc] && cos12 * cos12 >= 0.99999f * (n[ic] * n[jc])) { + float x1 = (ci.inner_x(hh) - xo); + float y1 = (ci.inner_y(hh) - yo); + float z1 = (ci.inner_z(hh) - zo); + float n1 = x1 * x1 + y1 * y1 + z1 * z1; + + for (auto jc = ic + 1; jc < size; ++jc) { + unsigned int nextCell = bin[jc]; + auto& cj = cells[nextCell]; + if (cj.unused()) + continue; + if (checkTrack && cellTracksHisto->size(nextCell) == 0) + continue; +#ifdef GPU_DEBUG + printf("xx = %.2f yo = %.2f zo = %.2f xi = %.2f yi = %.2f zi = %.2f xj = %.2f yj = %.2f zj = %.2f\n", + xo, + yo, + zo, + ci.inner_x(hh), + ci.inner_y(hh), + ci.inner_z(hh), + cj.inner_x(hh), + cj.inner_y(hh), + cj.inner_z(hh)); +#endif + + if (ci.inner_detIndex(hh) == cj.inner_detIndex(hh)) + continue; + + float x2 = (cj.inner_x(hh) - xo); + float y2 = (cj.inner_y(hh) - yo); + float z2 = (cj.inner_z(hh) - zo); + float n2 = x2 * x2 + y2 * y2 + z2 * z2; + + auto cos12 = x1 * x2 + y1 * y2 + z1 * z2; + + if (cos12 * cos12 >= 0.99999f * (n1 * n2)) { // alligned: kill farthest (prefer consecutive layers) // if same layer prefer farthest (longer level arm) and make space for intermediate hit - bool sameLayer = l[ic] == l[jc]; - if (n[ic] > n[jc]) { + bool sameLayer = int(ci.layerPairId()) == int(cj.layerPairId()); + if (n1 > n2) { if (sameLayer) { cj.kill(); // closest + ci.setFishbone(acc, cj.inner_hit_id(), cj.inner_z(hh), hh); #ifdef GPU_DEBUG -printf("hit %d same layer cell %d kill %d \n",idy,cc[ic],cc[jc]); + printf( + "n1>n2 lic = %d ljc = %d dic = %.2f djc = %.2f cell %d kill %d cos = %.7f n1 = %.3f n2 = %.3f " + "same\n", + int(ci.layerPairId()), + int(cj.layerPairId()), + ci.inner_detIndex(hh), + cj.inner_detIndex(hh), + bin[ic], + bin[jc], + cos12 * cos12 / (n1 * n2), + n1, + n2); #endif - ci.setFishbone(acc, cj.inner_hit_id(), cj.inner_z(hh), hh); } else { ci.kill(); // farthest #ifdef GPU_DEBUG -printf("hit %d same layer cell %d kill %d \n",idy,cc[jc],cc[ic]); + printf( + "n1>n2 lic = %d ljc = %d dic = %.2f djc = %.2f cell %d kill %d cos = %.7f n1 = %.3f n2 = %.3f " + "diff\n", + int(ci.layerPairId()), + int(cj.layerPairId()), + ci.inner_detIndex(hh), + cj.inner_detIndex(hh), + bin[jc], + bin[ic], + cos12 * cos12 / (n1 * n2), + n1, + n2); #endif // break; // removed to improve reproducibility, keep it for reference and tests } @@ -149,18 +148,40 @@ printf("hit %d same layer cell %d kill %d \n",idy,cc[jc],cc[ic]); if (!sameLayer) { cj.kill(); // farthest #ifdef GPU_DEBUG -printf("hit %d diff layer cell %d kill %d \n",idy,cc[ic],cc[jc]); -#endif + printf( + "n2>n1 lic = %d ljc = %d dic = %.2f djc = %.2f cell %d kill %d cos = %.7f n1 = %.3f n2 = %.3f " + "diff\n", + int(ci.layerPairId()), + int(cj.layerPairId()), + ci.inner_detIndex(hh), + cj.inner_detIndex(hh), + bin[ic], + bin[jc], + cos12 * cos12 / (n1 * n2), + n1, + n2); +#endif } else { ci.kill(); // closest + cj.setFishbone(acc, ci.inner_hit_id(), ci.inner_z(hh), hh); #ifdef GPU_DEBUG -printf("hit %d diff layer cell %d kill %d \n",idy,cc[jc],cc[ic]); + printf( + "n2>n1 lic = %d ljc = %d dic = %.2f djc = %.2f cell %d kill %d cos = %.7f n1 = %.3f n2 = %.3f " + "same\n", + int(ci.layerPairId()), + int(cj.layerPairId()), + ci.inner_detIndex(hh), + cj.inner_detIndex(hh), + bin[jc], + bin[ic], + cos12 * cos12 / (n1 * n2), + n1, + n2); #endif - cj.setFishbone(acc, ci.inner_hit_id(), ci.inner_z(hh), hh); // break; // removed to improve reproducibility, keep it for reference and tests } } - } + } // cos } // cj } // ci } // hits @@ -170,4 +191,3 @@ printf("hit %d diff layer cell %d kill %d \n",idy,cc[jc],cc[ic]); } // namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets #endif // RecoTracker_PixelSeeding_plugins_alpaka_CAFishbone_h - diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc index cd1546bc95677..c2e2ffca88d86 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc @@ -37,7 +37,7 @@ #include "RecoTracker/PixelSeeding/interface/CAGeometrySoA.h" #include "DataFormats/SiStripDetId/interface/StripSubdetector.h" -// #define GPU_DEBUG +#define GPU_DEBUG namespace reco { struct CAGeometryParams { @@ -79,7 +79,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { using HitsConstView = ::reco::TrackingRecHitConstView; using HitsOnDevice = reco::TrackingRecHitsSoACollection; using HitsOnHost = ::reco::TrackingRecHitHost; - using TkSoAHost = ::reco::TracksHost; using TkSoADevice = reco::TracksSoACollection; @@ -163,7 +162,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { || trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF || trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF3D); }; - if constexpr (std::is_base_of_v) { + if constexpr (std::is_base_of_v) { int counter = 0; for (auto& det : dets) { DetId detid = det->geographicalId(); @@ -287,8 +286,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { return std::make_shared(std::move(product)); } - static std::unique_ptr<::reco::CAGeoemtryParams> initializeGlobalCache(edm::ParameterSet const& iConfig) { - return std::make_unique<::reco::CAGeoemtryParams>(iConfig.getParameterSet("geometry")); + static std::unique_ptr<::reco::CAGeometryParams> initializeGlobalCache(edm::ParameterSet const& iConfig) { + return std::make_unique<::reco::CAGeometryParams>(iConfig.getParameterSet("geometry")); } private: @@ -303,7 +302,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { template CAHitNtupletAlpaka::CAHitNtupletAlpaka(const edm::ParameterSet& iConfig, - const ::reco::CAGeoemtryParams* iCache) + const ::reco::CAGeometryParams* iCache) : EDProducer(iConfig), tokenField_(esConsumes()), tokenHit_(consumes(iConfig.getParameter("pixelRecHitSrc"))), @@ -352,3 +351,4 @@ using CAHitNtupletAlpakaPhase2OT = CAHitNtupletAlpaka; DEFINE_FWK_ALPAKA_MODULE(CAHitNtupletAlpakaPhase1); DEFINE_FWK_ALPAKA_MODULE(CAHitNtupletAlpakaHIonPhase1); DEFINE_FWK_ALPAKA_MODULE(CAHitNtupletAlpakaPhase2); +DEFINE_FWK_ALPAKA_MODULE(CAHitNtupletAlpakaPhase2OT); diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGenerator.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGenerator.cc index 4e205ba95f6b3..33291ac460060 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGenerator.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGenerator.cc @@ -415,6 +415,60 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { "Zip)."); } + // TODO: fill me properly + template <> + void CAHitNtupletGenerator::fillPSetDescription(edm::ParameterSetDescription& desc) { + + fillDescriptionsCommon(desc); + + edm::ParameterSetDescription trackQualityCuts; + trackQualityCuts.add("maxChi2", 5.)->setComment("Max normalized chi2"); + trackQualityCuts.add("minPt", 0.5)->setComment("Min pT in GeV"); + trackQualityCuts.add("maxTip", 0.3)->setComment("Max |Tip| in cm"); + trackQualityCuts.add("maxZip", 12.)->setComment("Max |Zip|, in cm"); + desc.add("trackQualityCuts", trackQualityCuts) + ->setComment( + "Quality cuts based on the results of the track fit:\n - apply cuts based on the fit results (pT, Tip, " + "Zip)."); + + edm::ParameterSetDescription geometryParams; + using namespace phase2PixelTopology; + // layers params + geometryParams + .add>("caDCACuts", + std::vector(std::begin(dcaCuts), std::begin(dcaCuts) + numberOfLayers)) + ->setComment("Cut on RZ alignement. One per layer, the layer being the middle one for a triplet."); + geometryParams + .add>("caThetaCuts", + std::vector(std::begin(thetaCuts), std::begin(thetaCuts) + numberOfLayers)) + ->setComment("Cut on origin radius. One per layer, the layer being the innermost one for a triplet."); + geometryParams + .add>("startingPairs", {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}) + ->setComment( + "The list of the ids of pairs from which the CA ntuplets building may start."); //TODO could be parsed via an expression + // cells params + geometryParams + .add>("pairGraph", + std::vector(std::begin(layerPairs), std::begin(layerPairs) + (nPairs * 2))) + ->setComment("CA graph"); + geometryParams + .add>("phiCuts", std::vector(std::begin(phicuts), std::begin(phicuts) + nPairs)) + ->setComment("Cuts in phi for cells"); + geometryParams.add>("minZ", std::vector(std::begin(minz), std::begin(minz) + nPairs)) + ->setComment("Cuts in min z (on inner hit) for cells"); + geometryParams.add>("maxZ", std::vector(std::begin(maxz), std::begin(maxz) + nPairs)) + ->setComment("Cuts in max z (on inner hit) for cells"); + geometryParams.add>("maxR", std::vector(std::begin(maxr), std::begin(maxr) + nPairs)) + ->setComment("Cuts in max r for cells"); + + desc.add("geometry", geometryParams) + ->setComment( + "Quality cuts based on the results of the track fit:\n - apply cuts based on the fit results (pT, Tip, " + "Zip)."); + + } + template reco::TracksSoACollection CAHitNtupletGenerator::makeTuplesAsync(HitsOnDevice const& hits_d, CAGeometryOnDevice const& geometry_d, @@ -482,5 +536,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { template class CAHitNtupletGenerator; template class CAHitNtupletGenerator; + template class CAHitNtupletGenerator; template class CAHitNtupletGenerator; } // namespace ALPAKA_ACCELERATOR_NAMESPACE diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h index a36421a23cd4e..a474541c42c22 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h @@ -1,7 +1,7 @@ #ifndef RecoTracker_PixelSeeding_plugins_alpaka_CAHitNtupletGeneratorKernelsImpl_h #define RecoTracker_PixelSeeding_plugins_alpaka_CAHitNtupletGeneratorKernelsImpl_h -// #define GPU_DEBUG +#define GPU_DEBUG // #define NTUPLE_DEBUG // #define CA_DEBUG // #define CA_WARNINGS diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/HelixFit.cc b/RecoTracker/PixelSeeding/plugins/alpaka/HelixFit.cc index 9185bd8b2fb94..20a032d113c35 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/HelixFit.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/HelixFit.cc @@ -20,5 +20,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { template class HelixFit; template class HelixFit; + template class HelixFit; template class HelixFit; } // namespace ALPAKA_ACCELERATOR_NAMESPACE diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/RiemannFit.dev.cc b/RecoTracker/PixelSeeding/plugins/alpaka/RiemannFit.dev.cc index e1ecf5825b106..d255840a613c4 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/RiemannFit.dev.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/RiemannFit.dev.cc @@ -389,6 +389,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { template class HelixFit; template class HelixFit; + template class HelixFit; template class HelixFit; } // namespace ALPAKA_ACCELERATOR_NAMESPACE From 1eee46a0b4a9e61d2bdcf102ea9ea9cf5fb970d4 Mon Sep 17 00:00:00 2001 From: adriano Date: Mon, 26 May 2025 13:50:07 +0200 Subject: [PATCH 23/40] Code formats --- .../interface/ClusteringConstants.h | 3 +- .../interface/TrackingRecHitsDevice.h | 1 - .../interface/SimplePixelTopology.h | 6 +- .../alpaka/Phase2OTRecHitsSoAConverter.cc | 370 ++++++++-------- .../alpaka/SiPixelRecHitExtendedAlpaka.cc | 9 +- .../plugins/alpaka/CAHitNtuplet.cc | 410 +++++++++--------- .../plugins/alpaka/CAHitNtupletGenerator.cc | 6 +- .../CAHitNtupletGeneratorKernels.dev.cc | 8 +- .../alpaka/CAHitNtupletGeneratorKernelsImpl.h | 87 ++-- 9 files changed, 454 insertions(+), 446 deletions(-) diff --git a/DataFormats/SiPixelClusterSoA/interface/ClusteringConstants.h b/DataFormats/SiPixelClusterSoA/interface/ClusteringConstants.h index da219c63919e6..d2db8b10f5e88 100644 --- a/DataFormats/SiPixelClusterSoA/interface/ClusteringConstants.h +++ b/DataFormats/SiPixelClusterSoA/interface/ClusteringConstants.h @@ -23,7 +23,8 @@ namespace pixelClustering { constexpr uint16_t clusterThresholdPhase2OtherLayers = 4000; constexpr uint32_t maxNumDigis = 3 * 256 * 1024; // @PU=200 µ=530k σ=50k this is >4σ away - constexpr uint16_t maxNumModules = 5000 + 2872; // This is an upperlimit taking into account D110 has 4000 modules + 3 layer of OT for CA Extension + constexpr uint16_t maxNumModules = + 5000 + 2872; // This is an upperlimit taking into account D110 has 4000 modules + 3 layer of OT for CA Extension constexpr int32_t maxNumClustersPerModules = maxHitsInModule(); constexpr uint16_t invalidModuleId = std::numeric_limits::max() - 1; diff --git a/DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsDevice.h b/DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsDevice.h index d2dfc4a314141..96455bf938a87 100644 --- a/DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsDevice.h +++ b/DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsDevice.h @@ -33,7 +33,6 @@ namespace reco { : HitPortableCollectionDevice({{int(nHits), int(nModules + 1)}}, queue) {} // N.B. why this + 1? Because the HitModulesLayout is holding the - // N.B. why this + 1? Because the HitModulesLayout is holding the // moduleStart vector that is a cumulative sum of all the hits // in each module. The extra element of the array (the last one) // is used to hold the total number of hits. We are "hiding" this diff --git a/Geometry/CommonTopologies/interface/SimplePixelTopology.h b/Geometry/CommonTopologies/interface/SimplePixelTopology.h index 7e9816524e068..be68e240bf3ce 100644 --- a/Geometry/CommonTopologies/interface/SimplePixelTopology.h +++ b/Geometry/CommonTopologies/interface/SimplePixelTopology.h @@ -9,8 +9,8 @@ namespace pixelTopology { constexpr auto maxNumberOfLadders = 160; - constexpr uint8_t maxLayers = 28 + 3; // CA Extension to 3 OT barrel layers - constexpr uint8_t maxPairs = 64 + 64; // CA + constexpr uint8_t maxLayers = 28 + 3; // CA Extension to 3 OT barrel layers + constexpr uint8_t maxPairs = 64 + 64; // CA // TODO // Once CUDA is dropped this could be wrapped in #ifdef CA_TRIPLETS_HOLE @@ -441,7 +441,7 @@ namespace pixelTopology { }; struct Phase2OT : public Phase2 { - static constexpr uint32_t numberOfLayers = 28 + 3; //OT Barrel Extension + static constexpr uint32_t numberOfLayers = 28 + 3; //OT Barrel Extension }; struct Phase1 { diff --git a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc index 9692b8ce18c78..ed64e782033e3 100644 --- a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc +++ b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc @@ -30,141 +30,134 @@ #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h" - namespace ALPAKA_ACCELERATOR_NAMESPACE { -class Phase2OTRecHitsSoAConverter : public stream::EDProducer<> { - - using Hits = reco::TrackingRecHitsSoACollection; - using HitsHost = ::reco::TrackingRecHitHost; - using HMSstorage = typename std::vector; - -public: - explicit Phase2OTRecHitsSoAConverter(const edm::ParameterSet& iConfig); - ~Phase2OTRecHitsSoAConverter() override = default; - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - -private: - void produce(device::Event& iEvent, const device::EventSetup& es) override; - - const edm::ESGetToken geomToken_; - const edm::EDGetTokenT recHitToken_; - const edm::EDGetTokenT<::reco::BeamSpot> beamSpotToken_; - const edm::EDGetTokenT pixelHitsSoA_; - - const device::EDPutToken stripSoADevice_; - const edm::EDPutTokenT hitModuleStart_; -}; - - -Phase2OTRecHitsSoAConverter::Phase2OTRecHitsSoAConverter(const edm::ParameterSet& iConfig) - : stream::EDProducer<>(iConfig), - geomToken_(esConsumes()), - recHitToken_{consumes(iConfig.getParameter("otRecHitSource"))}, - beamSpotToken_(consumes<::reco::BeamSpot>(iConfig.getParameter("beamSpot"))), - pixelHitsSoA_{consumes(iConfig.getParameter("pixelRecHitSoASource"))}, - stripSoADevice_{produces()}, - hitModuleStart_{produces()} { } + class Phase2OTRecHitsSoAConverter : public stream::EDProducer<> { + using Hits = reco::TrackingRecHitsSoACollection; + using HitsHost = ::reco::TrackingRecHitHost; + using HMSstorage = typename std::vector; + public: + explicit Phase2OTRecHitsSoAConverter(const edm::ParameterSet& iConfig); + ~Phase2OTRecHitsSoAConverter() override = default; -void Phase2OTRecHitsSoAConverter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - edm::ParameterSetDescription desc; + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - desc.add("pixelRecHitSoASource", edm::InputTag("hltPhase2SiPixelRecHitsSoA")); - desc.add("otRecHitSource", edm::InputTag("hltSiPhase2RecHits")); - desc.add("beamSpot", edm::InputTag("hltOnlineBeamSpot")); + private: + void produce(device::Event& iEvent, const device::EventSetup& es) override; - descriptions.addWithDefaultLabel(desc); + const edm::ESGetToken geomToken_; + const edm::EDGetTokenT recHitToken_; + const edm::EDGetTokenT<::reco::BeamSpot> beamSpotToken_; + const edm::EDGetTokenT pixelHitsSoA_; -} - -//https://github.com/cms-sw/cmssw/blob/3f06ef32d66bd2a7fa04e411fa4db4845193bd3c/RecoTracker/MkFit/plugins/convertHits.h - -void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSetup const& iSetup) { + const device::EDPutToken stripSoADevice_; + const edm::EDPutTokenT hitModuleStart_; + }; - auto queue = iEvent.queue(); - auto& bs = iEvent.get(beamSpotToken_); - const auto &trackerGeometry = &iSetup.getData(geomToken_); - auto const& stripHits = iEvent.get(recHitToken_); + Phase2OTRecHitsSoAConverter::Phase2OTRecHitsSoAConverter(const edm::ParameterSet& iConfig) + : stream::EDProducer<>(iConfig), + geomToken_(esConsumes()), + recHitToken_{consumes(iConfig.getParameter("otRecHitSource"))}, + beamSpotToken_(consumes<::reco::BeamSpot>(iConfig.getParameter("beamSpot"))), + pixelHitsSoA_{consumes(iConfig.getParameter("pixelRecHitSoASource"))}, + stripSoADevice_{produces()}, + hitModuleStart_{produces()} {} - auto const& pixelHitsHost = iEvent.get(pixelHitsSoA_); - int nPixelHits = pixelHitsHost.view().metadata().size(); + void Phase2OTRecHitsSoAConverter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; - // Count strip hits and active strip modules - const int nStripHits = stripHits.data().size(); - const int activeStripModules = stripHits.size(); + desc.add("pixelRecHitSoASource", edm::InputTag("hltPhase2SiPixelRecHitsSoA")); + desc.add("otRecHitSource", edm::InputTag("hltSiPhase2RecHits")); + desc.add("beamSpot", edm::InputTag("hltOnlineBeamSpot")); - auto isPinPSinOTBarrel = [&](DetId detId) { -// std::cout << (int)trackerGeometry->getDetectorType(detId) << " " << (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP) << "\n"; -// std::cout << (int)detId.subdetId() << " " << (detId.subdetId() == StripSubdetector::TOB) << std::endl; - // Select only P-hits from the OT barrel - return (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP && - detId.subdetId() == StripSubdetector::TOB); - }; - auto isPh2Pixel = [&](DetId detId) { - return (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXB - || trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXB3D - || trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF - || trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF3D); - }; + descriptions.addWithDefaultLabel(desc); + } - auto const& detUnits = trackerGeometry->detUnits(); - std::map detIdToIndex; - std::set p_modulesInPSInOTBarrel; - int modulesInPixel = 0; -// auto subSystem = GeomDetEnumerators::P2OTEC; -// auto subSystemName = GeomDetEnumerators::tkDetEnum[subSystem]; -// modulesInPixel += trackerGeometry->offsetDU(subSystemName); - - for (auto& detUnit : detUnits) - { - DetId detId(detUnit->geographicalId()); - if (isPh2Pixel(detId)) + //https://github.com/cms-sw/cmssw/blob/3f06ef32d66bd2a7fa04e411fa4db4845193bd3c/RecoTracker/MkFit/plugins/convertHits.h + + void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSetup const& iSetup) { + auto queue = iEvent.queue(); + auto& bs = iEvent.get(beamSpotToken_); + const auto& trackerGeometry = &iSetup.getData(geomToken_); + auto const& stripHits = iEvent.get(recHitToken_); + + auto const& pixelHitsHost = iEvent.get(pixelHitsSoA_); + int nPixelHits = pixelHitsHost.view().metadata().size(); + + // Count strip hits and active strip modules + const int nStripHits = stripHits.data().size(); + const int activeStripModules = stripHits.size(); + + auto isPinPSinOTBarrel = [&](DetId detId) { + // std::cout << (int)trackerGeometry->getDetectorType(detId) << " " << (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP) << "\n"; + // std::cout << (int)detId.subdetId() << " " << (detId.subdetId() == StripSubdetector::TOB) << std::endl; + // Select only P-hits from the OT barrel + return (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP && + detId.subdetId() == StripSubdetector::TOB); + }; + auto isPh2Pixel = [&](DetId detId) { + return (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXB || + trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXB3D || + trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF || + trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF3D); + }; + + auto const& detUnits = trackerGeometry->detUnits(); + std::map detIdToIndex; + std::set p_modulesInPSInOTBarrel; + int modulesInPixel = 0; + // auto subSystem = GeomDetEnumerators::P2OTEC; + // auto subSystemName = GeomDetEnumerators::tkDetEnum[subSystem]; + // modulesInPixel += trackerGeometry->offsetDU(subSystemName); + + for (auto& detUnit : detUnits) { + DetId detId(detUnit->geographicalId()); + if (isPh2Pixel(detId)) modulesInPixel++; - if (isPinPSinOTBarrel(detId)) { - detIdToIndex[detUnit->geographicalId()] = detUnit->index(); - p_modulesInPSInOTBarrel.insert(detUnit->index()); -// std::cout << "Inserted " << detUnit->index() << " " << p_modulesInPSInOTBarrel.size() << " on layer " << int((detId.rawId() >> 20) & 0xF) << std::endl; - } - } - // Count the number of P hits in the OT to dimension the SoA - int PHitsInOTBarrel = 0; - for (const auto& detSet : stripHits) { - for (const auto& recHit : detSet) { - DetId detId(recHit.geographicalId()); - if (isPinPSinOTBarrel(detId)) - PHitsInOTBarrel++; - } - } - std::cout << "Tot number of modules in Pixels " << modulesInPixel << std::endl; - std::cout << "Tot number of p_modulesInPSInOTBarrel: " << p_modulesInPSInOTBarrel.size() << std::endl; - std::cout << "Number of strip (active) modules: " << activeStripModules << std::endl; - std::cout << "Number of strip hits: " << nStripHits << std::endl; - std::cout << "Total hits of PinOTBarrel: " << PHitsInOTBarrel << std::endl; - - HitsHost stripHitsHost(queue, PHitsInOTBarrel, p_modulesInPSInOTBarrel.size() + 1); - auto& stripHitsModuleView = stripHitsHost.view<::reco::HitModuleSoA>(); - - std::vector counterOfHitsPerModule(p_modulesInPSInOTBarrel.size(), 0); - assert(p_modulesInPSInOTBarrel.size()); - for (const auto& detSet : stripHits) { - auto firstHit = detSet.begin(); - auto detId = firstHit->rawId(); - auto index = detIdToIndex[detId]; - int offset = 0; - if (isPinPSinOTBarrel(DetId(detId))) { - auto it = p_modulesInPSInOTBarrel.find(index); - if (it != p_modulesInPSInOTBarrel.end()) { - offset = std::distance(p_modulesInPSInOTBarrel.begin(), it); - } else { - assert(0); + if (isPinPSinOTBarrel(detId)) { + detIdToIndex[detUnit->geographicalId()] = detUnit->index(); + p_modulesInPSInOTBarrel.insert(detUnit->index()); + // std::cout << "Inserted " << detUnit->index() << " " << p_modulesInPSInOTBarrel.size() << " on layer " << int((detId.rawId() >> 20) & 0xF) << std::endl; } + } + // Count the number of P hits in the OT to dimension the SoA + int PHitsInOTBarrel = 0; + for (const auto& detSet : stripHits) { for (const auto& recHit : detSet) { - counterOfHitsPerModule[offset]++; + DetId detId(recHit.geographicalId()); + if (isPinPSinOTBarrel(detId)) + PHitsInOTBarrel++; + } + } + std::cout << "Tot number of modules in Pixels " << modulesInPixel << std::endl; + std::cout << "Tot number of p_modulesInPSInOTBarrel: " << p_modulesInPSInOTBarrel.size() << std::endl; + std::cout << "Number of strip (active) modules: " << activeStripModules << std::endl; + std::cout << "Number of strip hits: " << nStripHits << std::endl; + std::cout << "Total hits of PinOTBarrel: " << PHitsInOTBarrel << std::endl; + + HitsHost stripHitsHost(queue, PHitsInOTBarrel, p_modulesInPSInOTBarrel.size() + 1); + auto& stripHitsModuleView = stripHitsHost.view<::reco::HitModuleSoA>(); + + std::vector counterOfHitsPerModule(p_modulesInPSInOTBarrel.size(), 0); + assert(p_modulesInPSInOTBarrel.size()); + for (const auto& detSet : stripHits) { + auto firstHit = detSet.begin(); + auto detId = firstHit->rawId(); + auto index = detIdToIndex[detId]; + int offset = 0; + if (isPinPSinOTBarrel(DetId(detId))) { + auto it = p_modulesInPSInOTBarrel.find(index); + if (it != p_modulesInPSInOTBarrel.end()) { + offset = std::distance(p_modulesInPSInOTBarrel.begin(), it); + } else { + assert(0); + } + for (const auto& recHit : detSet) { + counterOfHitsPerModule[offset]++; + } } } - } #if 0 int modId = 0; for (auto c : counterOfHitsPerModule) { @@ -173,64 +166,65 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe } #endif - std::vector cumulativeHitPerModule(counterOfHitsPerModule.size()); - std::partial_sum(counterOfHitsPerModule.begin(), counterOfHitsPerModule.end(), cumulativeHitPerModule.begin()); - // Create new vector with first element as 0, then shifted contents from counterOfHitsPerModule - std::vector shifted(cumulativeHitPerModule.size(), 0); - stripHitsModuleView[0].moduleStart() = nPixelHits; -// std::cout << "Module start: 0 with hits: " << stripHitsModuleView[0].moduleStart() << std::endl; - for (size_t i = 1; i < cumulativeHitPerModule.size(); ++i) { - shifted[i] = cumulativeHitPerModule[i - 1]; - stripHitsModuleView[i].moduleStart() = cumulativeHitPerModule[i-1] + nPixelHits; - // std::cout << "Module start: " << i << " with hits: " << stripHitsModuleView[i].moduleStart() << std::endl; - } + std::vector cumulativeHitPerModule(counterOfHitsPerModule.size()); + std::partial_sum(counterOfHitsPerModule.begin(), counterOfHitsPerModule.end(), cumulativeHitPerModule.begin()); + // Create new vector with first element as 0, then shifted contents from counterOfHitsPerModule + std::vector shifted(cumulativeHitPerModule.size(), 0); + stripHitsModuleView[0].moduleStart() = nPixelHits; + // std::cout << "Module start: 0 with hits: " << stripHitsModuleView[0].moduleStart() << std::endl; + for (size_t i = 1; i < cumulativeHitPerModule.size(); ++i) { + shifted[i] = cumulativeHitPerModule[i - 1]; + stripHitsModuleView[i].moduleStart() = cumulativeHitPerModule[i - 1] + nPixelHits; + // std::cout << "Module start: " << i << " with hits: " << stripHitsModuleView[i].moduleStart() << std::endl; + } - for (const auto& detSet : stripHits) { - auto firstHit = detSet.begin(); - auto detId = firstHit->rawId(); - auto det = trackerGeometry->idToDet(detId); - auto index = detIdToIndex[detId]; - int offset = 0; - if (isPinPSinOTBarrel(DetId(detId))) { - auto it = p_modulesInPSInOTBarrel.find(index); - if (it != p_modulesInPSInOTBarrel.end()) { - offset = std::distance(p_modulesInPSInOTBarrel.begin(), it); -// stripHitsModuleView[offset].moduleStart() = cumulativeHitPerModule[offset] + nPixelHits; -// std::cout << "Module start: " << offset << " " << index << " with hits: " << stripHitsModuleView[offset].moduleStart() << std::endl; - } else { - assert(0); - } - for (const auto& recHit : detSet) { - // Select only P-hits from the OT barrel - if (isPinPSinOTBarrel(DetId(detId))) { - int idx = shifted[offset]++; - assert(idx < PHitsInOTBarrel); - stripHitsHost.view()[idx].xLocal() = recHit.localPosition().x(); - stripHitsHost.view()[idx].yLocal() = recHit.localPosition().y(); - stripHitsHost.view()[idx].xerrLocal() = recHit.localPositionError().xx(); - stripHitsHost.view()[idx].yerrLocal() = recHit.localPositionError().yy(); - auto globalPosition = det->toGlobal(recHit.localPosition()); - double gx = globalPosition.x() - bs.x0(); - double gy = globalPosition.y() - bs.y0(); - double gz = globalPosition.z() - bs.z0(); - // std::cout << gx << std::endl; - stripHitsHost.view()[idx].xGlobal() = gx; - stripHitsHost.view()[idx].yGlobal() = gy; - stripHitsHost.view()[idx].zGlobal() = gz; - stripHitsHost.view()[idx].rGlobal() = sqrt(gx * gx + gy * gy); - stripHitsHost.view()[idx].iphi() = unsafe_atan2s<7>(gy, gx); - stripHitsHost.view()[idx].chargeAndStatus().charge = 0; - stripHitsHost.view()[idx].chargeAndStatus().status = {0, 0, 0, 0, 0}; - stripHitsHost.view()[idx].clusterSizeX() = -1; - stripHitsHost.view()[idx].clusterSizeY() = -1; - stripHitsHost.view()[idx].detectorIndex() = modulesInPixel + offset; + for (const auto& detSet : stripHits) { + auto firstHit = detSet.begin(); + auto detId = firstHit->rawId(); + auto det = trackerGeometry->idToDet(detId); + auto index = detIdToIndex[detId]; + int offset = 0; + if (isPinPSinOTBarrel(DetId(detId))) { + auto it = p_modulesInPSInOTBarrel.find(index); + if (it != p_modulesInPSInOTBarrel.end()) { + offset = std::distance(p_modulesInPSInOTBarrel.begin(), it); + // stripHitsModuleView[offset].moduleStart() = cumulativeHitPerModule[offset] + nPixelHits; + // std::cout << "Module start: " << offset << " " << index << " with hits: " << stripHitsModuleView[offset].moduleStart() << std::endl; + } else { + assert(0); + } + for (const auto& recHit : detSet) { + // Select only P-hits from the OT barrel + if (isPinPSinOTBarrel(DetId(detId))) { + int idx = shifted[offset]++; + assert(idx < PHitsInOTBarrel); + stripHitsHost.view()[idx].xLocal() = recHit.localPosition().x(); + stripHitsHost.view()[idx].yLocal() = recHit.localPosition().y(); + stripHitsHost.view()[idx].xerrLocal() = recHit.localPositionError().xx(); + stripHitsHost.view()[idx].yerrLocal() = recHit.localPositionError().yy(); + auto globalPosition = det->toGlobal(recHit.localPosition()); + double gx = globalPosition.x() - bs.x0(); + double gy = globalPosition.y() - bs.y0(); + double gz = globalPosition.z() - bs.z0(); + // std::cout << gx << std::endl; + stripHitsHost.view()[idx].xGlobal() = gx; + stripHitsHost.view()[idx].yGlobal() = gy; + stripHitsHost.view()[idx].zGlobal() = gz; + stripHitsHost.view()[idx].rGlobal() = sqrt(gx * gx + gy * gy); + stripHitsHost.view()[idx].iphi() = unsafe_atan2s<7>(gy, gx); + stripHitsHost.view()[idx].chargeAndStatus().charge = 0; + stripHitsHost.view()[idx].chargeAndStatus().status = {0, 0, 0, 0, 0}; + stripHitsHost.view()[idx].clusterSizeX() = -1; + stripHitsHost.view()[idx].clusterSizeY() = -1; + stripHitsHost.view()[idx].detectorIndex() = modulesInPixel + offset; + } } } } - } - stripHitsModuleView[p_modulesInPSInOTBarrel.size()].moduleStart() = cumulativeHitPerModule[p_modulesInPSInOTBarrel.size()-1]+nPixelHits; + stripHitsModuleView[p_modulesInPSInOTBarrel.size()].moduleStart() = + cumulativeHitPerModule[p_modulesInPSInOTBarrel.size() - 1] + nPixelHits; - std::cout << "DONE" << std::endl; + std::cout << "DONE" << std::endl; #if 0 int current = 0; for (int h = 0; h < stripHitsHost.view().metadata().size(); ++h) { @@ -244,27 +238,27 @@ void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSe } #endif - auto moduleStartView = cms::alpakatools::make_host_view(stripHitsModuleView.moduleStart(), stripHitsModuleView.metadata().size()); - HMSstorage moduleStartVec(stripHitsModuleView.metadata().size()); + auto moduleStartView = cms::alpakatools::make_host_view(stripHitsModuleView.moduleStart(), + stripHitsModuleView.metadata().size()); + HMSstorage moduleStartVec(stripHitsModuleView.metadata().size()); - // Put in the event the hit module start vector. - // Now, this could be avoided having the Host Hit SoA - // consumed by the downstream module (converters to legacy formats). - // But this is the common practice at the moment - // also for legacy data formats. - alpaka::memcpy(queue, moduleStartVec, moduleStartView); - iEvent.emplace(hitModuleStart_, std::move(moduleStartVec)); + // Put in the event the hit module start vector. + // Now, this could be avoided having the Host Hit SoA + // consumed by the downstream module (converters to legacy formats). + // But this is the common practice at the moment + // also for legacy data formats. + alpaka::memcpy(queue, moduleStartVec, moduleStartView); + iEvent.emplace(hitModuleStart_, std::move(moduleStartVec)); - Hits stripHitsDevice(queue, stripHitsHost.view().metadata().size(), stripHitsModuleView.metadata().size()); - alpaka::memcpy(queue, stripHitsDevice.buffer(), stripHitsHost.buffer()); - stripHitsDevice.updateFromDevice(queue); + Hits stripHitsDevice(queue, stripHitsHost.view().metadata().size(), stripHitsModuleView.metadata().size()); + alpaka::memcpy(queue, stripHitsDevice.buffer(), stripHitsHost.buffer()); + stripHitsDevice.updateFromDevice(queue); - // Would be useful to have a way to prompt a special CopyToDevice for EDProducers - iEvent.emplace(stripSoADevice_, std::move(stripHitsDevice)); - -} + // Would be useful to have a way to prompt a special CopyToDevice for EDProducers + iEvent.emplace(stripSoADevice_, std::move(stripHitsDevice)); + } -} +} // namespace ALPAKA_ACCELERATOR_NAMESPACE #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h" DEFINE_FWK_ALPAKA_MODULE(Phase2OTRecHitsSoAConverter); diff --git a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc index 302240cad441a..5f9f88002b7de 100644 --- a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc +++ b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc @@ -36,7 +36,7 @@ #include namespace ALPAKA_ACCELERATOR_NAMESPACE { - + class SiPixelRecHitExtendedAlpaka : public global::EDProducer<> { public: explicit SiPixelRecHitExtendedAlpaka(const edm::ParameterSet& iConfig); @@ -53,14 +53,12 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { const device::EDPutToken outputRecHitsSoAToken_; }; - SiPixelRecHitExtendedAlpaka::SiPixelRecHitExtendedAlpaka(const edm::ParameterSet& iConfig) : EDProducer(iConfig), pixelRecHitToken_(consumes(iConfig.getParameter("pixelRecHitsSoA"))), trackerRecHitToken_(consumes(iConfig.getParameter("trackerRecHitsSoA"))), outputRecHitsSoAToken_(produces()) {} - void SiPixelRecHitExtendedAlpaka::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; @@ -70,10 +68,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { descriptions.addWithDefaultLabel(desc); } - void SiPixelRecHitExtendedAlpaka::produce(edm::StreamID streamID, - device::Event& iEvent, - const device::EventSetup& es) const { + device::Event& iEvent, + const device::EventSetup& es) const { // get both Pixel and Tracker recHits const auto& pixelRecHitsSoA = iEvent.get(pixelRecHitToken_); const auto& otRecHitsSoA = iEvent.get(trackerRecHitToken_); diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc index c2e2ffca88d86..0e3508f80e98a 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc @@ -75,10 +75,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { template class CAHitNtupletAlpaka : public stream::EDProducer, - edm::RunCache>> { + edm::RunCache>> { using HitsConstView = ::reco::TrackingRecHitConstView; using HitsOnDevice = reco::TrackingRecHitsSoACollection; using HitsOnHost = ::reco::TrackingRecHitHost; + using TkSoAHost = ::reco::TracksHost; using TkSoADevice = reco::TracksSoACollection; @@ -87,7 +88,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { using CAGeometryCache = cms::alpakatools::MoveToDeviceCache; using Rotation = SOARotation; using Frame = SOAFrame; - + public: explicit CAHitNtupletAlpaka(const edm::ParameterSet& iConfig, const ::reco::CAGeometryParams* iCache); ~CAHitNtupletAlpaka() override = default; @@ -100,250 +101,247 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { RunContext const* iContext) { /* Do nothing */ }; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - + static std::shared_ptr globalBeginRun(edm::Run const& iRun, - edm::EventSetup const& iSetup, - GlobalCache const* iCache) { - assert(iCache->minZ_.size() == iCache->maxZ_.size()); - assert(iCache->minZ_.size() == iCache->maxR_.size()); - assert(iCache->minZ_.size() == iCache->phiCuts_.size()); - - assert(iCache->caThetaCuts_.size() == iCache->caDCACuts_.size()); - - int n_layers = iCache->caThetaCuts_.size(); - int n_pairs = iCache->pairGraph_.size() / 2; - int n_modules = 0; - + edm::EventSetup const& iSetup, + GlobalCache const* iCache) { + assert(iCache->minZ_.size() == iCache->maxZ_.size()); + assert(iCache->minZ_.size() == iCache->maxR_.size()); + assert(iCache->minZ_.size() == iCache->phiCuts_.size()); + + assert(iCache->caThetaCuts_.size() == iCache->caDCACuts_.size()); + + int n_layers = iCache->caThetaCuts_.size(); + int n_pairs = iCache->pairGraph_.size() / 2; + int n_modules = 0; + #ifdef GPU_DEBUG - std::cout << "No. Layers to be used = " << n_layers << std::endl; - std::cout << "No. Pairs to be used = " << n_pairs << std::endl; + std::cout << "No. Layers to be used = " << n_layers << std::endl; + std::cout << "No. Pairs to be used = " << n_pairs << std::endl; #endif - assert(int(n_pairs) == int(iCache->minZ_.size())); - assert(int(*std::max_element(iCache->startingPairs_.begin(), iCache->startingPairs_.end())) <= n_pairs); - assert(int(*std::max_element(iCache->pairGraph_.begin(), iCache->pairGraph_.end())) < n_layers); + assert(int(n_pairs) == int(iCache->minZ_.size())); + assert(int(*std::max_element(iCache->startingPairs_.begin(), iCache->startingPairs_.end())) <= n_pairs); + assert(int(*std::max_element(iCache->pairGraph_.begin(), iCache->pairGraph_.end())) < n_layers); - const auto& trackerGeometry = iSetup.getData(iCache->tokenGeometry_); - const auto& trackerTopology = iSetup.getData(iCache->tokenTopology_); - auto const& dets = trackerGeometry.dets(); + const auto& trackerGeometry = iSetup.getData(iCache->tokenGeometry_); + const auto& trackerTopology = iSetup.getData(iCache->tokenTopology_); + auto const& dets = trackerGeometry.dets(); #ifdef GPU_DEBUG - auto subSystem = 1; - auto subSystemName = GeomDetEnumerators::tkDetEnum[subSystem]; - auto subSystemOffset = trackerGeometry.offsetDU(subSystemName); - std::cout - << "=========================================================================================================" - << std::endl; - std::cout << " ===================== Subsystem: " << subSystemName << std::endl; - subSystemName = GeomDetEnumerators::tkDetEnum[++subSystem]; - subSystemOffset = trackerGeometry.offsetDU(subSystemName); + auto subSystem = 1; + auto subSystemName = GeomDetEnumerators::tkDetEnum[subSystem]; + auto subSystemOffset = trackerGeometry.offsetDU(subSystemName); + std::cout + << "=========================================================================================================" + << std::endl; + std::cout << " ===================== Subsystem: " << subSystemName << std::endl; + subSystemName = GeomDetEnumerators::tkDetEnum[++subSystem]; + subSystemOffset = trackerGeometry.offsetDU(subSystemName); #endif - auto oldLayer = 0u; - auto layerCount = 0; + auto oldLayer = 0u; + auto layerCount = 0; + + std::vector layerStarts(n_layers + 1); + //^ why n_layers + 1? This is a cumulative sum of the number + // of modules each layer has. And we need the extra spot + // at the end to hold the total number of modules. + + std::vector moduleToindexInDets; + + auto isPinPSinOTBarrel = [&](DetId detId) { + // std::cout << (int)trackerGeometry->getDetectorType(detId) << " " << (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP) << "\n"; + // std::cout << (int)detId.subdetId() << " " << (detId.subdetId() == StripSubdetector::TOB) << std::endl; + // Select only P-hits from the OT barrel + return (trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP && + detId.subdetId() == StripSubdetector::TOB); + }; + auto isPh2Pixel = [&](DetId detId) { + return (trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXB || + trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXB3D || + trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF || + trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF3D); + }; + if constexpr (std::is_base_of_v) { + int counter = 0; + for (auto& det : dets) { + DetId detid = det->geographicalId(); + auto layer = trackerTopology.layer(detid); + // Logic: + // - if we are not inside pixels, we need to ignore anything **but** the OT. + // - for the time being, this is assuming that the CA extension will + // only cover the OT barrel part, and will ignore the OT forward. + if (isPh2Pixel(detid)) { + if (layer != oldLayer) { + std::cout << "Pixel LayerStart: " << layerCount << " has " << n_modules << " modules." << std::endl; + layerStarts[layerCount++] = n_modules; + if (layerCount > n_layers + 1) + break; + oldLayer = layer; + } + moduleToindexInDets.push_back(counter); + n_modules++; + } else { + auto const& detUnits = det->components(); + for (auto& detUnit : detUnits) { + DetId unitDetId(detUnit->geographicalId()); + if (isPinPSinOTBarrel(unitDetId)) { + if (layer != oldLayer) { + std::cout << "OT LayerStart: " << layerCount << " has " << n_modules << " modules." << std::endl; + layerStarts[layerCount++] = n_modules; + if (layerCount > n_layers + 1) + break; + oldLayer = layer; + } + moduleToindexInDets.push_back(counter); + n_modules++; + } + } + } + counter++; + } + layerStarts[n_layers] = n_modules; + std::cout << "OT LayerStart: " << n_layers << " has " << n_modules << " modules." << std::endl; + } else { + for (auto& det : dets) { + DetId detid = det->geographicalId(); +#ifdef GPU_DEBUG + if (n_modules >= int(subSystemOffset)) { + subSystemName = GeomDetEnumerators::tkDetEnum[++subSystem]; + subSystemOffset = trackerGeometry.offsetDU(subSystemName); + std::cout << " ===================== Subsystem: " << subSystemName << std::endl; + } +#endif + + auto layer = trackerTopology.layer(detid); - std::vector layerStarts(n_layers + 1); - //^ why n_layers + 1? This is a cumulative sum of the number - // of modules each layer has. And we need the extra spot - // at the end to hold the total number of modules. - - std::vector moduleToindexInDets; - - auto isPinPSinOTBarrel = [&](DetId detId) { - // std::cout << (int)trackerGeometry->getDetectorType(detId) << " " << (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP) << "\n"; - // std::cout << (int)detId.subdetId() << " " << (detId.subdetId() == StripSubdetector::TOB) << std::endl; - // Select only P-hits from the OT barrel - return (trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP && - detId.subdetId() == StripSubdetector::TOB); - }; - auto isPh2Pixel = [&](DetId detId) { - return (trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXB - || trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXB3D - || trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF - || trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF3D); - }; - if constexpr (std::is_base_of_v) { - int counter = 0; - for (auto& det : dets) { - DetId detid = det->geographicalId(); - auto layer = trackerTopology.layer(detid); - // Logic: - // - if we are not inside pixels, we need to ignore anything **but** the OT. - // - for the time being, this is assuming that the CA extension will - // only cover the OT barrel part, and will ignore the OT forward. - if (isPh2Pixel(detid)) { if (layer != oldLayer) { - std::cout << "Pixel LayerStart: " << layerCount << " has " << n_modules << " modules." << std::endl; layerStarts[layerCount++] = n_modules; + if (layerCount > n_layers + 1) break; + oldLayer = layer; +#ifdef GPU_DEBUG + std::cout << " > New layer at module : " << n_modules << " (detId: " << detid << ")" << std::endl; +#endif } - moduleToindexInDets.push_back(counter); + n_modules++; - } else { - auto const & detUnits = det->components(); - for (auto& detUnit : detUnits) - { - DetId unitDetId(detUnit->geographicalId()); - if (isPinPSinOTBarrel(unitDetId)) { - if (layer != oldLayer) { - std::cout << "OT LayerStart: " << layerCount << " has " << n_modules << " modules." << std::endl; - layerStarts[layerCount++] = n_modules; - if (layerCount > n_layers + 1) - break; - oldLayer = layer; - } - moduleToindexInDets.push_back(counter); - n_modules++; - } - } } - counter++; } - layerStarts[n_layers] = n_modules; - std::cout << "OT LayerStart: " << n_layers << " has " << n_modules << " modules." << std::endl; - } else { + reco::CAGeometryHost product{{{n_layers + 1, n_pairs, n_modules}}, cms::alpakatools::host()}; - for (auto& det : dets) { - DetId detid = det->geographicalId(); -#ifdef GPU_DEBUG - if (n_modules >= int(subSystemOffset)) { - subSystemName = GeomDetEnumerators::tkDetEnum[++subSystem]; - subSystemOffset = trackerGeometry.offsetDU(subSystemName); - std::cout << " ===================== Subsystem: " << subSystemName << std::endl; - } -#endif - - auto layer = trackerTopology.layer(detid); + auto layerSoA = product.view(); + auto cellSoA = product.view<::reco::CAGraphSoA>(); + auto modulesSoA = product.view<::reco::CAModulesSoA>(); - if (layer != oldLayer) { - layerStarts[layerCount++] = n_modules; - - if (layerCount > n_layers + 1) - break; + if constexpr (std::is_base_of_v) { + for (int i = 0; i < n_modules; ++i) { + auto idx = moduleToindexInDets[i]; + auto det = dets[idx]; + auto vv = det->surface().position(); + auto rr = Rotation(det->surface().rotation()); + modulesSoA[i].detFrame() = Frame(vv.x(), vv.y(), vv.z(), rr); + } - oldLayer = layer; -#ifdef GPU_DEBUG - std::cout << " > New layer at module : " << n_modules << " (detId: " << detid << ")" << std::endl; -#endif + for (int i = 0; i < n_layers; ++i) { + layerSoA.layerStarts()[i] = layerStarts[i]; + layerSoA.caThetaCut()[i] = iCache->caThetaCuts_[i]; + layerSoA.caDCACut()[i] = iCache->caDCACuts_[i]; + } + } else { + for (int i = 0; i < n_modules; ++i) { + auto det = dets[i]; + auto vv = det->surface().position(); + auto rr = Rotation(det->surface().rotation()); + modulesSoA[i].detFrame() = Frame(vv.x(), vv.y(), vv.z(), rr); } - n_modules++; + for (int i = 0; i < n_layers; ++i) { + layerSoA.layerStarts()[i] = layerStarts[i]; + layerSoA.caThetaCut()[i] = iCache->caThetaCuts_[i]; + layerSoA.caDCACut()[i] = iCache->caDCACuts_[i]; + } } - } - reco::CAGeometryHost product{{{n_layers + 1, n_pairs, n_modules}}, cms::alpakatools::host()}; + layerSoA.layerStarts()[n_layers] = layerStarts[n_layers]; - auto layerSoA = product.view(); - auto cellSoA = product.view<::reco::CAGraphSoA>(); - auto modulesSoA = product.view<::reco::CAModulesSoA>(); - - if constexpr (std::is_base_of_v) { - for (int i = 0; i < n_modules; ++i) { - auto idx = moduleToindexInDets[i]; - auto det = dets[idx]; - auto vv = det->surface().position(); - auto rr = Rotation(det->surface().rotation()); - modulesSoA[i].detFrame() = Frame(vv.x(), vv.y(), vv.z(), rr); + for (int i = 0; i < n_pairs; ++i) { + cellSoA.graph()[i] = {{uint32_t(iCache->pairGraph_[2 * i]), uint32_t(iCache->pairGraph_[2 * i + 1])}}; + cellSoA.phiCuts()[i] = iCache->phiCuts_[i]; + cellSoA.minz()[i] = iCache->minZ_[i]; + cellSoA.maxz()[i] = iCache->maxZ_[i]; + cellSoA.maxr()[i] = iCache->maxR_[i]; + cellSoA.startingPair()[i] = false; } - for (int i = 0; i < n_layers; ++i) { - layerSoA.layerStarts()[i] = layerStarts[i]; - layerSoA.caThetaCut()[i] = iCache->caThetaCuts_[i]; - layerSoA.caDCACut()[i] = iCache->caDCACuts_[i]; - } - } else { - for (int i = 0; i < n_modules; ++i) { - auto det = dets[i]; - auto vv = det->surface().position(); - auto rr = Rotation(det->surface().rotation()); - modulesSoA[i].detFrame() = Frame(vv.x(), vv.y(), vv.z(), rr); - } + for (const int& i : iCache->startingPairs_) + cellSoA.startingPair()[i] = true; - for (int i = 0; i < n_layers; ++i) { - layerSoA.layerStarts()[i] = layerStarts[i]; - layerSoA.caThetaCut()[i] = iCache->caThetaCuts_[i]; - layerSoA.caDCACut()[i] = iCache->caDCACuts_[i]; - } + return std::make_shared(std::move(product)); } - layerSoA.layerStarts()[n_layers] = layerStarts[n_layers]; - - for (int i = 0; i < n_pairs; ++i) { - cellSoA.graph()[i] = {{uint32_t(iCache->pairGraph_[2 * i]), uint32_t(iCache->pairGraph_[2 * i + 1])}}; - cellSoA.phiCuts()[i] = iCache->phiCuts_[i]; - cellSoA.minz()[i] = iCache->minZ_[i]; - cellSoA.maxz()[i] = iCache->maxZ_[i]; - cellSoA.maxr()[i] = iCache->maxR_[i]; - cellSoA.startingPair()[i] = false; + static std::unique_ptr<::reco::CAGeometryParams> initializeGlobalCache(edm::ParameterSet const& iConfig) { + return std::make_unique<::reco::CAGeometryParams>(iConfig.getParameterSet("geometry")); } - for (const int& i : iCache->startingPairs_) - cellSoA.startingPair()[i] = true; + private: + const edm::ESGetToken tokenField_; + const device::EDGetToken tokenHit_; + const device::EDPutToken tokenTrack_; + + const TFormula maxNumberOfDoublets_; + const TFormula maxNumberOfTuples_; + Algo deviceAlgo_; + }; + + template + CAHitNtupletAlpaka::CAHitNtupletAlpaka(const edm::ParameterSet& iConfig, + const ::reco::CAGeometryParams* iCache) + : EDProducer(iConfig), + tokenField_(esConsumes()), + tokenHit_(consumes(iConfig.getParameter("pixelRecHitSrc"))), + tokenTrack_(produces()), + maxNumberOfDoublets_( + TFormula("doubletsHitsDependecy", iConfig.getParameter("maxNumberOfDoublets").data())), + maxNumberOfTuples_( + TFormula("tracksHitsDependency", iConfig.getParameter("maxNumberOfTuples").data())), + deviceAlgo_(iConfig) { + iCache->tokenGeometry_ = esConsumes(); + iCache->tokenTopology_ = esConsumes(); + } + + template + void CAHitNtupletAlpaka::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + + desc.add("pixelRecHitSrc", edm::InputTag("siPixelRecHitsPreSplittingAlpaka")); - return std::make_shared(std::move(product)); + Algo::fillPSetDescription(desc); + descriptions.addWithDefaultLabel(desc); } - static std::unique_ptr<::reco::CAGeometryParams> initializeGlobalCache(edm::ParameterSet const& iConfig) { - return std::make_unique<::reco::CAGeometryParams>(iConfig.getParameterSet("geometry")); + template + void CAHitNtupletAlpaka::produce(device::Event& iEvent, const device::EventSetup& es) { + auto bf = 1. / es.getData(tokenField_).inverseBzAtOriginInGeV(); + + auto const& geometry = runCache()->get(iEvent.queue()); + auto const& hits = iEvent.get(tokenHit_); + + uint32_t const maxTuples = maxNumberOfTuples_.Eval(hits.nHits()); + uint32_t const maxDoublets = maxNumberOfDoublets_.Eval(hits.nHits()); + + iEvent.emplace(tokenTrack_, + deviceAlgo_.makeTuplesAsync(hits, geometry, bf, maxDoublets, maxTuples, iEvent.queue())); } -private: - const edm::ESGetToken tokenField_; - const device::EDGetToken tokenHit_; - const device::EDPutToken tokenTrack_; - - const TFormula maxNumberOfDoublets_; - const TFormula maxNumberOfTuples_; - Algo deviceAlgo_; -}; - -template -CAHitNtupletAlpaka::CAHitNtupletAlpaka(const edm::ParameterSet& iConfig, - const ::reco::CAGeometryParams* iCache) - : EDProducer(iConfig), - tokenField_(esConsumes()), - tokenHit_(consumes(iConfig.getParameter("pixelRecHitSrc"))), - tokenTrack_(produces()), - maxNumberOfDoublets_( - TFormula("doubletsHitsDependecy", iConfig.getParameter("maxNumberOfDoublets").data())), - maxNumberOfTuples_( - TFormula("tracksHitsDependency", iConfig.getParameter("maxNumberOfTuples").data())), - deviceAlgo_(iConfig) { - iCache->tokenGeometry_ = esConsumes(); - iCache->tokenTopology_ = esConsumes(); -} - -template -void CAHitNtupletAlpaka::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - edm::ParameterSetDescription desc; - - desc.add("pixelRecHitSrc", edm::InputTag("siPixelRecHitsPreSplittingAlpaka")); - - Algo::fillPSetDescription(desc); - descriptions.addWithDefaultLabel(desc); -} - -template -void CAHitNtupletAlpaka::produce(device::Event& iEvent, const device::EventSetup& es) { - auto bf = 1. / es.getData(tokenField_).inverseBzAtOriginInGeV(); - - auto const& geometry = runCache()->get(iEvent.queue()); - auto const& hits = iEvent.get(tokenHit_); - - uint32_t const maxTuples = maxNumberOfTuples_.Eval(hits.nHits()); - uint32_t const maxDoublets = maxNumberOfDoublets_.Eval(hits.nHits()); - - iEvent.emplace(tokenTrack_, - deviceAlgo_.makeTuplesAsync(hits, geometry, bf, maxDoublets, maxTuples, iEvent.queue())); -} - -using CAHitNtupletAlpakaPhase1 = CAHitNtupletAlpaka; -using CAHitNtupletAlpakaHIonPhase1 = CAHitNtupletAlpaka; -using CAHitNtupletAlpakaPhase2 = CAHitNtupletAlpaka; -using CAHitNtupletAlpakaPhase2OT = CAHitNtupletAlpaka; + using CAHitNtupletAlpakaPhase1 = CAHitNtupletAlpaka; + using CAHitNtupletAlpakaHIonPhase1 = CAHitNtupletAlpaka; + using CAHitNtupletAlpakaPhase2 = CAHitNtupletAlpaka; + using CAHitNtupletAlpakaPhase2OT = CAHitNtupletAlpaka; } // namespace ALPAKA_ACCELERATOR_NAMESPACE #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h" diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGenerator.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGenerator.cc index 33291ac460060..302b024c59e94 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGenerator.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGenerator.cc @@ -260,7 +260,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { "pairGraph", std::vector(std::begin(layerPairs), std::begin(layerPairs) + (pixelTopology::Phase1::nPairsForQuadruplets * 2))) - ->setComment("CA graph"); + ->setComment("CA graph"); geometryParams .add>( "phiCuts", @@ -418,9 +418,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { // TODO: fill me properly template <> void CAHitNtupletGenerator::fillPSetDescription(edm::ParameterSetDescription& desc) { - fillDescriptionsCommon(desc); - + edm::ParameterSetDescription trackQualityCuts; trackQualityCuts.add("maxChi2", 5.)->setComment("Max normalized chi2"); trackQualityCuts.add("minPt", 0.5)->setComment("Min pT in GeV"); @@ -466,7 +465,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { ->setComment( "Quality cuts based on the results of the track fit:\n - apply cuts based on the fit results (pT, Tip, " "Zip)."); - } template diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc index e42a185c0c46b..aa77113a6e44b 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc @@ -810,12 +810,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { this->device_hitContainer_.data(), this->counters_.data()); - - workDiv1D = cms::alpakatools::make_workdiv(1,1); + workDiv1D = cms::alpakatools::make_workdiv(1, 1); alpaka::exec(queue, workDiv1D, Kernel_printCounters{}, this->counters_.data()); alpaka::wait(queue); - workDiv1D = cms::alpakatools::make_workdiv(1,1); + workDiv1D = cms::alpakatools::make_workdiv(1, 1); alpaka::exec(queue, workDiv1D, Kernel_print_found_ntuplets{}, @@ -827,8 +826,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { 100, 0); alpaka::wait(queue); - } - + } #ifdef GPU_DEBUG alpaka::wait(queue); diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h index a474541c42c22..142f4f6bfcf37 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h @@ -389,7 +389,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { auto ro = thisCell.outer_r(hh); auto zo = thisCell.outer_z(hh); auto thetaCut = ll[thisCell.innerLayer()].caThetaCut(); - + // loop on inner cells for (uint32_t j : cms::alpakatools::independent_group_elements_x(acc, numberOfPossibleNeighbors)) { auto otherCell = outerHitCells[j]; @@ -1062,7 +1062,19 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { // Print header printf("TK: %10s %3s %3s %3s %6s %9s %8s %8s %9s %9s %9s %9s %9s\n", - "ID", "Q", "nH", "nL", "Qchg", "pT", "Eta", "Phi", "Tip", "Zip", "Chi2", "z1", "z2"); + "ID", + "Q", + "nH", + "nL", + "Qchg", + "pT", + "Eta", + "Phi", + "Tip", + "Zip", + "Chi2", + "z1", + "z2"); for (auto i : cms::alpakatools::uniform_elements(acc, firstPrint, std::min(lastPrint, foundNtuplets->nOnes()))) { auto nh = foundNtuplets->size(i); if (nh < 3) @@ -1071,19 +1083,19 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { continue; printf("TK: %10d %3d %3d %3d %6.1f %9.3f %8.3f %8.3f %9.3f %9.3f %9.3f %9.3f %9.3f\n", - 10000 * iev + i, // ID - int(tracks_view[i].quality()), // Quality - nh, // Number of hits - tracks_view[i].nLayers(), // Number of layers - reco::charge(tracks_view, i), // Charge - tracks_view[i].pt(), // Pt - tracks_view[i].eta(), // Eta - reco::phi(tracks_view, i), // Phi - reco::tip(tracks_view, i), // Tip - reco::zip(tracks_view, i), // Zip - tracks_view[i].chi2(), // Chi2 - hh[*foundNtuplets->begin(i)].zGlobal(), // z1 - hh[*(foundNtuplets->begin(i) + 1)].zGlobal()// z2 + 10000 * iev + i, // ID + int(tracks_view[i].quality()), // Quality + nh, // Number of hits + tracks_view[i].nLayers(), // Number of layers + reco::charge(tracks_view, i), // Charge + tracks_view[i].pt(), // Pt + tracks_view[i].eta(), // Eta + reco::phi(tracks_view, i), // Phi + reco::tip(tracks_view, i), // Tip + reco::zip(tracks_view, i), // Zip + tracks_view[i].chi2(), // Chi2 + hh[*foundNtuplets->begin(i)].zGlobal(), // z1 + hh[*(foundNtuplets->begin(i) + 1)].zGlobal() // z2 ); } } @@ -1094,9 +1106,20 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { ALPAKA_FN_ACC void operator()(Acc1D const &acc, Counters const *counters) const { auto const &c = *counters; printf("||%-15s|%10s|%10s|%10s|%10s|%14s|%16s|%14s|%11s|%10s|%13s|%15s|%12s|%17s||\n", - "Counters", "nEvents", "nHits", "nCells", "nTuples", "nFitTracks", - "nLooseTracks", "nGoodTracks", "nUsedHits", "nDupHits", "nFishCells", - "nKilledCells", "nUsedCells", "nZeroTrackCells"); + "Counters", + "nEvents", + "nHits", + "nCells", + "nTuples", + "nFitTracks", + "nLooseTracks", + "nGoodTracks", + "nUsedHits", + "nDupHits", + "nFishCells", + "nKilledCells", + "nUsedCells", + "nZeroTrackCells"); printf("||%-15s|%10lld|%10lld|%10lld|%10lld|%14lld|%16lld|%14lld|%11lld|%10lld|%13lld|%15lld|%12lld|%17lld||\n", "Raw", c.nEvents, @@ -1113,20 +1136,20 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { c.nEmptyCells, c.nZeroTrackCells); printf("||%-15s|%10lld|%10.1f|%10.1f|%10.1f|%14.1f|%16.1f|%14.1f|%11.1f|%10.3f|%13.3f|%15.3f|%12.3f|%17.3f||\n", - "Norm", - c.nEvents, - c.nHits / double(c.nEvents), - c.nCells / double(c.nEvents), - c.nTuples / double(c.nEvents), - c.nFitTracks / double(c.nEvents), - c.nLooseTracks / double(c.nEvents), - c.nGoodTracks / double(c.nEvents), - c.nUsedHits / double(c.nEvents), - c.nDupHits / double(c.nEvents), - c.nFishCells / double(c.nCells), - c.nKilledCells / double(c.nCells), - c.nEmptyCells / double(c.nCells), - c.nZeroTrackCells / double(c.nCells)); + "Norm", + c.nEvents, + c.nHits / double(c.nEvents), + c.nCells / double(c.nEvents), + c.nTuples / double(c.nEvents), + c.nFitTracks / double(c.nEvents), + c.nLooseTracks / double(c.nEvents), + c.nGoodTracks / double(c.nEvents), + c.nUsedHits / double(c.nEvents), + c.nDupHits / double(c.nEvents), + c.nFishCells / double(c.nCells), + c.nKilledCells / double(c.nCells), + c.nEmptyCells / double(c.nCells), + c.nZeroTrackCells / double(c.nCells)); } }; From f02ad5e2d22516d07e0d15ab56c03edf42351577 Mon Sep 17 00:00:00 2001 From: adriano Date: Mon, 26 May 2025 13:50:34 +0200 Subject: [PATCH 24/40] updateFromDevice for merged SoA --- .../alpaka/SiPixelRecHitExtendedAlpaka.cc | 180 +++++++++--------- 1 file changed, 91 insertions(+), 89 deletions(-) diff --git a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc index 5f9f88002b7de..b8f92132b54d5 100644 --- a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc +++ b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc @@ -72,6 +72,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { device::Event& iEvent, const device::EventSetup& es) const { // get both Pixel and Tracker recHits + auto queue = iEvent.queue(); const auto& pixelRecHitsSoA = iEvent.get(pixelRecHitToken_); const auto& otRecHitsSoA = iEvent.get(trackerRecHitToken_); std::cout << "----------------- Merging Pixel and Tracker RecHits -----------------" << std::endl; @@ -84,178 +85,179 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { std::cout << "Number of Tracker modules: " << otRecHitsSoA.nModules() << std::endl; const int nTotModules = pixelRecHitsSoA.nModules() + otRecHitsSoA.nModules(); - auto outputSoA = reco::TrackingRecHitsSoACollection(iEvent.queue(), nTotHits, nTotModules + 1); + auto outputSoA = reco::TrackingRecHitsSoACollection(queue, nTotHits, nTotModules + 1); std::cout << "Total number of recHits: " << outputSoA.nHits() << std::endl; // copy all columns from pixelRecHitsSoA and otRecHitsSoA to outputSoA // xLocal - auto xLocalOutputPixel = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xLocal(), nPixelHits); + auto xLocalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().xLocal(), nPixelHits); auto xLocalOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xLocal() + nPixelHits, nTrackerHits); - auto xLocalPixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().xLocal(), nPixelHits); - auto xLocalTracker = cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().xLocal(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), xLocalOutputPixel, xLocalPixel); - alpaka::memcpy(iEvent.queue(), xLocalOutputTracker, xLocalTracker); + cms::alpakatools::make_device_view(queue, outputSoA.view().xLocal() + nPixelHits, nTrackerHits); + auto xLocalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().xLocal(), nPixelHits); + auto xLocalTracker = cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().xLocal(), nTrackerHits); + alpaka::memcpy(queue, xLocalOutputPixel, xLocalPixel); + alpaka::memcpy(queue, xLocalOutputTracker, xLocalTracker); // yLocal - auto yLocalOutputPixel = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yLocal(), nPixelHits); + auto yLocalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().yLocal(), nPixelHits); auto yLocalOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yLocal() + nPixelHits, nTrackerHits); - auto yLocalPixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().yLocal(), nPixelHits); - auto yLocalTracker = cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().yLocal(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), yLocalOutputPixel, yLocalPixel); - alpaka::memcpy(iEvent.queue(), yLocalOutputTracker, yLocalTracker); + cms::alpakatools::make_device_view(queue, outputSoA.view().yLocal() + nPixelHits, nTrackerHits); + auto yLocalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().yLocal(), nPixelHits); + auto yLocalTracker = cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().yLocal(), nTrackerHits); + alpaka::memcpy(queue, yLocalOutputPixel, yLocalPixel); + alpaka::memcpy(queue, yLocalOutputTracker, yLocalTracker); // xerrLocal auto xerrLocalOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xerrLocal(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().xerrLocal(), nPixelHits); auto xerrLocalOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xerrLocal() + nPixelHits, nTrackerHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().xerrLocal() + nPixelHits, nTrackerHits); auto xerrLocalPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().xerrLocal(), nPixelHits); + cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().xerrLocal(), nPixelHits); auto xerrLocalTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().xerrLocal(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), xerrLocalOutputPixel, xerrLocalPixel); - alpaka::memcpy(iEvent.queue(), xerrLocalOutputTracker, xerrLocalTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().xerrLocal(), nTrackerHits); + alpaka::memcpy(queue, xerrLocalOutputPixel, xerrLocalPixel); + alpaka::memcpy(queue, xerrLocalOutputTracker, xerrLocalTracker); // yerrLocal auto yerrLocalOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yerrLocal(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().yerrLocal(), nPixelHits); auto yerrLocalOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yerrLocal() + nPixelHits, nTrackerHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().yerrLocal() + nPixelHits, nTrackerHits); auto yerrLocalPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().yerrLocal(), nPixelHits); + cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().yerrLocal(), nPixelHits); auto yerrLocalTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().yerrLocal(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), yerrLocalOutputPixel, yerrLocalPixel); - alpaka::memcpy(iEvent.queue(), yerrLocalOutputTracker, yerrLocalTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().yerrLocal(), nTrackerHits); + alpaka::memcpy(queue, yerrLocalOutputPixel, yerrLocalPixel); + alpaka::memcpy(queue, yerrLocalOutputTracker, yerrLocalTracker); // xGlobal auto xGlobalOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xGlobal(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().xGlobal(), nPixelHits); auto xGlobalOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().xGlobal() + nPixelHits, nTrackerHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().xGlobal() + nPixelHits, nTrackerHits); auto xGlobalPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().xGlobal(), nPixelHits); + cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().xGlobal(), nPixelHits); auto xGlobalTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().xGlobal(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), xGlobalOutputPixel, xGlobalPixel); - alpaka::memcpy(iEvent.queue(), xGlobalOutputTracker, xGlobalTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().xGlobal(), nTrackerHits); + alpaka::memcpy(queue, xGlobalOutputPixel, xGlobalPixel); + alpaka::memcpy(queue, xGlobalOutputTracker, xGlobalTracker); // yGlobal auto yGlobalOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yGlobal(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().yGlobal(), nPixelHits); auto yGlobalOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().yGlobal() + nPixelHits, nTrackerHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().yGlobal() + nPixelHits, nTrackerHits); auto yGlobalPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().yGlobal(), nPixelHits); + cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().yGlobal(), nPixelHits); auto yGlobalTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().yGlobal(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), yGlobalOutputPixel, yGlobalPixel); - alpaka::memcpy(iEvent.queue(), yGlobalOutputTracker, yGlobalTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().yGlobal(), nTrackerHits); + alpaka::memcpy(queue, yGlobalOutputPixel, yGlobalPixel); + alpaka::memcpy(queue, yGlobalOutputTracker, yGlobalTracker); // zGlobal auto zGlobalOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().zGlobal(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().zGlobal(), nPixelHits); auto zGlobalOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().zGlobal() + nPixelHits, nTrackerHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().zGlobal() + nPixelHits, nTrackerHits); auto zGlobalPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().zGlobal(), nPixelHits); + cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().zGlobal(), nPixelHits); auto zGlobalTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().zGlobal(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), zGlobalOutputPixel, zGlobalPixel); - alpaka::memcpy(iEvent.queue(), zGlobalOutputTracker, zGlobalTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().zGlobal(), nTrackerHits); + alpaka::memcpy(queue, zGlobalOutputPixel, zGlobalPixel); + alpaka::memcpy(queue, zGlobalOutputTracker, zGlobalTracker); // rGlobal auto rGlobalOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().rGlobal(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().rGlobal(), nPixelHits); auto rGlobalOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().rGlobal() + nPixelHits, nTrackerHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().rGlobal() + nPixelHits, nTrackerHits); auto rGlobalPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().rGlobal(), nPixelHits); + cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().rGlobal(), nPixelHits); auto rGlobalTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().rGlobal(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), rGlobalOutputPixel, rGlobalPixel); - alpaka::memcpy(iEvent.queue(), rGlobalOutputTracker, rGlobalTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().rGlobal(), nTrackerHits); + alpaka::memcpy(queue, rGlobalOutputPixel, rGlobalPixel); + alpaka::memcpy(queue, rGlobalOutputTracker, rGlobalTracker); // iphi - auto iphiOutputPixel = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().iphi(), nPixelHits); + auto iphiOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().iphi(), nPixelHits); auto iphiOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().iphi() + nPixelHits, nTrackerHits); - auto iphiPixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().iphi(), nPixelHits); - auto iphiTracker = cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().iphi(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), iphiOutputPixel, iphiPixel); - alpaka::memcpy(iEvent.queue(), iphiOutputTracker, iphiTracker); + cms::alpakatools::make_device_view(queue, outputSoA.view().iphi() + nPixelHits, nTrackerHits); + auto iphiPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().iphi(), nPixelHits); + auto iphiTracker = cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().iphi(), nTrackerHits); + alpaka::memcpy(queue, iphiOutputPixel, iphiPixel); + alpaka::memcpy(queue, iphiOutputTracker, iphiTracker); // chargeAndStatus auto chargeAndStatusOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().chargeAndStatus(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().chargeAndStatus(), nPixelHits); auto chargeAndStatusOutputTracker = cms::alpakatools::make_device_view( - iEvent.queue(), outputSoA.view().chargeAndStatus() + nPixelHits, nTrackerHits); + queue, outputSoA.view().chargeAndStatus() + nPixelHits, nTrackerHits); auto chargeAndStatusPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().chargeAndStatus(), nPixelHits); + cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().chargeAndStatus(), nPixelHits); auto chargeAndStatusTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().chargeAndStatus(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), chargeAndStatusOutputPixel, chargeAndStatusPixel); - alpaka::memcpy(iEvent.queue(), chargeAndStatusOutputTracker, chargeAndStatusTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().chargeAndStatus(), nTrackerHits); + alpaka::memcpy(queue, chargeAndStatusOutputPixel, chargeAndStatusPixel); + alpaka::memcpy(queue, chargeAndStatusOutputTracker, chargeAndStatusTracker); // clusterSizeX auto clusterSizeXOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().clusterSizeX(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().clusterSizeX(), nPixelHits); auto clusterSizeXOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().clusterSizeX() + nPixelHits, nTrackerHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().clusterSizeX() + nPixelHits, nTrackerHits); auto clusterSizeXPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().clusterSizeX(), nPixelHits); + cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().clusterSizeX(), nPixelHits); auto clusterSizeXTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().clusterSizeX(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), clusterSizeXOutputPixel, clusterSizeXPixel); - alpaka::memcpy(iEvent.queue(), clusterSizeXOutputTracker, clusterSizeXTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().clusterSizeX(), nTrackerHits); + alpaka::memcpy(queue, clusterSizeXOutputPixel, clusterSizeXPixel); + alpaka::memcpy(queue, clusterSizeXOutputTracker, clusterSizeXTracker); // clusterSizeY auto clusterSizeYOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().clusterSizeY(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().clusterSizeY(), nPixelHits); auto clusterSizeYOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().clusterSizeY() + nPixelHits, nTrackerHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().clusterSizeY() + nPixelHits, nTrackerHits); auto clusterSizeYPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().clusterSizeY(), nPixelHits); + cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().clusterSizeY(), nPixelHits); auto clusterSizeYTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().clusterSizeY(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), clusterSizeYOutputPixel, clusterSizeYPixel); - alpaka::memcpy(iEvent.queue(), clusterSizeYOutputTracker, clusterSizeYTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().clusterSizeY(), nTrackerHits); + alpaka::memcpy(queue, clusterSizeYOutputPixel, clusterSizeYPixel); + alpaka::memcpy(queue, clusterSizeYOutputTracker, clusterSizeYTracker); // detectorIndex auto detectorIndexOutputPixel = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().detectorIndex(), nPixelHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().detectorIndex(), nPixelHits); auto detectorIndexOutputTracker = - cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().detectorIndex() + nPixelHits, nTrackerHits); + cms::alpakatools::make_device_view(queue, outputSoA.view().detectorIndex() + nPixelHits, nTrackerHits); auto detectorIndexPixel = - cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().detectorIndex(), nPixelHits); + cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().detectorIndex(), nPixelHits); auto detectorIndexTracker = - cms::alpakatools::make_device_view(iEvent.queue(), otRecHitsSoA.view().detectorIndex(), nTrackerHits); - alpaka::memcpy(iEvent.queue(), detectorIndexOutputPixel, detectorIndexPixel); - alpaka::memcpy(iEvent.queue(), detectorIndexOutputTracker, detectorIndexTracker); + cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().detectorIndex(), nTrackerHits); + alpaka::memcpy(queue, detectorIndexOutputPixel, detectorIndexPixel); + alpaka::memcpy(queue, detectorIndexOutputTracker, detectorIndexTracker); - auto offsetBPIX2Output = cms::alpakatools::make_device_view(iEvent.queue(), outputSoA.view().offsetBPIX2()); - auto offsetBPIX2Pixel = cms::alpakatools::make_device_view(iEvent.queue(), pixelRecHitsSoA.view().offsetBPIX2()); - alpaka::memcpy(iEvent.queue(), offsetBPIX2Output, offsetBPIX2Pixel); + auto offsetBPIX2Output = cms::alpakatools::make_device_view(queue, outputSoA.view().offsetBPIX2()); + auto offsetBPIX2Pixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().offsetBPIX2()); + alpaka::memcpy(queue, offsetBPIX2Output, offsetBPIX2Pixel); // copy the moduleStart from pixelRecHitsSoA and otRecHitsSoA to outputSoA const int nPixelModules = pixelRecHitsSoA.nModules(); const int nTrackerModules = otRecHitsSoA.nModules() + 1; auto hitModuleStartOutputPixel = cms::alpakatools::make_device_view( - iEvent.queue(), outputSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); + queue, outputSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); auto hitModuleStartOutputTracker = cms::alpakatools::make_device_view( - iEvent.queue(), outputSoA.view<::reco::HitModuleSoA>().moduleStart() + nPixelModules, nTrackerModules); + queue, outputSoA.view<::reco::HitModuleSoA>().moduleStart() + nPixelModules, nTrackerModules); const auto hitModuleStartPixel = cms::alpakatools::make_device_view( - iEvent.queue(), pixelRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); + queue, pixelRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); const auto hitModuleStartTracker = cms::alpakatools::make_device_view( - iEvent.queue(), otRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nTrackerModules); - - alpaka::memcpy(iEvent.queue(), hitModuleStartOutputPixel, hitModuleStartPixel); - alpaka::memcpy(iEvent.queue(), hitModuleStartOutputTracker, hitModuleStartTracker); + queue, otRecHitsSoA.view<::reco::HitModuleSoA>().moduleStart(), nTrackerModules); + alpaka::memcpy(queue, hitModuleStartOutputPixel, hitModuleStartPixel); + alpaka::memcpy(queue, hitModuleStartOutputTracker, hitModuleStartTracker); + + outputSoA.updateFromDevice(queue); // emplace the merged SoA in the event iEvent.emplace(outputRecHitsSoAToken_, std::move(outputSoA)); } From da945f1c42279ffe5e36ad797bc8e3683a2ad418 Mon Sep 17 00:00:00 2001 From: Luca Ferragina Date: Mon, 26 May 2025 18:13:50 +0200 Subject: [PATCH 25/40] Remove +1 in number of modules (now taken care of by the HitPortableCollection) --- .../alpaka/SiPixelRecHitExtendedAlpaka.cc | 68 +++++++------------ 1 file changed, 25 insertions(+), 43 deletions(-) diff --git a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc index b8f92132b54d5..b58ff38e9da06 100644 --- a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc +++ b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc @@ -85,7 +85,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { std::cout << "Number of Tracker modules: " << otRecHitsSoA.nModules() << std::endl; const int nTotModules = pixelRecHitsSoA.nModules() + otRecHitsSoA.nModules(); - auto outputSoA = reco::TrackingRecHitsSoACollection(queue, nTotHits, nTotModules + 1); + auto outputSoA = reco::TrackingRecHitsSoACollection(queue, nTotHits, nTotModules); std::cout << "Total number of recHits: " << outputSoA.nHits() << std::endl; // copy all columns from pixelRecHitsSoA and otRecHitsSoA to outputSoA @@ -108,74 +108,56 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { alpaka::memcpy(queue, yLocalOutputTracker, yLocalTracker); // xerrLocal - auto xerrLocalOutputPixel = - cms::alpakatools::make_device_view(queue, outputSoA.view().xerrLocal(), nPixelHits); + auto xerrLocalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().xerrLocal(), nPixelHits); auto xerrLocalOutputTracker = cms::alpakatools::make_device_view(queue, outputSoA.view().xerrLocal() + nPixelHits, nTrackerHits); - auto xerrLocalPixel = - cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().xerrLocal(), nPixelHits); - auto xerrLocalTracker = - cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().xerrLocal(), nTrackerHits); + auto xerrLocalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().xerrLocal(), nPixelHits); + auto xerrLocalTracker = cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().xerrLocal(), nTrackerHits); alpaka::memcpy(queue, xerrLocalOutputPixel, xerrLocalPixel); alpaka::memcpy(queue, xerrLocalOutputTracker, xerrLocalTracker); // yerrLocal - auto yerrLocalOutputPixel = - cms::alpakatools::make_device_view(queue, outputSoA.view().yerrLocal(), nPixelHits); + auto yerrLocalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().yerrLocal(), nPixelHits); auto yerrLocalOutputTracker = cms::alpakatools::make_device_view(queue, outputSoA.view().yerrLocal() + nPixelHits, nTrackerHits); - auto yerrLocalPixel = - cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().yerrLocal(), nPixelHits); - auto yerrLocalTracker = - cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().yerrLocal(), nTrackerHits); + auto yerrLocalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().yerrLocal(), nPixelHits); + auto yerrLocalTracker = cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().yerrLocal(), nTrackerHits); alpaka::memcpy(queue, yerrLocalOutputPixel, yerrLocalPixel); alpaka::memcpy(queue, yerrLocalOutputTracker, yerrLocalTracker); // xGlobal - auto xGlobalOutputPixel = - cms::alpakatools::make_device_view(queue, outputSoA.view().xGlobal(), nPixelHits); + auto xGlobalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().xGlobal(), nPixelHits); auto xGlobalOutputTracker = cms::alpakatools::make_device_view(queue, outputSoA.view().xGlobal() + nPixelHits, nTrackerHits); - auto xGlobalPixel = - cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().xGlobal(), nPixelHits); - auto xGlobalTracker = - cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().xGlobal(), nTrackerHits); + auto xGlobalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().xGlobal(), nPixelHits); + auto xGlobalTracker = cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().xGlobal(), nTrackerHits); alpaka::memcpy(queue, xGlobalOutputPixel, xGlobalPixel); alpaka::memcpy(queue, xGlobalOutputTracker, xGlobalTracker); // yGlobal - auto yGlobalOutputPixel = - cms::alpakatools::make_device_view(queue, outputSoA.view().yGlobal(), nPixelHits); + auto yGlobalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().yGlobal(), nPixelHits); auto yGlobalOutputTracker = cms::alpakatools::make_device_view(queue, outputSoA.view().yGlobal() + nPixelHits, nTrackerHits); - auto yGlobalPixel = - cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().yGlobal(), nPixelHits); - auto yGlobalTracker = - cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().yGlobal(), nTrackerHits); + auto yGlobalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().yGlobal(), nPixelHits); + auto yGlobalTracker = cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().yGlobal(), nTrackerHits); alpaka::memcpy(queue, yGlobalOutputPixel, yGlobalPixel); alpaka::memcpy(queue, yGlobalOutputTracker, yGlobalTracker); // zGlobal - auto zGlobalOutputPixel = - cms::alpakatools::make_device_view(queue, outputSoA.view().zGlobal(), nPixelHits); + auto zGlobalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().zGlobal(), nPixelHits); auto zGlobalOutputTracker = cms::alpakatools::make_device_view(queue, outputSoA.view().zGlobal() + nPixelHits, nTrackerHits); - auto zGlobalPixel = - cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().zGlobal(), nPixelHits); - auto zGlobalTracker = - cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().zGlobal(), nTrackerHits); + auto zGlobalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().zGlobal(), nPixelHits); + auto zGlobalTracker = cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().zGlobal(), nTrackerHits); alpaka::memcpy(queue, zGlobalOutputPixel, zGlobalPixel); alpaka::memcpy(queue, zGlobalOutputTracker, zGlobalTracker); // rGlobal - auto rGlobalOutputPixel = - cms::alpakatools::make_device_view(queue, outputSoA.view().rGlobal(), nPixelHits); + auto rGlobalOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().rGlobal(), nPixelHits); auto rGlobalOutputTracker = cms::alpakatools::make_device_view(queue, outputSoA.view().rGlobal() + nPixelHits, nTrackerHits); - auto rGlobalPixel = - cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().rGlobal(), nPixelHits); - auto rGlobalTracker = - cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().rGlobal(), nTrackerHits); + auto rGlobalPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().rGlobal(), nPixelHits); + auto rGlobalTracker = cms::alpakatools::make_device_view(queue, otRecHitsSoA.view().rGlobal(), nTrackerHits); alpaka::memcpy(queue, rGlobalOutputPixel, rGlobalPixel); alpaka::memcpy(queue, rGlobalOutputTracker, rGlobalTracker); @@ -191,8 +173,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { // chargeAndStatus auto chargeAndStatusOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view().chargeAndStatus(), nPixelHits); - auto chargeAndStatusOutputTracker = cms::alpakatools::make_device_view( - queue, outputSoA.view().chargeAndStatus() + nPixelHits, nTrackerHits); + auto chargeAndStatusOutputTracker = + cms::alpakatools::make_device_view(queue, outputSoA.view().chargeAndStatus() + nPixelHits, nTrackerHits); auto chargeAndStatusPixel = cms::alpakatools::make_device_view(queue, pixelRecHitsSoA.view().chargeAndStatus(), nPixelHits); auto chargeAndStatusTracker = @@ -242,10 +224,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { // copy the moduleStart from pixelRecHitsSoA and otRecHitsSoA to outputSoA const int nPixelModules = pixelRecHitsSoA.nModules(); - const int nTrackerModules = otRecHitsSoA.nModules() + 1; + const int nTrackerModules = otRecHitsSoA.nModules(); - auto hitModuleStartOutputPixel = cms::alpakatools::make_device_view( - queue, outputSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); + auto hitModuleStartOutputPixel = + cms::alpakatools::make_device_view(queue, outputSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); auto hitModuleStartOutputTracker = cms::alpakatools::make_device_view( queue, outputSoA.view<::reco::HitModuleSoA>().moduleStart() + nPixelModules, nTrackerModules); @@ -256,7 +238,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { alpaka::memcpy(queue, hitModuleStartOutputPixel, hitModuleStartPixel); alpaka::memcpy(queue, hitModuleStartOutputTracker, hitModuleStartTracker); - + outputSoA.updateFromDevice(queue); // emplace the merged SoA in the event iEvent.emplace(outputRecHitsSoAToken_, std::move(outputSoA)); From c02e828711da36b333694e57b5bebebd2cc435e8 Mon Sep 17 00:00:00 2001 From: Luca Ferragina Date: Tue, 27 May 2025 09:44:43 +0200 Subject: [PATCH 26/40] Add back one +1 for merging --- .../plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc index b58ff38e9da06..64f27248a579f 100644 --- a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc +++ b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc @@ -224,7 +224,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { // copy the moduleStart from pixelRecHitsSoA and otRecHitsSoA to outputSoA const int nPixelModules = pixelRecHitsSoA.nModules(); - const int nTrackerModules = otRecHitsSoA.nModules(); + const int nTrackerModules = otRecHitsSoA.nModules() + 1; + // size of the copy nPixelModules + nTrackerModules + 1 to account for the last "hidden" + // element of the SoA, keeping track of the cumulative sum of all the hits in the previous + // modules (thus one more than the number of modules is required to account for the hits + // in the last tracker module) see also DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsDevice.h auto hitModuleStartOutputPixel = cms::alpakatools::make_device_view(queue, outputSoA.view<::reco::HitModuleSoA>().moduleStart(), nPixelModules); From 9c75ee1024c23c68e1a3895635b5723abcb4612d Mon Sep 17 00:00:00 2001 From: Luca Ferragina Date: Tue, 27 May 2025 16:11:55 +0200 Subject: [PATCH 27/40] Remove some leftover +1 in constructors' calls --- .../interface/alpaka/TrackingRecHitsSoACollection.h | 2 +- .../plugins/alpaka/Phase2OTRecHitsSoAConverter.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DataFormats/TrackingRecHitSoA/interface/alpaka/TrackingRecHitsSoACollection.h b/DataFormats/TrackingRecHitSoA/interface/alpaka/TrackingRecHitsSoACollection.h index 5370a9411505b..6750a42334bcb 100644 --- a/DataFormats/TrackingRecHitSoA/interface/alpaka/TrackingRecHitsSoACollection.h +++ b/DataFormats/TrackingRecHitSoA/interface/alpaka/TrackingRecHitsSoACollection.h @@ -63,7 +63,7 @@ namespace cms::alpakatools { auto nHits = hostData.nHits(); - reco::TrackingRecHitDevice deviceData(queue, nHits, hostData.nModules() + 1); + reco::TrackingRecHitDevice deviceData(queue, nHits, hostData.nModules()); if (nHits == 0) { std::memset( diff --git a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc index ed64e782033e3..c4f86f3d5bce5 100644 --- a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc +++ b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc @@ -136,7 +136,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { std::cout << "Number of strip hits: " << nStripHits << std::endl; std::cout << "Total hits of PinOTBarrel: " << PHitsInOTBarrel << std::endl; - HitsHost stripHitsHost(queue, PHitsInOTBarrel, p_modulesInPSInOTBarrel.size() + 1); + HitsHost stripHitsHost(queue, PHitsInOTBarrel, p_modulesInPSInOTBarrel.size()); auto& stripHitsModuleView = stripHitsHost.view<::reco::HitModuleSoA>(); std::vector counterOfHitsPerModule(p_modulesInPSInOTBarrel.size(), 0); @@ -250,7 +250,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { alpaka::memcpy(queue, moduleStartVec, moduleStartView); iEvent.emplace(hitModuleStart_, std::move(moduleStartVec)); - Hits stripHitsDevice(queue, stripHitsHost.view().metadata().size(), stripHitsModuleView.metadata().size()); + Hits stripHitsDevice(queue, stripHitsHost.view().metadata().size(), stripHitsHost.nModules()); alpaka::memcpy(queue, stripHitsDevice.buffer(), stripHitsHost.buffer()); stripHitsDevice.updateFromDevice(queue); From aeb88e48f70d71d37ba35c6c59a70abbb069f6cf Mon Sep 17 00:00:00 2001 From: Marco Musich Date: Tue, 27 May 2025 09:08:13 +0200 Subject: [PATCH 28/40] allow SingleMuPt15Eta0p_0p4 configuration fragment for NGT scouting workflow and add an alpaka variant for it --- .../python/upgradeWorkflowComponents.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Configuration/PyReleaseValidation/python/upgradeWorkflowComponents.py b/Configuration/PyReleaseValidation/python/upgradeWorkflowComponents.py index 42961bc4f8b83..9bc35cd0a4503 100644 --- a/Configuration/PyReleaseValidation/python/upgradeWorkflowComponents.py +++ b/Configuration/PyReleaseValidation/python/upgradeWorkflowComponents.py @@ -1978,7 +1978,7 @@ def setup_(self, step, stepName, stepDict, k, properties): else: stepDict[stepName][k] = merge([stepDict[step][k]]) def condition(self, fragment, stepList, key, hasHarvest): - return fragment=="TTbar_14TeV" and 'Run4' in key + return (fragment=="TTbar_14TeV" or fragment=="SingleMuPt15Eta0p_0p4") and 'Run4' in key upgradeWFs['NGTScouting'] = UpgradeWorkflow_NGTScouting( steps = [ 'Reco', @@ -2012,6 +2012,19 @@ def condition(self, fragment, stepList, key, hasHarvest): '-s':'HARVESTING:@hltValidation' } +upgradeWFs['NGTScoutingAlpaka'] = deepcopy(upgradeWFs['NGTScouting']) +upgradeWFs['NGTScoutingAlpaka'].suffix = '_NGTScoutingAlpaka' +upgradeWFs['NGTScoutingAlpaka'].offset = 0.771 +upgradeWFs['NGTScoutingAlpaka'].step2 = { + '-s':'DIGI:pdigi_valid,L1TrackTrigger,L1,L1P2GT,DIGI2RAW,HLT:NGTScouting,VALIDATION:@hltValidation', + '--procModifiers': 'alpaka', + '--datatier':'GEN-SIM-DIGI-RAW,DQMIO', + '--eventcontent':'FEVTDEBUGHLT,DQMIO' +} +upgradeWFs['NGTScoutingAlpaka'].step3 = { + '-s':'HARVESTING:@hltValidation' +} + class UpgradeWorkflow_L1Complete(UpgradeWorkflow): def setup_(self, step, stepName, stepDict, k, properties): if 'Digi' in step and 'NoHLT' not in step: From ba68f55ae2f3c6784addc651e252526c98ac73f4 Mon Sep 17 00:00:00 2001 From: adriano Date: Wed, 28 May 2025 00:59:17 +0200 Subject: [PATCH 29/40] Properly sizing hitToTuple buffers --- .../alpaka/CAHitNtupletGeneratorKernels.dev.cc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc index aa77113a6e44b..3a65d947f4b43 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc @@ -36,13 +36,17 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { // ALLOCATIONS FOR THE INTERMEDIATE RESULTS (STAYS ON WORKER) ////////////////////////////////////////////////////////// - counters_ = cms::alpakatools::make_device_buffer(queue); - // Here we define the OneToMany maps and the histograms - // allocating the buffers and defining the views. - // For each map/histo, we need: - // - a buffer for the offsets sized as the number of ones + 1 - // (with the last bin holding the total number of ones) - // - a buffer fot the content/storage itself sized as the number of many + // One to Many Maps + // Hits -> Track + device_hitToTuple_{cms::alpakatools::make_device_buffer(queue)}, + device_hitToTupleStorage_{cms::alpakatools::make_device_buffer( + queue, int(maxTuples * m_params.algoParams_.avgHitsPerTrack_) + 1)}, + device_hitToTupleOffsets_{cms::alpakatools::make_device_buffer(queue, nHits + 1)}, + device_hitToTupleView_{device_hitToTuple_.data(), + device_hitToTupleOffsets_.data(), + device_hitToTupleStorage_.data(), + int(nHits + 1), + int(maxTuples * m_params.algoParams_.avgHitsPerTrack_) + 1}, auto const &algoParams = m_params.algoParams_; int outerHits = From 5539b07341ae33d15f4b1150b06199db2eb9d615 Mon Sep 17 00:00:00 2001 From: Luca Ferragina Date: Fri, 6 Jun 2025 11:15:11 +0200 Subject: [PATCH 30/40] Fix CA to work both with and without OT extension The traits guarding Phase2 and Phase2OT should now be guarded correctly --- RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc index 0e3508f80e98a..3fd3026fe1e45 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc @@ -37,7 +37,7 @@ #include "RecoTracker/PixelSeeding/interface/CAGeometrySoA.h" #include "DataFormats/SiStripDetId/interface/StripSubdetector.h" -#define GPU_DEBUG +// #define GPU_DEBUG namespace reco { struct CAGeometryParams { @@ -163,7 +163,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF || trackerGeometry.getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF3D); }; - if constexpr (std::is_base_of_v) { + if constexpr (std::is_same_v) { int counter = 0; for (auto& det : dets) { DetId detid = det->geographicalId(); @@ -238,7 +238,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { auto cellSoA = product.view<::reco::CAGraphSoA>(); auto modulesSoA = product.view<::reco::CAModulesSoA>(); - if constexpr (std::is_base_of_v) { + if constexpr (std::is_same_v) { for (int i = 0; i < n_modules; ++i) { auto idx = moduleToindexInDets[i]; auto det = dets[idx]; From 0e86ec0975f2f46201f4867098d011cb37d77b7d Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Tue, 10 Jun 2025 15:41:15 +0200 Subject: [PATCH 31/40] WIP on CA-EXT. --- .../interface/alpaka/TrackUtilities.h | 2 + .../modules/hltPhase2PixelTracksSoA_cfi.py | 596 +++++++++++++++++- .../alpaka/Phase2OTRecHitsSoAConverter.cc | 4 + .../plugins/alpaka/BrokenLineFit.dev.cc | 14 +- .../plugins/alpaka/CAHitNtuplet.cc | 24 +- .../alpaka/CAHitNtupletGeneratorKernelsImpl.h | 31 +- .../plugins/alpaka/CAPixelDoubletsAlgos.h | 67 +- .../plugins/alpaka/CASimpleCell.h | 302 +++++++++ .../interface/alpaka/BrokenLine.h | 2 +- .../PixelTrackProducerFromSoAAlpaka.cc | 8 +- 10 files changed, 997 insertions(+), 53 deletions(-) create mode 100644 RecoTracker/PixelSeeding/plugins/alpaka/CASimpleCell.h diff --git a/DataFormats/TrackSoA/interface/alpaka/TrackUtilities.h b/DataFormats/TrackSoA/interface/alpaka/TrackUtilities.h index 8d9a65f69d67c..ffcac69e26f68 100644 --- a/DataFormats/TrackSoA/interface/alpaka/TrackUtilities.h +++ b/DataFormats/TrackSoA/interface/alpaka/TrackUtilities.h @@ -1,6 +1,8 @@ #ifndef DataFormats_TrackSoA_interface_alpaka_TrackUtilities_h #define DataFormats_TrackSoA_interface_alpaka_TrackUtilities_h +// MRMR #define NTUPLE_FIT_DEBUG // MRMR + #include #include #include diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py index e0405af677071..19c7d8ad286da 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py @@ -1,24 +1,27 @@ import FWCore.ParameterSet.Config as cms +removeOT = False + hltPhase2PixelTracksSoA = cms.EDProducer('CAHitNtupletAlpakaPhase2OT@alpaka', pixelRecHitSrc = cms.InputTag('hltPhase2PixelRecHitsExtendedSoA'), ptmin = cms.double(0.9), - hardCurvCut = cms.double(0.0328407225), +# hardCurvCut = cms.double(0.0328407225), + hardCurvCut = cms.double(0.01425), # corresponds to 800 MeV in 3.8T. earlyFishbone = cms.bool(True), lateFishbone = cms.bool(False), fillStatistics = cms.bool(True), - minHitsPerNtuplet = cms.uint32(4), - maxNumberOfDoublets = cms.string(str(5*512*1024)), - maxNumberOfTuples = cms.string(str(60*1024)), - cellPtCut = cms.double(0.85), - cellZ0Cut = cms.double(7.5), + minHitsPerNtuplet = cms.uint32(5), + maxNumberOfDoublets = cms.string(str(15*512*1024)), + maxNumberOfTuples = cms.string(str(2*60*1024)), + cellPtCut = cms.double(0.85), # Corresponds to 1 GeV * this cut, i.e., 850 MeV, as minimum p_t + cellZ0Cut = cms.double(12.5), # it's half the BS width! It has nothing to do with the sample!! minYsizeB1 = cms.int32(25), minYsizeB2 = cms.int32(15), maxDYsize12 = cms.int32(12), maxDYsize = cms.int32(10), maxDYPred = cms.int32(20), avgHitsPerTrack = cms.double(10.0), - avgCellsPerHit = cms.double(20), + avgCellsPerHit = cms.double(25), avgCellsPerCell = cms.double(5), avgTracksPerCell = cms.double(5), minHitsForSharingCut = cms.uint32(10), @@ -31,18 +34,579 @@ maxChi2 = cms.double(5.0), minPt = cms.double(0.9), maxTip = cms.double(0.3), - maxZip = cms.double(12.), + maxZip = cms.double(12), ), geometry = cms.PSet( - caDCACuts = cms.vdouble(0.15, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25), - caThetaCuts = cms.vdouble(0.002, 0.002, 0.002, 0.002, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003), - startingPairs = cms.vint32(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32), - pairGraph = cms.vint32(0, 1, 0, 4, 0, 16, 1, 2, 1, 4, 1, 16, 2, 3, 2, 4, 2, 16, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 0, 2, 0, 5, 0, 17, 0, 6, 0, 18, 1, 3, 1, 5, 1, 17, 1, 6, 1, 18, 11, 12, 12, 13, 13, 14, 14, 15, 23, 24, 24, 25, 25, 26, 26, 27, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 16, 18, 17, 19, 18, 20, 19, 21, 20, 22, 21, 23, 22, 24, 2, 28, 3, 28, 3, 29, 28, 29, 28, 30, 29, 30), - phiCuts = cms.vint32(522, 522, 522, 626, 730, 730, 626, 730, 730, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522, 522), - minZ = cms.vdouble(-16, 4, -22, -17, 6, -22, -18, 11, -22, 23, 30, 39, 50, 65, 82, 109, -28, -35, -44, -55, -70, -87, -113, -16, 7, -22, 11, -22, -17, 9, -22, 13, -22, 137, 173, 199, 229, -142, -177, -203, -233, 23, 30, 39, 50, 65, 82, 109, -28, -35, -44, -55, -70, -87, -113, -1000, -1000, -1000, -1000, -1000, -1000), - maxZ = cms.vdouble(17, 22, -4, 17, 22, -6, 18, 22, -11, 28, 35, 44, 55, 70, 87, 113, -23, -30, -39, -50, -65, -82, -109, 17, 22, -7, 22, -10, 17, 22, -9, 22, -13, 142, 177, 203, 233, -137, -173, -199, -229, 28, 35, 44, 55, 70, 87, 113, -23, -30, -39, -50, -65, -82, -109, 1000, 1000, 1000, 1000, 1000, 1000), - maxR = cms.vdouble(5, 5, 5, 7, 8, 8, 7, 7, 7, 6, 6, 6, 6, 5, 6, 5, 6, 6, 6, 6, 5, 6, 5, 5, 5, 5, 5, 5, 5, 8, 8, 8, 8, 6, 5, 5, 5, 6, 5, 5, 5, 9, 9, 9, 8, 8, 8, 11, 9, 9, 9, 8, 8, 8, 11, 60, 60, 60, 60, 60, 60) + # This cut also uses the hardCurvCut parameters inside the + # Kernel_connect "function". This is used to cut connections that have + # either a too low p_t or that do not intersect the BS+tolerance + # region. Internally, this cut is compared against the circle.dca0() in + # natural units divided by circle.curvature(), where circle is the + # circle passing through the 3 points of the triplet under + # investigation. Therefore the cut represent the compatibility of the + # circle in the transverse plane and the units are meant to be cm. + caDCACuts = cms.vdouble( + 0.15, # 0 + 0.25, # 1 + 0.20, # 2 + 0.20, # End PXB # 3 + 0.25, # 4 + 0.25, # 5 + 0.25, # 6 + 0.25, # 7 + 0.25, # 8 + 0.25, # 9 + 0.25, # 10 + 0.25, # 11 + 0.25, # 12 + 0.25, # 13 + 0.25, # 14 + 0.25, # End PXFWD+ # 15 + 0.25, # 16 + 0.25, # 17 + 0.25, # 18 + 0.25, # 19 + 0.25, # 20 + 0.25, # 21 + 0.25, # 22 + 0.25, # 23 + 0.25, # 24 + 0.25, # 25 + 0.25, # 26 + 0.25, # End PXFWD- # 27 + 0.10, # 28 + 0.10, # 29 + 0.25), # End of OT PinPS # 30 + # caThetaCut is used in the areAlignedRZ function to check if two + # sibling cell are compatible in the R-Z plane. In that same function, + # we also use ptmin variable. The caThetaCut is assigned to the SoA of + # the layers, and is percolated into this compatibility function via + # the SoA itself. + caThetaCuts = cms.vdouble( + 0.002, # 0 + 0.002, # 1 + 0.002, # 2 + 0.002, # 3 + 0.003, # 4 + 0.003, # 5 + 0.003, # 6 + 0.003, # 7 + 0.003, # 8 + 0.003, # 9 + 0.003, # 10 + 0.003, # 11 + 0.003, # 12 + 0.003, # 13 + 0.003, # 14 + 0.003, # 15 + 0.003, # 16 + 0.003, # 17 + 0.003, # 18 + 0.003, # 19 + 0.003, # 20 + 0.003, # 21 + 0.003, # 22 + 0.003, # 23 + 0.003, # 24 + 0.003, # 25 + 0.003, # 26 + 0.003, # 26 + 0.003, # 27 + 0.003, # 29 + 0.003), # 30 + startingPairs = cms.vint32( + 0, # PXB0-1 + 1, # PXB0-4 + 2, # PXB0-16 + 3, # PXB1-2 + 4, # PXB1-4 + 5, # PXB1-16 + 6, # PXB2-3 + 7, # PXB2-4 + 8, # PXB2-16 + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28), +# 29, +# 30, +# 31, +# 32), + pairGraph = cms.vint32( + 0, 1, # 0 + 0, 4, # 1 + 0, 16, # 2 + 1, 2, # 3 + 1, 4, # 4 + 1, 16, # 5 + 2, 3, # 6 + 2, 4, # 7 + 2, 16, # 8 + 4, 5, # 9 + 5, 6, # 10 + 6, 7, # 11 + 7, 8, # 12 + 8, 9, # 13 + 9, 10, # 14 + 10, 11, # 15 + 16, 17, # 16 + 17, 18, # 17 + 18, 19, # 18 + 19, 20, # 19 + 20, 21, # 20 + 21, 22, # 21 + 22, 23, # 22 + 0, 2, # 23 + 0, 5, # 24 + 0, 17, # 25 + 0, 6, # 26 + 0, 18, # 27 + 1, 3, # 28 +# 2, 5, # 29 + 1, 5, # 31 + 1, 17, # 30 +# 1, 18, # last starting pair # 32 + 11, 12, # 33 + 12, 13, # 34 + 13, 14, # 35 + 14, 15, # 36 + 23, 24, # 37 + 24, 25, # 38 + 25, 26, # 39 + 26, 27, # 40 + 4, 6, # 41 + 5, 7, # 42 + 6, 8, # 43 + 7, 9, # 44 + 8, 10, # 45 + 9, 11, # 46 + 10, 12, # 47 + 16, 18, # 48 + 17, 19, # 49 + 18, 20, # 50 + 19, 21, # 51 + 20, 22, # 52 + 21, 23, # 53 + 22, 24, # 54 + 2, 28, # 55 + 3, 28, # 56 +# 3, 29, # 57 + 28, 29, # 58 +# 28, 30, # 59 + 29, 30, # 60 + 4, 28, # 61 + 5, 28, # 62 +## 6, 28, # 63 +# 7, 28, # 64 from top 0 # 64 +# 8, 28, # 65 +# 9, 28, # 66 + 16, 28, # 67 + 17, 28, # 68 +## 18, 28, # 69 +# 19, 28, # 70 +# 20, 28, # 71 +# 21, 28, # 72 +# 4, 29, # 73 +# 5, 29, # 74 +# 6, 29, # 75 +# 7, 29, # 76 +# 8, 29, # 77 +# 16, 29, # 78 +# 17, 29, # 79 +# 18, 29, # 80 +# 19, 29, # 81 +# 20, 29 # 82 + ), + phiCuts = cms.vint32( + 522, # 0 + 522, # 1 + 522, # 2 + 626, # 3 + 730, # 4 + 730, # 5 + 626, # 6 + 730, # 7 + 730, # 8 + 522, # 9 + 522, # 10 + 522, # 11 + 522, # 12 + 522, # 13 + 522, # 14 + 522, # 15 + 522, # 16 + 522, # 17 + 522, # 18 + 522, # 19 + 522, # 20 + 522, # 21 + 522, # 22 + 522, # 23 + 522, # 24 + 522, # 25 + 522, # 26 + 522, # 27 + 522, # 28 +# 730, # 29 + 730, # 30 + 730, # 31 +# 730, # 32 + 730, # 33 + 730, # 34 + 730, # 35 + 730, # 36 + 730, # 37 + 730, # 38 + 730, # 39 + 730, # 40 + 730, # 41 + 730, # 42 + 730, # 43 + 730, # 44 + 730, # 45 + 730, # 46 + 1000, # 47 + 1000, # 48 + 1000, # 49 + 1000, # 50 + 1000, # 51 + 1000, # 52 + 1000, # 53 + 1000, # 54 + 1000, # 55 + 1000, # 56 +# 1000, # 57 + 1000, # 58 +# 1000, # 59 + 1000, # 60 + 1000, # 61 + 1000, # 62 +## 1000, # 63 +# 1000, # 64 # 64 from top 0 +# 1000, # 65 +# 1000, # 66 + 1000, # 67 + 1000, # 68 +## 1000, # 69 +# 1000, # 70 +# 1000, # 71 +# 1000, # 72 +# 1000, # 73 +# 1000, # 74 +# 1000, # 75 +# 1000, # 76 +# 1000, # 77 +# 1000, # 78 +# 1000, # 79 +# 1000, # 80 +# 1000, # 81 +# 1000 # 82 + ), + # minZ and maxZ are the limit in Z for the inner cell of a doublets in + # order to be able to make a doublet with the other layer. + minZ = cms.vdouble( + -17, # 0 + 4, # 1 + -22, # 2 + -18, # 3 + 8, # 4 + -22, # 5 + -22, # 6 + 11, # 7 + -22, # 8 + 23, # 9 + 30, # 10 + 39, # 11 + 50, # 12 + 65, # 13 + 82, # 14 + 109, # 15 + -28, # 16 + -35, # 17 + -44, # 18 + -55, # 19 + -70, # 20 + -87, # 21 + -113, # 22 + -17, # 23 + 7, # 24 + -22, # 25 + 11, # 26 + -22, # 27 + -19, # 28 +# 9, # 29 + -22, # 30 + 9, # 31 +# -22, # 32 + 137, # 33 + 173, # 34 + 199, # 35 + 229, # 36 + -142, # 37 + -177, # 38 + -203, # 39 + -233, # 40 + 23, # 41 + 30, # 42 + 39, # 43 + 50, # 44 + 65, # 45 + 82, # 46 + 109, # 47 + -28, # 48 + -35, # 49 + -44, # 50 + -55, # 51 + -70, # 52 + -87, # 53 + -113, # 54 + -20, # 55 + -20, # 56 +# -40, # 57 + -1200, # 58 +# -40, # 59 + -1200, # 60 + 23, # 61 + 30, # 62 +## -20, # 63 +# -1000, # 64 # 64 from top 0 +# -1000, # 65 +# -1000, # 66 + -28, # 67 + -35, # 68 +## -20, # 69 +# -1000, # 70 +# -1000, # 71 +# -1000, # 72 +# -1000, # 73 +# -1000, # 74 +# -1000, # 75 +# -1000, # 76 +# -1000, # 77 +# -1000, # 78 +# -1000, # 79 +# -1000, # 80 +# -1000, # 81 +# -1000 # 82 + ), + maxZ = cms.vdouble( + 17, # 0 + 22, # 1 + -4, # 2 + 18, # 3 + 22, # 4 + -8, # 5 + 22, # 6 + 22, # 7 + -11, # 8 + 28, # 9 + 35, # 10 + 44, # 11 + 55, # 12 + 70, # 13 + 87, # 14 + 113, # 15 + -23, # 16 + -30, # 17 + -39, # 18 + -50, # 19 + -65, # 20 + -82, # 21 + -109, # 22 + 17, # 23 + 22, # 24 + -7, # 25 + 22, # 26 + -11, # 27 + 19, # 28 +# 22, # 29 + -9, # 30 + 22, # 31 +# -13, # 32 + 142, # 33 + 177, # 34 + 203, # 35 + 233, # 36 + -137, # 37 + -173, # 38 + -199, # 39 + -229, # 40 + 28, # 41 + 35, # 42 + 44, # 43 + 55, # 44 + 70, # 45 + 87, # 46 + 113, # 47 + -23, # 48 + -30, # 49 + -39, # 50 + -50, # 51 + -65, # 52 + -82, # 53 + -109, # 54 + 20, # 55 + 20, # 56 +# 40, # 57 + 1200, # 58 +# 40, # 59 + 1200, # 60 + 28, # 61 + 35, # 62 +## 20, # 63 +# 1000, # 64 64 gtom top 0 +# 1000, # 65 +# 1000, # 66 + -23, # 67 + -30, # 68 +## 20, # 69 +# 1000, # 70 +# 1000, # 71 +# 1000, # 72 +# 1000, # 73 +# 1000, # 74 +# 1000, # 75 +# 1000, # 76 +# 1000, # 77 +# 1000, # 78 +# 1000, # 79 +# 1000, # 80 +# 1000, # 81 +# 1000 # 82 + ), + maxR = cms.vdouble( + 5, # 0 + 5, # 1 + 5, # 2 + 7, # 3 + 8, # 4 + 8, # 5 + 7, # 6 + 7, # 7 + 7, # 8 + 6, # 9 + 6, # 10 + 6, # 11 + 6, # 12 + 5, # 13 + 6, # 14 + 5, # 15 + 6, # 16 + 6, # 17 + 6, # 18 + 6, # 19 + 5, # 20 + 6, # 21 + 5, # 22 + 10, # 23 + 10, # 24 + 10, # 25 + 5, # 26 + 5, # 27 + 10, # 28 +# 10, # 29 + 10, # 30 + 8, # 31 +# 8, # 32 + 6, # 33 + 5, # 34 + 5, # 35 + 5, # 36 + 6, # 37 + 5, # 38 + 5, # 39 + 5, # 40 + 9, # 41 + 9, # 42 + 9, # 43 + 8, # 44 + 8, # 45 + 8, # 46 + 11, # 47 + 9, # 48 + 9, # 49 + 9, # 50 + 8, # 51 + 8, # 52 + 8, # 53 + 11, # 54 + 60, # 55 + 60, # 56 +# 60, # 57 + 60, # 58 +# 60, # 59 + 60, # 60 + 60, # 61 + 60, # 62 +## 60,# 63 +# 60, # 64 64 from top 0 +# 60, # 65 +# 60, # 66 + 60, # 67 + 60, # 68 +## 60,# 69 +# 60, # 70 +# 60, # 71 +# 60, # 72 +# 60, # 73 +# 60, # 74 +# 60, # 75 +# 60, # 76 +# 60, # 77 +# 60, # 78 +# 60, # 79 +# 60, # 80 +# 60, # 81 +# 60 # 82 + ) ), # autoselect the alpaka backend alpaka = cms.untracked.PSet(backend = cms.untracked.string('')) ) + + +def exclude_layers(hltPhase2PixelTracksSoA, layers_to_exclude): + keep_indices = [] + num_pairs = len(hltPhase2PixelTracksSoA.geometry.pairGraph) // 2 + for i in range(num_pairs): + a = hltPhase2PixelTracksSoA.geometry.pairGraph[2*i] + b = hltPhase2PixelTracksSoA.geometry.pairGraph[2*i + 1] + if a not in layers_to_exclude and b not in layers_to_exclude: + keep_indices.append(i) + # Now update in place + # For pairGraph, build the new flat list from kept pairs + new_pairGraph = [] + for i in keep_indices: + new_pairGraph.extend([hltPhase2PixelTracksSoA.geometry.pairGraph[2*i], hltPhase2PixelTracksSoA.geometry.pairGraph[2*i+1]]) + + hltPhase2PixelTracksSoA.geometry.pairGraph[:] = new_pairGraph + # Update all other lists in place + hltPhase2PixelTracksSoA.geometry.phiCuts[:] = [hltPhase2PixelTracksSoA.geometry.phiCuts[i] for i in keep_indices] + hltPhase2PixelTracksSoA.geometry.minZ[:] = [hltPhase2PixelTracksSoA.geometry.minZ[i] for i in keep_indices] + hltPhase2PixelTracksSoA.geometry.maxZ[:] = [hltPhase2PixelTracksSoA.geometry.maxZ[i] for i in keep_indices] + hltPhase2PixelTracksSoA.geometry.maxR[:] = [hltPhase2PixelTracksSoA.geometry.maxR[i] for i in keep_indices] + + + +if removeOT: + ot_layers_ = [28, 29, 30] + exclude_layers(hltPhase2PixelTracksSoA, layers_to_exclude=ot_layers_) + +print("Using {} pair connections: {}".format(len(hltPhase2PixelTracksSoA.geometry.pairGraph), hltPhase2PixelTracksSoA.geometry.pairGraph)) + diff --git a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc index c4f86f3d5bce5..9b800bfc983d0 100644 --- a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc +++ b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc @@ -103,6 +103,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF3D); }; + // TODO(rovere) move this logic out of produce, since it's partially bound only to the geometry...?? auto const& detUnits = trackerGeometry->detUnits(); std::map detIdToIndex; std::set p_modulesInPSInOTBarrel; @@ -202,10 +203,13 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { stripHitsHost.view()[idx].yLocal() = recHit.localPosition().y(); stripHitsHost.view()[idx].xerrLocal() = recHit.localPositionError().xx(); stripHitsHost.view()[idx].yerrLocal() = recHit.localPositionError().yy(); + std::cout << "Local (x, y) with (xx, yy) --> (" << recHit.localPosition().x() << ", " << recHit.localPosition().y() << ") with (" << recHit.localPositionError().xx() << ", " << recHit.localPositionError().yy() << ")" << std::endl; auto globalPosition = det->toGlobal(recHit.localPosition()); double gx = globalPosition.x() - bs.x0(); double gy = globalPosition.y() - bs.y0(); double gz = globalPosition.z() - bs.z0(); + std::cout << "Global (x, y, z) --> (" << globalPosition.x() << ", " << globalPosition.y() << ", " << globalPosition.z() << ")" << std::endl; + std::cout << "Corrected Global (x, y, z) --> (" << gx << ", " << gy << ", " << gz << ")" << std::endl; // std::cout << gx << std::endl; stripHitsHost.view()[idx].xGlobal() = gx; stripHitsHost.view()[idx].yGlobal() = gy; diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/BrokenLineFit.dev.cc b/RecoTracker/PixelSeeding/plugins/alpaka/BrokenLineFit.dev.cc index 841ae7a74b6dd..21620747cd51d 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/BrokenLineFit.dev.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/BrokenLineFit.dev.cc @@ -1,6 +1,6 @@ -// #define BROKENLINE_DEBUG -// #define BL_DUMP_HITS -// #define GPU_DEBUG +// MRMR #define BROKENLINE_DEBUG // MRMR +// MRMR #define BL_DUMP_HITS // MRMR +// MRMR #define GPU_DEBUG // MRMR #include #include @@ -137,7 +137,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { #ifdef BL_DUMP_HITS bool dump = foundNtuplets->size(tkid) == 5; if (dump) { - printf("Track id %d %d Hit %d on %d\nGlobal: hits.col(%d) << %f,%f,%f\n", + printf("Track id %d %d Hit %d on %d\nGlobal: hits.col(%d) << %f,%f,r(%f),%f\n", local_idx, tkid, hit, @@ -145,6 +145,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { i, hh[hit].xGlobal(), hh[hit].yGlobal(), + sqrt(hh[hit].xGlobal()*hh[hit].xGlobal()+hh[hit].yGlobal()*hh[hit].yGlobal()), hh[hit].zGlobal()); printf("Error: hits_ge.col(%d) << %e,%e,%e,%e,%e,%e\n", i, ge[0], ge[1], ge[2], ge[3], ge[4], ge[5]); } @@ -154,6 +155,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { hits_ge.col(i) << ge[0], ge[1], ge[2], ge[3], ge[4], ge[5]; } brokenline::fastFit(acc, hits, fast_fit); +#if 0 + printf("Fast Fit: %f, %f, %f, %f\n", fast_fit(0), fast_fit(1), fast_fit(2), fast_fit(3)); +#endif #ifdef BROKENLINE_DEBUG // any NaN value should cause the track to be rejected at a later stage @@ -226,7 +230,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { circle.par(1), circle.par(2)); printf("kernelBLHits line.par(0,1): %d %f,%f\n", tkid, line.par(0), line.par(1)); - printf("kernelBLHits chi2 cov %f/%f %e,%e,%e,%e,%e\n", + printf("kernelBLHits chi2 cov circle/line %f/%f %e,%e,%e,%e,%e\n", circle.chi2, line.chi2, circle.cov(0, 0), diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc index 3fd3026fe1e45..ac3a7137d4821 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc @@ -168,13 +168,15 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { for (auto& det : dets) { DetId detid = det->geographicalId(); auto layer = trackerTopology.layer(detid); +// std::cout << "Looping on " << detid.rawId() << " on layer " << layer << std::endl; // Logic: // - if we are not inside pixels, we need to ignore anything **but** the OT. // - for the time being, this is assuming that the CA extension will // only cover the OT barrel part, and will ignore the OT forward. if (isPh2Pixel(detid)) { +// std::cout << "Good Pixel" << std::endl; if (layer != oldLayer) { - std::cout << "Pixel LayerStart: " << layerCount << " has " << n_modules << " modules." << std::endl; + std::cout << "Pixel LayerStart: " << layerCount << " at layer " << layer << " has " << n_modules << " modules." << std::endl; layerStarts[layerCount++] = n_modules; if (layerCount > n_layers + 1) break; @@ -187,8 +189,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { for (auto& detUnit : detUnits) { DetId unitDetId(detUnit->geographicalId()); if (isPinPSinOTBarrel(unitDetId)) { +// std::cout << "Good OT Barrel" << std::endl; if (layer != oldLayer) { - std::cout << "OT LayerStart: " << layerCount << " has " << n_modules << " modules." << std::endl; + std::cout << "OT LayerStart: " << layerCount << " at layer " << layer << " has " << n_modules << " modules." << std::endl; layerStarts[layerCount++] = n_modules; if (layerCount > n_layers + 1) break; @@ -196,8 +199,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { } moduleToindexInDets.push_back(counter); n_modules++; + } else { +// std::cout << "BAD OT" << std::endl; } } +// std::cout << "Done OT" << std::endl; } counter++; } @@ -242,9 +248,23 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { for (int i = 0; i < n_modules; ++i) { auto idx = moduleToindexInDets[i]; auto det = dets[idx]; +#ifdef GPU_DEBUG + auto const& detUnits = det->components(); + for (auto& detUnit : detUnits) { + DetId unitDetId(detUnit->geographicalId()); + if (isPinPSinOTBarrel(unitDetId)) { + std::cout << "Filling frame at index " << idx << " in SoA position " << i << " for det " << det->geographicalId() << " and detUnit->index: " << detUnit->index() << std::endl; + } + } + std::cout << "Filling frame at index " << idx << " in SoA position " << i << " for det " << det->geographicalId() << std::endl; +#endif auto vv = det->surface().position(); auto rr = Rotation(det->surface().rotation()); modulesSoA[i].detFrame() = Frame(vv.x(), vv.y(), vv.z(), rr); +#ifdef GPU_DEBUG + std::cout << "Position: " << vv << " with Rotation: " << det->surface().rotation() << std::endl; + std::cout << "Rotation in Z-r plane: " << atan2(det->surface().normalVector().perp(),det->surface().normalVector().z())*180./M_PI << std::endl; +#endif } for (int i = 0; i < n_layers; ++i) { diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h index 142f4f6bfcf37..eb5c4c3594997 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h @@ -401,18 +401,20 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { if (aligned && thisCell.dcaCut(hh, oc, dcaCut, params.hardCurvCut_)) { auto t_ind = alpaka::atomicAdd(acc, nTrips, 1u, alpaka::hierarchy::Blocks{}); #ifdef CA_DEBUG - printf("Triplet no. %d %.5f %.5f (%d %d) - %d %d -> (%d, %d, %d, %d) \n", - t_ind, - thetaCut, - dcaCut, - thisCell.layerPairId(), - oc.layerPairId(), - otherCell, - cellIndex, - thisCell.inner_hit_id(), - thisCell.outer_hit_id(), - oc.inner_hit_id(), - oc.outer_hit_id()); + if (cms::alpakatools::once_per_grid(acc)) + printf("%-10s %-7s %-7s %-3s %-3s %-3s %-3s %-4s %-4s %-4s %-4s\n", "Triplet#", "Theta", "DCA", "LI", "LO", "OC", "CI", "i1", "o1", "i2", "o2"); + printf("%-10d %-7.5f %-7.5f %-3d %-3d %-3d %-3d %-4d %-4d %-4d %-4d\n", + t_ind, + thetaCut, + dcaCut, + thisCell.layerPairId(), + oc.layerPairId(), + otherCell, + cellIndex, + thisCell.inner_hit_id(), + thisCell.outer_hit_id(), + oc.inner_hit_id(), + oc.outer_hit_id()); #endif #ifdef CA_DEBUG @@ -422,6 +424,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { if (t_ind >= maxTriplets) { #ifdef CA_WARNINGS printf("Warning!!!! Too many cell->cell (triplets) associations (limit = %d)!\n", cn.metadata().size()); + assert(0); #endif alpaka::atomicSub(acc, nTrips, 1u, alpaka::hierarchy::Blocks{}); break; @@ -1079,8 +1082,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { auto nh = foundNtuplets->size(i); if (nh < 3) continue; - if (tracks_view[i].quality() < loose) - continue; +// if (tracks_view[i].quality() < loose) +// continue; printf("TK: %10d %3d %3d %3d %6.1f %9.3f %8.3f %8.3f %9.3f %9.3f %9.3f %9.3f %9.3f\n", 10000 * iev + i, // ID diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoubletsAlgos.h b/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoubletsAlgos.h index b63d6afab60bd..e41385e477695 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoubletsAlgos.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoubletsAlgos.h @@ -22,9 +22,9 @@ #include "CAStructures.h" #include "CAHitNtupletGeneratorKernels.h" -// #define GPU_DEBUG -// #define DOUBLETS_DEBUG -// #define CA_WARNINGS +// MRMR #define GPU_DEBUG // MRMR +// MRMR #define DOUBLETS_DEBUG // MRMR +#define CA_WARNINGS namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { using namespace cms::alpakatools; @@ -220,8 +220,12 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { offsets[inner + 1]); #endif // found hit corresponding to our worker thread, now do the job - if (hh[i].detectorIndex() > ll.layerStarts()[ll.metadata().size() - 1]) //TODO use cc + if (hh[i].detectorIndex() > ll.layerStarts()[ll.metadata().size() - 1]) { //TODO use cc +#ifdef DOUBLETS_DEBUG + printf("Killed here 1\n"); +#endif continue; // invalid + } /* maybe clever, not effective when zoCut is on auto bpos = (mi%8)/4; // if barrel is 1 for z>0 @@ -231,15 +235,23 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { auto mez = hh[i].zGlobal(); - if (mez < cc.minz()[pairLayerId] || mez > cc.maxz()[pairLayerId]) + if (mez < cc.minz()[pairLayerId] || mez > cc.maxz()[pairLayerId]) { +#ifdef DOUBLETS_DEBUG + printf("Killed here 2 --> mez: %f [index: %d], miz: %f, maxz: %f\n", mez, hh[i].detectorIndex(), cc.minz()[pairLayerId], cc.maxz()[pairLayerId]); +#endif continue; + } #ifdef DOUBLETS_DEBUG if (doClusterCut && outer > pixelTopology::last_barrel_layer) printf("clustCut: %d %d \n", i, clusterCut(acc, hh, ll, params, i)); #endif - if (doClusterCut && outer > pixelTopology::last_barrel_layer && clusterCut(acc, hh, ll, params, i)) + if (doClusterCut && outer > pixelTopology::last_barrel_layer && clusterCut(acc, hh, ll, params, i)) { +#ifdef DOUBLETS_DEBUG + printf("Killed here 3\n"); +#endif continue; + } auto mep = hh[i].iphi(); auto mer = hh[i].rGlobal(); @@ -256,7 +268,12 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { auto zo = hh[j].zGlobal(); auto ro = hh[j].rGlobal(); auto dr = ro - mer; - return dr > cc.maxr()[pairLayerId] || dr < 0 || std::abs((mez * ro - mer * zo)) > params.cellZ0Cut_ * dr; +#ifdef DOUBLETS_DEBUG + printf("dr: %4.3f, %4.3f, %4.3f --> %d\n", mer, ro, dr, (dr > cc.maxr()[pairLayerId])); + printf("mez: %4.3f, zo: %4.3f, std::abs((mez * ro - mer * zo)): %4.3f --> %d\n", + mez, zo, std::abs((mez * ro - mer * zo)), (std::abs((mez * ro - mer * zo)) > params.cellZ0Cut_*dr)); +#endif + return dr > cc.maxr()[pairLayerId] || dr < 0 || std::abs((mez * ro - mer * zo)) > params.cellZ0Cut_ * dr; }; auto iphicut = cc.phiCuts()[pairLayerId]; @@ -265,7 +282,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { auto kh = PhiHisto::bin(int16_t(mep + iphicut)); auto incr = [](auto& k) { return k = (k + 1) % PhiHisto::nbins(); }; -#ifdef GPU_DEGBU +#ifdef GPU_DEBUG printf("pairLayerId %d %d %.2f %.2f %.2f \n", pairLayerId, cc.phiCuts()[pairLayerId], @@ -292,33 +309,57 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { auto oi = p[pIndex]; ALPAKA_ASSERT_ACC(oi >= offsets[outer]); ALPAKA_ASSERT_ACC(oi < offsets[outer + 1]); +#ifdef DOUBLETS_DEBUG + printf("Exploring couple i: %d o: %d\n", i, oi); +#endif auto mo = hh[oi].detectorIndex(); // invalid - if (mo > pixelClustering::maxNumModules) //FIXME use cc? + if (mo > pixelClustering::maxNumModules) { //FIXME use cc? +#ifdef DOUBLETS_DEBUG + printf("Killed here 4\n"); +#endif continue; + } - if (params.cellZ0Cut_ > 0. && z0cutoff(oi)) + if (params.cellZ0Cut_ > 0. && z0cutoff(oi)) { +#ifdef DOUBLETS_DEBUG + printf("Killed here 5\n"); +#endif continue; + } auto mop = hh[oi].iphi(); uint16_t idphi = std::min(std::abs(int16_t(mop - mep)), std::abs(int16_t(mep - mop))); - if (idphi > iphicut) + if (idphi > iphicut) { +#ifdef DOUBLETS_DEBUG + printf("Killed here 6\n"); +#endif continue; + } #ifdef DOUBLETS_DEBUG printf("zSizeCut: %d %d %d \n", i, oi, zSizeCut(acc, hh, ll, params, i, oi)); #endif - if (doZSizeCut && zSizeCut(acc, hh, ll, params, i, oi)) + if (doZSizeCut && zSizeCut(acc, hh, ll, params, i, oi)) { +#ifdef DOUBLETS_DEBUG + printf("Killed here 7\n"); +#endif continue; + } - if (params.cellPtCut_ > 0. && ptcut(oi, idphi)) + if (params.cellPtCut_ > 0. && ptcut(oi, idphi)) { +#ifdef DOUBLETS_DEBUG + printf("Killed here 8\n"); +#endif continue; + } auto ind = alpaka::atomicAdd(acc, nCells, 1u, alpaka::hierarchy::Blocks{}); if (ind >= maxNumOfDoublets) { #ifdef CA_WARNINGS printf("Warning!!!! Too many cells (limit = %d)!\n", maxNumOfDoublets); + assert(0); #endif alpaka::atomicSub(acc, nCells, 1u, alpaka::hierarchy::Blocks{}); break; diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CASimpleCell.h b/RecoTracker/PixelSeeding/plugins/alpaka/CASimpleCell.h new file mode 100644 index 0000000000000..57f5232151813 --- /dev/null +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CASimpleCell.h @@ -0,0 +1,302 @@ +#ifndef RecoTracker_PixelSeeding_plugins_alpaka_CASimpleCell_h +#define RecoTracker_PixelSeeding_plugins_alpaka_CASimpleCell_h + +// #define GPU_DEBUG +// #define CA_DEBUG +// #define CA_WARNINGS +#include +#include + +#include + +#include "DataFormats/TrackSoA/interface/TrackDefinitions.h" +#include "DataFormats/TrackSoA/interface/TracksSoA.h" +#include "DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsSoA.h" +#include "Geometry/CommonTopologies/interface/SimplePixelTopology.h" +#include "HeterogeneousCore/AlpakaInterface/interface/SimpleVector.h" +#include "HeterogeneousCore/AlpakaInterface/interface/VecArray.h" +#include "HeterogeneousCore/AlpakaInterface/interface/config.h" +#include "RecoTracker/PixelSeeding/interface/CircleEq.h" +#include "RecoTracker/PixelSeeding/interface/CAGeometrySoA.h" +#include "RecoTracker/PixelSeeding/interface/CACoupleSoA.h" + +#include "CAStructures.h" + +namespace ALPAKA_ACCELERATOR_NAMESPACE { + + using namespace ::caStructures; + + template + class CACellT; + + template + class CASimpleCell { + friend class CACellT; + + public: + ALPAKA_FN_ACC ALPAKA_FN_INLINE void init(const HitsConstView& hh, + int layerPairId, + uint8_t theInnerLayer, + uint8_t theOuterLayer, + hindex_type innerHitId, + hindex_type outerHitId) { + theInnerHitId = innerHitId; + theOuterHitId = outerHitId; + theLayerPairId_ = layerPairId; + theInnerLayer_ = theInnerLayer; + theOuterLayer_ = theOuterLayer; + theStatus_ = 0; + theFishboneId = invalidHitId; + + // optimization that depends on access pattern + theInnerZ = hh[innerHitId].zGlobal(); + theInnerR = hh[innerHitId].rGlobal(); + } + + using hindex_type = ::caStructures::hindex_type; + using tindex_type = ::caStructures::tindex_type; + + static constexpr auto invalidHitId = std::numeric_limits::max(); + + using TmpTuple = cms::alpakatools::VecArray; + using HitContainer = caStructures::SequentialContainer; + using CellToCell = caStructures::GenericContainer; + using CellToTracks = caStructures::GenericContainer; + using CACoupleSoAView = caStructures::CACoupleSoAView; + + using Quality = ::pixelTrack::Quality; + static constexpr auto bad = ::pixelTrack::Quality::bad; + + enum class StatusBit : uint16_t { kUsed = 1, kInTrack = 2, kKilled = 1 << 15 }; + + CASimpleCell() = default; + + constexpr unsigned int inner_hit_id() const { return theInnerHitId; } + constexpr unsigned int outer_hit_id() const { return theOuterHitId; } + + ALPAKA_FN_ACC ALPAKA_FN_INLINE void kill() { theStatus_ |= uint16_t(StatusBit::kKilled); } + ALPAKA_FN_ACC ALPAKA_FN_INLINE bool isKilled() const { return theStatus_ & uint16_t(StatusBit::kKilled); } + + ALPAKA_FN_ACC ALPAKA_FN_INLINE int16_t layerPairId() const { return theLayerPairId_; } + ALPAKA_FN_ACC ALPAKA_FN_INLINE int16_t innerLayer() const { return theInnerLayer_; } + ALPAKA_FN_ACC ALPAKA_FN_INLINE int16_t outerLayer() const { return theOuterLayer_; } + + ALPAKA_FN_ACC ALPAKA_FN_INLINE bool unused() const { return 0 == (uint16_t(StatusBit::kUsed) & theStatus_); } + ALPAKA_FN_ACC ALPAKA_FN_INLINE void setStatusBits(StatusBit mask) { theStatus_ |= uint16_t(mask); } + + ALPAKA_FN_ACC ALPAKA_FN_INLINE float inner_x(const HitsConstView& hh) const { return hh[theInnerHitId].xGlobal(); } + ALPAKA_FN_ACC ALPAKA_FN_INLINE float outer_x(const HitsConstView& hh) const { return hh[theOuterHitId].xGlobal(); } + ALPAKA_FN_ACC ALPAKA_FN_INLINE float inner_y(const HitsConstView& hh) const { return hh[theInnerHitId].yGlobal(); } + ALPAKA_FN_ACC ALPAKA_FN_INLINE float outer_y(const HitsConstView& hh) const { return hh[theOuterHitId].yGlobal(); } + ALPAKA_FN_ACC ALPAKA_FN_INLINE float inner_z(const HitsConstView& hh) const { return theInnerZ; } + ALPAKA_FN_ACC ALPAKA_FN_INLINE float outer_z(const HitsConstView& hh) const { return hh[theOuterHitId].zGlobal(); } + ALPAKA_FN_ACC ALPAKA_FN_INLINE float inner_r(const HitsConstView& hh) const { return theInnerR; } + ALPAKA_FN_ACC ALPAKA_FN_INLINE float outer_r(const HitsConstView& hh) const { return hh[theOuterHitId].rGlobal(); } + + ALPAKA_FN_ACC ALPAKA_FN_INLINE auto inner_iphi(const HitsConstView& hh) const { return hh[theInnerHitId].iphi(); } + ALPAKA_FN_ACC ALPAKA_FN_INLINE auto outer_iphi(const HitsConstView& hh) const { return hh[theOuterHitId].iphi(); } + + ALPAKA_FN_ACC ALPAKA_FN_INLINE float inner_detIndex(const HitsConstView& hh) const { + return hh[theInnerHitId].detectorIndex(); + } + ALPAKA_FN_ACC ALPAKA_FN_INLINE float outer_detIndex(const HitsConstView& hh) const { + return hh[theOuterHitId].detectorIndex(); + } + + ALPAKA_FN_ACC ALPAKA_FN_INLINE auto fishboneId() const { return theFishboneId; } + ALPAKA_FN_ACC ALPAKA_FN_INLINE bool hasFishbone() const { return theFishboneId != invalidHitId; } + + ALPAKA_FN_ACC void print_cell() const { + printf("printing cell: on layerPair: %d, innerLayer: %d, outerLayer: %d, innerHitId: %d, outerHitId: %d \n", + theLayerPairId_, + theInnerLayer_, + theOuterLayer_, + theInnerHitId, + theOuterHitId); + } + + template + ALPAKA_FN_ACC ALPAKA_FN_INLINE void setFishbone(TAcc const& acc, hindex_type id, float z, const HitsConstView& hh) { + // make it deterministic: use the farther apart (in z) + auto old = theFishboneId; + while (old != + alpaka::atomicCas( + acc, + &theFishboneId, + old, + (invalidHitId == old || std::abs(z - theInnerZ) > std::abs(hh[old].zGlobal() - theInnerZ)) ? id : old, + alpaka::hierarchy::Blocks{})) + old = theFishboneId; + } + + ALPAKA_FN_ACC ALPAKA_FN_INLINE __attribute__((always_inline)) static bool areAlignedRZ( + float r1, float z1, float ri, float zi, float ro, float zo, const float ptmin, const float thetaCut) { + float radius_diff = std::abs(r1 - ro); + float distance_13_squared = radius_diff * radius_diff + (z1 - zo) * (z1 - zo); + + float pMin = ptmin * std::sqrt(distance_13_squared); // this needs to be divided by + // radius_diff later + + float tan_12_13_half_mul_distance_13_squared = fabs(z1 * (ri - ro) + zi * (ro - r1) + zo * (r1 - ri)); + return tan_12_13_half_mul_distance_13_squared * pMin <= thetaCut * distance_13_squared * radius_diff; + } + + ALPAKA_FN_ACC ALPAKA_FN_INLINE bool dcaCut(const HitsConstView& hh, + CASimpleCell const& otherCell, + const float region_origin_radius_plus_tolerance, + const float maxCurv) const { + auto x1 = otherCell.inner_x(hh); + auto y1 = otherCell.inner_y(hh); + + auto x2 = inner_x(hh); + auto y2 = inner_y(hh); + + auto x3 = outer_x(hh); + auto y3 = outer_y(hh); + + CircleEq eq(x1, y1, x2, y2, x3, y3); + +// MRMR printf("Computed curvature: %f, vs parameter: %f\n", eq.curvature(), maxCurv); + if (eq.curvature() > maxCurv) + return false; + + return std::abs(eq.dca0()) < region_origin_radius_plus_tolerance * std::abs(eq.curvature()); + } + + // trying to free the track building process from hardcoded layers, leaving + // the visit of the graph based on the neighborhood connections between cells. + + template + ALPAKA_FN_ACC ALPAKA_FN_INLINE void find_ntuplets(TAcc const& acc, + const ::reco::CAGraphSoAConstView& cc, + CASimpleCell* __restrict__ cells, + HitContainer& foundNtuplets, + CellToCell const* __restrict__ cellNeighborsHisto, + CellToTracks* cellTracksHisto, + uint32_t* nCellTracks, + CACoupleSoAView ct, + cms::alpakatools::AtomicPairCounter& apc, + Quality* __restrict__ quality, + TmpTuple& tmpNtuplet, + const unsigned int minHitsPerNtuplet) const { + // the building process for a track ends if: + // it has no right neighbor + // it has no compatible neighbor + // the ntuplets is then saved if the number of hits it contains is greater + // than a threshold + if constexpr (DEPTH <= 0) { + printf("ERROR: CASimpleCell::find_ntuplets reached full depth!\n"); + ALPAKA_ASSERT_ACC(false); + } else { + auto doubletId = this - cells; + tmpNtuplet.push_back_unsafe(doubletId); // if we move this to be safe we could parallelize further below? + ALPAKA_ASSERT_ACC(tmpNtuplet.size() <= int(TrackerTraits::maxHitsOnTrack - 3)); + + bool last = true; + auto const* __restrict__ bin = cellNeighborsHisto->begin(doubletId); + auto nInBin = cellNeighborsHisto->size(doubletId); + + for (auto idx = 0u; idx < nInBin; idx++) { + // FIXME implement alpaka::ldg and use it here? or is it const* __restrict__ enough? + unsigned int otherCell = bin[idx]; + if (cells[otherCell].isKilled()) + continue; +#ifdef CA_DEBUG + printf("Doublet no. %d | Idx: %d | DoubletID: %ld | OtherCell: %d | isKilled: %d | " + "This(i,o): (%d,%d) -> Other(i,o): (%d,%d) | Idx: %d | BinN: %d\n", + tmpNtuplet.size(), + idx, + doubletId, + otherCell, + cells[otherCell].isKilled(), + this->inner_hit_id(), + this->outer_hit_id(), + cells[otherCell].inner_hit_id(), + cells[otherCell].outer_hit_id(), + idx, + nInBin); +#endif + + last = false; + cells[otherCell].template find_ntuplets(acc, + cc, + cells, + foundNtuplets, + cellNeighborsHisto, + cellTracksHisto, + nCellTracks, + ct, + apc, + quality, + tmpNtuplet, + minHitsPerNtuplet); + } + if (last) { // if long enough save... + if ((unsigned int)(tmpNtuplet.size()) >= minHitsPerNtuplet - 1) { + { + hindex_type hits[TrackerTraits::maxDepth + 2]; + auto nh = 0U; + constexpr int maxFB = 2; // for the time being let's limit this + int nfb = 0; + for (auto c : tmpNtuplet) { + hits[nh++] = cells[c].theInnerHitId; + if (nfb < maxFB && cells[c].hasFishbone()) { + ++nfb; + hits[nh++] = cells[c].theFishboneId; // Fishbone hit is always outer than inner hit + } + } + ALPAKA_ASSERT_ACC(nh < TrackerTraits::maxHitsOnTrack); + hits[nh] = theOuterHitId; + auto it = foundNtuplets.bulkFill(acc, apc, hits, nh + 1); +#ifdef CA_DEBUG + printf("track n. %d nhits %d with cells: \n", it, nh + 1); +#endif + if (it >= 0) { // if negative is overflow.... + for (auto c : tmpNtuplet) { +#ifdef CA_DEBUG + printf("%d - ", c); +#endif + auto t_ind = alpaka::atomicAdd(acc, nCellTracks, (uint32_t)1, alpaka::hierarchy::Blocks{}); + + if (t_ind >= uint32_t(ct.metadata().size())) { +#ifdef CA_WARNINGS + printf("Warning!!!! Too many cell->tracks associations (limit = %d)!\n", ct.metadata().size()); + assert(0); +#endif + alpaka::atomicSub(acc, nCellTracks, (uint32_t)1, alpaka::hierarchy::Blocks{}); + break; + } + cellTracksHisto->count(acc, c); + + ct[t_ind].inner() = c; //cell + ct[t_ind].outer() = it; //track + } +#ifdef CA_DEBUG + printf("\n"); +#endif + quality[it] = bad; // initialize to bad + } + } + } + } + tmpNtuplet.pop_back(); + ALPAKA_ASSERT_ACC(tmpNtuplet.size() < int(TrackerTraits::maxHitsOnTrack - 1)); + } + } + + protected: + int16_t theLayerPairId_; + uint8_t theInnerLayer_; + uint8_t theOuterLayer_; + uint16_t theStatus_; // tbd + + float theInnerZ; + float theInnerR; + hindex_type theInnerHitId; + hindex_type theOuterHitId; + hindex_type theFishboneId; + }; + +} // namespace ALPAKA_ACCELERATOR_NAMESPACE + +#endif // RecoTracker_PixelSeeding_plugins_alpaka_CASimpleCell_h diff --git a/RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h b/RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h index 21b1ac1564ff9..057326543f184 100644 --- a/RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h +++ b/RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h @@ -60,7 +60,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::brokenline { ALPAKA_FN_ACC ALPAKA_FN_INLINE double multScatt( const TAcc& acc, const double& length, const double bField, const double radius, int layer, double slope) { // limit R to 20GeV... - auto pt2 = alpaka::math::min(acc, 20., bField * radius); + auto pt2 = alpaka::math::min(acc, 50., bField * radius); pt2 *= pt2; constexpr double inv_X0 = 0.06 / 16.; //!< inverse of radiation length of the material in cm //if(Layer==1) XXI_0=0.06/16.; diff --git a/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc b/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc index 9f821d733c816..0a4a982d5dc88 100644 --- a/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc +++ b/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc @@ -196,6 +196,7 @@ void PixelTrackProducerFromSoAAlpaka::produce(edm::StreamID streamID, hitmap.resize(idx + 256, nullptr); // only in case of hit overflow in one module assert(nullptr == hitmap[idx]); + std::cout << "Filling hitmap at position " << idx << " with a pixel hit." << std::endl; hitmap[idx] = &pixelHit; } @@ -241,7 +242,8 @@ void PixelTrackProducerFromSoAAlpaka::produce(edm::StreamID streamID, if (it != p_modulesInPSInOTBarrel.end()) { return std::distance(p_modulesInPSInOTBarrel.begin(), it); } else { - return -1L; + assert(0); +// return -1L; } }; @@ -273,6 +275,7 @@ void PixelTrackProducerFromSoAAlpaka::produce(edm::StreamID streamID, if (isPinPSinOTBarrel(DetId(detId))) { for (int idx = moduleStartOT[getModuleIdOT(detId)]; auto const &recHit : detSet) { hitmap[idx] = &recHit; + std::cout << "Filling hitmap at position " << idx << " with an OT hit with index " << getModuleIdOT(detId) << std::endl; idx++; } } @@ -332,7 +335,8 @@ void PixelTrackProducerFromSoAAlpaka::produce(edm::StreamID streamID, for (auto iHit = start; iHit < end; ++iHit) hits[iHit - start] = hitmap[hitIdxs[iHit]]; -#ifdef CA_DEBUG +//#ifdef CA_DEBUG +#if 1 std::cout << "track soa : " << it << " with hits: "; for (auto iHit = start; iHit < end; ++iHit) std::cout << hitIdxs[iHit] << " - "; From d29a4d4cf415eb0373b4041e6709a799f4270f85 Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Fri, 13 Jun 2025 11:42:55 +0200 Subject: [PATCH 32/40] Working configuration. --- .../modules/hltPhase2PixelTracksSoA_cfi.py | 74 ++++++++++--------- .../PixelTrackProducerFromSoAAlpaka.cc | 2 +- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py index 19c7d8ad286da..21045cc47d738 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py @@ -12,7 +12,7 @@ fillStatistics = cms.bool(True), minHitsPerNtuplet = cms.uint32(5), maxNumberOfDoublets = cms.string(str(15*512*1024)), - maxNumberOfTuples = cms.string(str(2*60*1024)), + maxNumberOfTuples = cms.string(str(2*60*1024)), cellPtCut = cms.double(0.85), # Corresponds to 1 GeV * this cut, i.e., 850 MeV, as minimum p_t cellZ0Cut = cms.double(12.5), # it's half the BS width! It has nothing to do with the sample!! minYsizeB1 = cms.int32(25), @@ -33,7 +33,7 @@ trackQualityCuts = cms.PSet( maxChi2 = cms.double(5.0), minPt = cms.double(0.9), - maxTip = cms.double(0.3), + maxTip = cms.double(2.5), maxZip = cms.double(12), ), geometry = cms.PSet( @@ -46,13 +46,13 @@ # investigation. Therefore the cut represent the compatibility of the # circle in the transverse plane and the units are meant to be cm. caDCACuts = cms.vdouble( - 0.15, # 0 + 0.15, # 0 0.25, # 1 0.20, # 2 0.20, # End PXB # 3 - 0.25, # 4 - 0.25, # 5 - 0.25, # 6 + 0.25, # 4 + 0.25, # 5 + 0.25, # 6 0.25, # 7 0.25, # 8 0.25, # 9 @@ -144,12 +144,14 @@ 26, 27, 28), +# 30, +# 31), # 29, # 30, # 31, # 32), pairGraph = cms.vint32( - 0, 1, # 0 + 0, 1, # 0 0, 4, # 1 0, 16, # 2 1, 2, # 3 @@ -179,8 +181,8 @@ 0, 18, # 27 1, 3, # 28 # 2, 5, # 29 - 1, 5, # 31 - 1, 17, # 30 + 1, 5, # 30 + 1, 17, # 31 # 1, 18, # last starting pair # 32 11, 12, # 33 12, 13, # 34 @@ -212,14 +214,14 @@ 29, 30, # 60 4, 28, # 61 5, 28, # 62 -## 6, 28, # 63 + 6, 28, # 63 # 7, 28, # 64 from top 0 # 64 # 8, 28, # 65 # 9, 28, # 66 16, 28, # 67 17, 28, # 68 -## 18, 28, # 69 -# 19, 28, # 70 + 18, 28, # 69 +# 19, 28, # 70 # 20, 28, # 71 # 21, 28, # 72 # 4, 29, # 73 @@ -234,7 +236,7 @@ # 20, 29 # 82 ), phiCuts = cms.vint32( - 522, # 0 + 522, # 0 522, # 1 522, # 2 626, # 3 @@ -297,13 +299,13 @@ 1000, # 60 1000, # 61 1000, # 62 -## 1000, # 63 + 1000, # 63 # 1000, # 64 # 64 from top 0 # 1000, # 65 # 1000, # 66 1000, # 67 1000, # 68 -## 1000, # 69 + 1000, # 69 # 1000, # 70 # 1000, # 71 # 1000, # 72 @@ -318,10 +320,10 @@ # 1000, # 81 # 1000 # 82 ), - # minZ and maxZ are the limit in Z for the inner cell of a doublets in + # minZ and maxZ are the limits in Z for the inner cell of a doublets in # order to be able to make a doublet with the other layer. minZ = cms.vdouble( - -17, # 0 + -19, # 0 4, # 1 -22, # 2 -18, # 3 @@ -344,15 +346,15 @@ -70, # 20 -87, # 21 -113, # 22 - -17, # 23 + -19, # 23 7, # 24 -22, # 25 11, # 26 -22, # 27 -19, # 28 # 9, # 29 - -22, # 30 - 9, # 31 + 7, # 30 + -22, # 31 # -22, # 32 137, # 33 173, # 34 @@ -384,14 +386,14 @@ -1200, # 60 23, # 61 30, # 62 -## -20, # 63 -# -1000, # 64 # 64 from top 0 + 39, # 63 +# 50, # 64 # 64 from top 0 # -1000, # 65 # -1000, # 66 -28, # 67 -35, # 68 -## -20, # 69 -# -1000, # 70 + -44, # 69 +# -55, # 70 # -1000, # 71 # -1000, # 72 # -1000, # 73 @@ -406,7 +408,7 @@ # -1000 # 82 ), maxZ = cms.vdouble( - 17, # 0 + 19, # 0 22, # 1 -4, # 2 18, # 3 @@ -429,15 +431,15 @@ -65, # 20 -82, # 21 -109, # 22 - 17, # 23 + 19, # 23 22, # 24 -7, # 25 22, # 26 -11, # 27 19, # 28 # 22, # 29 - -9, # 30 - 22, # 31 + 22, # 30 + -7, # 31 # -13, # 32 142, # 33 177, # 34 @@ -469,14 +471,14 @@ 1200, # 60 28, # 61 35, # 62 -## 20, # 63 -# 1000, # 64 64 gtom top 0 + 44, # 63 +# 55, # 64 64 gtom top 0 # 1000, # 65 # 1000, # 66 -23, # 67 -30, # 68 -## 20, # 69 -# 1000, # 70 + -39, # 69 +# -50, # 70 # 1000, # 71 # 1000, # 72 # 1000, # 73 @@ -491,7 +493,7 @@ # 1000 # 82 ), maxR = cms.vdouble( - 5, # 0 + 5, # 0 5, # 1 5, # 2 7, # 3 @@ -554,13 +556,13 @@ 60, # 60 60, # 61 60, # 62 -## 60,# 63 -# 60, # 64 64 from top 0 + 60, # 63 +# 60, # 64 64 from top 0 # 60, # 65 # 60, # 66 60, # 67 60, # 68 -## 60,# 69 + 60,# 69 # 60, # 70 # 60, # 71 # 60, # 72 diff --git a/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc b/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc index 0a4a982d5dc88..280603fdc880b 100644 --- a/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc +++ b/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc @@ -45,7 +45,7 @@ * objects from the output of SoA CA. */ -#define GPU_DEBUG +// #define GPU_DEBUG class PixelTrackProducerFromSoAAlpaka : public edm::global::EDProducer<> { using TrackSoAHost = reco::TracksHost; From 2a9463f28917344b524776a49897c66e983349dc Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Sat, 14 Jun 2025 10:32:58 +0200 Subject: [PATCH 33/40] Cache PinPSinOTBarrel. Use vector and unordered_map instead of set. --- .../alpaka/Phase2OTRecHitsSoAConverter.cc | 47 ++++++++----------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc index 9b800bfc983d0..5fb43a3cb9915 100644 --- a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc +++ b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc @@ -103,10 +103,13 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF3D); }; + // TODO(rovere) move this logic out of produce, since it's partially bound only to the geometry...?? + std::unordered_map detIdIsP; + std::vector orderedModules; + std::unordered_map moduleIndexToOffset; auto const& detUnits = trackerGeometry->detUnits(); std::map detIdToIndex; - std::set p_modulesInPSInOTBarrel; int modulesInPixel = 0; // auto subSystem = GeomDetEnumerators::P2OTEC; // auto subSystemName = GeomDetEnumerators::tkDetEnum[subSystem]; @@ -114,11 +117,13 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { for (auto& detUnit : detUnits) { DetId detId(detUnit->geographicalId()); + detIdIsP[detId.rawId()] = isPinPSinOTBarrel(detId); if (isPh2Pixel(detId)) modulesInPixel++; - if (isPinPSinOTBarrel(detId)) { + if (detIdIsP[detId.rawId()]) { detIdToIndex[detUnit->geographicalId()] = detUnit->index(); - p_modulesInPSInOTBarrel.insert(detUnit->index()); + moduleIndexToOffset[detUnit->index()] = orderedModules.size(); + orderedModules.push_back(detUnit->index()); // std::cout << "Inserted " << detUnit->index() << " " << p_modulesInPSInOTBarrel.size() << " on layer " << int((detId.rawId() >> 20) & 0xF) << std::endl; } } @@ -127,33 +132,28 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { for (const auto& detSet : stripHits) { for (const auto& recHit : detSet) { DetId detId(recHit.geographicalId()); - if (isPinPSinOTBarrel(detId)) + if (detIdIsP[detId.rawId()]) PHitsInOTBarrel++; } } std::cout << "Tot number of modules in Pixels " << modulesInPixel << std::endl; - std::cout << "Tot number of p_modulesInPSInOTBarrel: " << p_modulesInPSInOTBarrel.size() << std::endl; + std::cout << "Tot number of p_modulesInPSInOTBarrel: " << orderedModules.size() << std::endl; std::cout << "Number of strip (active) modules: " << activeStripModules << std::endl; std::cout << "Number of strip hits: " << nStripHits << std::endl; std::cout << "Total hits of PinOTBarrel: " << PHitsInOTBarrel << std::endl; - HitsHost stripHitsHost(queue, PHitsInOTBarrel, p_modulesInPSInOTBarrel.size()); + HitsHost stripHitsHost(queue, PHitsInOTBarrel, orderedModules.size()); auto& stripHitsModuleView = stripHitsHost.view<::reco::HitModuleSoA>(); - std::vector counterOfHitsPerModule(p_modulesInPSInOTBarrel.size(), 0); - assert(p_modulesInPSInOTBarrel.size()); + std::vector counterOfHitsPerModule(orderedModules.size(), 0); + assert(orderedModules.size()); for (const auto& detSet : stripHits) { auto firstHit = detSet.begin(); auto detId = firstHit->rawId(); auto index = detIdToIndex[detId]; int offset = 0; - if (isPinPSinOTBarrel(DetId(detId))) { - auto it = p_modulesInPSInOTBarrel.find(index); - if (it != p_modulesInPSInOTBarrel.end()) { - offset = std::distance(p_modulesInPSInOTBarrel.begin(), it); - } else { - assert(0); - } + if (detIdIsP[detId]) { + offset = moduleIndexToOffset[index]; for (const auto& recHit : detSet) { counterOfHitsPerModule[offset]++; } @@ -185,18 +185,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { auto det = trackerGeometry->idToDet(detId); auto index = detIdToIndex[detId]; int offset = 0; - if (isPinPSinOTBarrel(DetId(detId))) { - auto it = p_modulesInPSInOTBarrel.find(index); - if (it != p_modulesInPSInOTBarrel.end()) { - offset = std::distance(p_modulesInPSInOTBarrel.begin(), it); - // stripHitsModuleView[offset].moduleStart() = cumulativeHitPerModule[offset] + nPixelHits; - // std::cout << "Module start: " << offset << " " << index << " with hits: " << stripHitsModuleView[offset].moduleStart() << std::endl; - } else { - assert(0); - } + if (detIdIsP[detId]) { + offset = moduleIndexToOffset[index]; for (const auto& recHit : detSet) { // Select only P-hits from the OT barrel - if (isPinPSinOTBarrel(DetId(detId))) { + if (detIdIsP[detId]) { int idx = shifted[offset]++; assert(idx < PHitsInOTBarrel); stripHitsHost.view()[idx].xLocal() = recHit.localPosition().x(); @@ -225,8 +218,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { } } } - stripHitsModuleView[p_modulesInPSInOTBarrel.size()].moduleStart() = - cumulativeHitPerModule[p_modulesInPSInOTBarrel.size() - 1] + nPixelHits; + stripHitsModuleView[orderedModules.size()].moduleStart() = + cumulativeHitPerModule[orderedModules.size() - 1] + nPixelHits; std::cout << "DONE" << std::endl; #if 0 From ea5fd304e7768a1a2644b296cb572744b80696bb Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Sat, 14 Jun 2025 11:14:35 +0200 Subject: [PATCH 34/40] Move geometry-related logic in BeginRun. --- .../alpaka/Phase2OTRecHitsSoAConverter.cc | 101 +++++++++--------- 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc index 5fb43a3cb9915..875101e3cc828 100644 --- a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc +++ b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc @@ -43,26 +43,37 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + void beginRun(edm::Run const& run, edm::EventSetup const& setup) override; + private: void produce(device::Event& iEvent, const device::EventSetup& es) override; const edm::ESGetToken geomToken_; + const edm::ESGetToken geomTokenRun_; const edm::EDGetTokenT recHitToken_; const edm::EDGetTokenT<::reco::BeamSpot> beamSpotToken_; const edm::EDGetTokenT pixelHitsSoA_; const device::EDPutToken stripSoADevice_; const edm::EDPutTokenT hitModuleStart_; + + int modulesInPixel_; + std::unordered_map detIdIsP_; + std::vector orderedModules_; + std::unordered_map moduleIndexToOffset_; + std::map detIdToIndex_; }; Phase2OTRecHitsSoAConverter::Phase2OTRecHitsSoAConverter(const edm::ParameterSet& iConfig) : stream::EDProducer<>(iConfig), geomToken_(esConsumes()), + geomTokenRun_(esConsumes()), recHitToken_{consumes(iConfig.getParameter("otRecHitSource"))}, beamSpotToken_(consumes<::reco::BeamSpot>(iConfig.getParameter("beamSpot"))), pixelHitsSoA_{consumes(iConfig.getParameter("pixelRecHitSoASource"))}, stripSoADevice_{produces()}, - hitModuleStart_{produces()} {} + hitModuleStart_{produces()}, + modulesInPixel_(0) {} void Phase2OTRecHitsSoAConverter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; @@ -74,21 +85,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { descriptions.addWithDefaultLabel(desc); } - //https://github.com/cms-sw/cmssw/blob/3f06ef32d66bd2a7fa04e411fa4db4845193bd3c/RecoTracker/MkFit/plugins/convertHits.h - - void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSetup const& iSetup) { - auto queue = iEvent.queue(); - auto& bs = iEvent.get(beamSpotToken_); - const auto& trackerGeometry = &iSetup.getData(geomToken_); - auto const& stripHits = iEvent.get(recHitToken_); - - auto const& pixelHitsHost = iEvent.get(pixelHitsSoA_); - int nPixelHits = pixelHitsHost.view().metadata().size(); - - // Count strip hits and active strip modules - const int nStripHits = stripHits.data().size(); - const int activeStripModules = stripHits.size(); - + void Phase2OTRecHitsSoAConverter::beginRun(edm::Run const &iRun, edm::EventSetup const& iSetup) { + const auto& trackerGeometry = &iSetup.getData(geomTokenRun_); auto isPinPSinOTBarrel = [&](DetId detId) { // std::cout << (int)trackerGeometry->getDetectorType(detId) << " " << (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP) << "\n"; // std::cout << (int)detId.subdetId() << " " << (detId.subdetId() == StripSubdetector::TOB) << std::endl; @@ -103,57 +101,64 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PXF3D); }; - - // TODO(rovere) move this logic out of produce, since it's partially bound only to the geometry...?? - std::unordered_map detIdIsP; - std::vector orderedModules; - std::unordered_map moduleIndexToOffset; auto const& detUnits = trackerGeometry->detUnits(); - std::map detIdToIndex; - int modulesInPixel = 0; - // auto subSystem = GeomDetEnumerators::P2OTEC; - // auto subSystemName = GeomDetEnumerators::tkDetEnum[subSystem]; - // modulesInPixel += trackerGeometry->offsetDU(subSystemName); for (auto& detUnit : detUnits) { DetId detId(detUnit->geographicalId()); - detIdIsP[detId.rawId()] = isPinPSinOTBarrel(detId); + detIdIsP_[detId.rawId()] = isPinPSinOTBarrel(detId); if (isPh2Pixel(detId)) - modulesInPixel++; - if (detIdIsP[detId.rawId()]) { - detIdToIndex[detUnit->geographicalId()] = detUnit->index(); - moduleIndexToOffset[detUnit->index()] = orderedModules.size(); - orderedModules.push_back(detUnit->index()); + modulesInPixel_++; + if (detIdIsP_[detId.rawId()]) { + detIdToIndex_[detUnit->geographicalId()] = detUnit->index(); + moduleIndexToOffset_[detUnit->index()] = orderedModules_.size(); + orderedModules_.push_back(detUnit->index()); // std::cout << "Inserted " << detUnit->index() << " " << p_modulesInPSInOTBarrel.size() << " on layer " << int((detId.rawId() >> 20) & 0xF) << std::endl; } } + } + + //https://github.com/cms-sw/cmssw/blob/3f06ef32d66bd2a7fa04e411fa4db4845193bd3c/RecoTracker/MkFit/plugins/convertHits.h + + void Phase2OTRecHitsSoAConverter::produce(device::Event& iEvent, device::EventSetup const& iSetup) { + auto queue = iEvent.queue(); + auto& bs = iEvent.get(beamSpotToken_); + const auto& trackerGeometry = &iSetup.getData(geomToken_); + auto const& stripHits = iEvent.get(recHitToken_); + + auto const& pixelHitsHost = iEvent.get(pixelHitsSoA_); + int nPixelHits = pixelHitsHost.view().metadata().size(); + + // Count strip hits and active strip modules + const int nStripHits = stripHits.data().size(); + const int activeStripModules = stripHits.size(); + // Count the number of P hits in the OT to dimension the SoA int PHitsInOTBarrel = 0; for (const auto& detSet : stripHits) { for (const auto& recHit : detSet) { DetId detId(recHit.geographicalId()); - if (detIdIsP[detId.rawId()]) + if (detIdIsP_[detId.rawId()]) PHitsInOTBarrel++; } } - std::cout << "Tot number of modules in Pixels " << modulesInPixel << std::endl; - std::cout << "Tot number of p_modulesInPSInOTBarrel: " << orderedModules.size() << std::endl; + std::cout << "Tot number of modules in Pixels " << modulesInPixel_ << std::endl; + std::cout << "Tot number of p_modulesInPSInOTBarrel: " << orderedModules_.size() << std::endl; std::cout << "Number of strip (active) modules: " << activeStripModules << std::endl; std::cout << "Number of strip hits: " << nStripHits << std::endl; std::cout << "Total hits of PinOTBarrel: " << PHitsInOTBarrel << std::endl; - HitsHost stripHitsHost(queue, PHitsInOTBarrel, orderedModules.size()); + HitsHost stripHitsHost(queue, PHitsInOTBarrel, orderedModules_.size()); auto& stripHitsModuleView = stripHitsHost.view<::reco::HitModuleSoA>(); - std::vector counterOfHitsPerModule(orderedModules.size(), 0); - assert(orderedModules.size()); + std::vector counterOfHitsPerModule(orderedModules_.size(), 0); + assert(orderedModules_.size()); for (const auto& detSet : stripHits) { auto firstHit = detSet.begin(); auto detId = firstHit->rawId(); - auto index = detIdToIndex[detId]; + auto index = detIdToIndex_[detId]; int offset = 0; - if (detIdIsP[detId]) { - offset = moduleIndexToOffset[index]; + if (detIdIsP_[detId]) { + offset = moduleIndexToOffset_[index]; for (const auto& recHit : detSet) { counterOfHitsPerModule[offset]++; } @@ -183,13 +188,13 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { auto firstHit = detSet.begin(); auto detId = firstHit->rawId(); auto det = trackerGeometry->idToDet(detId); - auto index = detIdToIndex[detId]; + auto index = detIdToIndex_[detId]; int offset = 0; - if (detIdIsP[detId]) { - offset = moduleIndexToOffset[index]; + if (detIdIsP_[detId]) { + offset = moduleIndexToOffset_[index]; for (const auto& recHit : detSet) { // Select only P-hits from the OT barrel - if (detIdIsP[detId]) { + if (detIdIsP_[detId]) { int idx = shifted[offset]++; assert(idx < PHitsInOTBarrel); stripHitsHost.view()[idx].xLocal() = recHit.localPosition().x(); @@ -213,13 +218,13 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { stripHitsHost.view()[idx].chargeAndStatus().status = {0, 0, 0, 0, 0}; stripHitsHost.view()[idx].clusterSizeX() = -1; stripHitsHost.view()[idx].clusterSizeY() = -1; - stripHitsHost.view()[idx].detectorIndex() = modulesInPixel + offset; + stripHitsHost.view()[idx].detectorIndex() = modulesInPixel_ + offset; } } } } - stripHitsModuleView[orderedModules.size()].moduleStart() = - cumulativeHitPerModule[orderedModules.size() - 1] + nPixelHits; + stripHitsModuleView[orderedModules_.size()].moduleStart() = + cumulativeHitPerModule[orderedModules_.size() - 1] + nPixelHits; std::cout << "DONE" << std::endl; #if 0 From 5699ae15d97c64d3659ac557711e7ccc956906e7 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Mon, 16 Jun 2025 15:38:45 +0200 Subject: [PATCH 35/40] Update logic in PixelTrackProducerFromSoAAlpaka to reuse the HitModuleStart for the OT RecHits as well --- .../PixelTrackProducerFromSoAAlpaka.cc | 163 +++++++++--------- 1 file changed, 83 insertions(+), 80 deletions(-) diff --git a/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc b/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc index 280603fdc880b..9df4bb5cdf9e6 100644 --- a/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc +++ b/RecoTracker/PixelTrackFitting/plugins/PixelTrackProducerFromSoAAlpaka.cc @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -23,6 +24,7 @@ #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/Framework/interface/global/EDProducer.h" +// #include "FWCore/Framework/interface/RunCache.h" #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" @@ -46,8 +48,18 @@ */ // #define GPU_DEBUG +// struct that holds two maps for detIds of the OT modules +struct DetIdMaps { + DetIdMaps() : detIdToOTModuleId_(), detIdIsUsedOTModule_() {} + + // map from the detId of OT modules to the moduleId among the used OT modules + // (starting from 0 for first module of first OT layer) + std::map detIdToOTModuleId_; + // map from detId to bool if used as OT extension + std::map detIdIsUsedOTModule_; +}; -class PixelTrackProducerFromSoAAlpaka : public edm::global::EDProducer<> { +class PixelTrackProducerFromSoAAlpaka : public edm::global::EDProducer> { using TrackSoAHost = reco::TracksHost; using HMSstorage = std::vector; using IndToEdm = std::vector; @@ -58,6 +70,8 @@ class PixelTrackProducerFromSoAAlpaka : public edm::global::EDProducer<> { ~PixelTrackProducerFromSoAAlpaka() override = default; static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); + std::shared_ptr globalBeginRun(edm::Run const &, edm::EventSetup const &) const override; + void globalEndRun(edm::Run const &, edm::EventSetup const &) const override {}; private: void produce(edm::StreamID streamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override; @@ -67,11 +81,13 @@ class PixelTrackProducerFromSoAAlpaka : public edm::global::EDProducer<> { const edm::EDGetTokenT trackSoAToken_; const edm::EDGetTokenT pixelRecHitsToken_; edm::EDGetTokenT otRecHitsToken_; - const edm::EDGetTokenT hmsToken_; + const edm::EDGetTokenT pixelHMSToken_; + edm::EDGetTokenT otHMSToken_; // Event Setup tokens const edm::ESGetToken idealMagneticFieldToken_; const edm::ESGetToken trackerTopologyToken_; - const edm::ESGetToken trackerGeometryToken_; + // const edm::ESGetToken trackerGeometryToken_; + const edm::ESGetToken trackerGeometryTokenRun_; int32_t const minNumberOfHits_; pixelTrack::Quality const minQuality_; @@ -83,10 +99,11 @@ PixelTrackProducerFromSoAAlpaka::PixelTrackProducerFromSoAAlpaka(const edm::Para trackSoAToken_(consumes(iConfig.getParameter("trackSrc"))), pixelRecHitsToken_( consumes(iConfig.getParameter("pixelRecHitLegacySrc"))), - hmsToken_(consumes(iConfig.getParameter("pixelRecHitLegacySrc"))), + pixelHMSToken_(consumes(iConfig.getParameter("pixelRecHitLegacySrc"))), idealMagneticFieldToken_(esConsumes()), trackerTopologyToken_(esConsumes()), - trackerGeometryToken_(esConsumes()), + // trackerGeometryToken_(esConsumes()), + trackerGeometryTokenRun_(esConsumes()), minNumberOfHits_(iConfig.getParameter("minNumberOfHits")), minQuality_(pixelTrack::qualityByName(iConfig.getParameter("minQuality"))), useOTExtension_(iConfig.getParameter("useOTExtension")) { @@ -110,7 +127,43 @@ PixelTrackProducerFromSoAAlpaka::PixelTrackProducerFromSoAAlpaka(const edm::Para if (useOTExtension_) { otRecHitsToken_ = consumes(iConfig.getParameter("outerTrackerRecHitSrc")); + otHMSToken_ = consumes(iConfig.getParameter("outerTrackerRecHitSoAConverterSrc")); + } +} + +std::shared_ptr PixelTrackProducerFromSoAAlpaka::globalBeginRun(const edm::Run &iRun, + const edm::EventSetup &iSetup) const { + // make the maps object + auto detIdMaps = std::make_shared(); + + // if OT RecHits are used in PixelTracks, fill the detIdToOTModuleId_ map + if (useOTExtension_) { + // get track geometry + const auto &trackerGeometry = &iSetup.getData(trackerGeometryTokenRun_); + + // function to check if given module is used as OT for CA + auto isPinPSinOTBarrel = [&](DetId detId) { + // Select only P-hits from the OT barrel + return (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP && + detId.subdetId() == StripSubdetector::TOB); + }; + + // loop over all modules and fill the map detIdToOTModuleId_ + auto const &detUnits = trackerGeometry->detUnits(); + for (uint32_t otModuleId{0}; auto &detUnit : detUnits) { + DetId detId(detUnit->geographicalId()); + // check if the module is used for OT extension + bool isUsedOTModule = isPinPSinOTBarrel(detId); + detIdMaps->detIdIsUsedOTModule_[detUnit->geographicalId()] = isUsedOTModule; + if (isUsedOTModule) { + // save the module index among the extension modules + detIdMaps->detIdToOTModuleId_[detUnit->geographicalId()] = otModuleId; + otModuleId++; + } + } } + + return detIdMaps; } void PixelTrackProducerFromSoAAlpaka::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { @@ -119,6 +172,7 @@ void PixelTrackProducerFromSoAAlpaka::fillDescriptions(edm::ConfigurationDescrip desc.add("trackSrc", edm::InputTag("pixelTracksAlpaka")); desc.add("pixelRecHitLegacySrc", edm::InputTag("siPixelRecHitsPreSplittingLegacy")); desc.add("outerTrackerRecHitSrc", edm::InputTag("hltSiPhase2RecHits")); + desc.add("outerTrackerRecHitSoAConverterSrc", edm::InputTag("phase2OTRecHitsSoAConverter")); desc.add("minNumberOfHits", 0); desc.add("minQuality", "loose"); desc.add("useOTExtension", false); @@ -151,16 +205,19 @@ void PixelTrackProducerFromSoAAlpaka::produce(edm::StreamID streamID, // prepare container for legacy tracks pixeltrackfitting::TracksWithRecHits tracks; - // get trackerTopology and trackerGeometry + // get trackerTopology auto const &trackerTopology = iSetup.getData(trackerTopologyToken_); - const auto &trackerGeometry = &iSetup.getData(trackerGeometryToken_); + + // get the maps for the detId of the OT modules + auto const &detIdIsUsedOTModule = runCache(iEvent.getRun().index())->detIdIsUsedOTModule_; + auto const &detIdToOTModuleId = runCache(iEvent.getRun().index())->detIdToOTModuleId_; // get beamspot const auto &bsh = iEvent.get(beamSpotToken_); GlobalPoint bs(bsh.x0(), bsh.y0(), bsh.z0()); // get the module's starting indices in the hit collection - auto const &hitsModuleStart = iEvent.get(hmsToken_); + auto const &pixelHitsModuleStart = iEvent.get(pixelHMSToken_); // get Pixel RecHits auto const &pixelRecHitsDSV = iEvent.get(pixelRecHitsToken_); @@ -190,92 +247,38 @@ void PixelTrackProducerFromSoAAlpaka::produce(edm::StreamID streamID, assert(clus.isPixel()); // get hit identifier as (hit offset of the module) + (hit index in this module) - auto const idx = hitsModuleStart[detI] + clus.pixelCluster().originalId(); - - if (idx >= hitmap.size()) - hitmap.resize(idx + 256, nullptr); // only in case of hit overflow in one module + auto const idx = pixelHitsModuleStart[detI] + clus.pixelCluster().originalId(); assert(nullptr == hitmap[idx]); - std::cout << "Filling hitmap at position " << idx << " with a pixel hit." << std::endl; + // std::cout << "Filling hitmap at position " << idx << " with a pixel hit." << std::endl; hitmap[idx] = &pixelHit; } - // function to select only P-hits from the OT barrel - auto isPinPSinOTBarrel = [&](DetId detId) { - return (trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP && - detId.subdetId() == StripSubdetector::TOB); - }; - // if OT RecHits are used in PixelTracks, fill the hitmap also with those if (useOTExtension_) { // The RecHits in the SoA are ordered according to the detUnit->index() - // of the respective OT module. For this reason, in order to infer the - // hit position in the SoA, we need to know which modules are there and - // how many hits each module has. - // We use: - // - detIdToIndex: map the detId to detUnit->index() - // (NOTE: technically, we wouldn't need the detUnit at all if the order - // of detIds and detUnit->index is identical, to be checked) - // - p_modulesInPSInOTBarrel: set of detUnit->index() of considered modules - // (used for finding the "moduleIdOT", position of the module in the SoA) - // - moduleStartOT: map from moduleIdOT to position of first RecHit of that - // layer in the RecHit SoA + // of the respective OT module. For this reason, we need the map from the + // detId to the moduleId among all used OT modules. This otModuleId corresponds + // to the module's position in the otHitsModuleStart that we get from the event. - auto const &detUnits = trackerGeometry->detUnits(); - std::map detIdToIndex; - std::set p_modulesInPSInOTBarrel; - - // fill detIdToIndex map and p_modulesInPSInOTBarrel set of modules - for (auto &detUnit : detUnits) { - DetId detId(detUnit->geographicalId()); - if (isPinPSinOTBarrel(detId)) { - detIdToIndex[detUnit->geographicalId()] = detUnit->index(); - p_modulesInPSInOTBarrel.insert(detUnit->index()); - } - } - - // function to get the "moduleId" of the OT modules - // (NOT a general CMSSW Id but just the index of the OT module in moduleStartOT) - auto getModuleIdOT = [&](DetId detId) { - int index = detIdToIndex[detId]; - auto it = p_modulesInPSInOTBarrel.find(index); - if (it != p_modulesInPSInOTBarrel.end()) { - return std::distance(p_modulesInPSInOTBarrel.begin(), it); - } else { - assert(0); -// return -1L; - } - }; + // get the module's starting indices in the hit collection + auto const &otHitsModuleStart = iEvent.get(otHMSToken_); - // count hits in all considered OT modules and fill them in moduleStartOT - // at the position of the subsequent module - std::vector moduleStartOT; - moduleStartOT.resize(p_modulesInPSInOTBarrel.size() + 1, 0); + // perform the exact same loop of how the SoA is initially filled with OT hits + // and get the index by counting the hits (starting from the correpondign HitStartModule) for (auto const &detSet : *otRecHitsDSV) { auto detId = detSet.detId(); - if (isPinPSinOTBarrel(DetId(detId))) { - int moduleId = getModuleIdOT(detId); - if (moduleId != -1) { - moduleStartOT[moduleId + 1] = detSet.size(); - } else { - assert(0); - } - } - } - // accumulate the number of hits starting from the number of pixel hits - // to finalize the actual positions of the layers in the RecHit SoA - moduleStartOT[0] = nPixelHits; - std::partial_sum(moduleStartOT.cbegin(), moduleStartOT.cend(), moduleStartOT.begin()); + // check if module is used in extension + if (detIdIsUsedOTModule.find(detId)->second) { + // get the corresponding otModuleId + auto otModuleId = detIdToOTModuleId.find(detId)->second; - // perform the exact same loop of how the SoA is initially filled with OT hits - // and get the index by counting the hits (starting from nPixelHits) - for (auto const &detSet : *otRecHitsDSV) { - auto detId = detSet.detId(); - if (isPinPSinOTBarrel(DetId(detId))) { - for (int idx = moduleStartOT[getModuleIdOT(detId)]; auto const &recHit : detSet) { + // loop over the RecHits of the module and fill the hitmap + for (int idx = otHitsModuleStart[otModuleId]; auto const &recHit : detSet) { + assert(nullptr == hitmap[idx]); + // std::cout << "Filling hitmap at position " << idx << " with an OT hit." << std::endl; hitmap[idx] = &recHit; - std::cout << "Filling hitmap at position " << idx << " with an OT hit with index " << getModuleIdOT(detId) << std::endl; idx++; } } @@ -336,7 +339,7 @@ void PixelTrackProducerFromSoAAlpaka::produce(edm::StreamID streamID, hits[iHit - start] = hitmap[hitIdxs[iHit]]; //#ifdef CA_DEBUG -#if 1 +#if 0 std::cout << "track soa : " << it << " with hits: "; for (auto iHit = start; iHit < end; ++iHit) std::cout << hitIdxs[iHit] << " - "; From ea8371b6c3da7ec8d1f04893f5bde0924b6578bc Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Tue, 17 Jun 2025 10:05:16 +0200 Subject: [PATCH 36/40] fix the hardCurvCut bug also in the CASimpleCell class (which is the one being used...) --- RecoTracker/PixelSeeding/plugins/alpaka/CASimpleCell.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CASimpleCell.h b/RecoTracker/PixelSeeding/plugins/alpaka/CASimpleCell.h index 57f5232151813..fd76ba1358a40 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CASimpleCell.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CASimpleCell.h @@ -157,7 +157,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { CircleEq eq(x1, y1, x2, y2, x3, y3); // MRMR printf("Computed curvature: %f, vs parameter: %f\n", eq.curvature(), maxCurv); - if (eq.curvature() > maxCurv) + if (std::abs(eq.curvature()) > maxCurv) return false; return std::abs(eq.dca0()) < region_origin_radius_plus_tolerance * std::abs(eq.curvature()); From 85ac5f5bbf80648798d90dfc806ad8d794f0bc13 Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Thu, 19 Jun 2025 16:16:23 +0200 Subject: [PATCH 37/40] Add more debugging printouts in brokenline fit. --- .../plugins/alpaka/BrokenLineFit.dev.cc | 9 ++++++--- .../interface/alpaka/BrokenLine.h | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/BrokenLineFit.dev.cc b/RecoTracker/PixelSeeding/plugins/alpaka/BrokenLineFit.dev.cc index 21620747cd51d..df93a309f9ba4 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/BrokenLineFit.dev.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/BrokenLineFit.dev.cc @@ -136,8 +136,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { #ifdef BL_DUMP_HITS bool dump = foundNtuplets->size(tkid) == 5; + bool dump = foundNtuplets->size(tkid) >= 4; if (dump) { - printf("Track id %d %d Hit %d on %d\nGlobal: hits.col(%d) << %f,%f,r(%f),%f\n", + printf("Track local_id %d tkid: %d Hit %d on det: %d\nGlobal: hits.col(%d) << x: %f,y: %f, r(%f),z: %f\n", local_idx, tkid, hit, @@ -147,6 +148,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { hh[hit].yGlobal(), sqrt(hh[hit].xGlobal()*hh[hit].xGlobal()+hh[hit].yGlobal()*hh[hit].yGlobal()), hh[hit].zGlobal()); + printf("Local Error(%d): x2: %e, x[um]: %e, y2: %e, y[um]: %e\n", i, hh[hit].xerrLocal(), 1.e4*sqrt(hh[hit].xerrLocal()), hh[hit].yerrLocal(), 1.e4*sqrt(hh[hit].yerrLocal())); + printf("Error: hits_ge.col(%d) x[um]: %e, y[um]: %e, z[um]: %e\n", i, 1.e4*sqrt(ge[0]), 1.e4*sqrt(ge[2]), 1.e4*sqrt(ge[5])); printf("Error: hits_ge.col(%d) << %e,%e,%e,%e,%e,%e\n", i, ge[0], ge[1], ge[2], ge[3], ge[4], ge[5]); } #endif @@ -222,7 +225,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { #ifdef BROKENLINE_DEBUG if (!(circle.chi2 >= 0) || !(line.chi2 >= 0)) printf("kernelBLFit failed! %f/%f\n", circle.chi2, line.chi2); - printf("kernelBLFit size %d for %d hits circle.par(0,1,2): %d %f,%f,%f\n", + printf("kernelBLFit size %d for %d hits of tkid %d circle.par(0,1,2): %f,%f,%f\n", N, N, tkid, @@ -230,7 +233,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { circle.par(1), circle.par(2)); printf("kernelBLHits line.par(0,1): %d %f,%f\n", tkid, line.par(0), line.par(1)); - printf("kernelBLHits chi2 cov circle/line %f/%f %e,%e,%e,%e,%e\n", + printf("kernelBLHits chi2_circle: %f chi2_line: %f, cov(0-3)_circle: %e, %e, %e cov(1-2)_line %e,%e\n", circle.chi2, line.chi2, circle.cov(0, 0), diff --git a/RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h b/RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h index 057326543f184..08148bac33990 100644 --- a/RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h +++ b/RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h @@ -8,6 +8,8 @@ #include "HeterogeneousCore/AlpakaInterface/interface/config.h" #include "RecoTracker/PixelTrackFitting/interface/alpaka/FitUtils.h" +#define BL_DEEPDEBUG + namespace ALPAKA_ACCELERATOR_NAMESPACE::brokenline { using namespace cms::alpakatools; @@ -186,6 +188,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::brokenline { alpaka::math::atan2(acc, riemannFit::cross2D(acc, dVec, eVec), dVec.dot(eVec)); // calculates the arc length } riemannFit::VectorNd zVec = hits.block(2, 0, 1, n).transpose(); + #ifdef BL_DEEPDEBUG + for (u_int i = 0; i < n; i++) { + printf("Point %d, x, %f, y: %f, z: %f, s: %f\n", i, hits.block(0, 0, 2, n)(0, i), hits.block(0, 0, 2, n)(1, i), zVec(i), results.sTransverse(i)); + } + #endif //calculate sTotal and zVec riemannFit::Matrix2xNd pointsSZ = riemannFit::Matrix2xNd::Zero(); @@ -196,7 +203,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::brokenline { } results.sTotal = pointsSZ.block(0, 0, 1, n).transpose(); results.zInSZplane = pointsSZ.block(1, 0, 1, n).transpose(); - + #ifdef BL_DEEPDEBUG + for (u_int i = 0; i < n; i++) { + printf("Point %d, rot_s: %f, rot_z: %f\n", i, results.sTotal(i), results.zInSZplane(i)); + } + #endif //calculate varBeta results.varBeta(0) = results.varBeta(n - 1) = 0; for (u_int i = 1; i < n - 1; i++) { @@ -293,6 +304,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::brokenline { result(3) = result(2) * atan2(riemannFit::cross2D(acc, d, e), d.dot(e)) / (hits(2, n - 1) - hits(2, 0)); // ds/dz slope between last and first point + #ifdef BL_DEEPDEBUG + printf("FastFit results(x,y,R,tan(theta): %e, %e, %e, %e\n", result(0), result(1), result(2), result(3)); + #endif } /*! @@ -481,6 +495,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::brokenline { const auto& varBeta = data.varBeta; const double slope = -data.qCharge / fast_fit(3); + #ifdef BL_DEEPDEBUG + printf("Slope: %e, charge: %d, curvature: %e\n", slope, data.qCharge, fast_fit(3)); + #endif riemannFit::Matrix2d rotMat = rotationMatrix(acc, slope); riemannFit::Matrix3d vMat = riemannFit::Matrix3d::Zero(); // covariance matrix XYZ From aa7385061635ec702531bcd25d12c556b0467a8f Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Thu, 19 Jun 2025 16:17:27 +0200 Subject: [PATCH 38/40] Fix Jacobian for linefit in Brokenline. --- RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h b/RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h index 08148bac33990..d385811ddafdd 100644 --- a/RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h +++ b/RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h @@ -512,8 +512,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::brokenline { vMat(2, 1) = vMat(1, 2) = hits_ge.col(i)[4]; // cov_yz vMat(2, 2) = hits_ge.col(i)[5]; // z errors auto tmp = 1. / radii.block(0, i, 2, 1).norm(); - jacobXYZtosZ(0, 0) = radii(1, i) * tmp; - jacobXYZtosZ(0, 1) = -radii(0, i) * tmp; + jacobXYZtosZ(0, 0) = data.qCharge*radii(1, i) * tmp; + jacobXYZtosZ(0, 1) = -data.qCharge*radii(0, i) * tmp; jacobXYZtosZ(1, 2) = 1.; weights(i) = 1. / ((rotMat * jacobXYZtosZ * vMat * jacobXYZtosZ.transpose() * rotMat.transpose())( 1, 1)); // compute the orthogonal weight point by point From a2fe5da2c9d0f88efc620aa9a5d68cd7501fbf22 Mon Sep 17 00:00:00 2001 From: Luca Ferragina Date: Tue, 24 Jun 2025 11:08:33 +0200 Subject: [PATCH 39/40] Remove all debug printouts --- .../modules/hltPhase2PixelTracksSoA_cfi.py | 4 ++-- .../alpaka/Phase2OTRecHitsSoAConverter.cc | 18 +++++++++--------- .../alpaka/SiPixelRecHitExtendedAlpaka.cc | 12 ++++++------ .../plugins/alpaka/CAHitNtuplet.cc | 6 +++--- .../interface/alpaka/BrokenLine.h | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py index 21045cc47d738..c3eba495604f5 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPhase2PixelTracksSoA_cfi.py @@ -9,7 +9,7 @@ hardCurvCut = cms.double(0.01425), # corresponds to 800 MeV in 3.8T. earlyFishbone = cms.bool(True), lateFishbone = cms.bool(False), - fillStatistics = cms.bool(True), + fillStatistics = cms.bool(False), minHitsPerNtuplet = cms.uint32(5), maxNumberOfDoublets = cms.string(str(15*512*1024)), maxNumberOfTuples = cms.string(str(2*60*1024)), @@ -610,5 +610,5 @@ def exclude_layers(hltPhase2PixelTracksSoA, layers_to_exclude): ot_layers_ = [28, 29, 30] exclude_layers(hltPhase2PixelTracksSoA, layers_to_exclude=ot_layers_) -print("Using {} pair connections: {}".format(len(hltPhase2PixelTracksSoA.geometry.pairGraph), hltPhase2PixelTracksSoA.geometry.pairGraph)) +#print("Using {} pair connections: {}".format(len(hltPhase2PixelTracksSoA.geometry.pairGraph), hltPhase2PixelTracksSoA.geometry.pairGraph)) diff --git a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc index 875101e3cc828..4f498bc7d52ab 100644 --- a/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc +++ b/RecoLocalTracker/Phase2TrackerRecHits/plugins/alpaka/Phase2OTRecHitsSoAConverter.cc @@ -141,11 +141,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { PHitsInOTBarrel++; } } - std::cout << "Tot number of modules in Pixels " << modulesInPixel_ << std::endl; - std::cout << "Tot number of p_modulesInPSInOTBarrel: " << orderedModules_.size() << std::endl; - std::cout << "Number of strip (active) modules: " << activeStripModules << std::endl; - std::cout << "Number of strip hits: " << nStripHits << std::endl; - std::cout << "Total hits of PinOTBarrel: " << PHitsInOTBarrel << std::endl; + //std::cout << "Tot number of modules in Pixels " << modulesInPixel_ << std::endl; + //std::cout << "Tot number of p_modulesInPSInOTBarrel: " << orderedModules_.size() << std::endl; + //std::cout << "Number of strip (active) modules: " << activeStripModules << std::endl; + //std::cout << "Number of strip hits: " << nStripHits << std::endl; + //std::cout << "Total hits of PinOTBarrel: " << PHitsInOTBarrel << std::endl; HitsHost stripHitsHost(queue, PHitsInOTBarrel, orderedModules_.size()); auto& stripHitsModuleView = stripHitsHost.view<::reco::HitModuleSoA>(); @@ -201,13 +201,13 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { stripHitsHost.view()[idx].yLocal() = recHit.localPosition().y(); stripHitsHost.view()[idx].xerrLocal() = recHit.localPositionError().xx(); stripHitsHost.view()[idx].yerrLocal() = recHit.localPositionError().yy(); - std::cout << "Local (x, y) with (xx, yy) --> (" << recHit.localPosition().x() << ", " << recHit.localPosition().y() << ") with (" << recHit.localPositionError().xx() << ", " << recHit.localPositionError().yy() << ")" << std::endl; + //std::cout << "Local (x, y) with (xx, yy) --> (" << recHit.localPosition().x() << ", " << recHit.localPosition().y() << ") with (" << recHit.localPositionError().xx() << ", " << recHit.localPositionError().yy() << ")" << std::endl; auto globalPosition = det->toGlobal(recHit.localPosition()); double gx = globalPosition.x() - bs.x0(); double gy = globalPosition.y() - bs.y0(); double gz = globalPosition.z() - bs.z0(); - std::cout << "Global (x, y, z) --> (" << globalPosition.x() << ", " << globalPosition.y() << ", " << globalPosition.z() << ")" << std::endl; - std::cout << "Corrected Global (x, y, z) --> (" << gx << ", " << gy << ", " << gz << ")" << std::endl; + //std::cout << "Global (x, y, z) --> (" << globalPosition.x() << ", " << globalPosition.y() << ", " << globalPosition.z() << ")" << std::endl; + //std::cout << "Corrected Global (x, y, z) --> (" << gx << ", " << gy << ", " << gz << ")" << std::endl; // std::cout << gx << std::endl; stripHitsHost.view()[idx].xGlobal() = gx; stripHitsHost.view()[idx].yGlobal() = gy; @@ -226,7 +226,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { stripHitsModuleView[orderedModules_.size()].moduleStart() = cumulativeHitPerModule[orderedModules_.size() - 1] + nPixelHits; - std::cout << "DONE" << std::endl; + //std::cout << "DONE" << std::endl; #if 0 int current = 0; for (int h = 0; h < stripHitsHost.view().metadata().size(); ++h) { diff --git a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc index 64f27248a579f..08b413339a502 100644 --- a/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc +++ b/RecoLocalTracker/SiPixelRecHits/plugins/alpaka/SiPixelRecHitExtendedAlpaka.cc @@ -75,18 +75,18 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { auto queue = iEvent.queue(); const auto& pixelRecHitsSoA = iEvent.get(pixelRecHitToken_); const auto& otRecHitsSoA = iEvent.get(trackerRecHitToken_); - std::cout << "----------------- Merging Pixel and Tracker RecHits -----------------" << std::endl; + //std::cout << "----------------- Merging Pixel and Tracker RecHits -----------------" << std::endl; const int nPixelHits = pixelRecHitsSoA.nHits(); - std::cout << "Number of Pixel recHits: " << nPixelHits << std::endl; + //std::cout << "Number of Pixel recHits: " << nPixelHits << std::endl; const int nTrackerHits = otRecHitsSoA.nHits(); - std::cout << "Number of Tracker recHits: " << nTrackerHits << std::endl; + //std::cout << "Number of Tracker recHits: " << nTrackerHits << std::endl; const int nTotHits = nPixelHits + nTrackerHits; - std::cout << "Number of Pixel modules: " << pixelRecHitsSoA.nModules() << std::endl; - std::cout << "Number of Tracker modules: " << otRecHitsSoA.nModules() << std::endl; + //std::cout << "Number of Pixel modules: " << pixelRecHitsSoA.nModules() << std::endl; + //std::cout << "Number of Tracker modules: " << otRecHitsSoA.nModules() << std::endl; const int nTotModules = pixelRecHitsSoA.nModules() + otRecHitsSoA.nModules(); auto outputSoA = reco::TrackingRecHitsSoACollection(queue, nTotHits, nTotModules); - std::cout << "Total number of recHits: " << outputSoA.nHits() << std::endl; + //std::cout << "Total number of recHits: " << outputSoA.nHits() << std::endl; // copy all columns from pixelRecHitsSoA and otRecHitsSoA to outputSoA // xLocal diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc index ac3a7137d4821..265f9ae917cb9 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc @@ -176,7 +176,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { if (isPh2Pixel(detid)) { // std::cout << "Good Pixel" << std::endl; if (layer != oldLayer) { - std::cout << "Pixel LayerStart: " << layerCount << " at layer " << layer << " has " << n_modules << " modules." << std::endl; + //std::cout << "Pixel LayerStart: " << layerCount << " at layer " << layer << " has " << n_modules << " modules." << std::endl; layerStarts[layerCount++] = n_modules; if (layerCount > n_layers + 1) break; @@ -191,7 +191,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { if (isPinPSinOTBarrel(unitDetId)) { // std::cout << "Good OT Barrel" << std::endl; if (layer != oldLayer) { - std::cout << "OT LayerStart: " << layerCount << " at layer " << layer << " has " << n_modules << " modules." << std::endl; + //std::cout << "OT LayerStart: " << layerCount << " at layer " << layer << " has " << n_modules << " modules." << std::endl; layerStarts[layerCount++] = n_modules; if (layerCount > n_layers + 1) break; @@ -208,7 +208,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { counter++; } layerStarts[n_layers] = n_modules; - std::cout << "OT LayerStart: " << n_layers << " has " << n_modules << " modules." << std::endl; + //std::cout << "OT LayerStart: " << n_layers << " has " << n_modules << " modules." << std::endl; } else { for (auto& det : dets) { DetId detid = det->geographicalId(); diff --git a/RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h b/RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h index d385811ddafdd..045578a27e1cb 100644 --- a/RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h +++ b/RecoTracker/PixelTrackFitting/interface/alpaka/BrokenLine.h @@ -8,7 +8,7 @@ #include "HeterogeneousCore/AlpakaInterface/interface/config.h" #include "RecoTracker/PixelTrackFitting/interface/alpaka/FitUtils.h" -#define BL_DEEPDEBUG +//#define BL_DEEPDEBUG namespace ALPAKA_ACCELERATOR_NAMESPACE::brokenline { From ab64c0531c47431bb817b5be8b835c0f5d0bf0f5 Mon Sep 17 00:00:00 2001 From: Bruno Alves Date: Mon, 30 Jun 2025 10:21:27 +0200 Subject: [PATCH 40/40] Resolve conflicts. --- .../PixelSeeding/interface/CACoupleDevice.h | 17 + .../PixelSeeding/interface/CACoupleHost.h | 15 + .../PixelSeeding/interface/CACoupleSoA.h | 20 + .../interface/alpaka/CACoupleSoACollection.h | 26 + .../PixelSeeding/plugins/alpaka/CACell.h | 401 +++++++-------- .../PixelSeeding/plugins/alpaka/CAFishbone.h | 5 +- .../plugins/alpaka/CAHitNtuplet.cc | 8 +- .../plugins/alpaka/CAHitNtupletGenerator.cc | 18 +- .../CAHitNtupletGeneratorKernels.dev.cc | 463 +++++++----------- .../alpaka/CAHitNtupletGeneratorKernels.h | 66 +-- .../alpaka/CAHitNtupletGeneratorKernelsImpl.h | 172 ++++--- .../plugins/alpaka/CAPixelDoublets.h | 75 ++- .../plugins/alpaka/CAPixelDoubletsAlgos.h | 2 +- .../PixelSeeding/test/alpaka/CAsizes_t.cpp | 4 +- 14 files changed, 670 insertions(+), 622 deletions(-) create mode 100644 RecoTracker/PixelSeeding/interface/CACoupleDevice.h create mode 100644 RecoTracker/PixelSeeding/interface/CACoupleHost.h create mode 100644 RecoTracker/PixelSeeding/interface/CACoupleSoA.h create mode 100644 RecoTracker/PixelSeeding/interface/alpaka/CACoupleSoACollection.h diff --git a/RecoTracker/PixelSeeding/interface/CACoupleDevice.h b/RecoTracker/PixelSeeding/interface/CACoupleDevice.h new file mode 100644 index 0000000000000..88f46f427615c --- /dev/null +++ b/RecoTracker/PixelSeeding/interface/CACoupleDevice.h @@ -0,0 +1,17 @@ +#ifndef RecoTracker_PixelSeeding_interface_CACoupleDevice_H +#define RecoTracker_PixelSeeding_interface_CACoupleDevice_H + +#include + +#include + +#include "DataFormats/Portable/interface/PortableDeviceCollection.h" +#include "RecoTracker/PixelSeeding/interface/CACoupleSoA.h" +#include "HeterogeneousCore/AlpakaInterface/interface/config.h" + +namespace caStructures { + template + using CACoupleDevice = PortableDeviceCollection; +} + +#endif // RecoTracker_PixelSeeding_interface_CACoupleDevice_H diff --git a/RecoTracker/PixelSeeding/interface/CACoupleHost.h b/RecoTracker/PixelSeeding/interface/CACoupleHost.h new file mode 100644 index 0000000000000..1d8a3c20affd1 --- /dev/null +++ b/RecoTracker/PixelSeeding/interface/CACoupleHost.h @@ -0,0 +1,15 @@ +#ifndef RecoTracker_PixelSeeding_interface_CACoupleHost_h +#define RecoTracker_PixelSeeding_interface_CACoupleHost_h + +#include + +#include + +#include "DataFormats/Portable/interface/PortableHostCollection.h" +#include "RecoTracker/PixelSeeding/interface/CACoupleSoA.h" +#include "HeterogeneousCore/AlpakaInterface/interface/config.h" + +namespace caStructures { + using CACoupleHost = PortableHostCollection; +} +#endif // RecoTracker_PixelSeeding_interface_CACoupleHost_h diff --git a/RecoTracker/PixelSeeding/interface/CACoupleSoA.h b/RecoTracker/PixelSeeding/interface/CACoupleSoA.h new file mode 100644 index 0000000000000..fd7f20dcd76cd --- /dev/null +++ b/RecoTracker/PixelSeeding/interface/CACoupleSoA.h @@ -0,0 +1,20 @@ +#ifndef RecoTracker_PixelSeeding_interface_CACoupleSoA_h +#define RecoTracker_PixelSeeding_interface_CACoupleSoA_h + +#include + +#include + +#include "DataFormats/SoATemplate/interface/SoALayout.h" + +namespace caStructures { + + GENERATE_SOA_LAYOUT(CACoupleLayout, SOA_COLUMN(uint32_t, inner), SOA_COLUMN(uint32_t, outer)) + + using CACoupleSoA = CACoupleLayout<>; + using CACoupleSoAView = CACoupleSoA::View; + using CACoupleSoAConstView = CACoupleSoA::ConstView; + +} // namespace caStructures + +#endif // RecoTracker_PixelSeeding_interface_CACoupleSoA_h diff --git a/RecoTracker/PixelSeeding/interface/alpaka/CACoupleSoACollection.h b/RecoTracker/PixelSeeding/interface/alpaka/CACoupleSoACollection.h new file mode 100644 index 0000000000000..d368fb136c302 --- /dev/null +++ b/RecoTracker/PixelSeeding/interface/alpaka/CACoupleSoACollection.h @@ -0,0 +1,26 @@ +#ifndef RecoTracker_PixelSeeding_interface_CACoupleSoACollection_h +#define RecoTracker_PixelSeeding_interface_CACoupleSoACollection_h + +#include + +#include + +#include "DataFormats/Portable/interface/alpaka/PortableCollection.h" +#include "RecoTracker/PixelSeeding/interface/CACoupleDevice.h" +#include "RecoTracker/PixelSeeding/interface/CACoupleHost.h" +#include "RecoTracker/PixelSeeding/interface/CACoupleSoA.h" +#include "HeterogeneousCore/AlpakaInterface/interface/CopyToHost.h" +#include "HeterogeneousCore/AlpakaInterface/interface/config.h" + +namespace ALPAKA_ACCELERATOR_NAMESPACE { + + using ::caStructures::CACoupleDevice; + using ::caStructures::CACoupleHost; + using CACoupleSoACollection = + std::conditional_t, CACoupleHost, CACoupleDevice>; + +} // namespace ALPAKA_ACCELERATOR_NAMESPACE + +ASSERT_DEVICE_MATCHES_HOST_COLLECTION(CACoupleSoACollection, ::caStructures::CACoupleHost); + +#endif // RecoTracker_PixelSeeding_interface_CACoupleSoACollection_h diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CACell.h b/RecoTracker/PixelSeeding/plugins/alpaka/CACell.h index 3c4fcf506e139..eabbc8a8d0a36 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CACell.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CACell.h @@ -1,9 +1,7 @@ #ifndef RecoTracker_PixelSeeding_plugins_alpaka_CACell_h #define RecoTracker_PixelSeeding_plugins_alpaka_CACell_h -// #define GPU_DEBUG -// #define CA_DEBUG -// #define CA_WARNINGS +// #define ONLY_TRIPLETS_IN_HOLE #include #include @@ -19,137 +17,157 @@ #include "HeterogeneousCore/AlpakaInterface/interface/config.h" #include "RecoTracker/PixelSeeding/interface/CircleEq.h" #include "RecoTracker/PixelSeeding/interface/CAGeometrySoA.h" -#include "RecoTracker/PixelSeeding/interface/CAPairSoA.h" +#include "RecoTracker/PixelSeeding/interface/CACoupleSoA.h" #include "CAStructures.h" +#include "CASimpleCell.h" namespace ALPAKA_ACCELERATOR_NAMESPACE { using namespace ::caStructures; template - class CACell { + class CACellT : public CASimpleCell { public: - ALPAKA_FN_ACC ALPAKA_FN_INLINE void init(const HitsConstView& hh, + using typename CASimpleCell::StatusBit; + using typename CASimpleCell::Quality; + using typename CASimpleCell::HitContainer; + using typename CASimpleCell::TmpTuple; + + using PtrAsInt = unsigned long long; + + using OuterHitOfCellContainer = OuterHitOfCellContainerT; + using OuterHitOfCell = OuterHitOfCellT; + using CellNeighbors = CellNeighborsT; + using CellTracks = CellTracksT; + using CellNeighborsVector = CellNeighborsVectorT; + using CellTracksVector = CellTracksVectorT; + + CACellT() = default; + + ALPAKA_FN_ACC ALPAKA_FN_INLINE void init(CellNeighborsVector& cellNeighbors, + CellTracksVector& cellTracks, + const HitsConstView& hh, int layerPairId, uint8_t theInnerLayer, uint8_t theOuterLayer, hindex_type innerHitId, hindex_type outerHitId) { - theInnerHitId_ = innerHitId; - theOuterHitId_ = outerHitId; - theLayerPairId_ = layerPairId; - theInnerLayer_ = theInnerLayer; - theOuterLayer_ = theOuterLayer; - theStatus_ = 0; - theFishboneId_ = invalidHitId; + this->theInnerHitId = innerHitId; + this->theOuterHitId = outerHitId; + this->theLayerPairId_ = layerPairId; + this->theInnerLayer_ = theInnerLayer; + this->theOuterLayer_ = theOuterLayer; + this->theStatus_ = 0; + this->theFishboneId = this->invalidHitId; // optimization that depends on access pattern - theInnerZ_ = hh[innerHitId].zGlobal(); - theInnerR_ = hh[innerHitId].rGlobal(); + this->theInnerZ = hh[innerHitId].zGlobal(); + this->theInnerR = hh[innerHitId].rGlobal(); + + // link to default empty + theOuterNeighbors = &cellNeighbors[0]; + theTracks = &cellTracks[0]; + ALPAKA_ASSERT_ACC(outerNeighbors().empty()); + ALPAKA_ASSERT_ACC(tracks().empty()); } - using hindex_type = ::caStructures::hindex_type; - using tindex_type = ::caStructures::tindex_type; - - static constexpr auto invalidHitId = std::numeric_limits::max(); - - using TmpTuple = cms::alpakatools::VecArray; - using HitContainer = caStructures::SequentialContainer; - using CellToCell = caStructures::GenericContainer; - using CellToTracks = caStructures::GenericContainer; - using CAPairSoAView = caStructures::CAPairSoAView; - - using Quality = ::pixelTrack::Quality; - static constexpr auto bad = ::pixelTrack::Quality::bad; - - enum class StatusBit : uint16_t { kUsed = 1, kInTrack = 2, kKilled = 1 << 15 }; - - CACell() = default; - - constexpr unsigned int inner_hit_id() const { return theInnerHitId_; } - constexpr unsigned int outer_hit_id() const { return theOuterHitId_; } - - ALPAKA_FN_ACC ALPAKA_FN_INLINE void kill() { theStatus_ |= uint16_t(StatusBit::kKilled); } - ALPAKA_FN_ACC ALPAKA_FN_INLINE bool isKilled() const { return theStatus_ & uint16_t(StatusBit::kKilled); } - - ALPAKA_FN_ACC ALPAKA_FN_INLINE int16_t layerPairId() const { return theLayerPairId_; } - ALPAKA_FN_ACC ALPAKA_FN_INLINE int16_t innerLayer() const { return theInnerLayer_; } - ALPAKA_FN_ACC ALPAKA_FN_INLINE int16_t outerLayer() const { return theOuterLayer_; } - - ALPAKA_FN_ACC ALPAKA_FN_INLINE bool unused() const { return 0 == (uint16_t(StatusBit::kUsed) & theStatus_); } - ALPAKA_FN_ACC ALPAKA_FN_INLINE void setStatusBits(StatusBit mask) { theStatus_ |= uint16_t(mask); } - - ALPAKA_FN_ACC ALPAKA_FN_INLINE float inner_x(const HitsConstView& hh) const { return hh[theInnerHitId_].xGlobal(); } - ALPAKA_FN_ACC ALPAKA_FN_INLINE float outer_x(const HitsConstView& hh) const { return hh[theOuterHitId_].xGlobal(); } - ALPAKA_FN_ACC ALPAKA_FN_INLINE float inner_y(const HitsConstView& hh) const { return hh[theInnerHitId_].yGlobal(); } - ALPAKA_FN_ACC ALPAKA_FN_INLINE float outer_y(const HitsConstView& hh) const { return hh[theOuterHitId_].yGlobal(); } - ALPAKA_FN_ACC ALPAKA_FN_INLINE float inner_z(const HitsConstView& hh) const { return theInnerZ_; } - ALPAKA_FN_ACC ALPAKA_FN_INLINE float outer_z(const HitsConstView& hh) const { return hh[theOuterHitId_].zGlobal(); } - ALPAKA_FN_ACC ALPAKA_FN_INLINE float inner_r(const HitsConstView& hh) const { return theInnerR_; } - ALPAKA_FN_ACC ALPAKA_FN_INLINE float outer_r(const HitsConstView& hh) const { return hh[theOuterHitId_].rGlobal(); } - - ALPAKA_FN_ACC ALPAKA_FN_INLINE auto inner_iphi(const HitsConstView& hh) const { return hh[theInnerHitId_].iphi(); } - ALPAKA_FN_ACC ALPAKA_FN_INLINE auto outer_iphi(const HitsConstView& hh) const { return hh[theOuterHitId_].iphi(); } - - ALPAKA_FN_ACC ALPAKA_FN_INLINE float inner_detIndex(const HitsConstView& hh) const { - return hh[theInnerHitId_].detectorIndex(); - } - ALPAKA_FN_ACC ALPAKA_FN_INLINE float outer_detIndex(const HitsConstView& hh) const { - return hh[theOuterHitId_].detectorIndex(); + template + ALPAKA_FN_ACC ALPAKA_FN_INLINE __attribute__((always_inline)) int addOuterNeighbor( + const TAcc& acc, typename TrackerTraits::cindex_type t, CellNeighborsVector& cellNeighbors) { + // use smart cache + if (outerNeighbors().empty()) { + auto i = cellNeighbors.extend(acc); // maybe wasted.... + if (i > 0) { + cellNeighbors[i].reset(); + alpaka::mem_fence(acc, alpaka::memory_scope::Grid{}); +#ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED + theOuterNeighbors = &cellNeighbors[i]; +#else + auto zero = (PtrAsInt)(&cellNeighbors[0]); + alpaka::atomicCas(acc, + (PtrAsInt*)(&theOuterNeighbors), + zero, + (PtrAsInt)(&cellNeighbors[i]), + alpaka::hierarchy::Blocks{}); // if fails we cannot give "i" back... +#endif + } else + return -1; + } + alpaka::mem_fence(acc, alpaka::memory_scope::Grid{}); + return outerNeighbors().push_back(acc, t); } - ALPAKA_FN_ACC ALPAKA_FN_INLINE auto fishboneId() const { return theFishboneId_; } - ALPAKA_FN_ACC ALPAKA_FN_INLINE bool hasFishbone() const { return theFishboneId_ != invalidHitId; } - - ALPAKA_FN_ACC void print_cell() const { - printf("printing cell: on layerPair: %d, innerLayer: %d, outerLayer: %d, innerHitId: %d, outerHitId: %d \n", - theLayerPairId_, - theInnerLayer_, - theOuterLayer_, - theInnerHitId_, - theOuterHitId_); - } + template + ALPAKA_FN_ACC ALPAKA_FN_INLINE __attribute__((always_inline)) int addTrack(TAcc const& acc, + tindex_type t, + CellTracksVector& cellTracks) { + if (tracks().empty()) { + auto i = cellTracks.extend(acc); // maybe wasted.... + if (i > 0) { + cellTracks[i].reset(); + alpaka::mem_fence(acc, alpaka::memory_scope::Grid{}); +#ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED + theTracks = &cellTracks[i]; +#else + auto zero = (PtrAsInt)(&cellTracks[0]); + alpaka::atomicCas(acc, + (PtrAsInt*)(&theTracks), + zero, + (PtrAsInt)(&cellTracks[i]), + alpaka::hierarchy::Blocks{}); // if fails we cannot give "i" back... - ALPAKA_FN_ACC ALPAKA_FN_INLINE void setFishbone(Acc2D const& acc, hindex_type id, float z, const HitsConstView& hh) { - // make it deterministic: use the farther apart (in z) - auto old = theFishboneId_; - while ( - old != - alpaka::atomicCas( - acc, - &theFishboneId_, - old, - (invalidHitId == old || std::abs(z - theInnerZ_) > std::abs(hh[old].zGlobal() - theInnerZ_)) ? id : old, - alpaka::hierarchy::Blocks{})) - old = theFishboneId_; +#endif + } else + return -1; + } + alpaka::mem_fence(acc, alpaka::memory_scope::Grid{}); + return tracks().push_back(acc, t); } - ALPAKA_FN_ACC ALPAKA_FN_INLINE static bool areAlignedRZ( - float r1, float z1, float ri, float zi, float ro, float zo, const float ptmin, const float thetaCut) { - float radius_diff = std::abs(r1 - ro); - float distance_13_squared = radius_diff * radius_diff + (z1 - zo) * (z1 - zo); - - float pMin = ptmin * std::sqrt(distance_13_squared); // this needs to be divided by - // radius_diff later - - float tan_12_13_half_mul_distance_13_squared = fabs(z1 * (ri - ro) + zi * (ro - r1) + zo * (r1 - ri)); - return tan_12_13_half_mul_distance_13_squared * pMin <= thetaCut * distance_13_squared * radius_diff; + ALPAKA_FN_ACC ALPAKA_FN_INLINE CellTracks& tracks() { return *theTracks; } + ALPAKA_FN_ACC ALPAKA_FN_INLINE CellTracks const& tracks() const { return *theTracks; } + ALPAKA_FN_ACC ALPAKA_FN_INLINE CellNeighbors& outerNeighbors() { return *theOuterNeighbors; } + ALPAKA_FN_ACC ALPAKA_FN_INLINE CellNeighbors const& outerNeighbors() const { return *theOuterNeighbors; } + + ALPAKA_FN_ACC bool check_alignment(const HitsConstView& hh, + CACellT const& otherCell, + const float ptmin, + const float hardCurvCut, + const float caThetaCutBarrel, + const float caThetaCutForward, + const float dcaCutInnerTriplet, + const float dcaCutOuterTriplet) const { + // detIndex of the layerStart for the Phase1 Pixel Detector: + // [BPX1, BPX2, BPX3, BPX4, FP1, FP2, FP3, FN1, FN2, FN3, LAST_VALID] + // [ 0, 96, 320, 672, 1184, 1296, 1408, 1520, 1632, 1744, 1856] + auto ri = this->inner_r(hh); + auto zi = this->inner_z(hh); + + auto ro = this->outer_r(hh); + auto zo = this->outer_z(hh); + + auto r1 = otherCell.inner_r(hh); + auto z1 = otherCell.inner_z(hh); + auto isBarrel = otherCell.outer_detIndex(hh) < TrackerTraits::last_barrel_detIndex; + // TODO tune CA cuts below (theta and dca) + bool aligned = areAlignedRZ(r1, z1, ri, zi, ro, zo, ptmin, isBarrel ? caThetaCutBarrel : caThetaCutForward); + return (aligned && dcaCut(hh, + otherCell, + otherCell.inner_detIndex(hh) < TrackerTraits::last_bpix1_detIndex ? dcaCutInnerTriplet + : dcaCutOuterTriplet, + hardCurvCut)); } - ALPAKA_FN_ACC ALPAKA_FN_INLINE bool dcaCut(const HitsConstView& hh, - CACell const& otherCell, - const float region_origin_radius_plus_tolerance, - const float maxCurv) const { - auto x1 = otherCell.inner_x(hh); - auto y1 = otherCell.inner_y(hh); - - auto x2 = inner_x(hh); - auto y2 = inner_y(hh); - - auto x3 = outer_x(hh); - auto y3 = outer_y(hh); - + ALPAKA_FN_ACC ALPAKA_FN_INLINE __attribute__((always_inline)) static bool dcaCutH( + float x1, + float y1, + float x2, + float y2, + float x3, + float y3, + const float region_origin_radius_plus_tolerance, + const float maxCurv) { CircleEq eq(x1, y1, x2, y2, x3, y3); if (std::abs(eq.curvature()) > maxCurv) @@ -158,116 +176,121 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { return std::abs(eq.dca0()) < region_origin_radius_plus_tolerance * std::abs(eq.curvature()); } +#ifdef ONLY_TRIPLETS_IN_HOLE + + // These functions have never been used in production + // They need an AverageGeometry to be filled + // Commenting for the moment since they are the only reason we + // fill the AverageGeometry and attach to the hit SoA + + ALPAKA_FN_ACC ALPAKA_FN_INLINE bool hole0(const HitsConstView& hh, + AverageGeometryConstView& ag, + CACellT const& innerCell) const { + using namespace phase1PixelTopology; + + int p = innerCell.inner_iphi(hh); + if (p < 0) + p += std::numeric_limits::max(); + p = (max_ladder_bpx0 * p) / std::numeric_limits::max(); + p %= max_ladder_bpx0; + auto il = first_ladder_bpx0 + p; + auto r0 = ag[il].ladderR(); + auto ri = innerCell.inner_r(hh); + auto zi = innerCell.inner_z(hh); + auto ro = this->outer_r(hh); + auto zo = this->outer_z(hh); + auto z0 = zi + (r0 - ri) * (zo - zi) / (ro - ri); + auto z_in_ladder = std::abs(z0 - ag[il].ladderZ()); + auto z_in_module = z_in_ladder - module_length_bpx0 * int(z_in_ladder / module_length_bpx0); + auto gap = z_in_module < module_tolerance_bpx0 || z_in_module > (module_length_bpx0 - module_tolerance_bpx0); + return gap; + } + + ALPAKA_FN_ACC ALPAKA_FN_INLINE bool hole4(const HitsConstView& hh, CACellT const& innerCell) const { + using namespace phase1PixelTopology; + + int p = this->outer_iphi(hh); + if (p < 0) + p += std::numeric_limits::max(); + p = (max_ladder_bpx4 * p) / std::numeric_limits::max(); + p %= max_ladder_bpx4; + auto il = first_ladder_bpx4 + p; + auto r4 = ag[il].ladderR(); + auto ri = innerCell.inner_r(hh); + auto zi = innerCell.inner_z(hh); + auto ro = this->outer_r(hh); + auto zo = this->outer_z(hh); + auto z4 = zo + (r4 - ro) * (zo - zi) / (ro - ri); + auto z_in_ladder = std::abs(z4 - ag[il].ladderZ()); + auto z_in_module = z_in_ladder - module_length_bpx4 * int(z_in_ladder / module_length_bpx4); + auto gap = z_in_module < module_tolerance_bpx4 || z_in_module > (module_length_bpx4 - module_tolerance_bpx4); + auto holeP = z4 > ag[il].ladderMaxZ() && z4 < ag[0].endCapZ(); + auto holeN = z4 < ag[il].ladderMinZ() && z4 > ag[1].endCapZ(); + return gap || holeP || holeN; + } +#endif + // trying to free the track building process from hardcoded layers, leaving // the visit of the graph based on the neighborhood connections between cells. - - template - ALPAKA_FN_ACC ALPAKA_FN_INLINE void find_ntuplets(Acc1D const& acc, - const ::reco::CAGraphSoAConstView& cc, - CACell* __restrict__ cells, + template + ALPAKA_FN_ACC ALPAKA_FN_INLINE void find_ntuplets(TAcc const& acc, + const HitsConstView& hh, + CACellT* __restrict__ cells, + CellTracksVector& cellTracks, HitContainer& foundNtuplets, - CellToCell const* __restrict__ cellNeighborsHisto, - CellToTracks* cellTracksHisto, - uint32_t* nCellTracks, - CAPairSoAView ct, cms::alpakatools::AtomicPairCounter& apc, Quality* __restrict__ quality, TmpTuple& tmpNtuplet, - const unsigned int minHitsPerNtuplet) const { + const unsigned int minHitsPerNtuplet, + bool startAt0) const { // the building process for a track ends if: // it has no right neighbor // it has no compatible neighbor // the ntuplets is then saved if the number of hits it contains is greater // than a threshold + if constexpr (DEPTH <= 0) { - printf("ERROR: CACell::find_ntuplets reached full depth!\n"); + printf("ERROR: CACellT::find_ntuplets reached full depth!\n"); ALPAKA_ASSERT_ACC(false); } else { auto doubletId = this - cells; - tmpNtuplet.push_back_unsafe(doubletId); // if we move this to be safe we could parallelize further below? + tmpNtuplet.push_back_unsafe(doubletId); ALPAKA_ASSERT_ACC(tmpNtuplet.size() <= int(TrackerTraits::maxHitsOnTrack - 3)); bool last = true; - auto const* __restrict__ bin = cellNeighborsHisto->begin(doubletId); - auto nInBin = cellNeighborsHisto->size(doubletId); - - for (auto idx = 0u; idx < nInBin; idx++) { - // FIXME implement alpaka::ldg and use it here? or is it const* __restrict__ enough? - unsigned int otherCell = bin[idx]; + for (unsigned int otherCell : outerNeighbors()) { if (cells[otherCell].isKilled()) - continue; -#ifdef CA_DEBUG - printf("Doublet no. %d %d doubletId: %ld -> %d (isKilled %d) (%d,%d) -> (%d,%d) %d %d\n", - tmpNtuplet.size(), - idx, - doubletId, - otherCell, - cells[otherCell].isKilled(), - this->inner_hit_id(), - this->outer_hit_id(), - cells[otherCell].inner_hit_id(), - cells[otherCell].outer_hit_id(), - idx, - nInBin); -#endif - + continue; // killed by earlyFishbone last = false; - cells[otherCell].template find_ntuplets(acc, - cc, - cells, - foundNtuplets, - cellNeighborsHisto, - cellTracksHisto, - nCellTracks, - ct, - apc, - quality, - tmpNtuplet, - minHitsPerNtuplet); + cells[otherCell].template find_ntuplets( + acc, hh, cells, cellTracks, foundNtuplets, apc, quality, tmpNtuplet, minHitsPerNtuplet, startAt0); } if (last) { // if long enough save... if ((unsigned int)(tmpNtuplet.size()) >= minHitsPerNtuplet - 1) { +#ifdef ONLY_TRIPLETS_IN_HOLE + // triplets accepted only pointing to the hole + if (tmpNtuplet.size() >= 3 || (startAt0 && hole4(hh, cells[tmpNtuplet[0]])) || + ((!startAt0) && hole0(hh, cells[tmpNtuplet[0]]))) +#endif { hindex_type hits[TrackerTraits::maxDepth + 2]; auto nh = 0U; constexpr int maxFB = 2; // for the time being let's limit this int nfb = 0; for (auto c : tmpNtuplet) { - hits[nh++] = cells[c].theInnerHitId_; + hits[nh++] = cells[c].theInnerHitId; if (nfb < maxFB && cells[c].hasFishbone()) { ++nfb; - hits[nh++] = cells[c].theFishboneId_; // Fishbone hit is always outer than inner hit + hits[nh++] = cells[c].theFishboneId; // Fishbone hit is always outer than inner hit } } ALPAKA_ASSERT_ACC(nh < TrackerTraits::maxHitsOnTrack); - hits[nh] = theOuterHitId_; + hits[nh] = this->theOuterHitId; auto it = foundNtuplets.bulkFill(acc, apc, hits, nh + 1); -#ifdef CA_DEBUG - printf("track n. %d nhits %d with cells: ", it, nh + 1); -#endif if (it >= 0) { // if negative is overflow.... - for (auto c : tmpNtuplet) { -#ifdef CA_DEBUG - printf("%d - ", c); -#endif - auto t_ind = alpaka::atomicAdd(acc, nCellTracks, 1u, alpaka::hierarchy::Blocks{}); - - if (t_ind >= uint32_t(ct.metadata().size())) { -#ifdef CA_WARNINGS - printf("Warning!!!! Too many cell->tracks associations (limit = %d)!\n", ct.metadata().size()); -#endif - alpaka::atomicSub(acc, nCellTracks, 1u, alpaka::hierarchy::Blocks{}); - break; - } - cellTracksHisto->count(acc, c); - - ct[t_ind].inner() = c; //cell - ct[t_ind].outer() = it; //track - } -#ifdef CA_DEBUG - printf("\n"); -#endif - quality[it] = bad; // initialize to bad + for (auto c : tmpNtuplet) + cells[c].addTrack(acc, it, cellTracks); + quality[it] = this->bad; // initialize to bad } } } @@ -278,16 +301,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { } private: - int16_t theLayerPairId_; - uint8_t theInnerLayer_; - uint8_t theOuterLayer_; - uint16_t theStatus_; // tbd - - float theInnerZ_; - float theInnerR_; - hindex_type theInnerHitId_; - hindex_type theOuterHitId_; - hindex_type theFishboneId_; + CellNeighbors* theOuterNeighbors; + CellTracks* theTracks; }; } // namespace ALPAKA_ACCELERATOR_NAMESPACE diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAFishbone.h b/RecoTracker/PixelSeeding/plugins/alpaka/CAFishbone.h index e2fb9608014c9..9f590b1c81cc5 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAFishbone.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAFishbone.h @@ -27,9 +27,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { template class CAFishbone { public: - ALPAKA_FN_ACC void operator()(Acc2D const& acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const& acc, HitsConstView hh, - CACell* cells, + CASimpleCell* cells, uint32_t const* __restrict__ nCells, HitToCell const* __restrict__ outerHitHisto, CellToTracks const* __restrict__ cellTracksHisto, diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc index 265f9ae917cb9..a9763033dfa2f 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc @@ -45,8 +45,8 @@ namespace reco { CAGeometryParams(edm::ParameterSet const& iConfig) : caThetaCuts_(iConfig.getParameter>("caThetaCuts")), caDCACuts_(iConfig.getParameter>("caDCACuts")), - pairGraph_(iConfig.getParameter>("pairGraph")), - startingPairs_(iConfig.getParameter>("startingPairs")), + pairGraph_(iConfig.getParameter>("pairGraph")), + startingPairs_(iConfig.getParameter>("startingPairs")), phiCuts_(iConfig.getParameter>("phiCuts")), minZ_(iConfig.getParameter>("minZ")), maxZ_(iConfig.getParameter>("maxZ")), @@ -57,8 +57,8 @@ namespace reco { const std::vector caDCACuts_; // Cells params - const std::vector pairGraph_; - const std::vector startingPairs_; + const std::vector pairGraph_; + const std::vector startingPairs_; const std::vector phiCuts_; const std::vector minZ_; const std::vector maxZ_; diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGenerator.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGenerator.cc index 302b024c59e94..9d8017c248ba7 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGenerator.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGenerator.cc @@ -251,14 +251,14 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { .add>("caThetaCuts", std::vector(std::begin(thetaCuts), std::begin(thetaCuts) + numberOfLayers)) ->setComment("Cut on origin radius. One per layer, the layer being the innermost one for a triplet."); - geometryParams.add>("startingPairs", {0u, 1u, 2u}) + geometryParams.add>("startingPairs", {0u, 1u, 2u}) ->setComment( "The list of the ids of pairs from which the CA ntuplets building may start."); //TODO could be parsed via an expression // cells params geometryParams - .add>( + .add>( "pairGraph", - std::vector(std::begin(layerPairs), + std::vector(std::begin(layerPairs), std::begin(layerPairs) + (pixelTopology::Phase1::nPairsForQuadruplets * 2))) ->setComment("CA graph"); geometryParams @@ -325,14 +325,14 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { std::vector(std::begin(phase1HIonPixelTopology::thetaCuts), std::begin(phase1HIonPixelTopology::thetaCuts) + numberOfLayers)) ->setComment("Cut on origin radius. One per layer, the layer being the innermost one for a triplet."); - geometryParams.add>("startingPairs", {0u, 1u, 2u}) + geometryParams.add>("startingPairs", {0u, 1u, 2u}) ->setComment( "The list of the ids of pairs from which the CA ntuplets building may start."); //TODO could be parsed via an expression // cells params geometryParams - .add>( + .add>( "pairGraph", - std::vector(std::begin(layerPairs), + std::vector(std::begin(layerPairs), std::begin(layerPairs) + (pixelTopology::Phase1::nPairsForQuadruplets * 2))) ->setComment("CA graph"); geometryParams @@ -389,15 +389,15 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { std::vector(std::begin(thetaCuts), std::begin(thetaCuts) + numberOfLayers)) ->setComment("Cut on origin radius. One per layer, the layer being the innermost one for a triplet."); geometryParams - .add>("startingPairs", + .add>("startingPairs", {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}) ->setComment( "The list of the ids of pairs from which the CA ntuplets building may start."); //TODO could be parsed via an expression // cells params geometryParams - .add>( - "pairGraph", std::vector(std::begin(layerPairs), std::begin(layerPairs) + (nPairs * 2))) + .add>( + "pairGraph", std::vector(std::begin(layerPairs), std::begin(layerPairs) + (nPairs * 2))) ->setComment("CA graph"); geometryParams .add>("phiCuts", std::vector(std::begin(phicuts), std::begin(phicuts) + nPairs)) diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc index 3a65d947f4b43..12e6138486abd 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc @@ -17,9 +17,9 @@ #include "CAHitNtupletGeneratorKernels.h" #include "CAHitNtupletGeneratorKernelsImpl.h" -// #define GPU_DEBUG -// #define NTUPLE_DEBUG -// #define CA_STATS +//#define GPU_DEBUG +//#define NTUPLE_DEBUG +//#define CA_STATS namespace ALPAKA_ACCELERATOR_NAMESPACE { @@ -31,10 +31,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { uint32_t maxTuples, uint16_t nLayers, Queue &queue) - : m_params(params) { - ////////////////////////////////////////////////////////// - // ALLOCATIONS FOR THE INTERMEDIATE RESULTS (STAYS ON WORKER) - ////////////////////////////////////////////////////////// + : m_params(params), + ////////////////////////////////////////////////////////// + // ALLOCATIONS FOR THE INTERMEDIATE RESULTS (STAYS ON WORKER) + ////////////////////////////////////////////////////////// + counters_{cms::alpakatools::make_device_buffer(queue)}, // One to Many Maps // Hits -> Track @@ -48,202 +49,117 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { int(nHits + 1), int(maxTuples * m_params.algoParams_.avgHitsPerTrack_) + 1}, - auto const &algoParams = m_params.algoParams_; - int outerHits = - nHits - offsetBPIX2; // the number of hits that may be used as outer hits for a cell (so not on bpix1) - - // These hold the max number of associations needed - int nHitsToTracks = std::max(int(maxTuples * algoParams.avgHitsPerTrack_), 1); - int nHitsToCells = std::max(int(outerHits * algoParams.avgCellsPerHit_), 1); - int nCellsToCells = std::max(int(maxDoublets * algoParams.avgCellsPerCell_), 1); - int nCellsToTracks = std::max(int(maxDoublets * algoParams.avgTracksPerCell_), 1); - - // Cell -> Neighbor Cells - device_cellToNeighbors_{cms::alpakatools::make_device_buffer(queue)}, - device_cellToNeighborsStorage_{cms::alpakatools::make_device_buffer( + // (Outer) Hits-> Cells + device_hitToCell_{cms::alpakatools::make_device_buffer(queue)}, + device_hitToCellStorage_{cms::alpakatools::make_device_buffer( + queue, int((nHits - offsetBPIX2) * m_params.algoParams_.avgCellsPerHit_) + 1)}, + device_hitToCellOffsets_{ + cms::alpakatools::make_device_buffer(queue, nHits - offsetBPIX2 + 1)}, + device_hitToCellView_{device_hitToCell_.data(), + device_hitToCellOffsets_.data(), + device_hitToCellStorage_.data(), + int(nHits - offsetBPIX2 + 1), + int((nHits - offsetBPIX2) * m_params.algoParams_.avgCellsPerHit_) + 1}, + + // Hits + device_hitPhiHist_{cms::alpakatools::make_device_buffer(queue)}, + device_phiBinnerStorage_{cms::alpakatools::make_device_buffer(queue, nHits)}, + device_hitPhiView_{device_hitPhiHist_.data(), nullptr, device_phiBinnerStorage_.data(), -1, int(nHits)}, + device_layerStarts_{cms::alpakatools::make_device_buffer(queue, nLayers + 1)}, + + // Cell -> Neighbor Cells + device_cellToNeighbors_{cms::alpakatools::make_device_buffer(queue)}, + device_cellToNeighborsStorage_{cms::alpakatools::make_device_buffer( queue, int(maxDoublets * m_params.algoParams_.avgCellsPerCell_) + 1)}, - device_cellToNeighborsOffsets_{ - cms::alpakatools::make_device_buffer(queue, maxDoublets + 1)}, - device_cellToNeighborsView_{device_cellToNeighbors_.data(), - device_cellToNeighborsOffsets_.data(), - device_cellToNeighborsStorage_.data(), - int(maxDoublets + 1), - int(maxDoublets * m_params.algoParams_.avgCellsPerCell_)}, - - // Cell -> Tracks - device_cellToTracks_{cms::alpakatools::make_device_buffer(queue)}, - device_cellToTracksStorage_{cms::alpakatools::make_device_buffer( + device_cellToNeighborsOffsets_{ + cms::alpakatools::make_device_buffer(queue, maxDoublets + 1)}, + device_cellToNeighborsView_{device_cellToNeighbors_.data(), + device_cellToNeighborsOffsets_.data(), + device_cellToNeighborsStorage_.data(), + int(maxDoublets + 1), + int(maxDoublets * m_params.algoParams_.avgCellsPerCell_)}, + + // Cell -> Tracks + device_cellToTracks_{cms::alpakatools::make_device_buffer(queue)}, + device_cellToTracksStorage_{cms::alpakatools::make_device_buffer( queue, int(maxDoublets * m_params.algoParams_.avgTracksPerCell_) + 1)}, - device_cellToTracksOffsets_{ - cms::alpakatools::make_device_buffer(queue, maxDoublets + 1)}, - device_cellToTracksView_{device_cellToTracks_.data(), - device_cellToTracksOffsets_.data(), - device_cellToTracksStorage_.data(), - int(maxDoublets + 1), - int(maxDoublets * m_params.algoParams_.avgTracksPerCell_) + 1}, - - // Tracks -> Hits - device_hitContainer_{cms::alpakatools::make_device_buffer(queue)}, - device_hitContainerStorage_{cms::alpakatools::make_device_buffer( + device_cellToTracksOffsets_{ + cms::alpakatools::make_device_buffer(queue, maxDoublets + 1)}, + device_cellToTracksView_{device_cellToTracks_.data(), + device_cellToTracksOffsets_.data(), + device_cellToTracksStorage_.data(), + int(maxDoublets + 1), + int(maxDoublets * m_params.algoParams_.avgTracksPerCell_) + 1}, + + // Tracks -> Hits + device_hitContainer_{cms::alpakatools::make_device_buffer(queue)}, + device_hitContainerStorage_{cms::alpakatools::make_device_buffer( queue, int(m_params.algoParams_.avgHitsPerTrack_ * maxTuples) + 1)}, - device_hitContainerOffsets_{ - cms::alpakatools::make_device_buffer(queue, maxTuples + 1)}, - device_hitContainerView_{device_hitContainer_.data(), - device_hitContainerOffsets_.data(), - device_hitContainerStorage_.data(), - int(maxTuples + 1), - int(m_params.algoParams_.avgHitsPerTrack_ * maxTuples) + 1}, - - // No.Hits -> Track (Multiplicity) - device_tupleMultiplicity_{cms::alpakatools::make_device_buffer(queue)}, - device_tupleMultiplicityStorage_{ - cms::alpakatools::make_device_buffer(queue, maxTuples)}, - device_tupleMultiplicityOffsets_{ - cms::alpakatools::make_device_buffer(queue, TrackerTraits::maxHitsOnTrack + 1)}, - device_tupleMultiplicityView_{device_tupleMultiplicity_.data(), - device_tupleMultiplicityOffsets_.data(), - device_tupleMultiplicityStorage_.data(), - int(TrackerTraits::maxHitsOnTrack + 1), - int(maxTuples)}, - - // Structures and Counters Storage - device_simpleCells_{cms::alpakatools::make_device_buffer(queue, maxDoublets)}, - device_extraStorage_{ - cms::alpakatools::make_device_buffer(queue, 5u)}, - device_hitTuple_apc_{reinterpret_cast(device_extraStorage_.data())}, - device_nCells_{ - cms::alpakatools::make_device_view(queue, *reinterpret_cast(device_extraStorage_.data() + 2))}, - device_nTriplets_{ - cms::alpakatools::make_device_view(queue, *reinterpret_cast(device_extraStorage_.data() + 3))}, - device_nCellTracks_{ + device_hitContainerOffsets_{ + cms::alpakatools::make_device_buffer(queue, maxTuples + 1)}, + device_hitContainerView_{device_hitContainer_.data(), + device_hitContainerOffsets_.data(), + device_hitContainerStorage_.data(), + int(maxTuples + 1), + int(m_params.algoParams_.avgHitsPerTrack_ * maxTuples) + 1}, + + // No.Hits -> Track (Multiplicity) + device_tupleMultiplicity_{cms::alpakatools::make_device_buffer(queue)}, + device_tupleMultiplicityStorage_{ + cms::alpakatools::make_device_buffer(queue, maxTuples)}, + device_tupleMultiplicityOffsets_{ + cms::alpakatools::make_device_buffer(queue, TrackerTraits::maxHitsOnTrack + 1)}, + device_tupleMultiplicityView_{device_tupleMultiplicity_.data(), + device_tupleMultiplicityOffsets_.data(), + device_tupleMultiplicityStorage_.data(), + int(TrackerTraits::maxHitsOnTrack + 1), + int(maxTuples)}, + + // Structures and Counters Storage + device_simpleCells_{cms::alpakatools::make_device_buffer(queue, maxDoublets)}, + device_extraStorage_{ + cms::alpakatools::make_device_buffer(queue, 5u)}, + device_hitTuple_apc_{reinterpret_cast(device_extraStorage_.data())}, + device_nCells_{ + cms::alpakatools::make_device_view(queue, *reinterpret_cast(device_extraStorage_.data() + 2))}, + device_nTriplets_{ + cms::alpakatools::make_device_view(queue, *reinterpret_cast(device_extraStorage_.data() + 3))}, + device_nCellTracks_{ cms::alpakatools::make_device_view(queue, *reinterpret_cast(device_extraStorage_.data() + 4))}, - deviceTriplets_{CACoupleSoACollection(maxDoublets * m_params.algoParams_.avgCellsPerCell_, queue)}, - deviceTracksCells_{ - CACoupleSoACollection(int(maxDoublets * m_params.algoParams_.avgTracksPerCell_) + 1, queue)} { - + deviceTriplets_{CACoupleSoACollection(maxDoublets * m_params.algoParams_.avgCellsPerCell_, queue)}, + deviceTracksCells_{ + CACoupleSoACollection(int(maxDoublets * m_params.algoParams_.avgTracksPerCell_) + 1, queue)} { #ifdef GPU_DEBUG - std::cout << "Allocation for tuple building with: " << std::endl; - std::cout << "- nHits = " << nHits << std::endl; - std::cout << "- maxDoublets = " << maxTuples << std::endl; - std::cout << "- maxTracks = " << maxDoublets << std::endl; - - std::cout << "- nCellsToCells = " << nCellsToCells << std::endl; - std::cout << "- nHitsToCells = " << nHitsToCells << std::endl; - std::cout << "- nCellsToTracks = " << nCellsToTracks << std::endl; - std::cout << "- nHitsToTracks = " << nHitsToTracks << std::endl; + std::cout << "Allocation for tuple building. N hits " << nHits << std::endl; + std::cout << "maxTrips = " << int(maxDoublets * m_params.algoParams_.avgCellsPerCell_) + 1 << std::endl; + std::cout << "maxDoublets = " << maxDoublets << std::endl; + std::cout << "maxTrackCell = " << int(maxDoublets * m_params.algoParams_.avgTracksPerCell_) + 1 << std::endl; #endif - // Hits -> Track - device_hitToTuple_ = cms::alpakatools::make_device_buffer(queue); - device_hitToTupleStorage_ = cms::alpakatools::make_device_buffer(queue, nHitsToTracks); - device_hitToTupleOffsets_ = cms::alpakatools::make_device_buffer(queue, nHits + 1); - device_hitToTupleView_ = {device_hitToTuple_->data(), - device_hitToTupleOffsets_->data(), - device_hitToTupleStorage_->data(), - int(nHits + 1), - nHitsToTracks}; + //TODO: if doStats? + alpaka::memset(queue, counters_, 0); + + alpaka::memset(queue, device_nCells_, 0); + alpaka::memset(queue, device_nTriplets_, 0); + alpaka::memset(queue, device_nCellTracks_, 0); + // Hits -> Track HitToTuple::template launchZero(device_hitToTupleView_, queue); // (Outer) Hits-> Cells - device_hitToCell_ = cms::alpakatools::make_device_buffer(queue); - device_hitToCellStorage_ = cms::alpakatools::make_device_buffer(queue, nHitsToCells); - device_hitToCellOffsets_ = cms::alpakatools::make_device_buffer(queue, outerHits + 1); - device_hitToCellView_ = {device_hitToCell_->data(), - device_hitToCellOffsets_->data(), - device_hitToCellStorage_->data(), - outerHits + 1, - nHitsToCells}; - HitToCell::template launchZero(device_hitToCellView_, queue); - // Hits Phi Histograms: one histogram per layer - device_hitPhiHist_ = cms::alpakatools::make_device_buffer(queue); - device_phiBinnerStorage_ = cms::alpakatools::make_device_buffer(queue, nHits); - device_hitPhiView_ = {device_hitPhiHist_->data(), nullptr, device_phiBinnerStorage_->data(), -1, int(nHits)}; - // This will hold where each layer starts in the hit soa - device_layerStarts_ = cms::alpakatools::make_device_buffer(queue, nLayers + 1); - - // Cell -> Neighbor Cells - device_cellToNeighbors_ = cms::alpakatools::make_device_buffer(queue); - device_cellToNeighborsStorage_ = - cms::alpakatools::make_device_buffer(queue, nCellsToCells); - device_cellToNeighborsOffsets_ = - cms::alpakatools::make_device_buffer(queue, maxDoublets + 1); - device_cellToNeighborsView_ = {device_cellToNeighbors_->data(), - device_cellToNeighborsOffsets_->data(), - device_cellToNeighborsStorage_->data(), - int(maxDoublets + 1), - nCellsToCells}; - + // Cells-> Neighbor Cells CellToCell::template launchZero(device_cellToNeighborsView_, queue); - // Cell -> Tracks - device_cellToTracks_ = cms::alpakatools::make_device_buffer(queue); - device_cellToTracksStorage_ = - cms::alpakatools::make_device_buffer(queue, nCellsToTracks); - device_cellToTracksOffsets_ = - cms::alpakatools::make_device_buffer(queue, maxDoublets + 1); - device_cellToTracksView_ = {device_cellToTracks_->data(), - device_cellToTracksOffsets_->data(), - device_cellToTracksStorage_->data(), - int(maxDoublets + 1), - nCellsToTracks}; - + // Cells-> Neighbor Cells CellToTrack::template launchZero(device_cellToTracksView_, queue); - // Track -> Hits - // - This is a OneToManyAssocSequential since each bin is filled - // in one go: all the hits forming a track are pushed together. - device_hitContainer_ = cms::alpakatools::make_device_buffer(queue); - device_hitContainerStorage_ = - cms::alpakatools::make_device_buffer(queue, nHitsToTracks); - device_hitContainerOffsets_ = - cms::alpakatools::make_device_buffer(queue, maxTuples + 1); - device_hitContainerView_ = {device_hitContainer_->data(), - device_hitContainerOffsets_->data(), - device_hitContainerStorage_->data(), - int(maxTuples + 1), - nHitsToTracks}; - - HitContainer::template launchZero(device_hitContainerView_, queue); - - // No.Hits -> Track (track multiplicity) - device_tupleMultiplicity_ = cms::alpakatools::make_device_buffer(queue); - device_tupleMultiplicityStorage_ = - cms::alpakatools::make_device_buffer(queue, maxTuples); - device_tupleMultiplicityOffsets_ = - cms::alpakatools::make_device_buffer(queue, TrackerTraits::maxHitsOnTrack + 1); - device_tupleMultiplicityView_ = { - device_tupleMultiplicity_->data(), - device_tupleMultiplicityOffsets_->data(), - device_tupleMultiplicityStorage_->data(), - int(TrackerTraits::maxHitsOnTrack + 1), //TODO: this could become configurable with some work - int(maxTuples)}; + // Tracks -> Hits TupleMultiplicity::template launchZero(device_tupleMultiplicityView_, queue); - // Structures and Counters Storage - device_simpleCells_ = cms::alpakatools::make_device_buffer(queue, maxDoublets); - - device_extraStorage_ = - cms::alpakatools::make_device_buffer(queue, 5u); - device_hitTuple_apc_ = reinterpret_cast(device_extraStorage_->data()); - device_nCells_ = - cms::alpakatools::make_device_view(queue, *reinterpret_cast(device_extraStorage_->data() + 2)); - device_nTriplets_ = - cms::alpakatools::make_device_view(queue, *reinterpret_cast(device_extraStorage_->data() + 3)); - device_nCellTracks_ = - cms::alpakatools::make_device_view(queue, *reinterpret_cast(device_extraStorage_->data() + 4)); - - deviceTriplets_ = CAPairSoACollection(maxDoublets * algoParams.avgCellsPerCell_, queue); - deviceTracksCells_ = CAPairSoACollection(nCellsToTracks, queue); - - //TODO: if doStats? - alpaka::memset(queue, *counters_, 0); - - alpaka::memset(queue, *device_nCells_, 0); - alpaka::memset(queue, *device_nTriplets_, 0); - alpaka::memset(queue, *device_nCellTracks_, 0); + // No.Hits -> Track (Multiplicity) + HitContainer::template launchZero(device_hitContainerView_, queue); maxNumberOfDoublets_ = maxDoublets; @@ -263,11 +179,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { const auto workDiv1D = cms::alpakatools::make_workdiv(1, ll.metadata().size() - 1); alpaka::exec(queue, workDiv1D, SetHitsLayerStart{}, mm, ll, this->device_layerStarts_.data()); - cms::alpakatools::fillManyFromVector(device_hitPhiHist_->data(), + cms::alpakatools::fillManyFromVector(device_hitPhiHist_.data(), device_hitPhiView_, TrackerTraits::numberOfLayers, // could be ll.metadata().size() - 1 hh.iphi(), - this->device_layerStarts_->data(), + this->device_layerStarts_.data(), hh.metadata().size(), (uint32_t)256, queue); @@ -322,12 +238,12 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { this->device_hitTuple_apc_, // needed only to be reset, ready for next kernel hh, ll, - this->deviceTriplets_->view(), - this->device_simpleCells_->data(), - this->device_nCells_->data(), - this->device_nTriplets_->data(), - this->device_hitToCell_->data(), - this->device_cellToNeighbors_->data(), + this->deviceTriplets_.view(), + this->device_simpleCells_.data(), + this->device_nCells_.data(), + this->device_nTriplets_.data(), + this->device_hitToCell_.data(), + this->device_cellToNeighbors_.data(), this->m_params.algoParams_); CellToCell::template launchFinalize(this->device_cellToNeighborsView_, queue); @@ -343,10 +259,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { alpaka::exec(queue, workDiv1D, - Kernel_fillGenericPair{}, - this->deviceTriplets_->view(), - this->device_nTriplets_->data(), - this->device_cellToNeighbors_->data()); + Kernel_fillGenericCouple{}, + this->deviceTriplets_.view(), + this->device_nTriplets_.data(), + this->device_cellToNeighbors_.data()); #ifdef GPU_DEBUG alpaka::wait(queue); @@ -366,10 +282,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { fishboneWorkDiv, CAFishbone{}, hh, - this->device_simpleCells_->data(), - this->device_nCells_->data(), - this->device_hitToCell_->data(), - this->device_cellToTracks_->data(), + this->device_simpleCells_.data(), + this->device_nCells_.data(), + this->device_hitToCell_.data(), + this->device_cellToTracks_.data(), nhits - offsetBPIX2, false); #ifdef GPU_DEBUG @@ -385,14 +301,14 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { Kernel_find_ntuplets{}, cc, tracks_view, - this->device_hitContainer_->data(), - this->device_cellToNeighbors_->data(), - this->device_cellToTracks_->data(), - this->deviceTracksCells_->view(), - this->device_simpleCells_->data(), - this->device_nCellTracks_->data(), - this->device_nTriplets_->data(), - this->device_nCells_->data(), + this->device_hitContainer_.data(), + this->device_cellToNeighbors_.data(), + this->device_cellToTracks_.data(), + this->deviceTracksCells_.view(), + this->device_simpleCells_.data(), + this->device_nCellTracks_.data(), + this->device_nTriplets_.data(), + this->device_nCells_.data(), this->device_hitTuple_apc_, this->m_params.algoParams_); @@ -408,18 +324,18 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { alpaka::exec(queue, workDiv1D, - Kernel_fillGenericPair{}, - this->deviceTracksCells_->view(), - this->device_nCellTracks_->data(), - this->device_cellToTracks_->data()); + Kernel_fillGenericCouple{}, + this->deviceTracksCells_.view(), + this->device_nCellTracks_.data(), + this->device_cellToTracks_.data()); if (this->m_params.algoParams_.doStats_) alpaka::exec(queue, workDiv1D, Kernel_mark_used{}, - this->device_simpleCells_->data(), - this->device_cellToTracks_->data(), - this->device_nCells_->data()); + this->device_simpleCells_.data(), + this->device_cellToTracks_.data(), + this->device_nCells_.data()); #ifdef GPU_DEBUG alpaka::wait(queue); @@ -433,7 +349,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { workDiv1D, typename HitContainer::finalizeBulk{}, this->device_hitTuple_apc_, - this->device_hitContainer_->data()); + this->device_hitContainer_.data()); #ifdef GPU_DEBUG alpaka::wait(queue); @@ -444,7 +360,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { Kernel_fillHitDetIndices{}, tracks_view, tracks_hits_view, - this->device_hitContainer_->data(), + this->device_hitContainer_.data(), hh); #ifdef GPU_DEBUG @@ -456,7 +372,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { Kernel_fillNLayers{}, tracks_view, tracks_hits_view, - this->device_layerStarts_->data(), + this->device_layerStarts_.data(), nLayers, this->device_hitTuple_apc_); @@ -472,9 +388,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { alpaka::exec(queue, workDiv1D, Kernel_earlyDuplicateRemover{}, - this->device_simpleCells_->data(), - this->device_nCells_->data(), - this->device_cellToTracks_->data(), + this->device_simpleCells_.data(), + this->device_nCells_.data(), + this->device_cellToTracks_.data(), tracks_view, this->m_params.algoParams_.dupPassThrough_); #ifdef GPU_DEBUG @@ -490,8 +406,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { workDiv1D, Kernel_countMultiplicity{}, tracks_view, - this->device_hitContainer_->data(), - this->device_tupleMultiplicity_->data()); + this->device_hitContainer_.data(), + this->device_tupleMultiplicity_.data()); GenericContainer::template launchFinalize(this->device_tupleMultiplicityView_, queue); #ifdef GPU_DEBUG @@ -504,8 +420,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { workDiv1D, Kernel_fillMultiplicity{}, tracks_view, - this->device_hitContainer_->data(), - this->device_tupleMultiplicity_->data()); + this->device_hitContainer_.data(), + this->device_tupleMultiplicity_.data()); #ifdef GPU_DEBUG alpaka::wait(queue); std::cout << "Kernel_fillMultiplicity -> done!" << std::endl; @@ -524,10 +440,12 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { workDiv2D, CAFishbone{}, hh, - this->device_simpleCells_->data(), - this->device_nCells_->data(), - this->device_hitToCell_->data(), - this->device_cellToTracks_->data(), + // this->device_theCells_.data(), + this->device_simpleCells_.data(), + this->device_nCells_.data(), + // this->isOuterHitOfCell_.data(), + this->device_hitToCell_.data(), + this->device_cellToTracks_.data(), nhits - offsetBPIX2, true); } @@ -545,7 +463,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { uint32_t offsetBPIX2, Queue &queue) { using namespace caPixelDoublets; - using namespace caHitNtupletGeneratorKernels; auto nhits = hh.metadata().size(); const auto maxDoublets = this->maxNumberOfDoublets_; @@ -575,14 +492,14 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { workDiv2D, GetDoubletsFromHisto{}, maxDoublets, - this->device_simpleCells_->data(), - this->device_nCells_->data(), + this->device_simpleCells_.data(), + this->device_nCells_.data(), hh, cc, ll, - this->device_layerStarts_->data(), - this->device_hitPhiHist_->data(), - this->device_hitToCell_->data(), + this->device_layerStarts_.data(), + this->device_hitPhiHist_.data(), + this->device_hitToCell_.data(), this->m_params.algoParams_); HitToCell::template launchFinalize(this->device_hitToCellView_, queue); @@ -599,10 +516,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { alpaka::exec(queue, workDiv1D, FillDoubletsHisto{}, - this->device_simpleCells_->data(), - this->device_nCells_->data(), + this->device_simpleCells_.data(), + this->device_nCells_.data(), offsetBPIX2, - this->device_hitToCell_->data()); + this->device_hitToCell_.data()); #ifdef GPU_DEBUG alpaka::wait(queue); @@ -633,7 +550,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { workDiv1D, Kernel_classifyTracks{}, tracks_view, - this->device_hitContainer_->data(), + this->device_hitContainer_.data(), this->m_params.qualityCuts_); #ifdef GPU_DEBUG alpaka::wait(queue); @@ -647,9 +564,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { alpaka::exec(queue, workDiv1D, Kernel_fishboneCleaner{}, - this->device_simpleCells_->data(), - this->device_nCells_->data(), - this->device_cellToTracks_->data(), + this->device_simpleCells_.data(), + this->device_nCells_.data(), + this->device_cellToTracks_.data(), tracks_view); } #ifdef GPU_DEBUG @@ -662,9 +579,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { alpaka::exec(queue, workDiv1D, Kernel_fastDuplicateRemover{}, - this->device_simpleCells_->data(), - this->device_nCells_->data(), - this->device_cellToTracks_->data(), + this->device_simpleCells_.data(), + this->device_nCells_.data(), + this->device_cellToTracks_.data(), tracks_view, this->m_params.algoParams_.dupPassThrough_); #ifdef GPU_DEBUG @@ -680,16 +597,16 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { workDiv1D, Kernel_countHitInTracks{}, tracks_view, - this->device_hitContainer_->data(), - this->device_hitToTuple_->data()); + this->device_hitContainer_.data(), + this->device_hitToTuple_.data()); GenericContainer::template launchFinalize(this->device_hitToTupleView_, queue); alpaka::exec(queue, workDiv1D, Kernel_fillHitInTracks{}, tracks_view, - this->device_hitContainer_->data(), - this->device_hitToTuple_->data()); + this->device_hitContainer_.data(), + this->device_hitToTuple_.data()); #ifdef GPU_DEBUG alpaka::wait(queue); std::cout << "Kernel_countHitInTracks -> done!" << std::endl; @@ -705,7 +622,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { Kernel_rejectDuplicate{}, tracks_view, this->m_params.algoParams_.dupPassThrough_, - this->device_hitToTuple_->data()); + this->device_hitToTuple_.data()); #ifdef GPU_DEBUG alpaka::wait(queue); std::cout << "Kernel_rejectDuplicate -> done!" << std::endl; @@ -715,11 +632,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { workDiv1D, Kernel_sharedHitCleaner{}, hh, - this->device_layerStarts_->data(), + this->device_layerStarts_.data(), tracks_view, this->m_params.algoParams_.minHitsForSharingCut_, this->m_params.algoParams_.dupPassThrough_, - this->device_hitToTuple_->data()); + this->device_hitToTuple_.data()); #ifdef GPU_DEBUG alpaka::wait(queue); std::cout << "Kernel_sharedHitCleaner -> done!" << std::endl; @@ -733,7 +650,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { Kernel_simpleTripletCleaner{}, tracks_view, this->m_params.algoParams_.dupPassThrough_, - this->device_hitToTuple_->data()); + this->device_hitToTuple_.data()); #ifdef GPU_DEBUG alpaka::wait(queue); std::cout << "Kernel_simpleTripletCleaner -> done!" << std::endl; @@ -747,7 +664,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { Kernel_tripletCleaner{}, tracks_view, this->m_params.algoParams_.dupPassThrough_, - this->device_hitToTuple_->data()); + this->device_hitToTuple_.data()); #ifdef GPU_DEBUG alpaka::wait(queue); std::cout << "Kernel_tripletCleaner -> done!" << std::endl; @@ -763,20 +680,20 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { workDiv1D, Kernel_checkOverflows{}, tracks_view, - this->device_hitContainer_->data(), - this->device_tupleMultiplicity_->data(), - this->device_hitToTuple_->data(), + this->device_hitContainer_.data(), + this->device_tupleMultiplicity_.data(), + this->device_hitToTuple_.data(), this->device_hitTuple_apc_, - this->device_simpleCells_->data(), - this->device_nCells_->data(), - this->device_nTriplets_->data(), - this->device_nCellTracks_->data(), - this->deviceTriplets_->view(), - this->deviceTracksCells_->view(), + this->device_simpleCells_.data(), + this->device_nCells_.data(), + this->device_nTriplets_.data(), + this->device_nCellTracks_.data(), + this->deviceTriplets_.view(), + this->deviceTracksCells_.view(), nhits, this->maxNumberOfDoublets_, this->m_params.algoParams_, - this->counters_->data()); + this->counters_.data()); } #ifdef CA_STATS @@ -787,9 +704,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { Kernel_printSizes{}, hh, tracks_view, - this->device_nCells_->data(), - this->device_nTriplets_->data(), - this->device_nCellTracks_->data()); + this->device_nCells_.data(), + this->device_nTriplets_.data(), + this->device_nCellTracks_.data()); alpaka::wait(queue); #endif @@ -802,8 +719,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { alpaka::exec(queue, workDiv1D, Kernel_doStatsForHitInTracks{}, - this->device_hitToTuple_->data(), - this->counters_->data()); + this->device_hitToTuple_.data(), + this->counters_.data()); numberOfBlocks = cms::alpakatools::divide_up_by(3 * maxTuples / 4, blockSize); workDiv1D = cms::alpakatools::make_workdiv(numberOfBlocks, blockSize); @@ -849,8 +766,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { Kernel_print_found_ntuplets{}, hh, tracks_view, - this->device_hitContainer_->data(), - this->device_hitToTuple_->data(), + this->device_hitContainer_.data(), + this->device_hitToTuple_.data(), k, k + 500, iev); @@ -861,7 +778,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { Kernel_print_found_ntuplets{}, hh, tracks_view, - this->device_hitToTuple_->data(), + this->device_hitToTuple_.data(), 20000, 1000000, iev); @@ -876,7 +793,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { template void CAHitNtupletGeneratorKernels::printCounters() { auto workDiv1D = cms::alpakatools::make_workdiv(1,1); - alpaka::exec(queue_, workDiv1D, Kernel_printCounters{}, this->counters_->data()); + alpaka::exec(queue_, workDiv1D, Kernel_printCounters{}, this->counters_.data()); } */ diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.h b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.h index 2634c1479b3f1..0c852c5f75ddc 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.h @@ -17,9 +17,9 @@ #include "HeterogeneousCore/AlpakaInterface/interface/config.h" #include "HeterogeneousCore/AlpakaInterface/interface/memory.h" #include "RecoTracker/PixelSeeding/interface/CAGeometrySoA.h" -#include "RecoTracker/PixelSeeding/interface/alpaka/CAPairSoACollection.h" +#include "RecoTracker/PixelSeeding/interface/alpaka/CACoupleSoACollection.h" -#include "CACell.h" +#include "CASimpleCell.h" #include "CAPixelDoublets.h" #include "CAStructures.h" @@ -101,7 +101,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { public: using TrackerTraits = TTTraits; - using SimpleCell = CACell; + using SimpleCell = CASimpleCell; using Params = caHitNtupletGenerator::ParamsT; using Counters = caHitNtupletGenerator::Counters; // Track qualities @@ -124,20 +124,16 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { using GenericContainer = caStructures::GenericContainer; using GenericContainerStorage = typename GenericContainer::index_type; using GenericContainerView = typename GenericContainer::View; - using DeviceGenericContainerBuffer = std::optional>; - using DeviceGenericStorageBuffer = - std::optional>; - using DeviceGenericOffsetsBuffer = - std::optional>; + using DeviceGenericContainerBuffer = cms::alpakatools::device_buffer; + using DeviceGenericStorageBuffer = cms::alpakatools::device_buffer; + using DeviceGenericOffsetsBuffer = cms::alpakatools::device_buffer; using SequentialContainer = caStructures::SequentialContainer; using SequentialContainerStorage = typename SequentialContainer::index_type; using SequentialContainerView = typename SequentialContainer::View; - using DeviceSequentialContainerBuffer = std::optional>; - using DeviceSequentialStorageBuffer = - std::optional>; - using DeviceSequentialOffsetsBuffer = - std::optional>; + using DeviceSequentialContainerBuffer = cms::alpakatools::device_buffer; + using DeviceSequentialStorageBuffer = cms::alpakatools::device_buffer; + using DeviceSequentialOffsetsBuffer = cms::alpakatools::device_buffer; CAHitNtupletGeneratorKernels(Params const& params, uint32_t nHits, @@ -148,12 +144,12 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { Queue& queue); ~CAHitNtupletGeneratorKernels() = default; - TupleMultiplicity const* tupleMultiplicity() const { return device_tupleMultiplicity_->data(); } - HitContainer const* hitContainer() const { return device_hitContainer_->data(); } - HitToCell const* hitToCell() const { return device_hitToCell_->data(); } - HitToTuple const* hitToTuple() const { return device_hitToTuple_->data(); } - CellToCell const* cellToCell() const { return device_cellToNeighbors_->data(); } - CellToTrack const* cellToTrack() const { return device_cellToTracks_->data(); } + TupleMultiplicity const* tupleMultiplicity() const { return device_tupleMultiplicity_.data(); } + HitContainer const* hitContainer() const { return device_hitContainer_.data(); } + HitToCell const* hitToCell() const { return device_hitToCell_.data(); } + HitToTuple const* hitToTuple() const { return device_hitToTuple_.data(); } + CellToCell const* cellToCell() const { return device_cellToNeighbors_.data(); } + CellToTrack const* cellToTrack() const { return device_cellToTracks_.data(); } void prepareHits(const HitsConstView& hh, const HitModulesConstView& mm, @@ -182,7 +178,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { private: // params Params const& m_params; - std::optional> counters_; + cms::alpakatools::device_buffer counters_; // Hits->Track DeviceGenericContainerBuffer device_hitToTuple_; @@ -197,10 +193,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { GenericContainerView device_hitToCellView_; // Hits Phi Binner - std::optional> device_hitPhiHist_; - std::optional> device_phiBinnerStorage_; + cms::alpakatools::device_buffer device_hitPhiHist_; + cms::alpakatools::device_buffer device_phiBinnerStorage_; PhiBinnerView device_hitPhiView_; - std::optional> device_layerStarts_; + cms::alpakatools::device_buffer device_layerStarts_; // Cells-> Neighbor Cells DeviceGenericContainerBuffer device_cellToNeighbors_; @@ -226,17 +222,23 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { DeviceGenericOffsetsBuffer device_tupleMultiplicityOffsets_; GenericContainerView device_tupleMultiplicityView_; - std::optional> device_simpleCells_; - - std::optional> - device_extraStorage_; + // cms::alpakatools::device_buffer device_theCells_; + cms::alpakatools::device_buffer device_simpleCells_; + // cms::alpakatools::device_buffer device_isOuterHitOfCell_; + // cms::alpakatools::device_buffer isOuterHitOfCell_; + // cms::alpakatools::device_buffer device_theCellNeighbors_; + // cms::alpakatools::device_buffer device_theCellTracks_; + // cms::alpakatools::device_buffer cellStorage_; + // CellNeighbors* device_theCellNeighborsContainer_; + // CellTracks* device_theCellTracksContainer_; + cms::alpakatools::device_buffer device_extraStorage_; cms::alpakatools::AtomicPairCounter* device_hitTuple_apc_; - std::optional> device_nCells_; - std::optional> device_nTriplets_; - std::optional> device_nCellTracks_; + cms::alpakatools::device_view device_nCells_; + cms::alpakatools::device_view device_nTriplets_; + cms::alpakatools::device_view device_nCellTracks_; - std::optional deviceTriplets_; - std::optional deviceTracksCells_; + CACoupleSoACollection deviceTriplets_; + CACoupleSoACollection deviceTracksCells_; // this could be inferred from the above buffers // but seems cleaner to have a dedicate variable diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h index eb5c4c3594997..faf785aa680d8 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h @@ -1,11 +1,10 @@ #ifndef RecoTracker_PixelSeeding_plugins_alpaka_CAHitNtupletGeneratorKernelsImpl_h #define RecoTracker_PixelSeeding_plugins_alpaka_CAHitNtupletGeneratorKernelsImpl_h -#define GPU_DEBUG -// #define NTUPLE_DEBUG -// #define CA_DEBUG -// #define CA_WARNINGS - +// MRMR #define GPU_DEBUG // MRMR +// MRMR #define NTUPLE_DEBUG // MRMR +// MRMR #define CA_DEBUG // MRMR +#define CA_WARNINGS // MRMR // C++ includes #include #include @@ -24,10 +23,10 @@ #include "HeterogeneousCore/AlpakaInterface/interface/config.h" #include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h" #include "FWCore/Utilities/interface/isFinite.h" -#include "RecoTracker/PixelSeeding/interface/CAPairSoA.h" +#include "RecoTracker/PixelSeeding/interface/CACoupleSoA.h" // local includes -#include "CACell.h" +#include "CASimpleCell.h" #include "CAHitNtupletGeneratorKernels.h" #include "CAStructures.h" @@ -60,7 +59,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { class SetHitsLayerStart { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, const reco::HitModuleSoAConstView &mm, const reco::CALayersSoAConstView &ll, uint32_t *__restrict__ hitsLayerStart) const { @@ -83,7 +83,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { class Kernel_printSizes { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, HitsConstView hh, TkSoAView tt, uint32_t const *__restrict__ nCells, @@ -104,18 +105,19 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_checkOverflows { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, TkSoAView tracks_view, HitContainer const *__restrict__ foundNtuplets, TupleMultiplicity const *tupleMultiplicity, HitToTuple const *hitToTuple, cms::alpakatools::AtomicPairCounter *apc, - CACell const *__restrict__ cells, + CASimpleCell const *__restrict__ cells, uint32_t const *__restrict__ nCells, uint32_t const *__restrict__ nTrips, uint32_t const *__restrict__ nCellTracks, - caStructures::CAPairSoAConstView cellCell, - caStructures::CAPairSoAConstView cellTrack, + caStructures::CACoupleSoAConstView cellCell, + caStructures::CACoupleSoAConstView cellTrack, int32_t nHits, uint32_t maxNumberOfDoublets, AlgoParams const ¶ms, @@ -184,8 +186,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_fishboneCleaner { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, - CACell const *cells, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, + CASimpleCell const *cells, uint32_t const *__restrict__ nCells, CellToTrack const *__restrict__ cellTracksHisto, TkSoAView tracks_view) const { @@ -208,8 +211,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_earlyDuplicateRemover { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, - CACell const *cells, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, + CASimpleCell const *cells, uint32_t const *__restrict__ nCells, CellToTrack const *__restrict__ cellTracksHisto, TkSoAView tracks_view, @@ -255,8 +259,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_fastDuplicateRemover { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, - CACell const *__restrict__ cells, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, + CASimpleCell const *__restrict__ cells, uint32_t const *__restrict__ nCells, CellToTrack const *__restrict__ cellTracksHisto, TkSoAView tracks_view, @@ -347,18 +352,19 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_connect { public: - ALPAKA_FN_ACC void operator()(Acc2D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, cms::alpakatools::AtomicPairCounter *apc, // just to zero them HitsConstView hh, reco::CALayersSoAConstView ll, - caStructures::CAPairSoAView cn, - CACell *cells, + caStructures::CACoupleSoAView cn, + CASimpleCell *cells, uint32_t const *nCells, uint32_t *nTrips, HitToCell const *__restrict__ outerHitHisto, CellToCell *cellNeighborsHisto, AlgoParams const ¶ms) const { - using Cell = CACell; + using Cell = CASimpleCell; uint32_t maxTriplets = cn.metadata().size(); if (cms::alpakatools::once_per_grid(acc)) { @@ -399,7 +405,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { auto dcaCut = ll[oc.innerLayer()].caDCACut(); bool aligned = Cell::areAlignedRZ(r1, z1, ri, zi, ro, zo, params.ptmin_, thetaCut); if (aligned && thisCell.dcaCut(hh, oc, dcaCut, params.hardCurvCut_)) { - auto t_ind = alpaka::atomicAdd(acc, nTrips, 1u, alpaka::hierarchy::Blocks{}); + auto t_ind = alpaka::atomicAdd(acc, nTrips, (uint32_t)1, alpaka::hierarchy::Blocks{}); #ifdef CA_DEBUG if (cms::alpakatools::once_per_grid(acc)) printf("%-10s %-7s %-7s %-3s %-3s %-3s %-3s %-4s %-4s %-4s %-4s\n", "Triplet#", "Theta", "DCA", "LI", "LO", "OC", "CI", "i1", "o1", "i2", "o2"); @@ -426,7 +432,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { printf("Warning!!!! Too many cell->cell (triplets) associations (limit = %d)!\n", cn.metadata().size()); assert(0); #endif - alpaka::atomicSub(acc, nTrips, 1u, alpaka::hierarchy::Blocks{}); + alpaka::atomicSub(acc, nTrips, (uint32_t)1, alpaka::hierarchy::Blocks{}); break; } @@ -444,26 +450,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { }; template - class FillDoubletsHisto { - public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, - CACell const *__restrict__ cells, - uint32_t *nCells, - uint32_t offsetBPIX2, - HitToCell *outerHitHisto) const { - for (auto cellIndex : cms::alpakatools::uniform_elements(acc, *nCells)) { -#ifdef DOUBLETS_DEBUG - printf("outerHitHisto;%d;%d\n", cellIndex, cells[cellIndex].outer_hit_id()); -#endif - outerHitHisto->fill(acc, cells[cellIndex].outer_hit_id() - offsetBPIX2, cellIndex); - } - } - }; - - class Kernel_fillGenericPair { + class Kernel_fillGenericCouple { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, - caStructures::CAPairSoAConstView cn, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, + caStructures::CACoupleSoAConstView cn, uint32_t const *nElements, GenericContainer *genericHisto) const { for (uint32_t index : cms::alpakatools::uniform_elements(acc, *nElements)) { @@ -475,20 +466,21 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_find_ntuplets { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, const ::reco::CAGraphSoAConstView &cc, TkSoAView tracks_view, HitContainer *foundNtuplets, CellToCell const *__restrict__ cellNeighborsHisto, CellToTrack *cellTracksHisto, - caStructures::CAPairSoAView ct, - CACell *__restrict__ cells, + caStructures::CACoupleSoAView ct, + CASimpleCell *__restrict__ cells, uint32_t *nCellTracks, uint32_t const *nTriplets, uint32_t const *nCells, cms::alpakatools::AtomicPairCounter *apc, AlgoParams const ¶ms) const { - using Cell = CACell; + using Cell = CASimpleCell; #ifdef GPU_DEBUG if (cms::alpakatools::once_per_grid(acc)) @@ -522,18 +514,18 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { typename Cell::TmpTuple stack; stack.reset(); - thisCell.template find_ntuplets(acc, - cc, - cells, - *foundNtuplets, - cellNeighborsHisto, - cellTracksHisto, - nCellTracks, - ct, - *apc, - tracks_view.quality(), - stack, - params.minHitsPerNtuplet_); + thisCell.template find_ntuplets(acc, + cc, + cells, + *foundNtuplets, + cellNeighborsHisto, + cellTracksHisto, + nCellTracks, + ct, + *apc, + tracks_view.quality(), + stack, + params.minHitsPerNtuplet_); ALPAKA_ASSERT_ACC(stack.empty()); } } @@ -543,11 +535,12 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_mark_used { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, - CACell *__restrict__ cells, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, + CASimpleCell *__restrict__ cells, CellToTrack const *__restrict__ cellTracksHisto, uint32_t const *nCells) const { - using Cell = CACell; + using Cell = CASimpleCell; for (auto idx : cms::alpakatools::uniform_elements(acc, (*nCells))) { auto &thisCell = cells[idx]; if (cellTracksHisto->size(idx) > 0) @@ -559,7 +552,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_countMultiplicity { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, TkSoAView tracks_view, HitContainer const *__restrict__ foundNtuplets, TupleMultiplicity *tupleMultiplicity) const { @@ -582,7 +576,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_fillMultiplicity { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, TkSoAView tracks_view, HitContainer const *__restrict__ foundNtuplets, TupleMultiplicity *tupleMultiplicity) const { @@ -605,7 +600,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_classifyTracks { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, TkSoAView tracks_view, HitContainer const *__restrict__ foundNtuplets, QualityCuts cuts) const { @@ -652,7 +648,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_doStatsForTracks { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, TkSoAView tracks_view, HitContainer const *__restrict__ foundNtuplets, Counters *counters) const { @@ -672,7 +669,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_countHitInTracks { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, TkSoAView tracks_view, HitContainer const *__restrict__ foundNtuplets, HitToTuple *hitToTuple) const { @@ -688,7 +686,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_fillHitInTracks { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, TkSoAView tracks_view, HitContainer const *__restrict__ foundNtuplets, HitToTuple *hitToTuple) const { @@ -704,7 +703,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_fillHitDetIndices { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, TkSoAView tracks_view, TkHitSoAView track_hits_view, HitContainer const *__restrict__ foundNtuplets, @@ -731,7 +731,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_fillNLayers { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, TkSoAView tracks_view, TkHitSoAView track_hits_view, uint32_t const *__restrict__ layerStarts, @@ -760,7 +761,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_doStatsForHitInTracks { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, HitToTuple const *__restrict__ hitToTuple, Counters *counters) const { auto &c = *counters; @@ -777,7 +779,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_countSharedHit { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, int *__restrict__ nshared, HitContainer const *__restrict__ ptuples, Quality const *__restrict__ quality, @@ -806,7 +809,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { for (auto it = hitToTuple.begin(idx); it != hitToTuple.end(idx); ++it) { if (foundNtuplets.size(*it) > 3) continue; - alpaka::atomicAdd(acc, &nshared[*it], 1, alpaka::hierarchy::Blocks{}); + alpaka::atomicAdd(acc, &nshared[*it], 1ull, alpaka::hierarchy::Blocks{}); } } // hit loop @@ -815,7 +818,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_markSharedHit { - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, int const *__restrict__ nshared, HitContainer const *__restrict__ tuples, Quality *__restrict__ quality, @@ -842,7 +846,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_rejectDuplicate { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, TkSoAView tracks_view, bool dupPassThrough, HitToTuple const *__restrict__ phitToTuple) const { @@ -897,7 +902,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_sharedHitCleaner { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, HitsConstView hh, uint32_t const *__restrict__ layerStarts, TkSoAView tracks_view, @@ -951,7 +957,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_tripletCleaner { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, TkSoAView tracks_view, bool dupPassThrough, HitToTuple const *__restrict__ phitToTuple) const { @@ -1009,7 +1016,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_simpleTripletCleaner { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, TkSoAView tracks_view, bool dupPassThrough, HitToTuple const *__restrict__ phitToTuple) const { @@ -1053,7 +1061,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { template class Kernel_print_found_ntuplets { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, HitsConstView hh, TkSoAView tracks_view, HitContainer const *__restrict__ foundNtuplets, @@ -1106,7 +1115,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caHitNtupletGeneratorKernels { class Kernel_printCounters { public: - ALPAKA_FN_ACC void operator()(Acc1D const &acc, Counters const *counters) const { + template >> + ALPAKA_FN_ACC void operator()(TAcc const &acc, Counters const *counters) const { auto const &c = *counters; printf("||%-15s|%10s|%10s|%10s|%10s|%14s|%16s|%14s|%11s|%10s|%13s|%15s|%12s|%17s||\n", "Counters", diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoublets.h b/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoublets.h index 46997a61b064b..0234a8366bb0a 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoublets.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoublets.h @@ -10,30 +10,55 @@ #include "CAPixelDoubletsAlgos.h" -namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { - - template - class GetDoubletsFromHisto { - public: - // #ifdef __CUDACC__ - // __launch_bounds__(getDoubletsFromHistoMaxBlockSize, getDoubletsFromHistoMinBlocksPerMP) // TODO: Alapakafy - // #endif - ALPAKA_FN_ACC void operator()(Acc2D const& acc, - uint32_t maxNumOfDoublets, - CACell* cells, - uint32_t* nCells, - HitsConstView hh, - ::reco::CAGraphSoAConstView cc, - ::reco::CALayersSoAConstView ll, - uint32_t const* __restrict__ offsets, - PhiBinner const* phiBinner, - HitToCell* outerHitHisto, - AlgoParams const& params) const { - doubletsFromHisto( - acc, maxNumOfDoublets, cells, nCells, hh, cc, ll, offsets, phiBinner, outerHitHisto, params); - } - }; - -} // namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets +namespace ALPAKA_ACCELERATOR_NAMESPACE { + using namespace alpaka; + using namespace cms::alpakatools; + + namespace caPixelDoublets { + + template + class GetDoubletsFromHisto { + public: + template >> + // #ifdef __CUDACC__ + // __launch_bounds__(getDoubletsFromHistoMaxBlockSize, getDoubletsFromHistoMinBlocksPerMP) // TODO: Alapakafy + // #endif + ALPAKA_FN_ACC void operator()(TAcc const& acc, + uint32_t maxNumOfDoublets, + CASimpleCell* cells, + uint32_t* nCells, + HitsConstView hh, + ::reco::CAGraphSoAConstView cc, + ::reco::CALayersSoAConstView ll, + uint32_t const* __restrict__ offsets, + PhiBinner const* phiBinner, + HitToCell* outerHitHisto, + AlgoParams const& params) const { + doubletsFromHisto( + acc, maxNumOfDoublets, cells, nCells, hh, cc, ll, offsets, phiBinner, outerHitHisto, params); + } + }; + + template + class FillDoubletsHisto { + public: + template >> + ALPAKA_FN_ACC void operator()(TAcc const& acc, + CASimpleCell const* __restrict__ cells, + uint32_t* nCells, + uint32_t offsetBPIX2, + HitToCell* outerHitHisto) const { + for (auto cellIndex : cms::alpakatools::uniform_elements(acc, *nCells)) { +#ifdef DOUBLETS_DEBUG + printf("outerHitHisto;%d;%d\n", cellIndex, cells[cellIndex].outer_hit_id()); +#endif + outerHitHisto->fill(acc, cells[cellIndex].outer_hit_id() - offsetBPIX2, cellIndex); + } + } + }; + + } // namespace caPixelDoublets + +} // namespace ALPAKA_ACCELERATOR_NAMESPACE #endif // RecoTracker_PixelSeeding_plugins_alpaka_CAPixelDoublets_h diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoubletsAlgos.h b/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoubletsAlgos.h index e41385e477695..4313dc702d32d 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoubletsAlgos.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoubletsAlgos.h @@ -18,7 +18,7 @@ #include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h" #include "RecoTracker/PixelSeeding/interface/CAGeometrySoA.h" -#include "CACell.h" +#include "CASimpleCell.h" #include "CAStructures.h" #include "CAHitNtupletGeneratorKernels.h" diff --git a/RecoTracker/PixelSeeding/test/alpaka/CAsizes_t.cpp b/RecoTracker/PixelSeeding/test/alpaka/CAsizes_t.cpp index 7b570f3e29ca0..9e164d1eb09e1 100644 --- a/RecoTracker/PixelSeeding/test/alpaka/CAsizes_t.cpp +++ b/RecoTracker/PixelSeeding/test/alpaka/CAsizes_t.cpp @@ -17,7 +17,7 @@ int main() { using namespace caStructures; //for Phase-I - print>(); + print>(); print>(); print>(); print>(); @@ -27,7 +27,7 @@ int main() { print>(); //for Phase-II - print>(); + print>(); print>(); print>(); print>();