Skip to content

Commit

Permalink
dynamic allocation for MDs, T3s, T5s
Browse files Browse the repository at this point in the history
  • Loading branch information
GNiendorf committed Jan 27, 2025
1 parent ea61e47 commit 1faa5f8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 19 deletions.
4 changes: 4 additions & 0 deletions RecoTracker/LSTCore/src/alpaka/LSTEvent.dev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ void LSTEvent::addPixelSegmentToEvent(std::vector<unsigned int> const& hitIndice
createMDArrayRangesGPU_workDiv,
CreateMDArrayRangesGPU{},
modules_.const_view<ModulesSoA>(),
hitsDC_->const_view<HitsRangesSoA>(),
rangesDC_->view(),
ptCut_);

Expand Down Expand Up @@ -348,6 +349,7 @@ void LSTEvent::createMiniDoublets() {
createMDArrayRangesGPU_workDiv,
CreateMDArrayRangesGPU{},
modules_.const_view<ModulesSoA>(),
hitsDC_->const_view<HitsRangesSoA>(),
rangesDC_->view(),
ptCut_);

Expand Down Expand Up @@ -457,6 +459,7 @@ void LSTEvent::createTriplets() {
CreateTripletArrayRanges{},
modules_.const_view<ModulesSoA>(),
rangesDC_->view(),
segmentsDC_->const_view<SegmentsSoA>(),
segmentsDC_->const_view<SegmentsOccupancySoA>(),
ptCut_);

Expand Down Expand Up @@ -862,6 +865,7 @@ void LSTEvent::createQuintuplets() {
modules_.const_view<ModulesSoA>(),
tripletsDC_->const_view<TripletsOccupancySoA>(),
rangesDC_->view(),
tripletsDC_->view<TripletsSoA>(),
ptCut_);

auto nEligibleT5Modules_buf = cms::alpakatools::make_host_buffer<uint16_t>(queue_);
Expand Down
23 changes: 16 additions & 7 deletions RecoTracker/LSTCore/src/alpaka/MiniDoublet.h
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

struct CreateMDArrayRangesGPU {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(TAcc const& acc, ModulesConst modules, ObjectRanges ranges, const float ptCut) const {
ALPAKA_FN_ACC void operator()(TAcc const& acc,
ModulesConst modules,
HitsRangesConst hitsRanges,
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 Down Expand Up @@ -840,24 +844,29 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
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];
// Dynamic allocation
const int nLower = hitsRanges.hitRangesnLower()[i];
const int nUpper = hitsRanges.hitRangesnUpper()[i];
const int dynamicMDs = nLower * nUpper;

// Matrix-based cap
short module_layers = modules.layers()[i];
short module_subdets = modules.subdets()[i];
short module_rings = modules.rings()[i];
float module_eta = alpaka::math::abs(acc, modules.eta()[i]);

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 {
if (category_number == -1 || eta_number == -1) {
printf("Unhandled case in createMDArrayRangesGPU! Module index = %i\n", i);
}
#endif

int occupancy = (category_number != -1 && eta_number != -1)
? alpaka::math::min(acc, dynamicMDs, occupancy_matrix[category_number][eta_number])
: dynamicMDs;
unsigned int nTotMDs = alpaka::atomicAdd(acc, &nTotalMDs, occupancy, alpaka::hierarchy::Threads{});

ranges.miniDoubletModuleIndices()[i] = nTotMDs;
Expand Down
33 changes: 25 additions & 8 deletions RecoTracker/LSTCore/src/alpaka/Quintuplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
ModulesConst modules,
TripletsOccupancyConst tripletsOccupancy,
ObjectRanges ranges,
Triplets triplets,
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");
Expand Down Expand Up @@ -1827,27 +1828,43 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

if (tripletsOccupancy.nTriplets()[i] == 0)
continue;
if (module_subdets == Barrel and module_layers >= 3)
if (module_subdets == Barrel && module_layers >= 3)
continue;
if (module_subdets == Endcap and module_layers > 1)
if (module_subdets == Endcap && module_layers > 1)
continue;

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

// How many triplets are in module i?
int nTriplets_i = tripletsOccupancy.nTriplets()[i];
int firstTripletIdx = ranges.tripletModuleIndices()[i];

// Loop over all triplets that live in module i
for (int t = 0; t < nTriplets_i; t++) {
int tripletIndex = firstTripletIdx + t;
uint16_t outerModule = triplets.lowerModuleIndices()[tripletIndex][2];
dynamic_count += tripletsOccupancy.nTriplets()[outerModule];
}

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 {
if (category_number == -1 || eta_number == -1) {
printf("Unhandled case in createEligibleModulesListForQuintupletsGPU! Module index = %i\n", i);
}
#endif

// Get matrix-based cap (use dynamic_count as fallback)
int matrix_cap =
(category_number != -1 && eta_number != -1) ? occupancy_matrix[category_number][eta_number] : dynamic_count;

// Cap occupancy at minimum of dynamic count and matrix value
int occupancy = alpaka::math::min(acc, dynamic_count, matrix_cap);

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

ranges.quintupletModuleIndices()[i] = nTotQ;
ranges.indicesOfEligibleT5Modules()[nEligibleT5Modules] = i;
ranges.quintupletModuleOccupancy()[i] = occupancy;
Expand Down
22 changes: 18 additions & 4 deletions RecoTracker/LSTCore/src/alpaka/Triplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
ALPAKA_FN_ACC void operator()(TAcc const& acc,
ModulesConst modules,
ObjectRanges ranges,
SegmentsConst segments,
SegmentsOccupancyConst segmentsOccupancy,
const float ptCut) const {
// implementation is 1D with a single block
Expand Down Expand Up @@ -895,15 +896,28 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
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];
int dynamic_count = 0;
// How many segments are in module i?
int nSegments_i = segmentsOccupancy.nSegments()[i];
int firstSegmentIdx = ranges.segmentRanges()[i][0];
// Loop over all segments that live in module i
for (int s = 0; s < nSegments_i; ++s) {
int segIndex = firstSegmentIdx + s;
uint16_t midModule = segments.outerLowerModuleIndices()[segIndex];
dynamic_count += segmentsOccupancy.nSegments()[midModule];
}

#ifdef WARNINGS
else {
if (category_number == -1 || eta_number == -1) {
printf("Unhandled case in createTripletArrayRanges! Module index = %i\n", i);
}
#endif
// Get matrix-based cap
int matrix_cap =
(category_number != -1 && eta_number != -1) ? occupancy_matrix[category_number][eta_number] : dynamic_count;

// Cap occupancy at minimum of dynamic count and matrix value
int occupancy = alpaka::math::min(acc, dynamic_count, matrix_cap);

ranges.tripletModuleOccupancy()[i] = occupancy;
unsigned int nTotT = alpaka::atomicAdd(acc, &nTotalTriplets, occupancy, alpaka::hierarchy::Threads{});
Expand Down

0 comments on commit 1faa5f8

Please sign in to comment.