Skip to content

Commit

Permalink
Merge pull request #54 from SegmentLinking/CMSSW_14_1_0_pre3_LST_X_LS…
Browse files Browse the repository at this point in the history
…TCore_realfiles_lowptocc

Add Low pT Occupancies
  • Loading branch information
slava77 authored Jul 5, 2024
2 parents 013be2f + 9633ad1 commit d944fbf
Show file tree
Hide file tree
Showing 6 changed files with 751 additions and 216 deletions.
13 changes: 8 additions & 5 deletions RecoTracker/LSTCore/src/alpaka/Event.dev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void SDL::Event<SDL::Acc>::addPixelSegmentToEvent(std::vector<unsigned int> hitI

SDL::createMDArrayRangesGPU createMDArrayRangesGPU_kernel;
auto const createMDArrayRangesGPUTask(alpaka::createTaskKernel<Acc>(
createMDArrayRangesGPU_workDiv, createMDArrayRangesGPU_kernel, *modulesBuffers_->data(), *rangesInGPU));
createMDArrayRangesGPU_workDiv, createMDArrayRangesGPU_kernel, *modulesBuffers_->data(), *rangesInGPU, ptCut));

alpaka::enqueue(queue, createMDArrayRangesGPUTask);
alpaka::wait(queue);
Expand Down Expand Up @@ -299,7 +299,8 @@ void SDL::Event<SDL::Acc>::addPixelSegmentToEvent(std::vector<unsigned int> hitI
createSegmentArrayRanges_kernel,
*modulesBuffers_->data(),
*rangesInGPU,
*mdsInGPU));
*mdsInGPU,
ptCut));

alpaka::enqueue(queue, createSegmentArrayRangesTask);
alpaka::wait(queue);
Expand Down Expand Up @@ -409,7 +410,7 @@ void SDL::Event<SDL::Acc>::createMiniDoublets() {

SDL::createMDArrayRangesGPU createMDArrayRangesGPU_kernel;
auto const createMDArrayRangesGPUTask(alpaka::createTaskKernel<Acc>(
createMDArrayRangesGPU_workDiv, createMDArrayRangesGPU_kernel, *modulesBuffers_->data(), *rangesInGPU));
createMDArrayRangesGPU_workDiv, createMDArrayRangesGPU_kernel, *modulesBuffers_->data(), *rangesInGPU, ptCut));

alpaka::enqueue(queue, createMDArrayRangesGPUTask);
alpaka::wait(queue);
Expand Down Expand Up @@ -523,7 +524,8 @@ void SDL::Event<SDL::Acc>::createTriplets() {
createTripletArrayRanges_kernel,
*modulesBuffers_->data(),
*rangesInGPU,
*segmentsInGPU));
*segmentsInGPU,
ptCut));

alpaka::enqueue(queue, createTripletArrayRangesTask);
alpaka::wait(queue);
Expand Down Expand Up @@ -917,7 +919,8 @@ void SDL::Event<SDL::Acc>::createQuintuplets() {
createEligibleModulesListForQuintupletsGPU_kernel,
*modulesBuffers_->data(),
*tripletsInGPU,
*rangesInGPU));
*rangesInGPU,
ptCut));

