Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Redundant Functions + 60% MD Speedup #98

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions RecoTracker/LSTCore/interface/alpaka/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ namespace lst {
// Since C++ can't represent infinity, lst_INF = 123456789 was used to represent infinity in the data table
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float lst_INF = 123456789.0;

ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kMiniDeltaTilted[3] = {0.26f, 0.26f, 0.26f};
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kMiniDeltaFlat[6] = {0.26f, 0.16f, 0.16f, 0.18f, 0.18f, 0.18f};
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kMiniDeltaLooseTilted[3] = {0.4f, 0.4f, 0.4f};
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kMiniDeltaEndcap[5][15] = {
{0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, /*10*/ 0.18f, 0.18f, 0.18f, 0.18f, 0.18f},
{0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, /*10*/ 0.18f, 0.18f, 0.18f, 0.18f, 0.18f},
{0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.18f, 0.18f, /*10*/ 0.18f, 0.18f, 0.18f, 0.18f, 0.18f},
{0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.18f, 0.18f, /*10*/ 0.18f, 0.18f, 0.18f, 0.18f, 0.18f},
{0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.18f, /*10*/ 0.18f, 0.18f, 0.18f, 0.18f, 0.18f}};

namespace t5dnn {

// Working points matching LST fake rate (43.9%) or signal acceptance (82.0%)
Expand Down
37 changes: 4 additions & 33 deletions RecoTracker/LSTCore/src/alpaka/MiniDoublet.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,35 +283,6 @@ namespace lst {
};

ALPAKA_FN_ACC ALPAKA_FN_INLINE float moduleGapSize(struct lst::Modules const& modulesInGPU, uint16_t moduleIndex) {
float miniDeltaTilted[3] = {0.26f, 0.26f, 0.26f};
float miniDeltaFlat[6] = {0.26f, 0.16f, 0.16f, 0.18f, 0.18f, 0.18f};
float miniDeltaLooseTilted[3] = {0.4f, 0.4f, 0.4f};
float miniDeltaEndcap[5][15];

for (size_t i = 0; i < 5; i++) {
Copy link
Member Author

@GNiendorf GNiendorf Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matrix creation code was being run many times, representing a significant portion of the MD creation time it seems like.

for (size_t j = 0; j < 15; j++) {
if (i == 0 || i == 1) {
if (j < 10) {
miniDeltaEndcap[i][j] = 0.4f;
} else {
miniDeltaEndcap[i][j] = 0.18f;
}
} else if (i == 2 || i == 3) {
if (j < 8) {
miniDeltaEndcap[i][j] = 0.4f;
} else {
miniDeltaEndcap[i][j] = 0.18f;
}
} else {
if (j < 9) {
miniDeltaEndcap[i][j] = 0.4f;
} else {
miniDeltaEndcap[i][j] = 0.18f;
}
}
}
}

unsigned int iL = modulesInGPU.layers[moduleIndex] - 1;
unsigned int iR = modulesInGPU.rings[moduleIndex] - 1;
short subdet = modulesInGPU.subdets[moduleIndex];
Expand All @@ -320,14 +291,14 @@ namespace lst {
float moduleSeparation = 0;

if (subdet == Barrel and side == Center) {
moduleSeparation = miniDeltaFlat[iL];
moduleSeparation = kMiniDeltaFlat[iL];
} else if (isTighterTiltedModules(modulesInGPU, moduleIndex)) {
moduleSeparation = miniDeltaTilted[iL];
moduleSeparation = kMiniDeltaTilted[iL];
} else if (subdet == Endcap) {
moduleSeparation = miniDeltaEndcap[iL][iR];
moduleSeparation = kMiniDeltaEndcap[iL][iR];
} else //Loose tilted modules
{
moduleSeparation = miniDeltaLooseTilted[iL];
moduleSeparation = kMiniDeltaLooseTilted[iL];
}

return moduleSeparation;
Expand Down
136 changes: 2 additions & 134 deletions RecoTracker/LSTCore/src/alpaka/PixelQuintuplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,138 +381,6 @@ namespace lst {
return true;
};

template <typename TAcc>
ALPAKA_FN_ACC ALPAKA_FN_INLINE float computeChiSquaredpT5(TAcc const& acc,
unsigned int nPoints,
float* xs,
float* ys,
float* delta1,
float* delta2,
float* slopes,
bool* isFlat,
float g,
float f,
float radius) {
/*
Given values of (g, f, radius) and a set of points (and its uncertainties) compute chi squared
*/
float c = g * g + f * f - radius * radius;
float chiSquared = 0.f;
float absArctanSlope, angleM, xPrime, yPrime, sigma2;
for (size_t i = 0; i < nPoints; i++) {
absArctanSlope = ((slopes[i] != lst::lst_INF) ? alpaka::math::abs(acc, alpaka::math::atan(acc, slopes[i]))
: 0.5f * float(M_PI));
if (xs[i] > 0 and ys[i] > 0) {
angleM = 0.5f * float(M_PI) - absArctanSlope;
} else if (xs[i] < 0 and ys[i] > 0) {
angleM = absArctanSlope + 0.5f * float(M_PI);
} else if (xs[i] < 0 and ys[i] < 0) {
angleM = -(absArctanSlope + 0.5f * float(M_PI));
} else if (xs[i] > 0 and ys[i] < 0) {
angleM = -(0.5f * float(M_PI) - absArctanSlope);
} else {
angleM = 0;
}
if (not isFlat[i]) {
xPrime = xs[i] * alpaka::math::cos(acc, angleM) + ys[i] * alpaka::math::sin(acc, angleM);
yPrime = ys[i] * alpaka::math::cos(acc, angleM) - xs[i] * alpaka::math::sin(acc, angleM);
} else {
xPrime = xs[i];
yPrime = ys[i];
}
sigma2 = 4 * ((xPrime * delta1[i]) * (xPrime * delta1[i]) + (yPrime * delta2[i]) * (yPrime * delta2[i]));
chiSquared += (xs[i] * xs[i] + ys[i] * ys[i] - 2 * g * xs[i] - 2 * f * ys[i] + c) *
(xs[i] * xs[i] + ys[i] * ys[i] - 2 * g * xs[i] - 2 * f * ys[i] + c) / (sigma2);
}
return chiSquared;
};

template <typename TAcc>
ALPAKA_FN_ACC ALPAKA_FN_INLINE void computeSigmasForRegression_pT5(TAcc const& acc,
lst::Modules const& modulesInGPU,
const uint16_t* lowerModuleIndices,
float* delta1,
float* delta2,
float* slopes,
bool* isFlat,
unsigned int nPoints = 5,
bool anchorHits = true) {
/*
bool anchorHits required to deal with a weird edge case wherein
the hits ultimately used in the regression are anchor hits, but the
lower modules need not all be Pixel Modules (in case of PS). Similarly,
when we compute the chi squared for the non-anchor hits, the "partner module"
need not always be a PS strip module, but all non-anchor hits sit on strip
modules.
*/
ModuleType moduleType;
short moduleSubdet, moduleSide;
float inv1 = kWidthPS / kWidth2S;
float inv2 = kPixelPSZpitch / kWidth2S;
float inv3 = kStripPSZpitch / kWidth2S;
for (size_t i = 0; i < nPoints; i++) {
moduleType = modulesInGPU.moduleType[lowerModuleIndices[i]];
moduleSubdet = modulesInGPU.subdets[lowerModuleIndices[i]];
moduleSide = modulesInGPU.sides[lowerModuleIndices[i]];
const float& drdz = modulesInGPU.drdzs[lowerModuleIndices[i]];
slopes[i] = modulesInGPU.dxdys[lowerModuleIndices[i]];
//category 1 - barrel PS flat
if (moduleSubdet == Barrel and moduleType == PS and moduleSide == Center) {
delta1[i] = inv1;
delta2[i] = inv1;
slopes[i] = -999.f;
isFlat[i] = true;
}
//category 2 - barrel 2S
else if (moduleSubdet == Barrel and moduleType == TwoS) {
delta1[i] = 1.f;
delta2[i] = 1.f;
slopes[i] = -999.f;
isFlat[i] = true;
}
//category 3 - barrel PS tilted
else if (moduleSubdet == Barrel and moduleType == PS and moduleSide != Center) {
delta1[i] = inv1;
isFlat[i] = false;

if (anchorHits) {
delta2[i] = (inv2 * drdz / alpaka::math::sqrt(acc, 1 + drdz * drdz));
} else {
delta2[i] = (inv3 * drdz / alpaka::math::sqrt(acc, 1 + drdz * drdz));
}
}
//category 4 - endcap PS
else if (moduleSubdet == Endcap and moduleType == PS) {
delta1[i] = inv1;
isFlat[i] = false;
/*
despite the type of the module layer of the lower module index,
all anchor hits are on the pixel side and all non-anchor hits are
on the strip side!
*/
if (anchorHits) {
delta2[i] = inv2;
} else {
delta2[i] = inv3;
}
}
//category 5 - endcap 2S
else if (moduleSubdet == Endcap and moduleType == TwoS) {
delta1[i] = 1.f;
delta2[i] = 500.f * inv1;
isFlat[i] = false;
}
#ifdef WARNINGS
else {
printf("ERROR!!!!! I SHOULDN'T BE HERE!!!! subdet = %d, type = %d, side = %d\n",
moduleSubdet,
moduleType,
moduleSide);
}
#endif
}
};

template <typename TAcc>
ALPAKA_FN_ACC ALPAKA_FN_INLINE float computePT5RPhiChiSquared(TAcc const& acc,
lst::Modules const& modulesInGPU,
Expand All @@ -530,8 +398,8 @@ namespace lst {
bool isFlat[5];
float chiSquared = 0;

computeSigmasForRegression_pT5(acc, modulesInGPU, lowerModuleIndices, delta1, delta2, slopes, isFlat);
chiSquared = computeChiSquaredpT5(acc, 5, xs, ys, delta1, delta2, slopes, isFlat, g, f, radius);
computeSigmasForRegression(acc, modulesInGPU, lowerModuleIndices, delta1, delta2, slopes, isFlat);
chiSquared = computeChiSquared(acc, 5, xs, ys, delta1, delta2, slopes, isFlat, g, f, radius);

return chiSquared;
};
Expand Down
Loading