Skip to content

Commit 2967c14

Browse files
committed
Dynamic Memory Allocation for LST Objects
1 parent 7905921 commit 2967c14

21 files changed

+505
-431
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef RecoTracker_LSTCore_interface_PixelSegmentsHostCollection_h
2+
#define RecoTracker_LSTCore_interface_PixelSegmentsHostCollection_h
3+
4+
#include "RecoTracker/LSTCore/interface/PixelSegmentsSoA.h"
5+
#include "DataFormats/Portable/interface/PortableHostCollection.h"
6+
7+
namespace lst {
8+
using PixelSegmentsHostCollection = PortableHostCollection<PixelSegmentsSoA>;
9+
} // namespace lst
10+
#endif
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef RecoTracker_LSTCore_interface_PixelSegmentsSoA_h
2+
#define RecoTracker_LSTCore_interface_PixelSegmentsSoA_h
3+
4+
#include "DataFormats/SoATemplate/interface/SoALayout.h"
5+
#include "DataFormats/Portable/interface/PortableCollection.h"
6+
7+
#include "RecoTracker/LSTCore/interface/Common.h"
8+
9+
namespace lst {
10+
11+
GENERATE_SOA_LAYOUT(PixelSegmentsSoALayout,
12+
SOA_COLUMN(unsigned int, seedIdx),
13+
SOA_COLUMN(int, charge),
14+
SOA_COLUMN(int, superbin),
15+
SOA_COLUMN(uint4, pLSHitsIdxs),
16+
SOA_COLUMN(PixelType, pixelType),
17+
SOA_COLUMN(char, isQuad),
18+
SOA_COLUMN(char, isDup),
19+
SOA_COLUMN(bool, partOfPT5),
20+
SOA_COLUMN(float, ptIn),
21+
SOA_COLUMN(float, ptErr),
22+
SOA_COLUMN(float, px),
23+
SOA_COLUMN(float, py),
24+
SOA_COLUMN(float, pz),
25+
SOA_COLUMN(float, etaErr),
26+
SOA_COLUMN(float, eta),
27+
SOA_COLUMN(float, phi),
28+
SOA_COLUMN(float, score),
29+
SOA_COLUMN(float, circleCenterX),
30+
SOA_COLUMN(float, circleCenterY),
31+
SOA_COLUMN(float, circleRadius))
32+
33+
using PixelSegmentsSoA = PixelSegmentsSoALayout<>;
34+
35+
using PixelSegments = PixelSegmentsSoA::View;
36+
using PixelSegmentsConst = PixelSegmentsSoA::ConstView;
37+
38+
} // namespace lst
39+
40+
#endif

RecoTracker/LSTCore/interface/SegmentsHostCollection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
#include "DataFormats/Portable/interface/PortableHostCollection.h"
66

77
namespace lst {
8-
using SegmentsHostCollection = PortableHostMultiCollection<SegmentsSoA, SegmentsOccupancySoA, SegmentsPixelSoA>;
8+
using SegmentsHostCollection = PortableHostMultiCollection<SegmentsSoA, SegmentsOccupancySoA>;
99
} // namespace lst
1010
#endif

RecoTracker/LSTCore/interface/SegmentsSoA.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,13 @@ namespace lst {
2525
SOA_COLUMN(unsigned int, nSegments), //number of segments per inner lower module
2626
SOA_COLUMN(unsigned int, totOccupancySegments))
2727

