Skip to content

Commit

Permalink
Moved segments to SoA+PortableCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
ariostas committed Sep 18, 2024
1 parent 46f7f22 commit d5da756
Show file tree
Hide file tree
Showing 15 changed files with 467 additions and 560 deletions.
2 changes: 2 additions & 0 deletions RecoTracker/LSTCore/interface/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define RecoTracker_LSTCore_interface_Constants_h

#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "DataFormats/Common/interface/StdArray.h"

#ifdef CACHE_ALLOC
#include "HeterogeneousCore/AlpakaInterface/interface/CachedBufAlloc.h"
Expand Down Expand Up @@ -62,6 +63,7 @@ namespace lst {
};
struct Params_LS {
static constexpr int kLayers = 2, kHits = 4;
using ArrayUxLayers = edm::StdArray<unsigned int, kLayers>;
};
struct Params_T3 {
static constexpr int kLayers = 3, kHits = 6;
Expand Down
153 changes: 72 additions & 81 deletions RecoTracker/LSTCore/src/alpaka/Event.dev.cc

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions RecoTracker/LSTCore/src/alpaka/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
std::optional<HitsBuffer<Device>> hitsBuffers_;
std::optional<MiniDoublets> mdsInGPU_;
std::optional<MiniDoubletsBuffer<Device>> miniDoubletsBuffers_;
std::optional<Segments> segmentsInGPU_;
std::optional<SegmentsBuffer<Device>> segmentsBuffers_;
std::optional<SegmentsDeviceCollection> segmentsDevCol_;
std::optional<Segments> segmentsDev_;
std::optional<Triplets> tripletsInGPU_;
std::optional<TripletsBuffer<Device>> tripletsBuffers_;
std::optional<Quintuplets> quintupletsInGPU_;
Expand All @@ -65,7 +65,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
std::optional<ObjectRangesBuffer<DevHost>> rangesInCPU_;
std::optional<HitsBuffer<DevHost>> hitsInCPU_;
std::optional<MiniDoubletsBuffer<DevHost>> mdsInCPU_;
std::optional<SegmentsBuffer<DevHost>> segmentsInCPU_;
std::optional<SegmentsHostCollection> segmentsHostCol_;
std::optional<Segments> segmentsHost_;
std::optional<TripletsBuffer<DevHost>> tripletsInCPU_;
std::optional<TrackCandidatesBuffer<DevHost>> trackCandidatesInCPU_;
std::optional<ModulesBuffer<DevHost>> modulesInCPU_;
Expand Down Expand Up @@ -184,7 +185,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
HitsBuffer<DevHost>& getHitsInCMSSW(bool sync = true);
ObjectRangesBuffer<DevHost>& getRanges(bool sync = true);
MiniDoubletsBuffer<DevHost>& getMiniDoublets(bool sync = true);
SegmentsBuffer<DevHost>& getSegments(bool sync = true);
Segments& getSegments(bool sync = true);
TripletsBuffer<DevHost>& getTriplets(bool sync = true);
QuintupletsBuffer<DevHost>& getQuintuplets(bool sync = true);
PixelTripletsBuffer<DevHost>& getPixelTriplets(bool sync = true);
Expand Down
44 changes: 22 additions & 22 deletions RecoTracker/LSTCore/src/alpaka/Kernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
pixelQuintupletsInGPU.isDup[pixelQuintupletIndex] = true;
}

