alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
warp.hpp
Go to the documentation of this file.
1/* Copyright 2025 Mehmet Yusufoglu, René Widera
2 * SPDX-License-Identifier: MPL-2.0
3 *
4 * Defines the Alpaka3 warp traits for kernel calls for votes and shuffles.
5 * Central helpers (all, any, ballot, shfl…) forward to trait::Op specializations.
6 *
7 * Dispatch now depends on api::X and deviceKind::Y tags, keeping the layer backend free.
8 * Provides a single entry point that works for host and GPU backends alike.
9 *
10 * Legacy Alpaka preferred the dispatch through ConceptWarp implementations per accelerator and used
11 * interface::ImplementationBase indirection to select the correct implementation.
12 */
13
14#pragma once
15
17#include "alpaka/api/trait.hpp"
19#include "alpaka/onAcc/Acc.hpp"
20#include "alpaka/tag.hpp"
21
22#include <cstdint>
23
24namespace alpaka::onAcc::warp::internal
25{
26 template<alpaka::onAcc::concepts::Acc T_Acc>
27 constexpr uint32_t getSize()
28 {
29 return T_Acc::getWarpSize();
30 }
31
32 /** Retrieve a bit-mask describing which warp lanes are active. */
33 struct Activemask
34 {
35 template<alpaka::onAcc::concepts::Acc T_Acc, alpaka::concepts::Api T_Api>
36 struct Op
37 {
38 constexpr auto operator()(T_Acc const&, T_Api) const
39 {
40 static_assert(sizeof(T_Acc) && false, "Missing warp Activemask implementation for the accelerator.");
41 return 0u;
42 }
43 };
44 };
45
46 struct GetLaneIdx
47 {
48 template<alpaka::onAcc::concepts::Acc T_Acc, alpaka::concepts::Api T_Api>
49 struct Op
50 {
51 constexpr auto operator()(T_Acc const&, T_Api) const
52 {
53 static_assert(sizeof(T_Acc) && false, "Missing warp GetLaneIdx implementation for the accelerator.");
54 return 0u;
55 }
56 };
57 };
58
59 /** Return the lane index of the current thread within its warp. */
60 constexpr uint32_t getLaneIdx(alpaka::onAcc::concepts::Acc auto const& acc)
61 {
62 using Acc = ALPAKA_TYPEOF(acc);
63 using Api = ALPAKA_TYPEOF(acc[object::api]);
64 return GetLaneIdx::Op<Acc, Api>{}(acc, Api{});
65 }
66
67 struct GetWarpIdx
68 {
69 template<alpaka::onAcc::concepts::Acc T_Acc, alpaka::concepts::Api T_Api>
70 struct Op
71 {
72 constexpr auto operator()(T_Acc const&, T_Api) const
73 {
74 static_assert(sizeof(T_Acc) && false, "Missing warp GetWarpIdx implementation for the accelerator.");
75 return 0u;
76 }
77 };
78 };
79
80 /** Return the warp index within the block. */
81 constexpr uint32_t getWarpIdx(alpaka::onAcc::concepts::Acc auto const& acc)
82 {
83 using Acc = ALPAKA_TYPEOF(acc);
84 using Api = ALPAKA_TYPEOF(acc[object::api]);
85 return GetWarpIdx::Op<Acc, Api>{}(acc, Api{});
86 }
87
88 struct All
89 {
90 template<alpaka::onAcc::concepts::Acc T_Acc, alpaka::concepts::Api T_Api>
91 struct Op
92 {
93 constexpr bool operator()(T_Acc const&, T_Api, int32_t predicate) const
94 {
95 alpaka::unused(predicate);
96 static_assert(sizeof(T_Acc) && false, "Missing warp All implementation for the accelerator.");
97 return false;
98 }
99 };
100 };
101
102 struct Any
103 {
104 template<alpaka::onAcc::concepts::Acc T_Acc, alpaka::concepts::Api T_Api>
105 struct Op
106 {
107 constexpr bool operator()(T_Acc const&, T_Api, int32_t predicate) const
108 {
109 alpaka::unused(predicate);
110 static_assert(sizeof(T_Acc) && false, "Missing warp Any implementation for the accelerator.");
111 return false;
112 }
113 };
114 };
115
116 struct Ballot
117 {
118 template<alpaka::onAcc::concepts::Acc T_Acc, alpaka::concepts::Api T_Api>
119 struct Op
120 {
121 constexpr auto operator()(T_Acc const&, T_Api, int32_t predicate) const
122 {
123 alpaka::unused(predicate);
124 static_assert(sizeof(T_Acc) && false, "Missing warp Ballot implementation for the accelerator.");
125 return 0;
126 }
127 };
128 };
129
130 struct Shfl
131 {
132 template<alpaka::onAcc::concepts::Acc T_Acc, alpaka::concepts::Api T_Api, typename T>
133 struct Op
134 {
135 constexpr T operator()(T_Acc const&, T_Api, T const& value, uint32_t srcLane, uint32_t width) const
136 {
137 alpaka::unused(value, srcLane, width);
138 static_assert(sizeof(T_Acc) && false, "Missing warp Shfl implementation for the accelerator.");
139 return T{};
140 }
141 };
142 };
143
144 struct ShflDown
145 {
146 template<alpaka::onAcc::concepts::Acc T_Acc, alpaka::concepts::Api T_Api, typename T>
147 struct Op
148 {
149 constexpr T operator()(T_Acc const&, T_Api, T const& value, uint32_t delta, uint32_t width) const
150 {
151 alpaka::unused(value, delta, width);
152 static_assert(sizeof(T_Acc) && false, "Missing warp ShflDown implementation for the accelerator.");
153 return T{};
154 }
155 };
156 };
157
158 struct ShflUp
159 {
160 template<alpaka::onAcc::concepts::Acc T_Acc, alpaka::concepts::Api T_Api, typename T>
161 struct Op
162 {
163 constexpr T operator()(T_Acc const&, T_Api, T const& value, uint32_t delta, uint32_t width) const
164 {
165 alpaka::unused(value, delta, width);
166 static_assert(sizeof(T_Acc) && false, "Missing warp ShflUp implementation for the accelerator.");
167 return T{};
168 }
169 };
170 };
171
172 struct ShflXor
173 {
174 template<alpaka::onAcc::concepts::Acc T_Acc, alpaka::concepts::Api T_Api, typename T>
175 struct Op
176 {
177 constexpr T operator()(T_Acc const&, T_Api, T const& value, uint32_t laneMask, uint32_t width) const
178 {
179 alpaka::unused(value, laneMask, width);
180 static_assert(sizeof(T_Acc) && false, "Missing warp ShflXor implementation for the accelerator.");
181 return T{};
182 }
183 };
184 };
185} // namespace alpaka::onAcc::warp::internal
#define ALPAKA_TYPEOF(...)
Get the type of instance.
Definition common.hpp:153
constexpr Api api
Definition tag.hpp:24
constexpr uint32_t getSize()
Return the warp size.
Definition warp.hpp:122