28-
GENERATE_SOA_LAYOUT(SegmentsPixelSoALayout,
29-
SOA_COLUMN(unsigned int, seedIdx),
30-
SOA_COLUMN(int, charge),
31-
SOA_COLUMN(int, superbin),
32-
SOA_COLUMN(uint4, pLSHitsIdxs),
33-
SOA_COLUMN(PixelType, pixelType),
34-
SOA_COLUMN(char, isQuad),
35-
SOA_COLUMN(char, isDup),
36-
SOA_COLUMN(bool, partOfPT5),
37-
SOA_COLUMN(float, ptIn),
38-
SOA_COLUMN(float, ptErr),
39-
SOA_COLUMN(float, px),
40-
SOA_COLUMN(float, py),
41-
SOA_COLUMN(float, pz),
42-
SOA_COLUMN(float, etaErr),
43-
SOA_COLUMN(float, eta),
44-
SOA_COLUMN(float, phi),
45-
SOA_COLUMN(float, score),
46-
SOA_COLUMN(float, circleCenterX),
47-
SOA_COLUMN(float, circleCenterY),
48-
SOA_COLUMN(float, circleRadius))
49-
5028
using SegmentsSoA = SegmentsSoALayout<>;
5129
using SegmentsOccupancySoA = SegmentsOccupancySoALayout<>;
52-
using SegmentsPixelSoA = SegmentsPixelSoALayout<>;
5330

5431
using Segments = SegmentsSoA::View;
5532
using SegmentsConst = SegmentsSoA::ConstView;
5633
using SegmentsOccupancy = SegmentsOccupancySoA::View;
5734
using SegmentsOccupancyConst = SegmentsOccupancySoA::ConstView;
58-
using SegmentsPixel = SegmentsPixelSoA::View;
59-
using SegmentsPixelConst = SegmentsPixelSoA::ConstView;
6035

6136
} // namespace lst
6237

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef RecoTracker_LSTCore_interface_alpaka_PixelSegmentsDeviceCollection_h
2+
#define RecoTracker_LSTCore_interface_alpaka_PixelSegmentsDeviceCollection_h
3+
4+
#include "DataFormats/Portable/interface/alpaka/PortableCollection.h"
5+
6+
#include "RecoTracker/LSTCore/interface/alpaka/Common.h"
7+
#include "RecoTracker/LSTCore/interface/PixelSegmentsSoA.h"
8+
9+
namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
10+
using PixelSegmentsDeviceCollection = PortableCollection<PixelSegmentsSoA>;
11+
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::lst
12+
13+
#endif

RecoTracker/LSTCore/interface/alpaka/SegmentsDeviceCollection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "RecoTracker/LSTCore/interface/SegmentsSoA.h"
88

99
namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
10-
using SegmentsDeviceCollection = PortableCollection3<SegmentsSoA, SegmentsOccupancySoA, SegmentsPixelSoA>;
10+
using SegmentsDeviceCollection = PortableCollection2<SegmentsSoA, SegmentsOccupancySoA>;
1111
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::lst
1212

1313
#endif

RecoTracker/LSTCore/src/alpaka/Kernels.h

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "RecoTracker/LSTCore/interface/MiniDoubletsSoA.h"
1010
#include "RecoTracker/LSTCore/interface/PixelQuintupletsSoA.h"
1111
#include "RecoTracker/LSTCore/interface/PixelTripletsSoA.h"
12+
#include "RecoTracker/LSTCore/interface/PixelSegmentsSoA.h"
1213
#include "RecoTracker/LSTCore/interface/QuintupletsSoA.h"
1314
#include "RecoTracker/LSTCore/interface/SegmentsSoA.h"
1415
#include "RecoTracker/LSTCore/interface/TripletsSoA.h"
@@ -30,10 +31,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
3031
pixelQuintuplets.isDup()[pixelQuintupletIndex] = true;
3132
}
3233