alpaka::enqueue(queue, createEligibleModulesListForQuintupletsGPUTask);
alpaka::wait(queue);
Expand Down
115 changes: 61 additions & 54 deletions RecoTracker/LSTCore/src/alpaka/MiniDoublet.h
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,8 @@ namespace SDL {
alpaka::atomicOp<alpaka::AtomicAdd>(acc, &mdsInGPU.totOccupancyMDs[lowerModuleIndex], 1u);
if (totOccupancyMDs >= (rangesInGPU.miniDoubletModuleOccupancy[lowerModuleIndex])) {
#ifdef Warnings
printf("Mini-doublet excess alert! Module index = %d\n", lowerModuleIndex);
printf(
"Mini-doublet excess alert! Module index = %d, Occupancy = %d\n", lowerModuleIndex, totOccupancyMDs);
#endif
} else {
int mdModuleIndex = alpaka::atomicOp<alpaka::AtomicAdd>(acc, &mdsInGPU.nMDs[lowerModuleIndex], 1u);
Expand Down Expand Up @@ -994,11 +995,41 @@ namespace SDL {
}
};

// Helper function to determine eta bin for occupancies
ALPAKA_FN_ACC ALPAKA_FN_INLINE int getEtaBin(const float module_eta) {
if (module_eta < 0.75f)
return 0;
else if (module_eta < 1.5f)
return 1;
else if (module_eta < 2.25f)
return 2;
else if (module_eta < 3.0f)
return 3;
return -1;
}

// Helper function to determine category number for occupancies
ALPAKA_FN_ACC ALPAKA_FN_INLINE int getCategoryNumber(const short module_layers,
const short module_subdets,
const short module_rings) {
if (module_subdets == SDL::Barrel) {
return (module_layers <= 3) ? 0 : 1;
} else if (module_subdets == SDL::Endcap) {
if (module_layers <= 2) {
return (module_rings >= 11) ? 2 : 3;
} else {
return (module_rings >= 8) ? 2 : 3;
}
}
return -1;
}

struct createMDArrayRangesGPU {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(TAcc const& acc,
struct SDL::modules modulesInGPU,
struct SDL::objectRanges rangesInGPU) const {
struct SDL::objectRanges rangesInGPU,
const float ptCut) const {
auto const globalThreadIdx = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc);
auto const gridThreadExtent = alpaka::getWorkDiv<alpaka::Grid, alpaka::Threads>(acc);

Expand All @@ -1007,76 +1038,52 @@ namespace SDL {
nTotalMDs = 0;
alpaka::syncBlockThreads(acc);

// Initialize variables outside of the for loop.
int occupancy, category_number, eta_number;
// Occupancy matrix for 0.8 GeV pT Cut
constexpr int p08_occupancy_matrix[4][4] = {
{49, 42, 37, 41}, // category 0
{100, 100, 0, 0}, // category 1
{0, 16, 19, 0}, // category 2
{0, 14, 20, 25} // category 3
};

// Occupancy matrix for 0.6 GeV pT Cut, 99.99%
constexpr int p06_occupancy_matrix[4][4] = {
{60, 57, 54, 48}, // category 0
{259, 195, 0, 0}, // category 1
{0, 23, 28, 0}, // category 2
{0, 25, 25, 33} // category 3
};

// Select the appropriate occupancy matrix based on ptCut
const auto& occupancy_matrix = (ptCut < 0.8f) ? p06_occupancy_matrix : p08_occupancy_matrix;

for (uint16_t i = globalThreadIdx[2]; i < *modulesInGPU.nLowerModules; i += gridThreadExtent[2]) {
short module_rings = modulesInGPU.rings[i];
short module_layers = modulesInGPU.layers[i];
short module_subdets = modulesInGPU.subdets[i];
float module_eta = alpaka::math::abs(acc, modulesInGPU.eta[i]);

if (module_layers <= 3 && module_subdets == 5)
category_number = 0;
else if (module_layers >= 4 && module_subdets == 5)
category_number = 1;
else if (module_layers <= 2 && module_subdets == 4 && module_rings >= 11)
category_number = 2;
else if (module_layers >= 3 && module_subdets == 4 && module_rings >= 8)
category_number = 2;
else if (module_layers <= 2 && module_subdets == 4 && module_rings <= 10)
category_number = 3;
else if (module_layers >= 3 && module_subdets == 4 && module_rings <= 7)
category_number = 3;
else
category_number = -1;

if (module_eta < 0.75)
eta_number = 0;
else if (module_eta > 0.75 && module_eta < 1.5)
eta_number = 1;
else if (module_eta > 1.5 && module_eta < 2.25)
eta_number = 2;
else if (module_eta > 2.25 && module_eta < 3)
eta_number = 3;
else
eta_number = -1;

if (category_number == 0 && eta_number == 0)
occupancy = 49;
else if (category_number == 0 && eta_number == 1)
occupancy = 42;
else if (category_number == 0 && eta_number == 2)
occupancy = 37;
else if (category_number == 0 && eta_number == 3)
occupancy = 41;
else if (category_number == 1)
occupancy = 100;
else if (category_number == 2 && eta_number == 1)
occupancy = 16;
else if (category_number == 2 && eta_number == 2)
occupancy = 19;
else if (category_number == 3 && eta_number == 1)
occupancy = 14;
else if (category_number == 3 && eta_number == 2)
occupancy = 20;
else if (category_number == 3 && eta_number == 3)
occupancy = 25;
else {
occupancy = 0;
int category_number = getCategoryNumber(module_layers, module_subdets, module_rings);
int eta_number = getEtaBin(module_eta);

int occupancy = 0;
if (category_number != -1 && eta_number != -1) {
occupancy = occupancy_matrix[category_number][eta_number];
}
#ifdef Warnings
else {
printf("Unhandled case in createMDArrayRangesGPU! Module index = %i\n", i);
#endif
}
#endif

unsigned int nTotMDs = alpaka::atomicOp<alpaka::AtomicAdd>(acc, &nTotalMDs, occupancy);

rangesInGPU.miniDoubletModuleIndices[i] = nTotMDs;
rangesInGPU.miniDoubletModuleOccupancy[i] = occupancy;
}

// Wait for all threads to finish before reporting final values
alpaka::syncBlockThreads(acc);

if (globalThreadIdx[2] == 0) {
rangesInGPU.miniDoubletModuleIndices[*modulesInGPU.nLowerModules] = nTotalMDs;
*rangesInGPU.device_nTotalMDs = nTotalMDs;
Expand Down
79 changes: 32 additions & 47 deletions RecoTracker/LSTCore/src/alpaka/Quintuplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -3063,7 +3063,9 @@ namespace SDL {
alpaka::atomicOp<alpaka::AtomicAdd>(acc, &quintupletsInGPU.totOccupancyQuintuplets[lowerModule1], 1u);
if (totOccupancyQuintuplets >= rangesInGPU.quintupletModuleOccupancy[lowerModule1]) {
#ifdef Warnings
printf("Quintuplet excess alert! Module index = %d\n", lowerModule1);
printf("Quintuplet excess alert! Module index = %d, Occupancy = %d\n",
lowerModule1,
totOccupancyQuintuplets);
#endif
} else {
int quintupletModuleIndex =
Expand Down Expand Up @@ -3126,7 +3128,8 @@ namespace SDL {
ALPAKA_FN_ACC void operator()(TAcc const& acc,
struct SDL::modules modulesInGPU,
struct SDL::triplets tripletsInGPU,
struct SDL::objectRanges rangesInGPU) const {
struct SDL::objectRanges rangesInGPU,
const float ptCut) const {
auto const globalThreadIdx = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc);
auto const gridThreadExtent = alpaka::getWorkDiv<alpaka::Grid, alpaka::Threads>(acc);

Expand All @@ -3137,8 +3140,24 @@ namespace SDL {
nEligibleT5Modulesx = 0;
alpaka::syncBlockThreads(acc);

// Initialize variables outside of the for loop.
int occupancy, category_number, eta_number;
// Occupancy matrix for 0.8 GeV pT Cut
constexpr int p08_occupancy_matrix[4][4] = {
{336, 414, 231, 146}, // category 0
{0, 0, 0, 0}, // category 1
{0, 0, 0, 0}, // category 2
{0, 0, 191, 106} // category 3
};

// Occupancy matrix for 0.6 GeV pT Cut, 99.99%
constexpr int p06_occupancy_matrix[4][4] = {
{325, 237, 217, 176}, // category 0
{0, 0, 0, 0}, // category 1
{0, 0, 0, 0}, // category 2
{0, 0, 129, 180} // category 3
};

// Select the appropriate occupancy matrix based on ptCut
const auto& occupancy_matrix = (ptCut < 0.8f) ? p06_occupancy_matrix : p08_occupancy_matrix;

for (int i = globalThreadIdx[2]; i < *modulesInGPU.nLowerModules; i += gridThreadExtent[2]) {
// Condition for a quintuple to exist for a module
Expand All @@ -3157,52 +3176,18 @@ namespace SDL {

int nEligibleT5Modules = alpaka::atomicOp<alpaka::AtomicAdd>(acc, &nEligibleT5Modulesx, 1);

if (module_layers <= 3 && module_subdets == 5)
category_number = 0;
else if (module_layers >= 4 && module_subdets == 5)
category_number = 1;
else if (module_layers <= 2 && module_subdets == 4 && module_rings >= 11)
category_number = 2;
else if (module_layers >= 3 && module_subdets == 4 && module_rings >= 8)
category_number = 2;
else if (module_layers <= 2 && module_subdets == 4 && module_rings <= 10)
category_number = 3;
else if (module_layers >= 3 && module_subdets == 4 && module_rings <= 7)
category_number = 3;
else
category_number = -1;

if (module_eta < 0.75)
eta_number = 0;
else if (module_eta > 0.75 && module_eta < 1.5)
eta_number = 1;
else if (module_eta > 1.5 && module_eta < 2.25)
eta_number = 2;
else if (module_eta > 2.25 && module_eta < 3)
eta_number = 3;
else
eta_number = -1;

if (category_number == 0 && eta_number == 0)
occupancy = 336;
else if (category_number == 0 && eta_number == 1)
occupancy = 414;
else if (category_number == 0 && eta_number == 2)
occupancy = 231;
else if (category_number == 0 && eta_number == 3)
occupancy = 146;
else if (category_number == 3 && eta_number == 1)
occupancy = 0;
else if (category_number == 3 && eta_number == 2)
occupancy = 191;
else if (category_number == 3 && eta_number == 3)
occupancy = 106;
else {
occupancy = 0;
int category_number = SDL::getCategoryNumber(module_layers, module_subdets, module_rings);
int eta_number = SDL::getEtaBin(module_eta);

int occupancy = 0;
if (category_number != -1 && eta_number != -1) {
occupancy = occupancy_matrix[category_number][eta_number];
}
#ifdef Warnings
else {
printf("Unhandled case in createEligibleModulesListForQuintupletsGPU! Module index = %i\n", i);
#endif
}
#endif

int nTotQ = alpaka::atomicOp<alpaka::AtomicAdd>(acc, &nTotalQuintupletsx, occupancy);
rangesInGPU.quintupletModuleIndices[i] = nTotQ;
Expand Down
Loading

0 comments on commit d944fbf

Please sign in to comment.