Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
ariostas committed Sep 23, 2024
1 parent 77ff0e5 commit 9e2a402
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 102 deletions.
54 changes: 38 additions & 16 deletions RecoTracker/LSTCore/src/alpaka/Event.dev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,12 @@ void Event::addPixelSegmentToEvent(std::vector<unsigned int> const& hitIndices0,

nTotalSegments_ += n_max_pixel_segments_per_module;

std::array<int, 3> const segments_sizes{{static_cast<int>(nTotalSegments_), static_cast<int>(nLowerModules_+1), static_cast<int>(n_max_pixel_segments_per_module)}};
std::array<int, 3> const segments_sizes{{static_cast<int>(nTotalSegments_),
static_cast<int>(nLowerModules_ + 1),
static_cast<int>(n_max_pixel_segments_per_module)}};
segmentsDev_.emplace(segments_sizes, queue_);
auto buf = segmentsDev_->buffer();
alpaka::memset(queue_, buf, 0u); // TODO: We don't need to initialize the entire buffer
alpaka::memset(queue_, buf, 0u); // TODO: We don't need to initialize the entire buffer
}

auto hitIndices0_dev = allocBufWrapper<unsigned int>(devAcc_, size, queue_);
Expand Down Expand Up @@ -258,13 +260,13 @@ void Event::addPixelSegmentToEvent(std::vector<unsigned int> const& hitIndices0,
auto src_view_mdSize = alpaka::createView(cms::alpakatools::host(), &mdSize, (Idx)1u);

SegmentsOccupancy segmentsOccupancy = segmentsDev_->view<SegmentsOccupancySoA>();
auto nSegments_view = alpaka::createView(devAcc_, segmentsOccupancy.nSegments(), (Idx)nLowerModules_+1);
auto nSegments_view = alpaka::createView(devAcc_, segmentsOccupancy.nSegments(), (Idx)nLowerModules_ + 1);
auto dst_view_segments = alpaka::createSubView(nSegments_view, (Idx)1u, (Idx)pixelModuleIndex);
alpaka::memcpy(queue_, dst_view_segments, src_view_size);

auto totOccupancySegments_view = alpaka::createView(devAcc_, segmentsOccupancy.totOccupancySegments(), (Idx)nLowerModules_+1);
auto dst_view_totOccupancySegments =
alpaka::createSubView(totOccupancySegments_view, (Idx)1u, (Idx)pixelModuleIndex);
auto totOccupancySegments_view =
alpaka::createView(devAcc_, segmentsOccupancy.totOccupancySegments(), (Idx)nLowerModules_ + 1);
auto dst_view_totOccupancySegments = alpaka::createSubView(totOccupancySegments_view, (Idx)1u, (Idx)pixelModuleIndex);
alpaka::memcpy(queue_, dst_view_totOccupancySegments, src_view_size);

auto dst_view_nMDs = alpaka::createSubView(miniDoubletsBuffers_->nMDs_buf, (Idx)1u, (Idx)pixelModuleIndex);
Expand Down Expand Up @@ -357,10 +359,12 @@ void Event::createMiniDoublets() {

void Event::createSegmentsWithModuleMap() {
if (!segmentsDev_) {
std::array<int, 3> const segments_sizes{{static_cast<int>(nTotalSegments_), static_cast<int>(nLowerModules_+1), static_cast<int>(n_max_pixel_segments_per_module)}};
std::array<int, 3> const segments_sizes{{static_cast<int>(nTotalSegments_),
static_cast<int>(nLowerModules_ + 1),
static_cast<int>(n_max_pixel_segments_per_module)}};
segmentsDev_.emplace(segments_sizes, queue_);
auto buf = segmentsDev_->buffer();
alpaka::memset(queue_, buf, 0u); // TODO: We don't need to initialize the entire buffer
alpaka::memset(queue_, buf, 0u); // TODO: We don't need to initialize the entire buffer
}

Vec3D const threadsPerBlockCreateSeg{1, 1, 64};
Expand Down Expand Up @@ -420,7 +424,8 @@ void Event::createTriplets() {

// Allocate and copy nSegments from device to host (only nLowerModules in OT, not the +1 with pLSs)
auto nSegments_buf_h = cms::alpakatools::make_host_buffer<unsigned int[]>(queue_, nLowerModules_);
auto nSegments_buf_d = alpaka::createView(devAcc_, segmentsDev_->const_view<SegmentsOccupancySoA>().nSegments(), nLowerModules_);
auto nSegments_buf_d =
alpaka::createView(devAcc_, segmentsDev_->const_view<SegmentsOccupancySoA>().nSegments(), nLowerModules_);
alpaka::memcpy(queue_, nSegments_buf_h, nSegments_buf_d, nLowerModules_);

// ... same for module_nConnectedModules
Expand Down Expand Up @@ -564,7 +569,13 @@ void Event::createTrackCandidates(bool no_pls_dupclean, bool tc_pls_triplets) {
WorkDiv3D const checkHitspLS_workDiv =
createWorkDiv(blocksPerGridCheckHitspLS, threadsPerBlockCheckHitspLS, elementsPerThread);

alpaka::exec<Acc3D>(queue_, checkHitspLS_workDiv, CheckHitspLS{}, *modulesBuffers_.data(), segmentsDev_->const_view<SegmentsOccupancySoA>(), segmentsDev_->view<SegmentsPixelSoA>(), true);
alpaka::exec<Acc3D>(queue_,
checkHitspLS_workDiv,
CheckHitspLS{},
*modulesBuffers_.data(),
segmentsDev_->const_view<SegmentsOccupancySoA>(),
segmentsDev_->view<SegmentsPixelSoA>(),
true);
}

Vec3D const threadsPerBlock_crossCleanpLS{1, 16, 32};
Expand Down Expand Up @@ -638,8 +649,10 @@ void Event::createPixelTriplets() {
auto superbins_buf = allocBufWrapper<int>(cms::alpakatools::host(), n_max_pixel_segments_per_module, queue_);
auto pixelTypes_buf = allocBufWrapper<PixelType>(cms::alpakatools::host(), n_max_pixel_segments_per_module, queue_);

alpaka::memcpy(queue_, superbins_buf, alpaka::createView(devAcc_, segmentsPixel.superbin(), n_max_pixel_segments_per_module));
alpaka::memcpy(queue_, pixelTypes_buf, alpaka::createView(devAcc_, segmentsPixel.pixelType(), n_max_pixel_segments_per_module));
alpaka::memcpy(
queue_, superbins_buf, alpaka::createView(devAcc_, segmentsPixel.superbin(), n_max_pixel_segments_per_module));
alpaka::memcpy(
queue_, pixelTypes_buf, alpaka::createView(devAcc_, segmentsPixel.pixelType(), n_max_pixel_segments_per_module));
auto const* superbins = superbins_buf.data();
auto const* pixelTypes = pixelTypes_buf.data();

Expand Down Expand Up @@ -824,7 +837,13 @@ void Event::pixelLineSegmentCleaning(bool no_pls_dupclean) {
WorkDiv3D const checkHitspLS_workDiv =
createWorkDiv(blocksPerGridCheckHitspLS, threadsPerBlockCheckHitspLS, elementsPerThread);

alpaka::exec<Acc3D>(queue_, checkHitspLS_workDiv, CheckHitspLS{}, *modulesBuffers_.data(), segmentsDev_->const_view<SegmentsOccupancySoA>(), segmentsDev_->view<SegmentsPixelSoA>(), false);
alpaka::exec<Acc3D>(queue_,
checkHitspLS_workDiv,
CheckHitspLS{},
*modulesBuffers_.data(),
segmentsDev_->const_view<SegmentsOccupancySoA>(),
segmentsDev_->view<SegmentsPixelSoA>(),
false);
}
}

Expand All @@ -845,8 +864,10 @@ void Event::createPixelQuintuplets() {
auto superbins_buf = allocBufWrapper<int>(cms::alpakatools::host(), n_max_pixel_segments_per_module, queue_);
auto pixelTypes_buf = allocBufWrapper<PixelType>(cms::alpakatools::host(), n_max_pixel_segments_per_module, queue_);

alpaka::memcpy(queue_, superbins_buf, alpaka::createView(devAcc_, segmentsPixel.superbin(), n_max_pixel_segments_per_module));
alpaka::memcpy(queue_, pixelTypes_buf, alpaka::createView(devAcc_, segmentsPixel.pixelType(), n_max_pixel_segments_per_module));
alpaka::memcpy(
queue_, superbins_buf, alpaka::createView(devAcc_, segmentsPixel.superbin(), n_max_pixel_segments_per_module));
alpaka::memcpy(
queue_, pixelTypes_buf, alpaka::createView(devAcc_, segmentsPixel.pixelType(), n_max_pixel_segments_per_module));
auto const* superbins = superbins_buf.data();
auto const* pixelTypes = pixelTypes_buf.data();

Expand Down Expand Up @@ -999,7 +1020,8 @@ void Event::addMiniDoubletsToEventExplicit() {

void Event::addSegmentsToEventExplicit() {
auto nSegmentsCPU_buf = allocBufWrapper<unsigned int>(cms::alpakatools::host(), nLowerModules_, queue_);
auto nSegments_buf = alpaka::createView(devAcc_, segmentsDev_->const_view<SegmentsOccupancySoA>().nSegments(), nLowerModules_);
auto nSegments_buf =
alpaka::createView(devAcc_, segmentsDev_->const_view<SegmentsOccupancySoA>().nSegments(), nLowerModules_);
alpaka::memcpy(queue_, nSegmentsCPU_buf, nSegments_buf, nLowerModules_);

// FIXME: replace by ES host data
Expand Down
6 changes: 5 additions & 1 deletion RecoTracker/LSTCore/src/alpaka/Kernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

struct CheckHitspLS {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(TAcc const& acc, Modules modulesInGPU, SegmentsOccupancyConst segmentsOccupancy, SegmentsPixel segmentsPixel, bool secondpass) const {
ALPAKA_FN_ACC void operator()(TAcc const& acc,
Modules modulesInGPU,
SegmentsOccupancyConst segmentsOccupancy,
SegmentsPixel segmentsPixel,
bool secondpass) const {
auto const globalThreadIdx = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc);
auto const gridThreadExtent = alpaka::getWorkDiv<alpaka::Grid, alpaka::Threads>(acc);

Expand Down
8 changes: 4 additions & 4 deletions RecoTracker/LSTCore/src/alpaka/PixelQuintuplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -925,10 +925,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
segmentsPixel.partOfPT5()[i_pLS] = true;
quintupletsInGPU.partOfPT5[quintupletIndex] = true;
} // tot occupancy
} // end success
} // end T5
} // end iLS
} // end i_pLS
} // end success
} // end T5
} // end iLS
} // end i_pLS
}
};
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::lst
Expand Down
12 changes: 6 additions & 6 deletions RecoTracker/LSTCore/src/alpaka/PixelTriplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1013,10 +1013,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
rPhiChiSquaredInwards);

