Skip to content

Commit

Permalink
Switched to only using views
Browse files Browse the repository at this point in the history
  • Loading branch information
ariostas committed Sep 20, 2024
1 parent a7e3ec3 commit acff43f
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 353 deletions.
125 changes: 66 additions & 59 deletions RecoTracker/LSTCore/src/alpaka/Event.dev.cc

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions RecoTracker/LSTCore/src/alpaka/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
std::optional<HitsBuffer<Device>> hitsBuffers_;
std::optional<MiniDoublets> mdsInGPU_;
std::optional<MiniDoubletsBuffer<Device>> miniDoubletsBuffers_;
std::optional<SegmentsDeviceCollection> segmentsDevCol_;
std::optional<Segments> segmentsDev_;
std::optional<SegmentsDeviceCollection> segmentsDev_;
std::optional<Triplets> tripletsInGPU_;
std::optional<TripletsBuffer<Device>> tripletsBuffers_;
std::optional<Quintuplets> quintupletsInGPU_;
Expand All @@ -65,8 +64,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
std::optional<ObjectRangesBuffer<DevHost>> rangesInCPU_;
std::optional<HitsBuffer<DevHost>> hitsInCPU_;
std::optional<MiniDoubletsBuffer<DevHost>> mdsInCPU_;
std::optional<SegmentsHostCollection> segmentsHostCol_;
std::optional<Segments> segmentsHost_;
std::optional<SegmentsHostCollection> segmentsHost_;
std::optional<TripletsBuffer<DevHost>> tripletsInCPU_;
std::optional<TrackCandidatesBuffer<DevHost>> trackCandidatesInCPU_;
std::optional<ModulesBuffer<DevHost>> modulesInCPU_;
Expand Down Expand Up @@ -185,7 +183,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
HitsBuffer<DevHost>& getHitsInCMSSW(bool sync = true);
ObjectRangesBuffer<DevHost>& getRanges(bool sync = true);
MiniDoubletsBuffer<DevHost>& getMiniDoublets(bool sync = true);
Segments& getSegments(bool sync = true);
template <typename TSoA>
typename TSoA::ConstView 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 segments,
ALPAKA_FN_ACC ALPAKA_FN_INLINE void rmPixelSegmentFromMemory(SegmentsPixel segmentsPixel,
unsigned int pixelSegmentArrayIndex,
bool secondpass = false) {
segments.pix.isDup()[pixelSegmentArrayIndex] |= 1 + secondpass;
segmentsPixel.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 segments, bool secondpass) const {
ALPAKA_FN_ACC void operator()(TAcc const& acc, Modules modulesInGPU, SegmentsOccupancyConst segmentsOccupancy, SegmentsPixel segmentsPixel, 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 = segments.mod.nSegments()[pixelModuleIndex];
unsigned int nPixelSegments = segmentsOccupancy.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 && (!segments.pix.isQuad()[ix] || (segments.pix.isDup()[ix] & 1)))
if (secondpass && (!segmentsPixel.isQuad()[ix] || (segmentsPixel.isDup()[ix] & 1)))
continue;

unsigned int phits1[Params_pLS::kHits];
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];
phits1[0] = segmentsPixel.pLSHitsIdxs()[ix].x;
phits1[1] = segmentsPixel.pLSHitsIdxs()[ix].y;
phits1[2] = segmentsPixel.pLSHitsIdxs()[ix].z;
phits1[3] = segmentsPixel.pLSHitsIdxs()[ix].w;
float eta_pix1 = segmentsPixel.eta()[ix];
float phi_pix1 = segmentsPixel.phi()[ix];

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

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

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

int8_t quad_diff = segments.pix.isQuad()[ix] - segments.pix.isQuad()[jx];
float score_diff = segments.pix.score()[ix] - segments.pix.score()[jx];
int8_t quad_diff = segmentsPixel.isQuad()[ix] - segmentsPixel.isQuad()[jx];
float score_diff = segmentsPixel.score()[ix] - segmentsPixel.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] = 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;
phits2[0] = segmentsPixel.pLSHitsIdxs()[jx].x;
phits2[1] = segmentsPixel.pLSHitsIdxs()[jx].y;
phits2[2] = segmentsPixel.pLSHitsIdxs()[jx].z;
phits2[3] = segmentsPixel.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(segments, idxToRemove, secondpass);
rmPixelSegmentFromMemory(segmentsPixel, 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(segments, idxToRemove, secondpass);
rmPixelSegmentFromMemory(segmentsPixel, 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 segments,
SegmentsConst 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 =
segments.mem.mdIndices()[2 * tripletsInGPU.segmentIndices[2 * innerTripletIndex + layer2_adjustment]][0];
segments.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
42 changes: 23 additions & 19 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 segments,
SegmentsConst 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] =
segments.mem.innerLowerModuleIndices()[pixelIndex];
segments.innerLowerModuleIndices()[pixelIndex];
pixelQuintupletsInGPU.lowerModuleIndices[Params_pT5::kLayers * pixelQuintupletIndex + 1] =
segments.mem.outerLowerModuleIndices()[pixelIndex];
segments.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 = segments.mem.mdIndices()[Params_pLS::kLayers * pixelIndex][0];
unsigned int pixelOuterMD = segments.mem.mdIndices()[Params_pLS::kLayers * pixelIndex][1];
unsigned int pixelInnerMD = segments.mdIndices()[Params_pLS::kLayers * pixelIndex][0];
unsigned int pixelOuterMD = segments.mdIndices()[Params_pLS::kLayers * pixelIndex][1];

pixelQuintupletsInGPU.hitIndices[Params_pT5::kHits * pixelQuintupletIndex] =
mdsInGPU.anchorHitIndices[pixelInnerMD];
Expand Down Expand Up @@ -676,7 +676,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
Modules const& modulesInGPU,
ObjectRanges const& rangesInGPU,
MiniDoublets const& mdsInGPU,
Segments segments,
SegmentsConst segments,
SegmentsPixelConst segmentsPixel,
Triplets const& tripletsInGPU,
Quintuplets const& quintupletsInGPU,
unsigned int pixelSegmentIndex,
Expand All @@ -700,6 +701,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
rangesInGPU,
mdsInGPU,
segments,
segmentsPixel,
tripletsInGPU,
pixelSegmentIndex,
T5InnerT3Index,
Expand All @@ -718,13 +720,13 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
unsigned int thirdSegmentIndex = tripletsInGPU.segmentIndices[2 * T5OuterT3Index];
unsigned int fourthSegmentIndex = tripletsInGPU.segmentIndices[2 * T5OuterT3Index + 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];
unsigned int pixelInnerMDIndex = segments.mdIndices()[pixelSegmentIndex][0];
unsigned int pixelOuterMDIndex = segments.mdIndices()[pixelSegmentIndex][1];
unsigned int firstMDIndex = segments.mdIndices()[firstSegmentIndex][0];
unsigned int secondMDIndex = segments.mdIndices()[secondSegmentIndex][0];
unsigned int thirdMDIndex = segments.mdIndices()[secondSegmentIndex][1];
unsigned int fourthMDIndex = segments.mdIndices()[thirdSegmentIndex][1];
unsigned int fifthMDIndex = segments.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 +776,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
mdsInGPU.anchorY[fifthMDIndex]};

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

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

Expand All @@ -872,6 +875,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
rangesInGPU,
mdsInGPU,
segments,
segmentsPixel,
tripletsInGPU,
quintupletsInGPU,
pixelSegmentIndex,
Expand Down Expand Up @@ -918,7 +922,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

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

0 comments on commit acff43f

Please sign in to comment.