Skip to content

Commit

Permalink
Even further work on naming values and sqrt, loop, etc. simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
VourMa committed Jul 9, 2024
1 parent c563eb0 commit a3a8054
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 299 deletions.
32 changes: 10 additions & 22 deletions RecoTracker/LSTCore/interface/alpaka/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,16 @@ namespace SDL {
constexpr unsigned int size_superbins = 45000;

//defining the constant host device variables right up here
namespace objLayers {
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr int kpLS =
2; // Currently pixel tracks treated as LSs with 2 double layers (IT layers 1+2 and 3+4). To be potentially handled better in the future.
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr int kLS = 2;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr int kT3 = 3;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr int kpT3 = 5;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr int kT5 = 5;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr int kpT5 = 7;
} // namespace objLayers

namespace objHits {
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr int kpLS =
4; // Currently pixel tracks treated as LSs with 4 hits. To be potentially handled better in the future.
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr int kLS = 4;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr int kT3 = 6;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr int kpT3 = 10;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr int kT5 = 10;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr int kpT5 = 14;
} // namespace objHits

ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kMulsInGev2 =
0.015; // 15 MeV constant from the approximate Bethe-Bloch formula
// Currently pixel tracks treated as LSs with 2 double layers (IT layers 1+2 and 3+4) and 4 hits. To be potentially handled better in the future.
struct Params_pLS { static constexpr int kLayers = 2, kHits = 4; };
struct Params_LS { static constexpr int kLayers = 2, kHits = 4; };
struct Params_T3 { static constexpr int kLayers = 3, kHits = 6; };
struct Params_pT3 { static constexpr int kLayers = 5, kHits = 10; };
struct Params_T5 { static constexpr int kLayers = 5, kHits = 10; };
struct Params_pT5 { static constexpr int kLayers = 7, kHits = 14; };

// 15 MeV constant from the approximate Bethe-Bloch formula
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kMulsInGeV = 0.015;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float miniMulsPtScaleBarrel[6] = {
0.0052, 0.0038, 0.0034, 0.0034, 0.0032, 0.0034};
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float miniMulsPtScaleEndcap[5] = {0.006, 0.006, 0.006, 0.006, 0.006};
Expand Down
12 changes: 6 additions & 6 deletions RecoTracker/LSTCore/src/alpaka/Event.dev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1623,9 +1623,9 @@ SDL::tripletsBuffer<alpaka::DevCpu>* SDL::Event<SDL::Acc>::getTriplets() {
alpaka::memcpy(queue, tripletsInCPU->rtLo_buf, tripletsBuffers->rtLo_buf, nMemHost);
alpaka::memcpy(queue, tripletsInCPU->rtHi_buf, tripletsBuffers->rtHi_buf, nMemHost);
#endif
alpaka::memcpy(queue, tripletsInCPU->hitIndices_buf, tripletsBuffers->hitIndices_buf, objHits::kT3 * nMemHost);
alpaka::memcpy(queue, tripletsInCPU->hitIndices_buf, tripletsBuffers->hitIndices_buf, Params_T3::kHits * nMemHost);
alpaka::memcpy(
queue, tripletsInCPU->logicalLayers_buf, tripletsBuffers->logicalLayers_buf, objLayers::kT3 * nMemHost);
queue, tripletsInCPU->logicalLayers_buf, tripletsBuffers->logicalLayers_buf, Params_T3::kLayers * nMemHost);
alpaka::memcpy(queue, tripletsInCPU->segmentIndices_buf, tripletsBuffers->segmentIndices_buf, 2 * nMemHost);
alpaka::memcpy(queue, tripletsInCPU->betaIn_buf, tripletsBuffers->betaIn_buf, nMemHost);
alpaka::memcpy(queue, tripletsInCPU->circleRadius_buf, tripletsBuffers->circleRadius_buf, nMemHost);
Expand Down Expand Up @@ -1655,7 +1655,7 @@ SDL::quintupletsBuffer<alpaka::DevCpu>* SDL::Event<SDL::Acc>::getQuintuplets() {
alpaka::memcpy(queue,
quintupletsInCPU->lowerModuleIndices_buf,
quintupletsBuffers->lowerModuleIndices_buf,
objLayers::kT5 * nMemHost);
Params_T5::kLayers * nMemHost);
alpaka::memcpy(queue, quintupletsInCPU->innerRadius_buf, quintupletsBuffers->innerRadius_buf, nMemHost);
alpaka::memcpy(queue, quintupletsInCPU->bridgeRadius_buf, quintupletsBuffers->bridgeRadius_buf, nMemHost);
alpaka::memcpy(queue, quintupletsInCPU->outerRadius_buf, quintupletsBuffers->outerRadius_buf, nMemHost);
Expand Down Expand Up @@ -1763,13 +1763,13 @@ SDL::trackCandidatesBuffer<alpaka::DevCpu>* SDL::Event<SDL::Acc>::getTrackCandid
alpaka::memcpy(queue,
trackCandidatesInCPU->hitIndices_buf,
trackCandidatesBuffers->hitIndices_buf,
objHits::kpT5 * nTrackCanHost);
Params_pT5::kHits * nTrackCanHost);
alpaka::memcpy(
queue, trackCandidatesInCPU->pixelSeedIndex_buf, trackCandidatesBuffers->pixelSeedIndex_buf, nTrackCanHost);
alpaka::memcpy(queue,
trackCandidatesInCPU->logicalLayers_buf,
trackCandidatesBuffers->logicalLayers_buf,
objLayers::kpT5 * nTrackCanHost);
Params_pT5::kLayers * nTrackCanHost);
alpaka::memcpy(queue,
trackCandidatesInCPU->directObjectIndices_buf,
trackCandidatesBuffers->directObjectIndices_buf,
Expand Down Expand Up @@ -1801,7 +1801,7 @@ SDL::trackCandidatesBuffer<alpaka::DevCpu>* SDL::Event<SDL::Acc>::getTrackCandid
alpaka::memcpy(queue,
trackCandidatesInCPU->hitIndices_buf,
trackCandidatesBuffers->hitIndices_buf,
objHits::kpT5 * nTrackCanHost);
Params_pT5::kHits * nTrackCanHost);
alpaka::memcpy(
queue, trackCandidatesInCPU->pixelSeedIndex_buf, trackCandidatesBuffers->pixelSeedIndex_buf, nTrackCanHost);
alpaka::memcpy(queue,
Expand Down
76 changes: 38 additions & 38 deletions RecoTracker/LSTCore/src/alpaka/Kernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ namespace SDL {
ALPAKA_FN_ACC ALPAKA_FN_INLINE int checkHitsT5(unsigned int ix,
unsigned int jx,
struct SDL::quintuplets& quintupletsInGPU) {
unsigned int hits1[objHits::kT5];
unsigned int hits2[objHits::kT5];
unsigned int hits1[Params_T5::kHits];
unsigned int hits2[Params_T5::kHits];

for (int i = 0; i < objHits::kT5; i++) {
hits1[i] = quintupletsInGPU.hitIndices[objHits::kT5 * ix + i];
hits2[i] = quintupletsInGPU.hitIndices[objHits::kT5 * jx + i];
for (int i = 0; i < Params_T5::kHits; i++) {
hits1[i] = quintupletsInGPU.hitIndices[Params_T5::kHits * ix + i];
hits2[i] = quintupletsInGPU.hitIndices[Params_T5::kHits * jx + i];
}

int nMatched = 0;
for (int i = 0; i < objHits::kT5; i++) {
for (int i = 0; i < Params_T5::kHits; i++) {
bool matched = false;
for (int j = 0; j < objHits::kT5; j++) {
for (int j = 0; j < Params_T5::kHits; j++) {
if (hits1[i] == hits2[j]) {
matched = true;
break;
Expand All @@ -64,18 +64,18 @@ namespace SDL {
ALPAKA_FN_ACC ALPAKA_FN_INLINE int checkHitspT5(unsigned int ix,
unsigned int jx,
struct SDL::pixelQuintuplets& pixelQuintupletsInGPU) {
unsigned int hits1[objHits::kpT5];
unsigned int hits2[objHits::kpT5];
unsigned int hits1[Params_pT5::kHits];
unsigned int hits2[Params_pT5::kHits];

for (int i = 0; i < objHits::kpT5; i++) {
hits1[i] = pixelQuintupletsInGPU.hitIndices[objHits::kpT5 * ix + i];
hits2[i] = pixelQuintupletsInGPU.hitIndices[objHits::kpT5 * jx + i];
for (int i = 0; i < Params_pT5::kHits; i++) {
hits1[i] = pixelQuintupletsInGPU.hitIndices[Params_pT5::kHits * ix + i];
hits2[i] = pixelQuintupletsInGPU.hitIndices[Params_pT5::kHits * jx + i];
}

int nMatched = 0;
for (int i = 0; i < objHits::kpT5; i++) {
for (int i = 0; i < Params_pT5::kHits; i++) {
bool matched = false;
for (int j = 0; j < objHits::kpT5; j++) {
for (int j = 0; j < Params_pT5::kHits; j++) {
if (hits1[i] == hits2[j]) {
matched = true;
break;
Expand All @@ -92,18 +92,18 @@ namespace SDL {
unsigned int jx,
struct SDL::pixelTriplets& pixelTripletsInGPU,
int* matched) {
int phits1[objHits::kpLS];
int phits2[objHits::kpLS];
int phits1[Params_pLS::kHits];
int phits2[Params_pLS::kHits];

for (int i = 0; i < objHits::kpLS; i++) {
phits1[i] = pixelTripletsInGPU.hitIndices[objHits::kpT3 * ix + i];
phits2[i] = pixelTripletsInGPU.hitIndices[objHits::kpT3 * jx + i];
for (int i = 0; i < Params_pLS::kHits; i++) {
phits1[i] = pixelTripletsInGPU.hitIndices[Params_pT3::kHits * ix + i];
phits2[i] = pixelTripletsInGPU.hitIndices[Params_pT3::kHits * jx + i];
}

int npMatched = 0;
for (int i = 0; i < objHits::kpLS; i++) {
for (int i = 0; i < Params_pLS::kHits; i++) {
bool pmatched = false;
for (int j = 0; j < objHits::kpLS; j++) {
for (int j = 0; j < Params_pLS::kHits; j++) {
if (phits1[i] == phits2[j]) {
pmatched = true;
break;
Expand All @@ -114,18 +114,18 @@ namespace SDL {
}
}

int hits1[objHits::kT3];
int hits2[objHits::kT3];
int hits1[Params_T3::kHits];
int hits2[Params_T3::kHits];

for (int i = 0; i < objHits::kpLS; i++) {
hits1[i] = pixelTripletsInGPU.hitIndices[objHits::kpT3 * ix + i + 4]; // Omitting the pLS hits
hits2[i] = pixelTripletsInGPU.hitIndices[objHits::kpT3 * jx + i + 4]; // Omitting the pLS hits
for (int i = 0; i < Params_pLS::kHits; i++) {
hits1[i] = pixelTripletsInGPU.hitIndices[Params_pT3::kHits * ix + i + 4]; // Omitting the pLS hits
hits2[i] = pixelTripletsInGPU.hitIndices[Params_pT3::kHits * jx + i + 4]; // Omitting the pLS hits
}

int nMatched = 0;
for (int i = 0; i < objHits::kT3; i++) {
for (int i = 0; i < Params_T3::kHits; i++) {
bool tmatched = false;
for (int j = 0; j < objHits::kT3; j++) {
for (int j = 0; j < Params_T3::kHits; j++) {
if (hits1[i] == hits2[j]) {
tmatched = true;
break;
Expand Down Expand Up @@ -281,17 +281,17 @@ namespace SDL {
const int minNHitsForDup_pT3 = 5;
if ((nMatched[0] + nMatched[1]) >= minNHitsForDup_pT3) {
// Check the layers
if (pixelTripletsInGPU.logicalLayers[objLayers::kpT3 * jx + 2] <
pixelTripletsInGPU.logicalLayers[objLayers::kpT3 * ix + 2]) {
if (pixelTripletsInGPU.logicalLayers[Params_pT3::kLayers * jx + 2] <
pixelTripletsInGPU.logicalLayers[Params_pT3::kLayers * ix + 2]) {
rmPixelTripletFromMemory(pixelTripletsInGPU, ix);
break;
} else if (pixelTripletsInGPU.logicalLayers[objLayers::kpT3 * ix + 2] ==
pixelTripletsInGPU.logicalLayers[objLayers::kpT3 * jx + 2] &&
} else if (pixelTripletsInGPU.logicalLayers[Params_pT3::kLayers * ix + 2] ==
pixelTripletsInGPU.logicalLayers[Params_pT3::kLayers * jx + 2] &&
__H2F(pixelTripletsInGPU.score[ix]) > __H2F(pixelTripletsInGPU.score[jx])) {
rmPixelTripletFromMemory(pixelTripletsInGPU, ix);
break;
} else if (pixelTripletsInGPU.logicalLayers[objLayers::kpT3 * ix + 2] ==
pixelTripletsInGPU.logicalLayers[objLayers::kpT3 * jx + 2] &&
} else if (pixelTripletsInGPU.logicalLayers[Params_pT3::kLayers * ix + 2] ==
pixelTripletsInGPU.logicalLayers[Params_pT3::kLayers * jx + 2] &&
(__H2F(pixelTripletsInGPU.score[ix]) == __H2F(pixelTripletsInGPU.score[jx])) && (ix < jx)) {
rmPixelTripletFromMemory(pixelTripletsInGPU, ix);
break;
Expand Down Expand Up @@ -348,7 +348,7 @@ namespace SDL {
if (secondpass && (!segmentsInGPU.isQuad[ix] || (segmentsInGPU.isDup[ix] & 1)))
continue;

unsigned int phits1[objHits::kpLS];
unsigned int phits1[Params_pLS::kHits];
phits1[0] = segmentsInGPU.pLSHitsIdxs[ix].x;
phits1[1] = segmentsInGPU.pLSHitsIdxs[ix].y;
phits1[2] = segmentsInGPU.pLSHitsIdxs[ix].z;
Expand Down Expand Up @@ -381,16 +381,16 @@ namespace SDL {
else
idxToRemove = ix;

unsigned int phits2[objHits::kpLS];
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;

int npMatched = 0;
for (int i = 0; i < objHits::kpLS; i++) {
for (int i = 0; i < Params_pLS::kHits; i++) {
bool pmatched = false;
for (int j = 0; j < objHits::kpLS; j++) {
for (int j = 0; j < Params_pLS::kHits; j++) {
if (phits1[i] == phits2[j]) {
pmatched = true;
break;
Expand Down
10 changes: 5 additions & 5 deletions RecoTracker/LSTCore/src/alpaka/LST.dev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,16 +397,16 @@ std::vector<unsigned int> SDL::LST<SDL::Acc>::getHitIdxs(const short trackCandid

unsigned int maxNHits = 0;
if (trackCandidateType == 7)
maxNHits = objHits::kpT5; // pT5
maxNHits = Params_pT5::kHits; // pT5
else if (trackCandidateType == 5)
maxNHits = objHits::kpT3; // pT3
maxNHits = Params_pT3::kHits; // pT3
else if (trackCandidateType == 4)
maxNHits = objHits::kT5; // T5
maxNHits = Params_T5::kHits; // T5
else if (trackCandidateType == 8)
maxNHits = objHits::kpLS; // pLS
maxNHits = Params_pLS::kHits; // pLS

for (unsigned int i = 0; i < maxNHits; i++) {
unsigned int hitIdxInGPU = TCHitIndices[objHits::kpT5 * TCIdx + i];
unsigned int hitIdxInGPU = TCHitIndices[Params_pT5::kHits * TCIdx + i];
unsigned int hitIdx =
(trackCandidateType == 8)
? hitIdxInGPU
Expand Down
Loading

0 comments on commit a3a8054

Please sign in to comment.