if (success) {
float phi =
mdsInGPU.anchorPhi[segments.mdIndices()[tripletsInGPU.segmentIndices[2 * outerTripletIndex]][layer2_adjustment]];
float eta =
mdsInGPU.anchorEta[segments.mdIndices()[tripletsInGPU.segmentIndices[2 * outerTripletIndex]][layer2_adjustment]];
float phi = mdsInGPU.anchorPhi[segments.mdIndices()[tripletsInGPU.segmentIndices[2 * outerTripletIndex]]
[layer2_adjustment]];
float eta = mdsInGPU.anchorEta[segments.mdIndices()[tripletsInGPU.segmentIndices[2 * outerTripletIndex]]
[layer2_adjustment]];
float eta_pix = segmentsPixel.eta()[i_pLS];
float phi_pix = segmentsPixel.phi()[i_pLS];
float pt = segmentsPixel.ptIn()[i_pLS];
Expand Down Expand Up @@ -1054,8 +1054,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
}
}
} // for outerTripletArrayIndex
} // for iLSModule < iLSModule_max
} // for i_pLS
} // for iLSModule < iLSModule_max
} // for i_pLS
}
};

Expand Down
6 changes: 4 additions & 2 deletions RecoTracker/LSTCore/src/alpaka/Quintuplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -2588,9 +2588,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
unsigned int quintupletIndex =
rangesInGPU.quintupletModuleIndices[lowerModule1] + quintupletModuleIndex;
float phi =
mdsInGPU.anchorPhi[segments.mdIndices()[tripletsInGPU.segmentIndices[2 * innerTripletIndex]][layer2_adjustment]];
mdsInGPU.anchorPhi[segments.mdIndices()[tripletsInGPU.segmentIndices[2 * innerTripletIndex]]
[layer2_adjustment]];
float eta =
mdsInGPU.anchorEta[segments.mdIndices()[tripletsInGPU.segmentIndices[2 * innerTripletIndex]][layer2_adjustment]];
mdsInGPU.anchorEta[segments.mdIndices()[tripletsInGPU.segmentIndices[2 * innerTripletIndex]]
[layer2_adjustment]];
float pt = (innerRadius + outerRadius) * k2Rinv1GeVf;
float scores = chiSquared + nonAnchorChiSquared;
addQuintupletToMemory(tripletsInGPU,
Expand Down
80 changes: 42 additions & 38 deletions RecoTracker/LSTCore/src/alpaka/Segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,45 @@
namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

GENERATE_SOA_LAYOUT(SegmentsSoALayout,
SOA_COLUMN(FPX, dPhis),
SOA_COLUMN(FPX, dPhiMins),
SOA_COLUMN(FPX, dPhiMaxs),
SOA_COLUMN(FPX, dPhiChanges),
SOA_COLUMN(FPX, dPhiChangeMins),
SOA_COLUMN(FPX, dPhiChangeMaxs),
SOA_COLUMN(uint16_t, innerLowerModuleIndices),
SOA_COLUMN(uint16_t, outerLowerModuleIndices),
SOA_COLUMN(Params_LS::ArrayUxLayers, mdIndices),
SOA_COLUMN(unsigned int, innerMiniDoubletAnchorHitIndices),
SOA_COLUMN(unsigned int, outerMiniDoubletAnchorHitIndices)
//SOA_SCALAR(unsigned int, nMemoryLocations)
)
SOA_COLUMN(FPX, dPhis),
SOA_COLUMN(FPX, dPhiMins),
SOA_COLUMN(FPX, dPhiMaxs),
SOA_COLUMN(FPX, dPhiChanges),
SOA_COLUMN(FPX, dPhiChangeMins),
SOA_COLUMN(FPX, dPhiChangeMaxs),
SOA_COLUMN(uint16_t, innerLowerModuleIndices),
SOA_COLUMN(uint16_t, outerLowerModuleIndices),
SOA_COLUMN(Params_LS::ArrayUxLayers, mdIndices),
SOA_COLUMN(unsigned int, innerMiniDoubletAnchorHitIndices),
SOA_COLUMN(unsigned int, outerMiniDoubletAnchorHitIndices)
//SOA_SCALAR(unsigned int, nMemoryLocations)
)

