Skip to content

Commit

Permalink
Formatted and removed unnecessary CopyToHost
Browse files Browse the repository at this point in the history
  • Loading branch information
ariostas committed Oct 4, 2024
1 parent 52377d1 commit f430d1b
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 128 deletions.
33 changes: 16 additions & 17 deletions RecoTracker/LSTCore/src/alpaka/Event.dev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,10 @@ void Event::addPixelSegmentToEvent(std::vector<unsigned int> const& hitIndices0,
*nTotalMDs_buf_h.data() += n_max_pixel_md_per_modules;
unsigned int nTotalMDs = *nTotalMDs_buf_h.data();

std::array<int, 2> const mds_sizes{{static_cast<int>(nTotalMDs),
static_cast<int>(nLowerModules_ + 1)}};
std::array<int, 2> const mds_sizes{{static_cast<int>(nTotalMDs), static_cast<int>(nLowerModules_ + 1)}};
mdsDev_.emplace(mds_sizes, queue_);

auto nMDs_view =
alpaka::createView(devAcc_, mdsDev_->view<MiniDoubletsOccupancySoA>().nMDs(), nLowerModules_ + 1);
auto nMDs_view = alpaka::createView(devAcc_, mdsDev_->view<MiniDoubletsOccupancySoA>().nMDs(), nLowerModules_ + 1);
auto totOccupancyMDs_view =
alpaka::createView(devAcc_, mdsDev_->view<MiniDoubletsOccupancySoA>().totOccupancyMDs(), nLowerModules_ + 1);
alpaka::memset(queue_, nMDs_view, 0u);
Expand Down Expand Up @@ -275,8 +273,7 @@ void Event::addPixelSegmentToEvent(std::vector<unsigned int> const& hitIndices0,
alpaka::memcpy(queue_, dst_view_nMDs, src_view_mdSize);

auto totOccupancyMDs_view = alpaka::createView(devAcc_, mdsOccupancy.totOccupancyMDs(), (Idx)nLowerModules_ + 1);
auto dst_view_totOccupancyMDs =
alpaka::createSubView(totOccupancyMDs_view, (Idx)1u, (Idx)pixelModuleIndex);
auto dst_view_totOccupancyMDs = alpaka::createSubView(totOccupancyMDs_view, (Idx)1u, (Idx)pixelModuleIndex);
alpaka::memcpy(queue_, dst_view_totOccupancyMDs, src_view_mdSize);

alpaka::wait(queue_); // FIXME: remove synch after inputs refactored to be in pinned memory
Expand Down Expand Up @@ -326,12 +323,10 @@ void Event::createMiniDoublets() {
unsigned int nTotalMDs = *nTotalMDs_buf_h.data();

if (!mdsDev_) {
std::array<int, 2> const mds_sizes{{static_cast<int>(nTotalMDs),
static_cast<int>(nLowerModules_ + 1)}};
std::array<int, 2> const mds_sizes{{static_cast<int>(nTotalMDs), static_cast<int>(nLowerModules_ + 1)}};
mdsDev_.emplace(mds_sizes, queue_);

auto nMDs_view =
alpaka::createView(devAcc_, mdsDev_->view<MiniDoubletsOccupancySoA>().nMDs(), nLowerModules_ + 1);
auto nMDs_view = alpaka::createView(devAcc_, mdsDev_->view<MiniDoubletsOccupancySoA>().nMDs(), nLowerModules_ + 1);
auto totOccupancyMDs_view =
alpaka::createView(devAcc_, mdsDev_->view<MiniDoubletsOccupancySoA>().totOccupancyMDs(), nLowerModules_ + 1);
alpaka::memset(queue_, nMDs_view, 0u);
Expand Down Expand Up @@ -1337,16 +1332,20 @@ ObjectRangesBuffer<alpaka_common::DevHost>& Event::getRanges(bool sync) {
return rangesInCPU_.value();
}

template <typename TSoA>
template <typename TSoA, typename TDev>
typename TSoA::ConstView Event::getMiniDoublets(bool sync) {
if constexpr (std::is_same_v<Device, DevHost>)
if constexpr (std::is_same_v<TDev, DevHost>) {
return mdsDev_->const_view<TSoA>();
if (!mdsHost_) {
mdsHost_.emplace(cms::alpakatools::CopyToHost<MiniDoubletsDeviceCollection>::copyAsync(queue_, *mdsDev_));
if (sync)
alpaka::wait(queue_); // host consumers expect filled data
} else {
if (!mdsHost_) {
mdsHost_.emplace(
cms::alpakatools::CopyToHost<
PortableMultiCollection<TDev, MiniDoubletsSoA, MiniDoubletsOccupancySoA>>::copyAsync(queue_, *mdsDev_));
if (sync)
alpaka::wait(queue_); // host consumers expect filled data
}
return mdsHost_->const_view<TSoA>();
}
return mdsHost_->const_view<TSoA>();
}
template MiniDoubletsConst Event::getMiniDoublets<MiniDoubletsSoA>(bool);
template MiniDoubletsOccupancyConst Event::getMiniDoublets<MiniDoubletsOccupancySoA>(bool);
Expand Down
2 changes: 1 addition & 1 deletion RecoTracker/LSTCore/src/alpaka/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
HitsBuffer<DevHost>& getHits(bool sync = true);
HitsBuffer<DevHost>& getHitsInCMSSW(bool sync = true);
ObjectRangesBuffer<DevHost>& getRanges(bool sync = true);
template <typename TSoA>
template <typename TSoA, typename TDev = Device>
typename TSoA::ConstView getMiniDoublets(bool sync = true);
SegmentsBuffer<DevHost>& getSegments(bool sync = true);
TripletsBuffer<DevHost>& getTriplets(bool sync = true);
Expand Down
38 changes: 15 additions & 23 deletions RecoTracker/LSTCore/src/alpaka/MiniDoublet.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
mds.anchorHighEdgeY()[idx] = hitsInGPU.highEdgeYs[anchorHitIndex];
mds.anchorLowEdgeX()[idx] = hitsInGPU.lowEdgeXs[anchorHitIndex];
mds.anchorLowEdgeY()[idx] = hitsInGPU.lowEdgeYs[anchorHitIndex];
mds.anchorHighEdgePhi()[idx] =
alpaka::math::atan2(acc, mds.anchorHighEdgeY()[idx], mds.anchorHighEdgeX()[idx]);
mds.anchorLowEdgePhi()[idx] =
alpaka::math::atan2(acc, mds.anchorLowEdgeY()[idx], mds.anchorLowEdgeX()[idx]);
mds.anchorHighEdgePhi()[idx] = alpaka::math::atan2(acc, mds.anchorHighEdgeY()[idx], mds.anchorHighEdgeX()[idx]);
mds.anchorLowEdgePhi()[idx] = alpaka::math::atan2(acc, mds.anchorLowEdgeY()[idx], mds.anchorLowEdgeX()[idx]);

mds.outerX()[idx] = hitsInGPU.xs[outerHitIndex];
mds.outerY()[idx] = hitsInGPU.ys[outerHitIndex];
Expand Down Expand Up @@ -746,8 +744,12 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

struct CreateMiniDoubletsInGPUv2 {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(
TAcc const& acc, Modules modulesInGPU, Hits hitsInGPU, MiniDoublets mds, MiniDoubletsOccupancy mdsOccupancy, ObjectRanges rangesInGPU) const {
ALPAKA_FN_ACC void operator()(TAcc const& acc,
Modules modulesInGPU,
Hits hitsInGPU,
MiniDoublets mds,
MiniDoubletsOccupancy mdsOccupancy,
ObjectRanges rangesInGPU) const {
auto const globalThreadIdx = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc);
auto const gridThreadExtent = alpaka::getWorkDiv<alpaka::Grid, alpaka::Threads>(acc);

Expand Down Expand Up @@ -804,8 +806,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
zUpper,
rtUpper);
if (success) {
int totOccupancyMDs =
alpaka::atomicAdd(acc, &mdsOccupancy.totOccupancyMDs()[lowerModuleIndex], 1u, alpaka::hierarchy::Threads{});
int totOccupancyMDs = alpaka::atomicAdd(
acc, &mdsOccupancy.totOccupancyMDs()[lowerModuleIndex], 1u, alpaka::hierarchy::Threads{});
if (totOccupancyMDs >= (rangesInGPU.miniDoubletModuleOccupancy[lowerModuleIndex])) {
#ifdef WARNINGS
printf("Mini-doublet excess alert! Module index = %d\n", lowerModuleIndex);
Expand Down Expand Up @@ -934,8 +936,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

struct AddMiniDoubletRangesToEventExplicit {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(
TAcc const& acc, Modules modulesInGPU, MiniDoubletsOccupancy mdsOccupancy, ObjectRanges rangesInGPU, Hits hitsInGPU) const {
ALPAKA_FN_ACC void operator()(TAcc const& acc,
Modules modulesInGPU,
MiniDoubletsOccupancy mdsOccupancy,
ObjectRanges rangesInGPU,
Hits hitsInGPU) 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 @@ -956,17 +961,4 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
};
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::lst

namespace cms::alpakatools {
// This is not used, but it is needed for compilation
template <typename T0, typename... Args>
struct CopyToHost<PortableHostMultiCollection<T0, Args...>> {
template <typename TQueue>
static auto copyAsync(TQueue& queue, PortableHostMultiCollection<T0, Args...> const& srcData) {
PortableHostMultiCollection<T0, Args...> dstData(srcData.sizes(), queue);
alpaka::memcpy(queue, dstData.buffer(), srcData.buffer());
return dstData;
}
};
} // namespace cms::alpakatools

#endif
40 changes: 20 additions & 20 deletions RecoTracker/LSTCore/src/alpaka/NeuralNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,40 +69,40 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
// Build DNN input vector (corresponding output N-tuple branch noted in parenthetical in comment)
float x[38] = {
alpaka::math::log10(acc, 2 * k2Rinv1GeVf * innerRadius), // inner T3 pT (t3_pt)
mds.anchorEta()[mdIndex1], // inner T3 anchor hit 1 eta (t3_0_eta)
mds.anchorPhi()[mdIndex1], // inner T3 anchor hit 1 phi (t3_0_phi)
mds.anchorZ()[mdIndex1], // inner T3 anchor hit 1 z (t3_0_z)
mds.anchorEta()[mdIndex1], // inner T3 anchor hit 1 eta (t3_0_eta)
mds.anchorPhi()[mdIndex1], // inner T3 anchor hit 1 phi (t3_0_phi)
mds.anchorZ()[mdIndex1], // inner T3 anchor hit 1 z (t3_0_z)
alpaka::math::sqrt(acc, x1 * x1 + y1 * y1), // inner T3 anchor hit 1 r (t3_0_r)
float(modulesInGPU.layers[lowerModuleIndex1] + 6 * is_endcap1), // inner T3 anchor hit 1 layer (t3_0_layer)
mds.anchorEta()[mdIndex2], // inner T3 anchor hit 2 eta (t3_2_eta)
mds.anchorPhi()[mdIndex2], // inner T3 anchor hit 2 phi (t3_2_phi)
mds.anchorZ()[mdIndex2], // inner T3 anchor hit 2 z (t3_2_z)
mds.anchorEta()[mdIndex2], // inner T3 anchor hit 2 eta (t3_2_eta)
mds.anchorPhi()[mdIndex2], // inner T3 anchor hit 2 phi (t3_2_phi)
mds.anchorZ()[mdIndex2], // inner T3 anchor hit 2 z (t3_2_z)
alpaka::math::sqrt(acc, x2 * x2 + y2 * y2), // inner T3 anchor hit 2 r (t3_2_r)
float(modulesInGPU.layers[lowerModuleIndex2] + 6 * is_endcap2), // inner T3 anchor hit 2 layer (t3_2_layer)
mds.anchorEta()[mdIndex3], // inner T3 anchor hit 3 eta (t3_4_eta)
mds.anchorPhi()[mdIndex3], // inner T3 anchor hit 3 phi (t3_4_phi)
mds.anchorZ()[mdIndex3], // inner T3 anchor hit 3 z (t3_4_z)
mds.anchorEta()[mdIndex3], // inner T3 anchor hit 3 eta (t3_4_eta)
mds.anchorPhi()[mdIndex3], // inner T3 anchor hit 3 phi (t3_4_phi)
mds.anchorZ()[mdIndex3], // inner T3 anchor hit 3 z (t3_4_z)
alpaka::math::sqrt(acc, x3 * x3 + y3 * y3), // inner T3 anchor hit 3 r (t3_4_r)
float(modulesInGPU.layers[lowerModuleIndex3] + 6 * is_endcap3), // inner T3 anchor hit 3 layer (t3_4_layer)
alpaka::math::log10(acc, 2 * k2Rinv1GeVf * outerRadius), // outer T3 pT (t3_pt)
mds.anchorEta()[mdIndex3], // outer T3 anchor hit 4 eta (t3_0_eta)
mds.anchorPhi()[mdIndex3], // outer T3 anchor hit 4 phi (t3_0_phi)
mds.anchorZ()[mdIndex3], // outer T3 anchor hit 3 eta (t3_0_z)
mds.anchorEta()[mdIndex3], // outer T3 anchor hit 4 eta (t3_0_eta)
mds.anchorPhi()[mdIndex3], // outer T3 anchor hit 4 phi (t3_0_phi)
mds.anchorZ()[mdIndex3], // outer T3 anchor hit 3 eta (t3_0_z)
alpaka::math::sqrt(acc, x3 * x3 + y3 * y3), // outer T3 anchor hit 3 r (t3_0_r)
float(modulesInGPU.layers[lowerModuleIndex3] + 6 * is_endcap3), // outer T3 anchor hit 3 layer (t3_0_layer)
mds.anchorEta()[mdIndex4], // outer T3 anchor hit 4 eta (t3_2_eta)
mds.anchorPhi()[mdIndex4], // outer T3 anchor hit 4 phi (t3_2_phi)
mds.anchorZ()[mdIndex4], // outer T3 anchor hit 4 z (t3_2_z)
mds.anchorEta()[mdIndex4], // outer T3 anchor hit 4 eta (t3_2_eta)
mds.anchorPhi()[mdIndex4], // outer T3 anchor hit 4 phi (t3_2_phi)
mds.anchorZ()[mdIndex4], // outer T3 anchor hit 4 z (t3_2_z)
alpaka::math::sqrt(acc, x4 * x4 + y4 * y4), // outer T3 anchor hit 4 r (t3_2_r)
float(modulesInGPU.layers[lowerModuleIndex4] + 6 * is_endcap4), // outer T3 anchor hit 4 layer (t3_2_layer)
mds.anchorEta()[mdIndex5], // outer T3 anchor hit 5 eta (t3_4_eta)
mds.anchorPhi()[mdIndex5], // outer T3 anchor hit 5 phi (t3_4_phi)
mds.anchorZ()[mdIndex5], // outer T3 anchor hit 5 z (t3_4_z)
mds.anchorEta()[mdIndex5], // outer T3 anchor hit 5 eta (t3_4_eta)
mds.anchorPhi()[mdIndex5], // outer T3 anchor hit 5 phi (t3_4_phi)
mds.anchorZ()[mdIndex5], // outer T3 anchor hit 5 z (t3_4_z)
alpaka::math::sqrt(acc, x5 * x5 + y5 * y5), // outer T3 anchor hit 5 r (t3_4_r)
float(modulesInGPU.layers[lowerModuleIndex5] + 6 * is_endcap5), // outer T3 anchor hit 5 layer (t3_4_layer)
alpaka::math::log10(acc, (innerRadius + outerRadius) * k2Rinv1GeVf), // T5 pT (t5_pt)
mds.anchorEta()[md_idx_for_t5_eta_phi], // T5 eta (t5_eta)
mds.anchorPhi()[md_idx_for_t5_eta_phi], // T5 phi (t5_phi)
mds.anchorEta()[md_idx_for_t5_eta_phi], // T5 eta (t5_eta)
mds.anchorPhi()[md_idx_for_t5_eta_phi], // T5 phi (t5_phi)
alpaka::math::log10(acc, innerRadius), // T5 inner radius (t5_innerRadius)
alpaka::math::log10(acc, bridgeRadius), // T5 bridge radius (t5_bridgeRadius)
alpaka::math::log10(acc, outerRadius) // T5 outer radius (t5_outerRadius)
Expand Down
3 changes: 1 addition & 2 deletions RecoTracker/LSTCore/src/alpaka/PixelQuintuplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
unsigned int pixelInnerMD = segmentsInGPU.mdIndices[Params_pLS::kLayers * pixelIndex];
unsigned int pixelOuterMD = segmentsInGPU.mdIndices[Params_pLS::kLayers * pixelIndex + 1];

pixelQuintupletsInGPU.hitIndices[Params_pT5::kHits * pixelQuintupletIndex] =
mds.anchorHitIndices()[pixelInnerMD];
pixelQuintupletsInGPU.hitIndices[Params_pT5::kHits * pixelQuintupletIndex] = mds.anchorHitIndices()[pixelInnerMD];
pixelQuintupletsInGPU.hitIndices[Params_pT5::kHits * pixelQuintupletIndex + 1] =
mds.outerHitIndices()[pixelInnerMD];
pixelQuintupletsInGPU.hitIndices[Params_pT5::kHits * pixelQuintupletIndex + 2] =
Expand Down
34 changes: 16 additions & 18 deletions RecoTracker/LSTCore/src/alpaka/PixelTriplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1007,10 +1007,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
if (success) {
float phi =
mds.anchorPhi()[segmentsInGPU.mdIndices[2 * tripletsInGPU.segmentIndices[2 * outerTripletIndex] +
layer2_adjustment]];
layer2_adjustment]];
float eta =
mds.anchorEta()[segmentsInGPU.mdIndices[2 * tripletsInGPU.segmentIndices[2 * outerTripletIndex] +
layer2_adjustment]];
layer2_adjustment]];
float eta_pix = segmentsInGPU.eta[i_pLS];
float phi_pix = segmentsInGPU.phi[i_pLS];
float pt = segmentsInGPU.ptIn[i_pLS];
Expand Down Expand Up @@ -1381,14 +1381,13 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

float dBetaROut = 0;
if (isEC_lastLayer) {
dBetaROut =
(alpaka::math::sqrt(acc,
mds.anchorHighEdgeX()[fourthMDIndex] * mds.anchorHighEdgeX()[fourthMDIndex] +
mds.anchorHighEdgeY()[fourthMDIndex] * mds.anchorHighEdgeY()[fourthMDIndex]) -
alpaka::math::sqrt(acc,
mds.anchorLowEdgeX()[fourthMDIndex] * mds.anchorLowEdgeX()[fourthMDIndex] +
mds.anchorLowEdgeY()[fourthMDIndex] * mds.anchorLowEdgeY()[fourthMDIndex])) *
sinDPhi / drt_tl_axis;
dBetaROut = (alpaka::math::sqrt(acc,
mds.anchorHighEdgeX()[fourthMDIndex] * mds.anchorHighEdgeX()[fourthMDIndex] +
mds.anchorHighEdgeY()[fourthMDIndex] * mds.anchorHighEdgeY()[fourthMDIndex]) -
alpaka::math::sqrt(acc,
mds.anchorLowEdgeX()[fourthMDIndex] * mds.anchorLowEdgeX()[fourthMDIndex] +
mds.anchorLowEdgeY()[fourthMDIndex] * mds.anchorLowEdgeY()[fourthMDIndex])) *
sinDPhi / drt_tl_axis;
}

const float dBetaROut2 = dBetaROut * dBetaROut;
Expand Down Expand Up @@ -1641,14 +1640,13 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

float dBetaROut = 0;
if (isEC_lastLayer) {
dBetaROut =
(alpaka::math::sqrt(acc,
mds.anchorHighEdgeX()[fourthMDIndex] * mds.anchorHighEdgeX()[fourthMDIndex] +
mds.anchorHighEdgeY()[fourthMDIndex] * mds.anchorHighEdgeY()[fourthMDIndex]) -
alpaka::math::sqrt(acc,
mds.anchorLowEdgeX()[fourthMDIndex] * mds.anchorLowEdgeX()[fourthMDIndex] +
mds.anchorLowEdgeY()[fourthMDIndex] * mds.anchorLowEdgeY()[fourthMDIndex])) *
sinDPhi / drt_tl_axis;
dBetaROut = (alpaka::math::sqrt(acc,
mds.anchorHighEdgeX()[fourthMDIndex] * mds.anchorHighEdgeX()[fourthMDIndex] +
mds.anchorHighEdgeY()[fourthMDIndex] * mds.anchorHighEdgeY()[fourthMDIndex]) -
alpaka::math::sqrt(acc,
mds.anchorLowEdgeX()[fourthMDIndex] * mds.anchorLowEdgeX()[fourthMDIndex] +
mds.anchorLowEdgeY()[fourthMDIndex] * mds.anchorLowEdgeY()[fourthMDIndex])) *
sinDPhi / drt_tl_axis;
}

const float dBetaROut2 = dBetaROut * dBetaROut;
Expand Down
Loading

0 comments on commit f430d1b

Please sign in to comment.