Skip to content

Commit

Permalink
Merge pull request #82 from SegmentLinking/more_review_fixes
Browse files Browse the repository at this point in the history
More review fixes
  • Loading branch information
slava77 authored Aug 14, 2024
2 parents d3549cb + 22192ec commit c1767fa
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 46 deletions.
4 changes: 3 additions & 1 deletion RecoTracker/LSTCore/interface/alpaka/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

#include "RecoTracker/LSTCore/interface/Constants.h"

#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
#if defined ALPAKA_ACC_GPU_CUDA_ENABLED
#include <cuda_fp16.h>
#elif defined ALPAKA_ACC_GPU_HIP_ENABLED
#include <hip/hip_fp16.h>
#endif

namespace lst {
Expand Down
10 changes: 6 additions & 4 deletions RecoTracker/LSTCore/src/ModuleConnectionMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,17 @@ void lst::ModuleConnectionMap::add(std::string const& filename) {
connected_detids.push_back(connected_detid);
}

auto& thisModuleConnections = moduleConnections_.at(detid);

// Concatenate
moduleConnections_[detid].insert(moduleConnections_[detid].end(), connected_detids.begin(), connected_detids.end());
thisModuleConnections.insert(thisModuleConnections.end(), connected_detids.begin(), connected_detids.end());

// Sort
std::sort(moduleConnections_[detid].begin(), moduleConnections_[detid].end());
std::sort(thisModuleConnections.begin(), thisModuleConnections.end());

// Unique
moduleConnections_[detid].erase(std::unique(moduleConnections_[detid].begin(), moduleConnections_[detid].end()),
moduleConnections_[detid].end());
thisModuleConnections.erase(std::unique(thisModuleConnections.begin(), thisModuleConnections.end()),
thisModuleConnections.end());
}
}

Expand Down
10 changes: 6 additions & 4 deletions RecoTracker/LSTCore/src/alpaka/Hit.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,15 @@ namespace lst {
hitsInGPU.lowEdgeYs[ihit] = ihit_y - 2.5f * sin_phi;
}
// Need to set initial value if index hasn't been seen before.
int old = alpaka::atomicOp<alpaka::AtomicCas>(
acc, &(hitsInGPU.hitRanges[lastModuleIndex * 2]), -1, static_cast<int>(ihit));
int old = alpaka::atomicCas(
acc, &(hitsInGPU.hitRanges[lastModuleIndex * 2]), -1, static_cast<int>(ihit), alpaka::hierarchy::Threads{});
// For subsequent visits, stores the min value.
if (old != -1)
alpaka::atomicOp<alpaka::AtomicMin>(acc, &hitsInGPU.hitRanges[lastModuleIndex * 2], static_cast<int>(ihit));
alpaka::atomicMin(
acc, &hitsInGPU.hitRanges[lastModuleIndex * 2], static_cast<int>(ihit), alpaka::hierarchy::Threads{});