GENERATE_SOA_LAYOUT(SegmentsOccupancySoALayout,
SOA_COLUMN(unsigned int, nSegments), //number of segments per inner lower module
SOA_COLUMN(unsigned int, totOccupancySegments))
SOA_COLUMN(unsigned int, nSegments), //number of segments per inner lower module
SOA_COLUMN(unsigned int, totOccupancySegments))

GENERATE_SOA_LAYOUT(SegmentsPixelSoALayout,
SOA_COLUMN(unsigned int, seedIdx),
SOA_COLUMN(int, charge),
SOA_COLUMN(int, superbin),
SOA_COLUMN(uint4, pLSHitsIdxs),
SOA_COLUMN(PixelType, pixelType),
SOA_COLUMN(char, isQuad),
SOA_COLUMN(char, isDup),
SOA_COLUMN(bool, partOfPT5),
SOA_COLUMN(float, ptIn),
SOA_COLUMN(float, ptErr),
SOA_COLUMN(float, px),
SOA_COLUMN(float, py),
SOA_COLUMN(float, pz),
SOA_COLUMN(float, etaErr),
SOA_COLUMN(float, eta),
SOA_COLUMN(float, phi),
SOA_COLUMN(float, score),
SOA_COLUMN(float, circleCenterX),
SOA_COLUMN(float, circleCenterY),
SOA_COLUMN(float, circleRadius))
SOA_COLUMN(unsigned int, seedIdx),
SOA_COLUMN(int, charge),
SOA_COLUMN(int, superbin),
SOA_COLUMN(uint4, pLSHitsIdxs),
SOA_COLUMN(PixelType, pixelType),
SOA_COLUMN(char, isQuad),
SOA_COLUMN(char, isDup),
SOA_COLUMN(bool, partOfPT5),
SOA_COLUMN(float, ptIn),
SOA_COLUMN(float, ptErr),
SOA_COLUMN(float, px),
SOA_COLUMN(float, py),
SOA_COLUMN(float, pz),
SOA_COLUMN(float, etaErr),
SOA_COLUMN(float, eta),
SOA_COLUMN(float, phi),
SOA_COLUMN(float, score),
SOA_COLUMN(float, circleCenterX),
SOA_COLUMN(float, circleCenterY),
SOA_COLUMN(float, circleRadius))

