Skip to content

Commit

Permalink
Update test to use once_per_block
Browse files Browse the repository at this point in the history
  • Loading branch information
fwyzard committed Apr 22, 2024
1 parent 4fc762b commit e08a9a8
Showing 1 changed file with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ enum class RangeType { Default, ExtentLimited, ExtentLimitedWithShift };
// The concurrency scope between threads
enum class LoopScope { Block, Grid };

// Utility for one time initializations
template <LoopScope loopScope, typename TAcc>
bool constexpr firstInLoopRange(TAcc const& acc) {
if constexpr (loopScope == LoopScope::Block)
return not alpaka::getIdx<alpaka::Block, alpaka::Threads>(acc)[0u];
if constexpr (loopScope == LoopScope::Grid)
return not alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc)[0u];
assert(false);
}

template <RangeType rangeType, LoopScope loopScope, typename TAcc>
size_t constexpr expectedCount(TAcc const& acc, size_t skip, size_t size) {
if constexpr (rangeType == RangeType::ExtentLimitedWithShift)
Expand Down Expand Up @@ -65,8 +55,9 @@ struct testWordDivisionDefaultRange {
(loopScope == LoopScope::Grid ? *globalCounter : alpaka::declareSharedVar<size_t, __COUNTER__>(acc));
// Init the counter for block range. Grid range does so my mean of memset.
if constexpr (loopScope == LoopScope::Block) {
if (firstInLoopRange<loopScope>(acc))
if (cms::alpakatools::once_per_block(acc)) {
counter = 0;
}
alpaka::syncBlockThreads(acc);
}
// The loop we are testing
Expand All @@ -82,7 +73,7 @@ struct testWordDivisionDefaultRange {
alpaka::syncBlockThreads(acc);
// Check the result. Grid range will check by memcpy-ing the result.
if constexpr (loopScope == LoopScope::Block) {
if (firstInLoopRange<loopScope>(acc)) {
if (cms::alpakatools::once_per_block(acc)) {
auto expected = expectedCount<rangeType, loopScope>(acc, skip, size);
ALPAKA_ASSERT_ACC(counter == expected);
}
Expand Down

0 comments on commit e08a9a8

Please sign in to comment.