ALPAKA_FN_ACC ALPAKA_FN_INLINE void rmPixelSegmentFromMemory(Segments& segmentsInGPU,
ALPAKA_FN_ACC ALPAKA_FN_INLINE void rmPixelSegmentFromMemory(Segments segments,
unsigned int pixelSegmentArrayIndex,
bool secondpass = false) {
segmentsInGPU.isDup[pixelSegmentArrayIndex] |= 1 + secondpass;
segments.pix.isDup()[pixelSegmentArrayIndex] |= 1 + secondpass;
}

ALPAKA_FN_ACC ALPAKA_FN_INLINE int checkHitsT5(unsigned int ix,
Expand Down Expand Up @@ -331,40 +331,40 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

struct CheckHitspLS {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(TAcc const& acc, Modules modulesInGPU, Segments segmentsInGPU, bool secondpass) const {
ALPAKA_FN_ACC void operator()(TAcc const& acc, Modules modulesInGPU, Segments segments, bool secondpass) const {
auto const globalThreadIdx = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc);
auto const gridThreadExtent = alpaka::getWorkDiv<alpaka::Grid, alpaka::Threads>(acc);

int pixelModuleIndex = *modulesInGPU.nLowerModules;
unsigned int nPixelSegments = segmentsInGPU.nSegments[pixelModuleIndex];
unsigned int nPixelSegments = segments.mod.nSegments()[pixelModuleIndex];

if (nPixelSegments > n_max_pixel_segments_per_module)
nPixelSegments = n_max_pixel_segments_per_module;

for (unsigned int ix = globalThreadIdx[1]; ix < nPixelSegments; ix += gridThreadExtent[1]) {
if (secondpass && (!segmentsInGPU.isQuad[ix] || (segmentsInGPU.isDup[ix] & 1)))
if (secondpass && (!segments.pix.isQuad()[ix] || (segments.pix.isDup()[ix] & 1)))
continue;

unsigned int phits1[Params_pLS::kHits];
phits1[0] = segmentsInGPU.pLSHitsIdxs[ix].x;
phits1[1] = segmentsInGPU.pLSHitsIdxs[ix].y;
phits1[2] = segmentsInGPU.pLSHitsIdxs[ix].z;
phits1[3] = segmentsInGPU.pLSHitsIdxs[ix].w;
float eta_pix1 = segmentsInGPU.eta[ix];
float phi_pix1 = segmentsInGPU.phi[ix];
phits1[0] = segments.pix.pLSHitsIdxs()[ix].x;
phits1[1] = segments.pix.pLSHitsIdxs()[ix].y;
phits1[2] = segments.pix.pLSHitsIdxs()[ix].z;
phits1[3] = segments.pix.pLSHitsIdxs()[ix].w;
float eta_pix1 = segments.pix.eta()[ix];
float phi_pix1 = segments.pix.phi()[ix];

for (unsigned int jx = ix + 1 + globalThreadIdx[2]; jx < nPixelSegments; jx += gridThreadExtent[2]) {
float eta_pix2 = segmentsInGPU.eta[jx];
float phi_pix2 = segmentsInGPU.phi[jx];
float eta_pix2 = segments.pix.eta()[jx];
float phi_pix2 = segments.pix.phi()[jx];

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

if (secondpass && (!segmentsInGPU.isQuad[jx] || (segmentsInGPU.isDup[jx] & 1)))
if (secondpass && (!segments.pix.isQuad()[jx] || (segments.pix.isDup()[jx] & 1)))
continue;

int8_t quad_diff = segmentsInGPU.isQuad[ix] - segmentsInGPU.isQuad[jx];
float score_diff = segmentsInGPU.score[ix] - segmentsInGPU.score[jx];
int8_t quad_diff = segments.pix.isQuad()[ix] - segments.pix.isQuad()[jx];
float score_diff = segments.pix.score()[ix] - segments.pix.score()[jx];
// Always keep quads over trips. If they are the same, we want the object with better score
int idxToRemove;
if (quad_diff > 0)
Expand All @@ -379,10 +379,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
idxToRemove = ix;

unsigned int phits2[Params_pLS::kHits];
phits2[0] = segmentsInGPU.pLSHitsIdxs[jx].x;
phits2[1] = segmentsInGPU.pLSHitsIdxs[jx].y;
phits2[2] = segmentsInGPU.pLSHitsIdxs[jx].z;
phits2[3] = segmentsInGPU.pLSHitsIdxs[jx].w;
phits2[0] = segments.pix.pLSHitsIdxs()[jx].x;
phits2[1] = segments.pix.pLSHitsIdxs()[jx].y;
phits2[2] = segments.pix.pLSHitsIdxs()[jx].z;
phits2[3] = segments.pix.pLSHitsIdxs()[jx].w;

int npMatched = 0;
for (int i = 0; i < Params_pLS::kHits; i++) {
Expand All @@ -402,15 +402,15 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
}
const int minNHitsForDup_pLS = 3;
if (npMatched >= minNHitsForDup_pLS) {
rmPixelSegmentFromMemory(segmentsInGPU, idxToRemove, secondpass);
rmPixelSegmentFromMemory(segments, idxToRemove, secondpass);
}
if (secondpass) {
float dEta = alpaka::math::abs(acc, eta_pix1 - eta_pix2);
float dPhi = calculate_dPhi(phi_pix1, phi_pix2);

float dR2 = dEta * dEta + dPhi * dPhi;
if ((npMatched >= 1) || (dR2 < 1e-5f)) {
rmPixelSegmentFromMemory(segmentsInGPU, idxToRemove, secondpass);
rmPixelSegmentFromMemory(segments, idxToRemove, secondpass);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions RecoTracker/LSTCore/src/alpaka/NeuralNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
ALPAKA_FN_ACC ALPAKA_FN_INLINE float runInference(TAcc const& acc,
Modules const& modulesInGPU,
MiniDoublets const& mdsInGPU,
Segments const& segmentsInGPU,
Segments segments,
Triplets const& tripletsInGPU,
const float* xVec,
const float* yVec,
Expand Down Expand Up @@ -59,7 +59,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
layer2_adjustment = 1; // get upper segment to be in second layer
}
unsigned int md_idx_for_t5_eta_phi =
segmentsInGPU.mdIndices[2 * tripletsInGPU.segmentIndices[2 * innerTripletIndex + layer2_adjustment]];
segments.mem.mdIndices()[2 * tripletsInGPU.segmentIndices[2 * innerTripletIndex + layer2_adjustment]][0];
bool is_endcap1 = (modulesInGPU.subdets[lowerModuleIndex1] == 4); // true if anchor hit 1 is in the endcap
bool is_endcap2 = (modulesInGPU.subdets[lowerModuleIndex2] == 4); // true if anchor hit 2 is in the endcap
bool is_endcap3 = (modulesInGPU.subdets[lowerModuleIndex3] == 4); // true if anchor hit 3 is in the endcap
Expand Down
44 changes: 22 additions & 22 deletions RecoTracker/LSTCore/src/alpaka/PixelQuintuplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

ALPAKA_FN_ACC ALPAKA_FN_INLINE void addPixelQuintupletToMemory(Modules const& modulesInGPU,
MiniDoublets const& mdsInGPU,
Segments const& segmentsInGPU,
Segments segments,
Quintuplets const& quintupletsInGPU,
PixelQuintuplets& pixelQuintupletsInGPU,
unsigned int pixelIndex,
Expand Down Expand Up @@ -150,9 +150,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
quintupletsInGPU.logicalLayers[T5Index * Params_T5::kLayers + 4];

pixelQuintupletsInGPU.lowerModuleIndices[Params_pT5::kLayers * pixelQuintupletIndex] =
segmentsInGPU.innerLowerModuleIndices[pixelIndex];
segments.mem.innerLowerModuleIndices()[pixelIndex];
pixelQuintupletsInGPU.lowerModuleIndices[Params_pT5::kLayers * pixelQuintupletIndex + 1] =
segmentsInGPU.outerLowerModuleIndices[pixelIndex];
segments.mem.outerLowerModuleIndices()[pixelIndex];
pixelQuintupletsInGPU.lowerModuleIndices[Params_pT5::kLayers * pixelQuintupletIndex + 2] =
quintupletsInGPU.lowerModuleIndices[T5Index * Params_T5::kLayers];
pixelQuintupletsInGPU.lowerModuleIndices[Params_pT5::kLayers * pixelQuintupletIndex + 3] =
Expand All @@ -164,8 +164,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
pixelQuintupletsInGPU.lowerModuleIndices[Params_pT5::kLayers * pixelQuintupletIndex + 6] =
quintupletsInGPU.lowerModuleIndices[T5Index * Params_T5::kLayers + 4];

unsigned int pixelInnerMD = segmentsInGPU.mdIndices[Params_pLS::kLayers * pixelIndex];
unsigned int pixelOuterMD = segmentsInGPU.mdIndices[Params_pLS::kLayers * pixelIndex + 1];
unsigned int pixelInnerMD = segments.mem.mdIndices()[Params_pLS::kLayers * pixelIndex][0];
unsigned int pixelOuterMD = segments.mem.mdIndices()[Params_pLS::kLayers * pixelIndex][1];

pixelQuintupletsInGPU.hitIndices[Params_pT5::kHits * pixelQuintupletIndex] =
mdsInGPU.anchorHitIndices[pixelInnerMD];
Expand Down Expand Up @@ -676,7 +676,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
Modules const& modulesInGPU,
ObjectRanges const& rangesInGPU,
MiniDoublets const& mdsInGPU,
Segments const& segmentsInGPU,
Segments segments,
Triplets const& tripletsInGPU,
Quintuplets const& quintupletsInGPU,
unsigned int pixelSegmentIndex,
Expand All @@ -699,7 +699,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
modulesInGPU,
rangesInGPU,
mdsInGPU,
segmentsInGPU,
segments,
tripletsInGPU,
pixelSegmentIndex,
T5InnerT3Index,
Expand All @@ -718,13 +718,13 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
unsigned int thirdSegmentIndex = tripletsInGPU.segmentIndices[2 * T5OuterT3Index];
unsigned int fourthSegmentIndex = tripletsInGPU.segmentIndices[2 * T5OuterT3Index + 1];

unsigned int pixelInnerMDIndex = segmentsInGPU.mdIndices[2 * pixelSegmentIndex];
unsigned int pixelOuterMDIndex = segmentsInGPU.mdIndices[2 * pixelSegmentIndex + 1];
unsigned int firstMDIndex = segmentsInGPU.mdIndices[2 * firstSegmentIndex];
unsigned int secondMDIndex = segmentsInGPU.mdIndices[2 * secondSegmentIndex];
unsigned int thirdMDIndex = segmentsInGPU.mdIndices[2 * secondSegmentIndex + 1];
unsigned int fourthMDIndex = segmentsInGPU.mdIndices[2 * thirdSegmentIndex + 1];
unsigned int fifthMDIndex = segmentsInGPU.mdIndices[2 * fourthSegmentIndex + 1];
unsigned int pixelInnerMDIndex = segments.mem.mdIndices()[pixelSegmentIndex][0];
unsigned int pixelOuterMDIndex = segments.mem.mdIndices()[pixelSegmentIndex][1];
unsigned int firstMDIndex = segments.mem.mdIndices()[firstSegmentIndex][0];
unsigned int secondMDIndex = segments.mem.mdIndices()[secondSegmentIndex][0];
unsigned int thirdMDIndex = segments.mem.mdIndices()[secondSegmentIndex][1];
unsigned int fourthMDIndex = segments.mem.mdIndices()[thirdSegmentIndex][1];
unsigned int fifthMDIndex = segments.mem.mdIndices()[fourthSegmentIndex][1];

uint16_t lowerModuleIndex1 = quintupletsInGPU.lowerModuleIndices[Params_T5::kLayers * quintupletIndex];
uint16_t lowerModuleIndex2 = quintupletsInGPU.lowerModuleIndices[Params_T5::kLayers * quintupletIndex + 1];
Expand Down Expand Up @@ -774,9 +774,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
mdsInGPU.anchorY[fifthMDIndex]};

//get the appropriate radii and centers
centerX = segmentsInGPU.circleCenterX[pixelSegmentArrayIndex];
centerY = segmentsInGPU.circleCenterY[pixelSegmentArrayIndex];
pixelRadius = segmentsInGPU.circleRadius[pixelSegmentArrayIndex];
centerX = segments.pix.circleCenterX()[pixelSegmentArrayIndex];
centerY = segments.pix.circleCenterY()[pixelSegmentArrayIndex];
pixelRadius = segments.pix.circleRadius()[pixelSegmentArrayIndex];

float T5CenterX = quintupletsInGPU.regressionG[quintupletIndex];
float T5CenterY = quintupletsInGPU.regressionF[quintupletIndex];
Expand Down Expand Up @@ -822,7 +822,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
ALPAKA_FN_ACC void operator()(TAcc const& acc,
Modules modulesInGPU,
MiniDoublets mdsInGPU,
Segments segmentsInGPU,
Segments segments,
Triplets tripletsInGPU,
Quintuplets quintupletsInGPU,
PixelQuintuplets pixelQuintupletsInGPU,
Expand All @@ -846,7 +846,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
if (modulesInGPU.moduleType[quintupletLowerModuleIndex] == TwoS)
continue;
uint16_t pixelModuleIndex = *modulesInGPU.nLowerModules;
if (segmentsInGPU.isDup[i_pLS])
if (segments.pix.isDup()[i_pLS])
continue;
unsigned int nOuterQuintuplets = quintupletsInGPU.nQuintuplets[quintupletLowerModuleIndex];

Expand All @@ -871,7 +871,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
modulesInGPU,
rangesInGPU,
mdsInGPU,
segmentsInGPU,
segments,
tripletsInGPU,
quintupletsInGPU,
pixelSegmentIndex,
Expand Down Expand Up @@ -899,7 +899,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

addPixelQuintupletToMemory(modulesInGPU,
mdsInGPU,
segmentsInGPU,
segments,
quintupletsInGPU,
pixelQuintupletsInGPU,
pixelSegmentIndex,
Expand All @@ -918,7 +918,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

tripletsInGPU.partOfPT5[quintupletsInGPU.tripletIndices[2 * quintupletIndex]] = true;
tripletsInGPU.partOfPT5[quintupletsInGPU.tripletIndices[2 * quintupletIndex + 1]] = true;
segmentsInGPU.partOfPT5[i_pLS] = true;
segments.pix.partOfPT5()[i_pLS] = true;
quintupletsInGPU.partOfPT5[quintupletIndex] = true;
} // tot occupancy
} // end success
Expand Down
Loading

0 comments on commit d5da756

Please sign in to comment.