using SegmentsSoA = SegmentsSoALayout<>;
using SegmentsOccupancySoA = SegmentsOccupancySoALayout<>;
Expand Down Expand Up @@ -654,8 +654,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
dPhiChange,
dPhiChangeMin,
dPhiChangeMax)) {
unsigned int totOccupancySegments = alpaka::atomicAdd(
acc, &segmentsOccupancy.totOccupancySegments()[innerLowerModuleIndex], 1u, alpaka::hierarchy::Threads{});
unsigned int totOccupancySegments =
alpaka::atomicAdd(acc,
&segmentsOccupancy.totOccupancySegments()[innerLowerModuleIndex],
1u,
alpaka::hierarchy::Threads{});
if (static_cast<int>(totOccupancySegments) >= rangesInGPU.segmentModuleOccupancy[innerLowerModuleIndex]) {
#ifdef WARNINGS
printf("Segment excess alert! Module index = %d\n", innerLowerModuleIndex);
Expand Down Expand Up @@ -810,7 +813,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
rangesInGPU.segmentRanges[i * 2 + 1] = -1;
} else {
rangesInGPU.segmentRanges[i * 2] = rangesInGPU.segmentModuleIndices[i];
rangesInGPU.segmentRanges[i * 2 + 1] = rangesInGPU.segmentModuleIndices[i] + segmentsOccupancy.nSegments()[i] - 1;
rangesInGPU.segmentRanges[i * 2 + 1] =
rangesInGPU.segmentModuleIndices[i] + segmentsOccupancy.nSegments()[i] - 1;
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions RecoTracker/LSTCore/src/alpaka/TrackCandidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
trackCandidatesInGPU.radius[trackCandidateIndex] = __F2H(radius);
}

ALPAKA_FN_ACC ALPAKA_FN_INLINE int checkPixelHits(unsigned int ix,
unsigned int jx,
MiniDoublets const& mdsInGPU,
SegmentsConst segments,
Hits const& hitsInGPU) {
ALPAKA_FN_ACC ALPAKA_FN_INLINE int checkPixelHits(
unsigned int ix, unsigned int jx, MiniDoublets const& mdsInGPU, SegmentsConst segments, Hits const& hitsInGPU) {
int phits1[Params_pLS::kHits];
int phits2[Params_pLS::kHits];

Expand Down Expand Up @@ -391,7 +388,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
TrackCandidates trackCandidatesInGPU,
SegmentsPixelConst segmentsPixel,
ObjectRanges rangesInGPU) 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 @@ -508,7 +504,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
unsigned int nPixels = segmentsOccupancy.nSegments()[nLowerModules];
for (unsigned int pixelArrayIndex = globalThreadIdx[2]; pixelArrayIndex < nPixels;
pixelArrayIndex += gridThreadExtent[2]) {
if ((tc_pls_triplets ? 0 : !segmentsPixel.isQuad()[pixelArrayIndex]) || (segmentsPixel.isDup()[pixelArrayIndex]))
if ((tc_pls_triplets ? 0 : !segmentsPixel.isQuad()[pixelArrayIndex]) ||
(segmentsPixel.isDup()[pixelArrayIndex]))
continue;

unsigned int trackCandidateIdx =
Expand Down Expand Up @@ -542,7 +539,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
TrackCandidates trackCandidatesInGPU,
SegmentsPixelConst segmentsPixel,
ObjectRanges rangesInGPU) 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
3 changes: 2 additions & 1 deletion RecoTracker/LSTCore/standalone/code/core/write_lst_ntuple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,8 @@ void debugPrintOutlierMultiplicities(Event* event) {
<< " trackCandidates->nTrackCandidates[idx]: " << trackCandidates->nTrackCandidates[idx] << std::endl;
std::cout << " idx: " << idx << " triplets->nTriplets[idx]: " << triplets->nTriplets[idx] << std::endl;
unsigned int i = idx; //modules->lowerModuleIndices[idx];
std::cout << " idx: " << idx << " i: " << i << " segmentsOccupancy.nSegments()[i]: " << segmentsOccupancy.nSegments()[i] << std::endl;
std::cout << " idx: " << idx << " i: " << i
<< " segmentsOccupancy.nSegments()[i]: " << segmentsOccupancy.nSegments()[i] << std::endl;
int nMD = miniDoublets->nMDs[2 * idx] + miniDoublets->nMDs[2 * idx + 1];
std::cout << " idx: " << idx << " nMD: " << nMD << std::endl;
int nHits = 0;
Expand Down
Loading

0 comments on commit 9e2a402

Please sign in to comment.