Skip to content

Commit 66176a1

Browse files
AdrianoDeeborzarinothingface0
authored andcommitted
Port the pixel gpu-vs-cpu validation to Alpaka
Rename "gpu" to "device" and "cpu" to "host". Co-authored-by: Breno Orzari <[email protected]> Co-authored-by: Dimitris Papagiannis <[email protected]>
1 parent 3f668a2 commit 66176a1

File tree

7 files changed

+1268
-1
lines changed

7 files changed

+1268
-1
lines changed

DQM/SiPixelHeterogeneous/plugins/BuildFile.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
<use name="DataFormats/Common"/>
66
<use name="Geometry/Records"/>
77
<use name="Geometry/TrackerGeometryBuilder"/>
8+
<use name="DataFormats/TrackingRecHitSoA"/>
9+
<use name="DataFormats/TrackSoA"/>
10+
<use name="DataFormats/VertexSoA"/>
11+
<use name="DataFormats/BeamSpot"/>
812
<use name="CUDADataFormats/TrackingRecHit"/>
913
<use name="CUDADataFormats/Track"/>
1014
<use name="CUDADataFormats/Vertex"/>
11-
<use name="DataFormats/BeamSpot"/>
1215
<flags EDM_PLUGIN="1"/>
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
#include "DQMServices/Core/interface/MonitorElement.h"
2+
#include "DQMServices/Core/interface/DQMEDAnalyzer.h"
3+
#include "DQMServices/Core/interface/DQMStore.h"
4+
#include "DataFormats/Math/interface/approx_atan2.h"
5+
#include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
6+
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
7+
#include "DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsHost.h"
8+
#include "DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsSoA.h"
9+
#include "FWCore/Framework/interface/Event.h"
10+
#include "FWCore/Framework/interface/Frameworkfwd.h"
11+
#include "FWCore/MessageLogger/interface/MessageLogger.h"
12+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
13+
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
14+
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
15+
#include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
16+
#include "Geometry/CommonTopologies/interface/PixelTopology.h"
17+
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
18+
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
19+
20+
template <typename T>
21+
class SiPixelCompareRecHitsSoAAlpaka : public DQMEDAnalyzer {
22+
public:
23+
using HitsOnHost = TrackingRecHitHost<T>;
24+
25+
explicit SiPixelCompareRecHitsSoAAlpaka(const edm::ParameterSet&);
26+
~SiPixelCompareRecHitsSoAAlpaka() override = default;
27+
void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
28+
void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
29+
void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
30+
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
31+
32+
private:
33+
const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
34+
const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
35+
const edm::EDGetTokenT<HitsOnHost> tokenSoAHitsHost_; //these two are both on Host but originally they have been
36+
const edm::EDGetTokenT<HitsOnHost> tokenSoAHitsDevice_; //produced on Host or on Device
37+
const std::string topFolderName_;
38+
const float mind2cut_;
39+
static constexpr uint32_t invalidHit_ = std::numeric_limits<uint32_t>::max();
40+
static constexpr float micron_ = 10000.;
41+
const TrackerGeometry* tkGeom_ = nullptr;
42+
const TrackerTopology* tTopo_ = nullptr;
43+
MonitorElement* hnHits_;
44+
MonitorElement* hBchargeL_[4]; // max 4 barrel hits
45+
MonitorElement* hBsizexL_[4];
46+
MonitorElement* hBsizeyL_[4];
47+
MonitorElement* hBposxL_[4];
48+
MonitorElement* hBposyL_[4];
49+
MonitorElement* hFchargeD_[2][12]; // max 12 endcap disks
50+
MonitorElement* hFsizexD_[2][12];
51+
MonitorElement* hFsizeyD_[2][12];
52+
MonitorElement* hFposxD_[2][12];
53+
MonitorElement* hFposyD_[2][12];
54+
//differences
55+
MonitorElement* hBchargeDiff_;
56+
MonitorElement* hFchargeDiff_;
57+
MonitorElement* hBsizeXDiff_;
58+
MonitorElement* hFsizeXDiff_;
59+
MonitorElement* hBsizeYDiff_;
60+
MonitorElement* hFsizeYDiff_;
61+
MonitorElement* hBposXDiff_;
62+
MonitorElement* hFposXDiff_;
63+
MonitorElement* hBposYDiff_;
64+
MonitorElement* hFposYDiff_;
65+
};
66+
67+
//
68+
// constructors
69+
//
70+
template <typename T>
71+
SiPixelCompareRecHitsSoAAlpaka<T>::SiPixelCompareRecHitsSoAAlpaka(const edm::ParameterSet& iConfig)
72+
: geomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>()),
73+
topoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()),
74+
tokenSoAHitsHost_(consumes(iConfig.getParameter<edm::InputTag>("pixelHitsSrcHost"))),
75+
tokenSoAHitsDevice_(consumes(iConfig.getParameter<edm::InputTag>("pixelHitsSrcDevice"))),
76+
topFolderName_(iConfig.getParameter<std::string>("topFolderName")),
77+
mind2cut_(iConfig.getParameter<double>("minD2cut")) {}
78+
79+
//
80+
// Begin Run
81+
//
82+
template <typename T>
83+
void SiPixelCompareRecHitsSoAAlpaka<T>::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
84+
tkGeom_ = &iSetup.getData(geomToken_);
85+
tTopo_ = &iSetup.getData(topoToken_);
86+
}
87+
88+
//
89+
// -- Analyze
90+
//
91+
template <typename T>
92+
void SiPixelCompareRecHitsSoAAlpaka<T>::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
93+
const auto& rhsoaHandleHost = iEvent.getHandle(tokenSoAHitsHost_);
94+
const auto& rhsoaHandleDevice = iEvent.getHandle(tokenSoAHitsDevice_);
95+
if (not rhsoaHandleHost or not rhsoaHandleDevice) {
96+
edm::LogWarning out("SiPixelCompareRecHitsSoAAlpaka");
97+
if (not rhsoaHandleHost) {
98+
out << "reference (Host) rechits not found; ";
99+
}
100+
if (not rhsoaHandleDevice) {
101+
out << "target (Device) rechits not found; ";
102+
}
103+
out << "the comparison will not run.";
104+
return;
105+
}
106+
107+
auto const& rhsoaHost = *rhsoaHandleHost;
108+
auto const& rhsoaDevice = *rhsoaHandleDevice;
109+
110+
auto const& soa2dHost = rhsoaHost.const_view();
111+
auto const& soa2dDevice = rhsoaDevice.const_view();
112+
113+
uint32_t nHitsHost = soa2dHost.metadata().size();
114+
uint32_t nHitsDevice = soa2dDevice.metadata().size();
115+
116+
hnHits_->Fill(nHitsHost, nHitsDevice);
117+
auto detIds = tkGeom_->detUnitIds();
118+
for (uint32_t i = 0; i < nHitsHost; i++) {
119+
float minD = mind2cut_;
120+
uint32_t matchedHit = invalidHit_;
121+
uint16_t indHost = soa2dHost[i].detectorIndex();
122+
float xLocalHost = soa2dHost[i].xLocal();
123+
float yLocalHost = soa2dHost[i].yLocal();
124+
for (uint32_t j = 0; j < nHitsDevice; j++) {
125+
if (soa2dDevice.detectorIndex(j) == indHost) {
126+
float dx = xLocalHost - soa2dDevice[j].xLocal();
127+
float dy = yLocalHost - soa2dDevice[j].yLocal();
128+
float distance = dx * dx + dy * dy;
129+
if (distance < minD) {
130+
minD = distance;
131+
matchedHit = j;
132+
}
133+
}
134+
}
135+
DetId id = detIds[indHost];
136+
uint32_t chargeHost = soa2dHost[i].chargeAndStatus().charge;
137+
int16_t sizeXHost = std::ceil(float(std::abs(soa2dHost[i].clusterSizeX()) / 8.));
138+
int16_t sizeYHost = std::ceil(float(std::abs(soa2dHost[i].clusterSizeY()) / 8.));
139+
uint32_t chargeDevice = 0;
140+
int16_t sizeXDevice = -99;
141+
int16_t sizeYDevice = -99;
142+
float xLocalDevice = -999.;
143+
float yLocalDevice = -999.;
144+
if (matchedHit != invalidHit_) {
145+
chargeDevice = soa2dDevice[matchedHit].chargeAndStatus().charge;
146+
sizeXDevice = std::ceil(float(std::abs(soa2dDevice[matchedHit].clusterSizeX()) / 8.));
147+
sizeYDevice = std::ceil(float(std::abs(soa2dDevice[matchedHit].clusterSizeY()) / 8.));
148+
xLocalDevice = soa2dDevice[matchedHit].xLocal();
149+
yLocalDevice = soa2dDevice[matchedHit].yLocal();
150+
}
151+
switch (id.subdetId()) {
152+
case PixelSubdetector::PixelBarrel:
153+
hBchargeL_[tTopo_->pxbLayer(id) - 1]->Fill(chargeHost, chargeDevice);
154+
hBsizexL_[tTopo_->pxbLayer(id) - 1]->Fill(sizeXHost, sizeXDevice);
155+
hBsizeyL_[tTopo_->pxbLayer(id) - 1]->Fill(sizeYHost, sizeYDevice);
156+
hBposxL_[tTopo_->pxbLayer(id) - 1]->Fill(xLocalHost, xLocalDevice);
157+
hBposyL_[tTopo_->pxbLayer(id) - 1]->Fill(yLocalHost, yLocalDevice);
158+
hBchargeDiff_->Fill(chargeHost - chargeDevice);
159+
hBsizeXDiff_->Fill(sizeXHost - sizeXDevice);
160+
hBsizeYDiff_->Fill(sizeYHost - sizeYDevice);
161+
hBposXDiff_->Fill(micron_ * (xLocalHost - xLocalDevice));
162+
hBposYDiff_->Fill(micron_ * (yLocalHost - yLocalDevice));
163+
break;
164+
case PixelSubdetector::PixelEndcap:
165+
hFchargeD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(chargeHost, chargeDevice);
166+
hFsizexD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(sizeXHost, sizeXDevice);
167+
hFsizeyD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(sizeYHost, sizeYDevice);
168+
hFposxD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(xLocalHost, xLocalDevice);
169+
hFposyD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(yLocalHost, yLocalDevice);
170+
hFchargeDiff_->Fill(chargeHost - chargeDevice);
171+
hFsizeXDiff_->Fill(sizeXHost - sizeXDevice);
172+
hFsizeYDiff_->Fill(sizeYHost - sizeYDevice);
173+
hFposXDiff_->Fill(micron_ * (xLocalHost - xLocalDevice));
174+
hFposYDiff_->Fill(micron_ * (yLocalHost - yLocalDevice));
175+
break;
176+
}
177+
}
178+
}
179+
180+
//
181+
// -- Book Histograms
182+
//
183+
template <typename T>
184+
void SiPixelCompareRecHitsSoAAlpaka<T>::bookHistograms(DQMStore::IBooker& iBook,
185+
edm::Run const& iRun,
186+
edm::EventSetup const& iSetup) {
187+
iBook.cd();
188+
iBook.setCurrentFolder(topFolderName_);
189+
190+
// clang-format off
191+
//Global
192+
hnHits_ = iBook.book2I("nHits", "HostvsDevice RecHits per event;#Host RecHits;#Device RecHits", 200, 0, 5000,200, 0, 5000);
193+
//Barrel Layer
194+
for(unsigned int il=0;il<tkGeom_->numberOfLayers(PixelSubdetector::PixelBarrel);il++){
195+
hBchargeL_[il] = iBook.book2I(Form("recHitsBLay%dCharge",il+1), Form("HostvsDevice RecHits Charge Barrel Layer%d;Host Charge;Device Charge",il+1), 250, 0, 100000, 250, 0, 100000);
196+
hBsizexL_[il] = iBook.book2I(Form("recHitsBLay%dSizex",il+1), Form("HostvsDevice RecHits SizeX Barrel Layer%d;Host SizeX;Device SizeX",il+1), 30, 0, 30, 30, 0, 30);
197+
hBsizeyL_[il] = iBook.book2I(Form("recHitsBLay%dSizey",il+1), Form("HostvsDevice RecHits SizeY Barrel Layer%d;Host SizeY;Device SizeY",il+1), 30, 0, 30, 30, 0, 30);
198+
hBposxL_[il] = iBook.book2D(Form("recHitsBLay%dPosx",il+1), Form("HostvsDevice RecHits x-pos in Barrel Layer%d;Host pos x;Device pos x",il+1), 200, -5, 5, 200,-5,5);
199+
hBposyL_[il] = iBook.book2D(Form("recHitsBLay%dPosy",il+1), Form("HostvsDevice RecHits y-pos in Barrel Layer%d;Host pos y;Device pos y",il+1), 200, -5, 5, 200,-5,5);
200+
}
201+
//Endcaps
202+
//Endcaps Disk
203+
for(int is=0;is<2;is++){
204+
int sign=is==0? -1:1;
205+
for(unsigned int id=0;id<tkGeom_->numberOfLayers(PixelSubdetector::PixelEndcap);id++){
206+
hFchargeD_[is][id] = iBook.book2I(Form("recHitsFDisk%+dCharge",id*sign+sign), Form("HostvsDevice RecHits Charge Endcaps Disk%+d;Host Charge;Device Charge",id*sign+sign), 250, 0, 100000, 250, 0, 100000);
207+
hFsizexD_[is][id] = iBook.book2I(Form("recHitsFDisk%+dSizex",id*sign+sign), Form("HostvsDevice RecHits SizeX Endcaps Disk%+d;Host SizeX;Device SizeX",id*sign+sign), 30, 0, 30, 30, 0, 30);
208+
hFsizeyD_[is][id] = iBook.book2I(Form("recHitsFDisk%+dSizey",id*sign+sign), Form("HostvsDevice RecHits SizeY Endcaps Disk%+d;Host SizeY;Device SizeY",id*sign+sign), 30, 0, 30, 30, 0, 30);
209+
hFposxD_[is][id] = iBook.book2D(Form("recHitsFDisk%+dPosx",id*sign+sign), Form("HostvsDevice RecHits x-pos Endcaps Disk%+d;Host pos x;Device pos x",id*sign+sign), 200, -5, 5, 200, -5, 5);
210+
hFposyD_[is][id] = iBook.book2D(Form("recHitsFDisk%+dPosy",id*sign+sign), Form("HostvsDevice RecHits y-pos Endcaps Disk%+d;Host pos y;Device pos y",id*sign+sign), 200, -5, 5, 200, -5, 5);
211+
}
212+
}
213+
//1D differences
214+
hBchargeDiff_ = iBook.book1D("rechitChargeDiffBpix","Charge differnce of rechits in BPix; rechit charge difference (Host - Device)", 101, -50.5, 50.5);
215+
hFchargeDiff_ = iBook.book1D("rechitChargeDiffFpix","Charge differnce of rechits in FPix; rechit charge difference (Host - Device)", 101, -50.5, 50.5);
216+
hBsizeXDiff_ = iBook.book1D("rechitsizeXDiffBpix","SizeX difference of rechits in BPix; rechit sizex difference (Host - Device)", 21, -10.5, 10.5);
217+
hFsizeXDiff_ = iBook.book1D("rechitsizeXDiffFpix","SizeX difference of rechits in FPix; rechit sizex difference (Host - Device)", 21, -10.5, 10.5);
218+
hBsizeYDiff_ = iBook.book1D("rechitsizeYDiffBpix","SizeY difference of rechits in BPix; rechit sizey difference (Host - Device)", 21, -10.5, 10.5);
219+
hFsizeYDiff_ = iBook.book1D("rechitsizeYDiffFpix","SizeY difference of rechits in FPix; rechit sizey difference (Host - Device)", 21, -10.5, 10.5);
220+
hBposXDiff_ = iBook.book1D("rechitsposXDiffBpix","x-position difference of rechits in BPix; rechit x-pos difference (Host - Device)", 1000, -10, 10);
221+
hFposXDiff_ = iBook.book1D("rechitsposXDiffFpix","x-position difference of rechits in FPix; rechit x-pos difference (Host - Device)", 1000, -10, 10);
222+
hBposYDiff_ = iBook.book1D("rechitsposYDiffBpix","y-position difference of rechits in BPix; rechit y-pos difference (Host - Device)", 1000, -10, 10);
223+
hFposYDiff_ = iBook.book1D("rechitsposYDiffFpix","y-position difference of rechits in FPix; rechit y-pos difference (Host - Device)", 1000, -10, 10);
224+
}
225+
226+
template<typename T>
227+
void SiPixelCompareRecHitsSoAAlpaka<T>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
228+
// monitorpixelRecHitsSoAAlpaka
229+
edm::ParameterSetDescription desc;
230+
desc.add<edm::InputTag>("pixelHitsSrcHost", edm::InputTag("siPixelRecHitsPreSplittingAlpakaSerial"));
231+
desc.add<edm::InputTag>("pixelHitsSrcDevice", edm::InputTag("siPixelRecHitsPreSplittingAlpaka"));
232+
desc.add<std::string>("topFolderName", "SiPixelHeterogeneous/PixelRecHitsCompareDeviceVSHost");
233+
desc.add<double>("minD2cut", 0.0001);
234+
descriptions.addWithDefaultLabel(desc);
235+
}
236+
237+
using SiPixelPhase1CompareRecHitsSoAAlpaka = SiPixelCompareRecHitsSoAAlpaka<pixelTopology::Phase1>;
238+
using SiPixelPhase2CompareRecHitsSoAAlpaka = SiPixelCompareRecHitsSoAAlpaka<pixelTopology::Phase2>;
239+
using SiPixelHIonPhase1CompareRecHitsSoAAlpaka = SiPixelCompareRecHitsSoAAlpaka<pixelTopology::HIonPhase1>;
240+
241+
#include "FWCore/Framework/interface/MakerMacros.h"
242+
DEFINE_FWK_MODULE(SiPixelPhase1CompareRecHitsSoAAlpaka);
243+
DEFINE_FWK_MODULE(SiPixelPhase2CompareRecHitsSoAAlpaka);
244+
DEFINE_FWK_MODULE(SiPixelHIonPhase1CompareRecHitsSoAAlpaka);

0 commit comments

Comments
 (0)