forked from alpaka-group/alpaka3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.hpp
More file actions
64 lines (56 loc) · 1.81 KB
/
utils.hpp
File metadata and controls
64 lines (56 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* Copyright 2025 Mehmet Yusufoglu
* SPDX-License-Identifier: MPL-2.0
*/
#pragma once
#include <alpaka/alpaka.hpp>
#include <algorithm>
#include <cstdint>
#include <limits>
namespace alpaka::test::warp
{
using WarpTestBackends = std::decay_t<decltype(onHost::allBackends(onHost::enabledApis, exec::enabledExecutors))>;
template<typename SuccessView>
// Marks the shared success flag false when a lane detects a failure without aborting execution.
constexpr void warpCheck(SuccessView success, bool condition)
{
if(!condition)
{
// Trip the shared success flag without aborting the kernel.
success[0u] = false;
}
}
// Builds a mask with all lanes active for the provided warp size.
constexpr std::uint64_t fullMask(std::uint32_t warpSize)
{
if(warpSize == 0u)
{
return 0u;
}
if(warpSize >= 64u)
{
return std::numeric_limits<std::uint64_t>::max();
}
return (std::uint64_t{1} << warpSize) - 1u;
}
// Produces a mask that enables every even-numbered lane up to the warp size.
constexpr std::uint64_t evenMask(std::uint32_t warpSize)
{
auto const limit = warpSize < 64u ? warpSize : 64u;
std::uint64_t mask = 0u;
for(std::uint32_t lane = 0u; lane < limit; lane += 2u)
{
// Populate only even-numbered lanes to model a checkerboard mask.
mask |= (std::uint64_t{1} << lane);
}
return mask;
}
// Returns a mask with only the requested lane bit set if it fits within 64 lanes.
constexpr std::uint64_t singleBit(std::uint32_t lane)
{
if(lane >= 64u)
{
return 0u;
}
return std::uint64_t{1} << lane;
}
} // namespace alpaka::test::warp