33-
ALPAKA_FN_ACC ALPAKA_FN_INLINE void rmPixelSegmentFromMemory(SegmentsPixel segmentsPixel,
34+
ALPAKA_FN_ACC ALPAKA_FN_INLINE void rmPixelSegmentFromMemory(PixelSegments pixelSegments,
3435
unsigned int pixelSegmentArrayIndex,
3536
bool secondpass = false) {
36-
segmentsPixel.isDup()[pixelSegmentArrayIndex] |= 1 + secondpass;
37+
pixelSegments.isDup()[pixelSegmentArrayIndex] |= 1 + secondpass;
3738
}
3839

3940
ALPAKA_FN_ACC ALPAKA_FN_INLINE int checkHitsT5(unsigned int ix, unsigned int jx, QuintupletsConst quintuplets) {
@@ -321,7 +322,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
321322
ALPAKA_FN_ACC void operator()(Acc2D const& acc,
322323
ModulesConst modules,
323324
SegmentsOccupancyConst segmentsOccupancy,
324-
SegmentsPixel segmentsPixel,
325+
PixelSegments pixelSegments,
325326
bool secondpass) const {
326327
int pixelModuleIndex = modules.nLowerModules();
327328
unsigned int nPixelSegments = segmentsOccupancy.nSegments()[pixelModuleIndex];
@@ -330,29 +331,29 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
330331
nPixelSegments = n_max_pixel_segments_per_module;
331332

332333
for (unsigned int ix : cms::alpakatools::uniform_elements_y(acc, nPixelSegments)) {
333-
if (secondpass && (!segmentsPixel.isQuad()[ix] || (segmentsPixel.isDup()[ix] & 1)))
334+
if (secondpass && (!pixelSegments.isQuad()[ix] || (pixelSegments.isDup()[ix] & 1)))
334335
continue;
335336

336337
unsigned int phits1[Params_pLS::kHits];
337-
phits1[0] = segmentsPixel.pLSHitsIdxs()[ix].x;
338-
phits1[1] = segmentsPixel.pLSHitsIdxs()[ix].y;
339-
phits1[2] = segmentsPixel.pLSHitsIdxs()[ix].z;
340-
phits1[3] = segmentsPixel.pLSHitsIdxs()[ix].w;
341-
float eta_pix1 = segmentsPixel.eta()[ix];
342-
float phi_pix1 = segmentsPixel.phi()[ix];
338+
phits1[0] = pixelSegments.pLSHitsIdxs()[ix].x;
339+
phits1[1] = pixelSegments.pLSHitsIdxs()[ix].y;
340+
phits1[2] = pixelSegments.pLSHitsIdxs()[ix].z;
341+
phits1[3] = pixelSegments.pLSHitsIdxs()[ix].w;
342+
float eta_pix1 = pixelSegments.eta()[ix];
343+
float phi_pix1 = pixelSegments.phi()[ix];
343344

344345
for (unsigned int jx : cms::alpakatools::uniform_elements_x(acc, ix + 1, nPixelSegments)) {
345-
float eta_pix2 = segmentsPixel.eta()[jx];
346-
float phi_pix2 = segmentsPixel.phi()[jx];
346+
float eta_pix2 = pixelSegments.eta()[jx];
347+
float phi_pix2 = pixelSegments.phi()[jx];
347348

348349
if (alpaka::math::abs(acc, eta_pix2 - eta_pix1) > 0.1f)
349350
continue;
350351

351-
if (secondpass && (!segmentsPixel.isQuad()[jx] || (segmentsPixel.isDup()[jx] & 1)))
352+
if (secondpass && (!pixelSegments.isQuad()[jx] || (pixelSegments.isDup()[jx] & 1)))
352353
continue;
353354

354-
int8_t quad_diff = segmentsPixel.isQuad()[ix] - segmentsPixel.isQuad()[jx];
355-
float score_diff = segmentsPixel.score()[ix] - segmentsPixel.score()[jx];
355+
int8_t quad_diff = pixelSegments.isQuad()[ix] - pixelSegments.isQuad()[jx];
356+
float score_diff = pixelSegments.score()[ix] - pixelSegments.score()[jx];
356357
// Always keep quads over trips. If they are the same, we want the object with better score
357358
int idxToRemove;
358359
if (quad_diff > 0)
@@ -367,10 +368,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
367368
idxToRemove = ix;
368369

369370
unsigned int phits2[Params_pLS::kHits];
370-
phits2[0] = segmentsPixel.pLSHitsIdxs()[jx].x;
371-
phits2[1] = segmentsPixel.pLSHitsIdxs()[jx].y;
372-
phits2[2] = segmentsPixel.pLSHitsIdxs()[jx].z;
373-
phits2[3] = segmentsPixel.pLSHitsIdxs()[jx].w;
371+
phits2[0] = pixelSegments.pLSHitsIdxs()[jx].x;
372+
phits2[1] = pixelSegments.pLSHitsIdxs()[jx].y;
373+
phits2[2] = pixelSegments.pLSHitsIdxs()[jx].z;
374+
phits2[3] = pixelSegments.pLSHitsIdxs()[jx].w;
374375

375376
int npMatched = 0;
376377
for (int i = 0; i < Params_pLS::kHits; i++) {
@@ -390,15 +391,15 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
390391
}
391392
const int minNHitsForDup_pLS = 3;
392393
if (npMatched >= minNHitsForDup_pLS) {
393-
rmPixelSegmentFromMemory(segmentsPixel, idxToRemove, secondpass);
394+
rmPixelSegmentFromMemory(pixelSegments, idxToRemove, secondpass);
394395
}
395396
if (secondpass) {
396397
float dEta = alpaka::math::abs(acc, eta_pix1 - eta_pix2);
397398
float dPhi = reco::deltaPhi(phi_pix1, phi_pix2);
398399

399400
float dR2 = dEta * dEta + dPhi * dPhi;
400401
if ((npMatched >= 1) || (dR2 < 1e-5f)) {
401-
rmPixelSegmentFromMemory(segmentsPixel, idxToRemove, secondpass);
402+
rmPixelSegmentFromMemory(pixelSegments, idxToRemove, secondpass);
402403
}
403404
}
404405
}

RecoTracker/LSTCore/src/alpaka/LST.cc

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -302,24 +302,19 @@ void LST::run(Queue& queue,
302302
ptCut);
303303

304304
event.addHitToEvent(in_trkX_, in_trkY_, in_trkZ_, in_hitId_, in_hitIdxs_);
305-
event.addPixelSegmentToEvent(in_hitIndices_vec0_,
306-
in_hitIndices_vec1_,
307-
in_hitIndices_vec2_,
308-
in_hitIndices_vec3_,
309-
in_deltaPhi_vec_,
310-
in_ptIn_vec_,
311-
in_ptErr_vec_,
312-
in_px_vec_,
313-
in_py_vec_,
314-
in_pz_vec_,
315-
in_eta_vec_,
316-
in_etaErr_vec_,
317-
in_phi_vec_,
318-
in_charge_vec_,
319-
in_seedIdx_vec_,
320-
in_superbin_vec_,
321-
in_pixelType_vec_,
322-
in_isQuad_vec_);
305+
event.addPixelSegmentToEventStart(in_ptIn_vec_,
306+
in_ptErr_vec_,
307+
in_px_vec_,
308+
in_py_vec_,
309+
in_pz_vec_,
310+
in_eta_vec_,
311+
in_etaErr_vec_,
312+
in_phi_vec_,
313+
in_charge_vec_,
314+
in_seedIdx_vec_,
315+
in_superbin_vec_,
316+
in_pixelType_vec_,
317+
in_isQuad_vec_);
323318
event.createMiniDoublets();
324319
if (verbose) {
325320
alpaka::wait(queue); // event calls are asynchronous: wait before printing
@@ -388,6 +383,9 @@ void LST::run(Queue& queue,
388383
printf("# of Quintuplets produced endcap layer 5: %d\n", event.getNumberOfQuintupletsByLayerEndcap(4));
389384
}
390385

386+
event.addPixelSegmentToEventFinalize(
387+
in_hitIndices_vec0_, in_hitIndices_vec1_, in_hitIndices_vec2_, in_hitIndices_vec3_, in_deltaPhi_vec_);
388+
391389
event.pixelLineSegmentCleaning(no_pls_dupclean);
392390

393391
event.createPixelQuintuplets();

0 commit comments

Comments
 (0)