Skip to content

Commit 7184d76

Browse files
antoniopetrefwyzard
authored andcommitted
[alpaka] format code
1 parent acdfe6f commit 7184d76

9 files changed

Lines changed: 248 additions & 323 deletions

File tree

src/alpaka/AlpakaCore/alpakaWorkDivHelper.h

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -326,18 +326,16 @@ namespace cms {
326326
template <typename T, typename T_Acc>
327327
class elements_with_stride {
328328
public:
329-
330329
ALPAKA_FN_ACC elements_with_stride(const T_Acc& acc,
331330
T extent,
332331
Idx elementIdxShift = 0,
333332
const unsigned int dimIndex = 0) {
334-
335333
const Idx threadIdxLocal(alpaka::getIdx<alpaka::Block, alpaka::Threads>(acc)[dimIndex]);
336334
const Idx blockIdxInGrid(alpaka::getIdx<alpaka::Grid, alpaka::Blocks>(acc)[dimIndex]);
337335

338336
const Idx blockDimension(alpaka::getWorkDiv<alpaka::Block, alpaka::Elems>(acc)[dimIndex]);
339337
const Idx gridDimension(alpaka::getWorkDiv<alpaka::Grid, alpaka::Blocks>(acc)[dimIndex]);
340-
338+
341339
thread_ = blockDimension * blockIdxInGrid + threadIdxLocal;
342340
thread_ = thread_ + elementIdxShift; // Add the shift
343341
stride_ = gridDimension * blockDimension;
@@ -347,9 +345,8 @@ namespace cms {
347345
}
348346

349347
ALPAKA_FN_ACC elements_with_stride(const T_Acc& acc) {
350-
351348
const Idx gridDimension(alpaka::getWorkDiv<alpaka::Grid, alpaka::Elems>(acc)[0]);
352-
elements_with_stride(acc, gridDimension);
349+
elements_with_stride(acc, gridDimension);
353350
}
354351

355352
class iterator {
@@ -359,15 +356,14 @@ namespace cms {
359356
ALPAKA_FN_ACC constexpr T operator*() const { return index_; }
360357

361358
ALPAKA_FN_ACC constexpr iterator& operator++() {
362-
363359
#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
364360
// increment the index
365361
index_ += stride_;
366362
if (index_ < extent_)
367363
return *this;
368364

369-
#else // CPU Backend
370-
// Iterate over all the elements for one thread
365+
#else // CPU Backend \
366+
// Iterate over all the elements for one thread
371367
index_ += 1;
372368
if (index_ < old_index_ + blockDim && index_ < extent_) {
373369
return *this;
@@ -392,12 +388,7 @@ namespace cms {
392388

393389
private:
394390
ALPAKA_FN_ACC constexpr iterator(T thread, T stride, T extent, T blockDim)
395-
: thread_{thread},
396-
stride_{stride},
397-
extent_{extent},
398-
index_{thread_},
399-
old_index_{index_},
400-
blockDim{blockDim} {}
391+
: thread_{thread}, stride_{stride}, extent_{extent}, index_{thread_}, old_index_{index_}, blockDim{blockDim} {}
401392

402393
ALPAKA_FN_ACC constexpr iterator(T thread, T stride, T extent, T index, T blockDim)
403394
: thread_{thread}, stride_{stride}, extent_{extent}, index_{index}, old_index_{index_}, blockDim{blockDim} {}
@@ -429,7 +420,6 @@ namespace cms {
429420
class elements_with_stride_1d {
430421
public:
431422
ALPAKA_FN_ACC elements_with_stride_1d(const T_Acc& acc) {
432-
433423
const Vec3 threadIdxLocal(alpaka::getIdx<alpaka::Block, alpaka::Threads>(acc));
434424
const Vec3 blockIdxInGrid(alpaka::getIdx<alpaka::Grid, alpaka::Blocks>(acc));
435425

@@ -469,7 +459,6 @@ namespace cms {
469459
ALPAKA_FN_ACC Vec3 operator*() const { return index_; }
470460

471461
ALPAKA_FN_ACC constexpr iterator& operator++() {
472-
473462
#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
474463
// increment the first coordinate
475464
index_[0u] += stride_[0u];
@@ -514,12 +503,7 @@ namespace cms {
514503

515504
private:
516505
ALPAKA_FN_ACC iterator(Vec3 thread, Vec3 stride, Vec3 extent, Vec3 blockDim)
517-
: thread_{thread},
518-
stride_{stride},
519-
extent_{extent},
520-
index_{thread_},
521-
old_index_{index_},
522-
blockDim{blockDim} {}
506+
: thread_{thread}, stride_{stride}, extent_{extent}, index_{thread_}, old_index_{index_}, blockDim{blockDim} {}
523507

524508
ALPAKA_FN_ACC iterator(Vec3 thread, Vec3 stride, Vec3 extent, Vec3 index, Vec3 blockDim)
525509
: thread_{thread}, stride_{stride}, extent_{extent}, index_{index}, old_index_{index_}, blockDim{blockDim} {}
@@ -551,7 +535,6 @@ namespace cms {
551535
class elements_with_stride_2d {
552536
public:
553537
ALPAKA_FN_ACC elements_with_stride_2d(const T_Acc& acc) {
554-
555538
const Vec3 threadIdxLocal(alpaka::getIdx<alpaka::Block, alpaka::Threads>(acc));
556539
const Vec3 blockIdxInGrid(alpaka::getIdx<alpaka::Grid, alpaka::Blocks>(acc));
557540

@@ -591,7 +574,6 @@ namespace cms {
591574
ALPAKA_FN_ACC Vec3 operator*() const { return index_; }
592575

593576
ALPAKA_FN_ACC constexpr iterator& operator++() {
594-
595577
#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
596578
// increment the first coordinate
597579
index_[0u] += stride_[0u];
@@ -645,12 +627,7 @@ namespace cms {
645627

646628
private:
647629
ALPAKA_FN_ACC iterator(Vec3 thread, Vec3 stride, Vec3 extent, Vec3 blockDim)
648-
: thread_{thread},
649-
stride_{stride},
650-
extent_{extent},
651-
index_{thread_},
652-
old_index_{index_},
653-
blockDim{blockDim} {}
630+
: thread_{thread}, stride_{stride}, extent_{extent}, index_{thread_}, old_index_{index_}, blockDim{blockDim} {}
654631

655632
ALPAKA_FN_ACC iterator(Vec3 thread, Vec3 stride, Vec3 extent, Vec3 index, Vec3 blockDim)
656633
: thread_{thread}, stride_{stride}, extent_{extent}, index_{index}, old_index_{index_}, blockDim{blockDim} {}
@@ -682,7 +659,6 @@ namespace cms {
682659
class elements_with_stride_3d {
683660
public:
684661
ALPAKA_FN_ACC elements_with_stride_3d(const T_Acc& acc) {
685-
686662
const Vec3 threadIdxLocal(alpaka::getIdx<alpaka::Block, alpaka::Threads>(acc));
687663
const Vec3 blockIdxInGrid(alpaka::getIdx<alpaka::Grid, alpaka::Blocks>(acc));
688664

@@ -692,7 +668,8 @@ namespace cms {
692668
thread_ = {blockDimension[0u] * blockIdxInGrid[0u] + threadIdxLocal[0u],
693669
blockDimension[1u] * blockIdxInGrid[1u] + threadIdxLocal[1u],
694670
blockDimension[2u] * blockIdxInGrid[2u] + threadIdxLocal[2u]};
695-
stride_ = {blockDimension[0u] * gridDimension[0u], blockDimension[1u] * gridDimension[1u],
671+
stride_ = {blockDimension[0u] * gridDimension[0u],
672+
blockDimension[1u] * gridDimension[1u],
696673
blockDimension[2u] * gridDimension[2u]};
697674
extent_ = stride_;
698675

@@ -711,7 +688,8 @@ namespace cms {
711688
blockDimension[1u] * blockIdxInGrid[1u] + threadIdxLocal[1u],
712689
blockDimension[2u] * blockIdxInGrid[2u] + threadIdxLocal[2u]};
713690
thread_ = thread_ + elementIdxShift;
714-
stride_ = {blockDimension[0u] * gridDimension[0u], blockDimension[1u] * gridDimension[1u],
691+
stride_ = {blockDimension[0u] * gridDimension[0u],
692+
blockDimension[1u] * gridDimension[1u],
715693
blockDimension[2u] * gridDimension[2u]};
716694

717695
blockDim = blockDimension;
@@ -724,7 +702,6 @@ namespace cms {
724702
ALPAKA_FN_ACC Vec3 operator*() const { return index_; }
725703

726704
ALPAKA_FN_ACC constexpr iterator& operator++() {
727-
728705
#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
729706
// increment the first coordinate
730707
index_[0u] += stride_[0u];
@@ -785,12 +762,7 @@ namespace cms {
785762

786763
private:
787764
ALPAKA_FN_ACC iterator(Vec3 thread, Vec3 stride, Vec3 extent, Vec3 blockDim)
788-
: thread_{thread},
789-
stride_{stride},
790-
extent_{extent},
791-
index_{thread_},
792-
old_index_{index_},
793-
blockDim{blockDim} {}
765+
: thread_{thread}, stride_{stride}, extent_{extent}, index_{thread_}, old_index_{index_}, blockDim{blockDim} {}
794766

795767
ALPAKA_FN_ACC iterator(Vec3 thread, Vec3 stride, Vec3 extent, Vec3 index, Vec3 blockDim)
796768
: thread_{thread}, stride_{stride}, extent_{extent}, index_{index}, old_index_{index_}, blockDim{blockDim} {}

src/alpaka/plugin-PixelTriplets/alpaka/CAHitNtupletGeneratorKernelsImpl.h

Lines changed: 54 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -246,58 +246,59 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
246246
(*apc2) = 0;
247247
} // ready for next kernel
248248

249-
for (uint32_t idx : cms::alpakatools::elements_with_stride<uint32_t, T_Acc>(acc, *nCells, elementShift, dimIndexY)) {
250-
auto cellIndex = idx;
251-
auto &thisCell = cells[idx];
252-
//if (thisCell.theDoubletId < 0 || thisCell.theUsed>1)
253-
// continue;
254-
auto innerHitId = thisCell.get_inner_hit_id();
255-
int numberOfPossibleNeighbors = isOuterHitOfCell[innerHitId].size();
256-
const auto *__restrict__ vi = isOuterHitOfCell[innerHitId].data();
257-
258-
constexpr uint32_t last_bpix1_detIndex = 96;
259-
constexpr uint32_t last_barrel_detIndex = 1184;
260-
auto ri = thisCell.get_inner_r(hh);
261-
auto zi = thisCell.get_inner_z(hh);
262-
263-
auto ro = thisCell.get_outer_r(hh);
264-
auto zo = thisCell.get_outer_z(hh);
265-
auto isBarrel = thisCell.get_inner_detIndex(hh) < last_barrel_detIndex;
266-
267-
cms::alpakatools::for_each_element_in_block_strided(
268-
acc,
269-
numberOfPossibleNeighbors,
270-
0u,
271-
[&](uint32_t j) {
272-
auto otherCell = vi[j]; // NB: Was with __ldg in legacy
273-
auto &oc = cells[otherCell];
274-
// if (cells[otherCell].theDoubletId < 0 ||
275-
// cells[otherCell].theUsed>1 )
276-
// continue;
277-
auto r1 = oc.get_inner_r(hh);
278-
auto z1 = oc.get_inner_z(hh);
279-
// auto isBarrel = oc.get_outer_detIndex(hh) < last_barrel_detIndex;
280-
bool aligned = GPUCACell::areAlignedRZ(
281-
r1,
282-
z1,
283-
ri,
284-
zi,
285-
ro,
286-
zo,
287-
ptmin,
288-
isBarrel ? CAThetaCutBarrel : CAThetaCutForward); // 2.f*thetaCut); // FIXME tune cuts
289-
if (aligned && thisCell.dcaCut(hh,
290-
oc,
291-
oc.get_inner_detIndex(hh) < last_bpix1_detIndex ? dcaCutInnerTriplet
292-
: dcaCutOuterTriplet,
293-
hardCurvCut)) { // FIXME tune cuts
294-
oc.addOuterNeighbor(acc, cellIndex, *cellNeighbors);
295-
thisCell.theUsed |= 1;
296-
oc.theUsed |= 1;
297-
}
298-
},
299-
dimIndexX); // loop on inner cells
300-
} // loop on outer cells
249+
for (uint32_t idx :
250+
cms::alpakatools::elements_with_stride<uint32_t, T_Acc>(acc, *nCells, elementShift, dimIndexY)) {
251+
auto cellIndex = idx;
252+
auto &thisCell = cells[idx];
253+
//if (thisCell.theDoubletId < 0 || thisCell.theUsed>1)
254+
// continue;
255+
auto innerHitId = thisCell.get_inner_hit_id();
256+
int numberOfPossibleNeighbors = isOuterHitOfCell[innerHitId].size();
257+
const auto *__restrict__ vi = isOuterHitOfCell[innerHitId].data();
258+
259+
constexpr uint32_t last_bpix1_detIndex = 96;
260+
constexpr uint32_t last_barrel_detIndex = 1184;
261+
auto ri = thisCell.get_inner_r(hh);
262+
auto zi = thisCell.get_inner_z(hh);
263+
264+
auto ro = thisCell.get_outer_r(hh);
265+
auto zo = thisCell.get_outer_z(hh);
266+
auto isBarrel = thisCell.get_inner_detIndex(hh) < last_barrel_detIndex;
267+
268+
cms::alpakatools::for_each_element_in_block_strided(
269+
acc,
270+
numberOfPossibleNeighbors,
271+
0u,
272+
[&](uint32_t j) {
273+
auto otherCell = vi[j]; // NB: Was with __ldg in legacy
274+
auto &oc = cells[otherCell];
275+
// if (cells[otherCell].theDoubletId < 0 ||
276+
// cells[otherCell].theUsed>1 )
277+
// continue;
278+
auto r1 = oc.get_inner_r(hh);
279+
auto z1 = oc.get_inner_z(hh);
280+
// auto isBarrel = oc.get_outer_detIndex(hh) < last_barrel_detIndex;
281+
bool aligned = GPUCACell::areAlignedRZ(
282+
r1,
283+
z1,
284+
ri,
285+
zi,
286+
ro,
287+
zo,
288+
ptmin,
289+
isBarrel ? CAThetaCutBarrel : CAThetaCutForward); // 2.f*thetaCut); // FIXME tune cuts
290+
if (aligned && thisCell.dcaCut(hh,
291+
oc,
292+
oc.get_inner_detIndex(hh) < last_bpix1_detIndex ? dcaCutInnerTriplet
293+
: dcaCutOuterTriplet,
294+
hardCurvCut)) { // FIXME tune cuts
295+
oc.addOuterNeighbor(acc, cellIndex, *cellNeighbors);
296+
thisCell.theUsed |= 1;
297+
oc.theUsed |= 1;
298+
}
299+
},
300+
dimIndexX); // loop on inner cells
301+
} // loop on outer cells
301302
}
302303
};
303304

@@ -358,7 +359,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
358359
HitContainer const *__restrict__ foundNtuplets,
359360
Quality const *__restrict__ quality,
360361
CAConstants::TupleMultiplicity *tupleMultiplicity) const {
361-
362362
for (uint32_t it : cms::alpakatools::elements_with_stride<uint32_t, T_Acc>(acc, foundNtuplets->nbins())) {
363363
auto nhits = foundNtuplets->size(it);
364364
if (nhits >= 3 && quality[it] != trackQuality::dup) {
@@ -378,7 +378,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
378378
HitContainer const *__restrict__ foundNtuplets,
379379
Quality const *__restrict__ quality,
380380
CAConstants::TupleMultiplicity *tupleMultiplicity) const {
381-
382381
for (uint32_t it : cms::alpakatools::elements_with_stride<uint32_t, T_Acc>(acc, foundNtuplets->nbins())) {
383382
auto nhits = foundNtuplets->size(it);
384383
if (nhits >= 3 && quality[it] != trackQuality::dup) {
@@ -399,7 +398,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
399398
TkSoA const *__restrict__ tracks,
400399
CAHitNtupletGeneratorKernels::QualityCuts cuts,
401400
Quality *__restrict__ quality) const {
402-
403401
for (uint32_t it : cms::alpakatools::elements_with_stride<uint32_t, T_Acc>(acc, tuples->nbins())) {
404402
auto nhits = tuples->size(it);
405403
if (nhits == 0)
@@ -466,7 +464,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
466464
HitContainer const *__restrict__ tuples,
467465
Quality const *__restrict__ quality,
468466
CAHitNtupletGeneratorKernels::Counters *counters) const {
469-
470467
for (uint32_t idx : cms::alpakatools::elements_with_stride<uint32_t, T_Acc>(acc, tuples->nbins())) {
471468
if (tuples->size(idx) == 0)
472469
return; //guard
@@ -483,7 +480,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
483480
HitContainer const *__restrict__ tuples,
484481
Quality const *__restrict__ quality,
485482
CAHitNtupletGeneratorKernels::HitToTuple *hitToTuple) const {
486-
487483
for (uint32_t idx : cms::alpakatools::elements_with_stride<uint32_t, T_Acc>(acc, tuples->nbins())) {
488484
if (tuples->size(idx) == 0)
489485
return; // guard
@@ -501,7 +497,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
501497
HitContainer const *__restrict__ tuples,
502498
Quality const *__restrict__ quality,
503499
CAHitNtupletGeneratorKernels::HitToTuple *hitToTuple) const {
504-
505500
for (uint32_t idx : cms::alpakatools::elements_with_stride<uint32_t, T_Acc>(acc, tuples->nbins())) {
506501
if (tuples->size(idx) == 0)
507502
return; // guard
@@ -608,7 +603,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
608603

609604
} // maxNh
610605
} // hitToTuple.size
611-
} // loop over hits
606+
} // loop over hits
612607
}
613608
};
614609

0 commit comments

Comments
 (0)