Skip to content

Commit

Permalink
Add Low pT Occupancies
Browse files Browse the repository at this point in the history
Co-authored-by: Gavin Niendorf <[email protected]>
  • Loading branch information
ariostas and GNiendorf committed Nov 25, 2024
1 parent 3d9a983 commit ac2e345
Show file tree
Hide file tree
Showing 6 changed files with 755 additions and 222 deletions.
15 changes: 10 additions & 5 deletions RecoTracker/LSTCore/src/alpaka/LSTEvent.dev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ void LSTEvent::addPixelSegmentToEvent(std::vector<unsigned int> const& hitIndice
createMDArrayRangesGPU_workDiv,
CreateMDArrayRangesGPU{},
modules_.const_view<ModulesSoA>(),
rangesDC_->view());
rangesDC_->view(),
ptCut_);

auto nTotalMDs_buf_h = cms::alpakatools::make_host_buffer<unsigned int>(queue_);
auto nTotalMDs_buf_d = cms::alpakatools::make_device_view(queue_, rangesOccupancy.nTotalMDs());
Expand Down Expand Up @@ -233,7 +234,8 @@ void LSTEvent::addPixelSegmentToEvent(std::vector<unsigned int> const& hitIndice
CreateSegmentArrayRanges{},
modules_.const_view<ModulesSoA>(),
rangesDC_->view(),
miniDoubletsDC_->const_view<MiniDoubletsSoA>());
miniDoubletsDC_->const_view<MiniDoubletsSoA>(),
ptCut_);

auto rangesOccupancy = rangesDC_->view();
auto nTotalSegments_view_h = cms::alpakatools::make_host_view(nTotalSegments_);
Expand Down Expand Up @@ -346,7 +348,8 @@ void LSTEvent::createMiniDoublets() {
createMDArrayRangesGPU_workDiv,
CreateMDArrayRangesGPU{},
modules_.const_view<ModulesSoA>(),
rangesDC_->view());
rangesDC_->view(),
ptCut_);

auto nTotalMDs_buf_h = cms::alpakatools::make_host_buffer<unsigned int>(queue_);
auto nTotalMDs_buf_d = cms::alpakatools::make_device_view(queue_, rangesOccupancy.nTotalMDs());
Expand Down Expand Up @@ -454,7 +457,8 @@ void LSTEvent::createTriplets() {
CreateTripletArrayRanges{},
modules_.const_view<ModulesSoA>(),
rangesDC_->view(),
segmentsDC_->const_view<SegmentsOccupancySoA>());
segmentsDC_->const_view<SegmentsOccupancySoA>(),
ptCut_);

// TODO: Why are we pulling this back down only to put it back on the device in a new struct?
auto rangesOccupancy = rangesDC_->view();
Expand Down Expand Up @@ -857,7 +861,8 @@ void LSTEvent::createQuintuplets() {
CreateEligibleModulesListForQuintuplets{},
modules_.const_view<ModulesSoA>(),
tripletsDC_->const_view<TripletsOccupancySoA>(),
rangesDC_->view());
rangesDC_->view(),
ptCut_);

auto nEligibleT5Modules_buf = cms::alpakatools::make_host_buffer<uint16_t>(queue_);
auto nTotalQuintuplets_buf = cms::alpakatools::make_host_buffer<unsigned int>(queue_);
Expand Down
114 changes: 60 additions & 54 deletions RecoTracker/LSTCore/src/alpaka/MiniDoublet.h
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
acc, &mdsOccupancy.totOccupancyMDs()[lowerModuleIndex], 1u, alpaka::hierarchy::Threads{});
if (totOccupancyMDs >= (ranges.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 =
Expand Down Expand Up @@ -773,9 +774,38 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
}
};

// 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 == Barrel) {
return (module_layers <= 3) ? 0 : 1;
} else if (module_subdets == 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, ModulesConst modules, ObjectRanges ranges) const {
ALPAKA_FN_ACC void operator()(TAcc const& acc, ModulesConst modules, ObjectRanges ranges, const float ptCut) const {
// implementation is 1D with a single block
static_assert(std::is_same_v<TAcc, ALPAKA_ACCELERATOR_NAMESPACE::Acc1D>, "Should be Acc1D");
ALPAKA_ASSERT_ACC((alpaka::getWorkDiv<alpaka::Grid, alpaka::Blocks>(acc)[0] == 1));
Expand All @@ -790,67 +820,43 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
}
alpaka::syncBlockThreads(acc);

// 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[0]; i < modules.nLowerModules(); i += gridThreadExtent[0]) {
short module_rings = modules.rings()[i];
short module_layers = modules.layers()[i];
short module_subdets = modules.subdets()[i];
float module_eta = alpaka::math::abs(acc, modules.eta()[i]);

int category_number;
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;

int eta_number;
if (module_eta < 0.75f)
eta_number = 0;
else if (module_eta < 1.5f)
eta_number = 1;
else if (module_eta < 2.25f)
eta_number = 2;
else if (module_eta < 3.0f)
eta_number = 3;
else
eta_number = -1;

int occupancy;
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::atomicAdd(acc, &nTotalMDs, occupancy, alpaka::hierarchy::Threads{});

Expand Down
81 changes: 33 additions & 48 deletions RecoTracker/LSTCore/src/alpaka/Quintuplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -2418,7 +2418,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
acc, &quintupletsOccupancy.totOccupancyQuintuplets()[lowerModule1], 1u, alpaka::hierarchy::Threads{});
if (totOccupancyQuintuplets >= ranges.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 = alpaka::atomicAdd(
Expand Down Expand Up @@ -2478,7 +2480,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
ALPAKA_FN_ACC void operator()(TAcc const& acc,
ModulesConst modules,
TripletsOccupancyConst tripletsOccupancy,
ObjectRanges ranges) const {
ObjectRanges ranges,
const float ptCut) const {
// implementation is 1D with a single block
static_assert(std::is_same_v<TAcc, ALPAKA_ACCELERATOR_NAMESPACE::Acc1D>, "Should be Acc1D");
ALPAKA_ASSERT_ACC((alpaka::getWorkDiv<alpaka::Grid, alpaka::Blocks>(acc)[0] == 1));
Expand All @@ -2495,6 +2498,25 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
}
alpaka::syncBlockThreads(acc);

// 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[0]; i < modules.nLowerModules(); i += gridThreadExtent[0]) {
// Condition for a quintuple to exist for a module
// TCs don't exist for layers 5 and 6 barrel, and layers 2,3,4,5 endcap
Expand All @@ -2512,55 +2534,18 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

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

int category_number;
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;

int eta_number;
if (module_eta < 0.75f)
eta_number = 0;
else if (module_eta < 1.5f)
eta_number = 1;
else if (module_eta < 2.25f)
eta_number = 2;
else if (module_eta < 3.0f)
eta_number = 3;
else
eta_number = -1;

int occupancy;
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 = 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 createEligibleModulesListForQuintupletsGPU! Module index = %i\n", i);
#endif
}
#endif

int nTotQ = alpaka::atomicAdd(acc, &nTotalQuintupletsx, occupancy, alpaka::hierarchy::Threads{});
ranges.quintupletModuleIndices()[i] = nTotQ;
Expand Down
Loading

0 comments on commit ac2e345

Please sign in to comment.