alpaka::atomicOp<alpaka::AtomicMax>(acc, &hitsInGPU.hitRanges[lastModuleIndex * 2 + 1], static_cast<int>(ihit));
alpaka::atomicMax(
acc, &hitsInGPU.hitRanges[lastModuleIndex * 2 + 1], static_cast<int>(ihit), alpaka::hierarchy::Threads{});
}
}
};
Expand Down
7 changes: 4 additions & 3 deletions RecoTracker/LSTCore/src/alpaka/MiniDoublet.h
Original file line number Diff line number Diff line change
Expand Up @@ -932,13 +932,14 @@ namespace lst {
rtUpper);
if (success) {
int totOccupancyMDs =
alpaka::atomicOp<alpaka::AtomicAdd>(acc, &mdsInGPU.totOccupancyMDs[lowerModuleIndex], 1u);
alpaka::atomicAdd(acc, &mdsInGPU.totOccupancyMDs[lowerModuleIndex], 1u, alpaka::hierarchy::Threads{});
if (totOccupancyMDs >= (rangesInGPU.miniDoubletModuleOccupancy[lowerModuleIndex])) {
#ifdef WARNINGS
printf("Mini-doublet excess alert! Module index = %d\n", lowerModuleIndex);
#endif
} else {
int mdModuleIndex = alpaka::atomicOp<alpaka::AtomicAdd>(acc, &mdsInGPU.nMDs[lowerModuleIndex], 1u);
int mdModuleIndex =
alpaka::atomicAdd(acc, &mdsInGPU.nMDs[lowerModuleIndex], 1u, alpaka::hierarchy::Threads{});
unsigned int mdIndex = rangesInGPU.miniDoubletModuleIndices[lowerModuleIndex] + mdModuleIndex;

addMDToMemory(acc,
Expand Down Expand Up @@ -1041,7 +1042,7 @@ namespace lst {
#endif
}

unsigned int nTotMDs = alpaka::atomicOp<alpaka::AtomicAdd>(acc, &nTotalMDs, occupancy);
unsigned int nTotMDs = alpaka::atomicAdd(acc, &nTotalMDs, occupancy, alpaka::hierarchy::Threads{});

rangesInGPU.miniDoubletModuleIndices[i] = nTotMDs;
rangesInGPU.miniDoubletModuleOccupancy[i] = occupancy;
Expand Down
6 changes: 3 additions & 3 deletions RecoTracker/LSTCore/src/alpaka/PixelQuintuplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -901,15 +901,15 @@ namespace lst {
centerY,
static_cast<unsigned int>(i_pLS));
if (success) {
unsigned int totOccupancyPixelQuintuplets =
alpaka::atomicOp<alpaka::AtomicAdd>(acc, pixelQuintupletsInGPU.totOccupancyPixelQuintuplets, 1u);
unsigned int totOccupancyPixelQuintuplets = alpaka::atomicAdd(
acc, pixelQuintupletsInGPU.totOccupancyPixelQuintuplets, 1u, alpaka::hierarchy::Threads{});
if (totOccupancyPixelQuintuplets >= n_max_pixel_quintuplets) {
#ifdef WARNINGS
printf("Pixel Quintuplet excess alert!\n");
#endif
} else {
unsigned int pixelQuintupletIndex =
alpaka::atomicOp<alpaka::AtomicAdd>(acc, pixelQuintupletsInGPU.nPixelQuintuplets, 1u);
alpaka::atomicAdd(acc, pixelQuintupletsInGPU.nPixelQuintuplets, 1u, alpaka::hierarchy::Threads{});
float eta = __H2F(quintupletsInGPU.eta[quintupletIndex]);
float phi = __H2F(quintupletsInGPU.phi[quintupletIndex]);

Expand Down
6 changes: 3 additions & 3 deletions RecoTracker/LSTCore/src/alpaka/PixelTriplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1025,15 +1025,15 @@ namespace lst {
float phi_pix = segmentsInGPU.phi[i_pLS];
float pt = segmentsInGPU.ptIn[i_pLS];
float score = rPhiChiSquared + rPhiChiSquaredInwards;
unsigned int totOccupancyPixelTriplets =
alpaka::atomicOp<alpaka::AtomicAdd>(acc, pixelTripletsInGPU.totOccupancyPixelTriplets, 1u);
unsigned int totOccupancyPixelTriplets = alpaka::atomicAdd(
acc, pixelTripletsInGPU.totOccupancyPixelTriplets, 1u, alpaka::hierarchy::Threads{});
if (totOccupancyPixelTriplets >= n_max_pixel_triplets) {
#ifdef WARNINGS
printf("Pixel Triplet excess alert!\n");
#endif
} else {
unsigned int pixelTripletIndex =
alpaka::atomicOp<alpaka::AtomicAdd>(acc, pixelTripletsInGPU.nPixelTriplets, 1u);
alpaka::atomicAdd(acc, pixelTripletsInGPU.nPixelTriplets, 1u, alpaka::hierarchy::Threads{});
addPixelTripletToMemory(mdsInGPU,
segmentsInGPU,
tripletsInGPU,
Expand Down
12 changes: 6 additions & 6 deletions RecoTracker/LSTCore/src/alpaka/Quintuplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -2602,15 +2602,15 @@ namespace lst {
TightCutFlag);

if (success) {
int totOccupancyQuintuplets =
alpaka::atomicOp<alpaka::AtomicAdd>(acc, &quintupletsInGPU.totOccupancyQuintuplets[lowerModule1], 1u);
int totOccupancyQuintuplets = alpaka::atomicAdd(
acc, &quintupletsInGPU.totOccupancyQuintuplets[lowerModule1], 1u, alpaka::hierarchy::Threads{});
if (totOccupancyQuintuplets >= rangesInGPU.quintupletModuleOccupancy[lowerModule1]) {
#ifdef WARNINGS
printf("Quintuplet excess alert! Module index = %d\n", lowerModule1);
#endif
} else {
int quintupletModuleIndex =
alpaka::atomicOp<alpaka::AtomicAdd>(acc, &quintupletsInGPU.nQuintuplets[lowerModule1], 1u);
int quintupletModuleIndex = alpaka::atomicAdd(
acc, &quintupletsInGPU.nQuintuplets[lowerModule1], 1u, alpaka::hierarchy::Threads{});
//this if statement should never get executed!
if (rangesInGPU.quintupletModuleIndices[lowerModule1] == -1) {
#ifdef WARNINGS
Expand Down Expand Up @@ -2700,7 +2700,7 @@ namespace lst {
if (module_subdets == lst::Endcap and module_layers > 1)
continue;

int nEligibleT5Modules = alpaka::atomicOp<alpaka::AtomicAdd>(acc, &nEligibleT5Modulesx, 1);
int nEligibleT5Modules = alpaka::atomicAdd(acc, &nEligibleT5Modulesx, 1, alpaka::hierarchy::Threads{});

if (module_layers <= 3 && module_subdets == 5)
category_number = 0;
Expand Down Expand Up @@ -2749,7 +2749,7 @@ namespace lst {
#endif
}

int nTotQ = alpaka::atomicOp<alpaka::AtomicAdd>(acc, &nTotalQuintupletsx, occupancy);
int nTotQ = alpaka::atomicAdd(acc, &nTotalQuintupletsx, occupancy, alpaka::hierarchy::Threads{});
rangesInGPU.quintupletModuleIndices[i] = nTotQ;
rangesInGPU.indicesOfEligibleT5Modules[nEligibleT5Modules] = i;
rangesInGPU.quintupletModuleOccupancy[i] = occupancy;
Expand Down
10 changes: 5 additions & 5 deletions RecoTracker/LSTCore/src/alpaka/Segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -763,15 +763,15 @@ namespace lst {
dPhiChange,
dPhiChangeMin,
dPhiChangeMax)) {
unsigned int totOccupancySegments = alpaka::atomicOp<alpaka::AtomicAdd>(
acc, &segmentsInGPU.totOccupancySegments[innerLowerModuleIndex], 1u);
unsigned int totOccupancySegments = alpaka::atomicAdd(
acc, &segmentsInGPU.totOccupancySegments[innerLowerModuleIndex], 1u, alpaka::hierarchy::Threads{});
if (static_cast<int>(totOccupancySegments) >= rangesInGPU.segmentModuleOccupancy[innerLowerModuleIndex]) {
#ifdef WARNINGS
printf("Segment excess alert! Module index = %d\n", innerLowerModuleIndex);
#endif
} else {
unsigned int segmentModuleIdx =
alpaka::atomicOp<alpaka::AtomicAdd>(acc, &segmentsInGPU.nSegments[innerLowerModuleIndex], 1u);
unsigned int segmentModuleIdx = alpaka::atomicAdd(
acc, &segmentsInGPU.nSegments[innerLowerModuleIndex], 1u, alpaka::hierarchy::Threads{});
unsigned int segmentIdx = rangesInGPU.segmentModuleIndices[innerLowerModuleIndex] + segmentModuleIdx;

addSegmentToMemory(segmentsInGPU,
Expand Down Expand Up @@ -882,7 +882,7 @@ namespace lst {
#endif
}

int nTotSegs = alpaka::atomicOp<alpaka::AtomicAdd>(acc, &nTotalSegments, occupancy);
int nTotSegs = alpaka::atomicAdd(acc, &nTotalSegments, occupancy, alpaka::hierarchy::Threads{});
rangesInGPU.segmentModuleIndices[i] = nTotSegs;
rangesInGPU.segmentModuleOccupancy[i] = occupancy;
}
Expand Down
24 changes: 12 additions & 12 deletions RecoTracker/LSTCore/src/alpaka/TrackCandidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,17 +401,17 @@ namespace lst {
continue;

unsigned int trackCandidateIdx =
alpaka::atomicOp<alpaka::AtomicAdd>(acc, trackCandidatesInGPU.nTrackCandidates, 1u);
alpaka::atomicAdd(acc, trackCandidatesInGPU.nTrackCandidates, 1u, alpaka::hierarchy::Threads{});
if (trackCandidateIdx >= n_max_pixel_track_candidates) // This is done before any non-pixel TCs are added
{
#ifdef WARNINGS
printf("Track Candidate excess alert! Type = pT3");
#endif
alpaka::atomicOp<alpaka::AtomicSub>(acc, trackCandidatesInGPU.nTrackCandidates, 1u);
alpaka::atomicSub(acc, trackCandidatesInGPU.nTrackCandidates, 1u, alpaka::hierarchy::Threads{});
break;

} else {
alpaka::atomicOp<alpaka::AtomicAdd>(acc, trackCandidatesInGPU.nTrackCandidatespT3, 1u);
alpaka::atomicAdd(acc, trackCandidatesInGPU.nTrackCandidatespT3, 1u, alpaka::hierarchy::Threads{});

float radius = 0.5f * (__H2F(pixelTripletsInGPU.pixelRadius[pixelTripletIndex]) +
__H2F(pixelTripletsInGPU.tripletRadius[pixelTripletIndex]));
Expand Down Expand Up @@ -457,18 +457,18 @@ namespace lst {
continue;

unsigned int trackCandidateIdx =
alpaka::atomicOp<alpaka::AtomicAdd>(acc, trackCandidatesInGPU.nTrackCandidates, 1u);
alpaka::atomicAdd(acc, trackCandidatesInGPU.nTrackCandidates, 1u, alpaka::hierarchy::Threads{});
if (trackCandidateIdx - *trackCandidatesInGPU.nTrackCandidatespT5 -
*trackCandidatesInGPU.nTrackCandidatespT3 >=
n_max_nonpixel_track_candidates) // pT5 and pT3 TCs have been added, but not pLS TCs
{
#ifdef WARNINGS
printf("Track Candidate excess alert! Type = T5");
#endif
alpaka::atomicOp<alpaka::AtomicSub>(acc, trackCandidatesInGPU.nTrackCandidates, 1u);
alpaka::atomicSub(acc, trackCandidatesInGPU.nTrackCandidates, 1u, alpaka::hierarchy::Threads{});
break;
} else {
alpaka::atomicOp<alpaka::AtomicAdd>(acc, trackCandidatesInGPU.nTrackCandidatesT5, 1u);
alpaka::atomicAdd(acc, trackCandidatesInGPU.nTrackCandidatesT5, 1u, alpaka::hierarchy::Threads{});
addTrackCandidateToMemory(trackCandidatesInGPU,
4 /*track candidate type T5=4*/,
quintupletIndex,
Expand Down Expand Up @@ -505,18 +505,18 @@ namespace lst {
continue;

unsigned int trackCandidateIdx =
alpaka::atomicOp<alpaka::AtomicAdd>(acc, trackCandidatesInGPU.nTrackCandidates, 1u);
alpaka::atomicAdd(acc, trackCandidatesInGPU.nTrackCandidates, 1u, alpaka::hierarchy::Threads{});
if (trackCandidateIdx - *trackCandidatesInGPU.nTrackCandidatesT5 >=
n_max_pixel_track_candidates) // T5 TCs have already been added
{
#ifdef WARNINGS
printf("Track Candidate excess alert! Type = pLS");
#endif
alpaka::atomicOp<alpaka::AtomicSub>(acc, trackCandidatesInGPU.nTrackCandidates, 1u);
alpaka::atomicSub(acc, trackCandidatesInGPU.nTrackCandidates, 1u, alpaka::hierarchy::Threads{});
break;

} else {
alpaka::atomicOp<alpaka::AtomicAdd>(acc, trackCandidatesInGPU.nTrackCandidatespLS, 1u);
alpaka::atomicAdd(acc, trackCandidatesInGPU.nTrackCandidatespLS, 1u, alpaka::hierarchy::Threads{});
addpLSTrackCandidateToMemory(trackCandidatesInGPU,
pixelArrayIndex,
trackCandidateIdx,
Expand Down Expand Up @@ -546,17 +546,17 @@ namespace lst {
continue;

unsigned int trackCandidateIdx =
alpaka::atomicOp<alpaka::AtomicAdd>(acc, trackCandidatesInGPU.nTrackCandidates, 1u);
alpaka::atomicAdd(acc, trackCandidatesInGPU.nTrackCandidates, 1u, alpaka::hierarchy::Threads{});
if (trackCandidateIdx >= n_max_pixel_track_candidates) // No other TCs have been added yet
{
#ifdef WARNINGS
printf("Track Candidate excess alert! Type = pT5");
#endif
alpaka::atomicOp<alpaka::AtomicSub>(acc, trackCandidatesInGPU.nTrackCandidates, 1u);
alpaka::atomicSub(acc, trackCandidatesInGPU.nTrackCandidates, 1u, alpaka::hierarchy::Threads{});
break;

} else {
alpaka::atomicOp<alpaka::AtomicAdd>(acc, trackCandidatesInGPU.nTrackCandidatespT5, 1u);
alpaka::atomicAdd(acc, trackCandidatesInGPU.nTrackCandidatespT5, 1u, alpaka::hierarchy::Threads{});

float radius = 0.5f * (__H2F(pixelQuintupletsInGPU.pixelRadius[pixelQuintupletIndex]) +
__H2F(pixelQuintupletsInGPU.quintupletRadius[pixelQuintupletIndex]));
Expand Down
13 changes: 8 additions & 5 deletions RecoTracker/LSTCore/src/alpaka/Triplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -868,16 +868,19 @@ namespace lst {
circleCenterY);

if (success) {
unsigned int totOccupancyTriplets = alpaka::atomicOp<alpaka::AtomicAdd>(
acc, &tripletsInGPU.totOccupancyTriplets[innerInnerLowerModuleIndex], 1u);
unsigned int totOccupancyTriplets =
alpaka::atomicAdd(acc,
&tripletsInGPU.totOccupancyTriplets[innerInnerLowerModuleIndex],
1u,
alpaka::hierarchy::Threads{});
if (static_cast<int>(totOccupancyTriplets) >=
rangesInGPU.tripletModuleOccupancy[innerInnerLowerModuleIndex]) {
#ifdef WARNINGS
printf("Triplet excess alert! Module index = %d\n", innerInnerLowerModuleIndex);
#endif
} else {
unsigned int tripletModuleIndex =
alpaka::atomicOp<alpaka::AtomicAdd>(acc, &tripletsInGPU.nTriplets[innerInnerLowerModuleIndex], 1u);
unsigned int tripletModuleIndex = alpaka::atomicAdd(
acc, &tripletsInGPU.nTriplets[innerInnerLowerModuleIndex], 1u, alpaka::hierarchy::Threads{});
unsigned int tripletIndex =
rangesInGPU.tripletModuleIndices[innerInnerLowerModuleIndex] + tripletModuleIndex;
#ifdef CUT_VALUE_DEBUG
Expand Down Expand Up @@ -1009,7 +1012,7 @@ namespace lst {
}

rangesInGPU.tripletModuleOccupancy[i] = occupancy;
unsigned int nTotT = alpaka::atomicOp<alpaka::AtomicAdd>(acc, &nTotalTriplets, occupancy);
unsigned int nTotT = alpaka::atomicAdd(acc, &nTotalTriplets, occupancy, alpaka::hierarchy::Threads{});
rangesInGPU.tripletModuleIndices[i] = nTotT;
}

Expand Down

0 comments on commit c1767fa

Please sign in to comment.