alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
interfaceImpl.hpp
Go to the documentation of this file.
1/* Copyright 2024 René Widera
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
7/** @file This file contains specializations of interfaces for the accelerator scope.
8 * The specializations must be separated from the definitions to avoid cyclic include dependencies.
9 */
10
13
14namespace alpaka::onAcc
15{
16 namespace internalCompute
17 {
18 template<concepts::Acc T_Acc>
19 struct GetIdxWithin::Op<T_Acc, ALPAKA_TYPEOF(origin::warp), ALPAKA_TYPEOF(unit::threads)>
20 {
21 constexpr alpaka::concepts::Vector<uint32_t, 1u> auto operator()(
22 T_Acc const& acc,
23 ALPAKA_TYPEOF(origin::warp),
24 ALPAKA_TYPEOF(unit::threads)) const
25 {
26 return Vec{warp::internal::getLaneIdx(acc)};
27 }
28 };
29
30 template<typename T_Acc>
31 struct GetIdxWithin::Op<T_Acc, ALPAKA_TYPEOF(origin::block), ALPAKA_TYPEOF(unit::threads)>
32 {
33 constexpr alpaka::concepts::Vector auto operator()(
34 T_Acc const& acc,
35 ALPAKA_TYPEOF(origin::block),
36 ALPAKA_TYPEOF(unit::threads)) const
37 {
38 return acc[layer::thread].idx();
39 }
40 };
41
42 template<concepts::Acc T_Acc>
43 struct GetIdxWithin::Op<T_Acc, ALPAKA_TYPEOF(origin::block), ALPAKA_TYPEOF(unit::warps)>
44 {
45 constexpr alpaka::concepts::Vector<uint32_t, 1u> auto operator()(
46 T_Acc const& acc,
47 ALPAKA_TYPEOF(origin::block),
48 ALPAKA_TYPEOF(unit::warps)) const
49 {
50 return Vec{warp::internal::getWarpIdx(acc)};
51 }
52 };
53
54 template<typename T_Acc>
55 struct GetIdxWithin::Op<T_Acc, ALPAKA_TYPEOF(origin::grid), ALPAKA_TYPEOF(unit::threads)>
56 {
57 constexpr alpaka::concepts::Vector auto operator()(
58 T_Acc const& acc,
59 ALPAKA_TYPEOF(origin::grid),
60 ALPAKA_TYPEOF(unit::threads)) const
61 {
62 return acc[layer::thread].count() * acc[layer::block].idx() + acc[layer::thread].idx();
63 }
64 };
65
66 template<concepts::Acc T_Acc>
67 struct GetIdxWithin::Op<T_Acc, ALPAKA_TYPEOF(origin::grid), ALPAKA_TYPEOF(unit::warps)>
68 {
69 constexpr alpaka::concepts::Vector<uint32_t, 1u> auto operator()(
70 T_Acc const& acc,
71 ALPAKA_TYPEOF(origin::grid),
72 ALPAKA_TYPEOF(unit::warps)) const
73 {
74 auto blockIdxInGrid = acc.getIdxWithin(onAcc::origin::grid, onAcc::unit::blocks);
75 auto numBlocksInGrid = acc.getExtentsOf(onAcc::origin::grid, onAcc::unit::blocks);
76 auto linearBlockIdx = linearize(numBlocksInGrid, blockIdxInGrid);
77
78 std::integral auto linearNumWarpsInBlock
79 = acc.getExtentsOf(onAcc::origin::block, onAcc::unit::warps).product();
80 return linearBlockIdx * linearNumWarpsInBlock + Vec{warp::internal::getWarpIdx(acc)};
81 }
82 };
83
84 template<concepts::Acc T_Acc>
85 struct GetIdxWithin::Op<T_Acc, ALPAKA_TYPEOF(origin::grid), ALPAKA_TYPEOF(unit::blocks)>
86 {
87 constexpr alpaka::concepts::Vector auto operator()(
88 T_Acc const& acc,
89 ALPAKA_TYPEOF(origin::grid),
90 ALPAKA_TYPEOF(unit::blocks)) const
91 {
92 return acc[layer::block].idx();
93 }
94 };
95
96 template<concepts::Acc T_Acc>
97 struct GetIdxWithin::Op<T_Acc, ALPAKA_TYPEOF(origin::thread), ALPAKA_TYPEOF(unit::threads)>
98 {
99 /** The identity of the thread.
100 *
101 * @return Zero for all components of the extent.
102 */
103 constexpr alpaka::concepts::Vector auto operator()(
104 T_Acc const& acc,
105 ALPAKA_TYPEOF(origin::thread),
106 ALPAKA_TYPEOF(unit::threads)) const
107 {
108 using ExtentType = ALPAKA_TYPEOF(acc[layer::thread].idx());
109
110 using ValueType = typename ExtentType::type;
111 constexpr uint32_t dim = ExtentType::dim();
112
114 }
115 };
116
117 template<concepts::Acc T_Acc>
118 struct GetExtentsOf::Op<T_Acc, ALPAKA_TYPEOF(origin::warp), ALPAKA_TYPEOF(unit::threads)>
119 {
120 constexpr alpaka::concepts::CVector<uint32_t> auto operator()(
121 T_Acc const& acc,
122 ALPAKA_TYPEOF(origin::warp),
123 ALPAKA_TYPEOF(unit::threads)) const
124 {
125 alpaka::unused(acc);
126 return alpaka::CVec<uint32_t, T_Acc::getWarpSize()>{};
127 }
128 };
129
130 template<concepts::Acc T_Acc>
131 struct GetExtentsOf::Op<T_Acc, ALPAKA_TYPEOF(origin::block), ALPAKA_TYPEOF(unit::threads)>
132 {
133 constexpr alpaka::concepts::Vector auto operator()(
134 T_Acc const& acc,
135 ALPAKA_TYPEOF(origin::block),
136 ALPAKA_TYPEOF(unit::threads)) const
137 {
138 return acc[layer::thread].count();
139 }
140 };
141
142 template<concepts::Acc T_Acc>
143 struct GetExtentsOf::Op<T_Acc, ALPAKA_TYPEOF(origin::block), ALPAKA_TYPEOF(unit::warps)>
144 {
145 constexpr alpaka::concepts::Vector<alpaka::NotRequired, 1u> auto operator()(
146 T_Acc const& acc,
147 ALPAKA_TYPEOF(origin::block),
148 ALPAKA_TYPEOF(unit::warps)) const
149 {
150 std::integral auto linearThreadsInBlock
151 = acc.getExtentsOf(onAcc::origin::block, onAcc::unit::threads).product();
152 using IndexType = alpaka::trait::GetValueType_t<ALPAKA_TYPEOF(linearThreadsInBlock)>;
153 return Vec{divCeil(linearThreadsInBlock, static_cast<IndexType>(T_Acc::getWarpSize()))};
154 }
155 };
156
157 template<concepts::Acc T_Acc>
158 struct GetExtentsOf::Op<T_Acc, ALPAKA_TYPEOF(origin::grid), ALPAKA_TYPEOF(unit::blocks)>
159 {
160 constexpr alpaka::concepts::Vector auto operator()(
161 T_Acc const& acc,
162 ALPAKA_TYPEOF(origin::grid),
163 ALPAKA_TYPEOF(unit::blocks)) const
164 {
165 return acc[layer::block].count();
166 }
167 };
168
169 template<concepts::Acc T_Acc>
170 struct GetExtentsOf::Op<T_Acc, ALPAKA_TYPEOF(origin::grid), ALPAKA_TYPEOF(unit::warps)>
171 {
172 constexpr alpaka::concepts::Vector<alpaka::NotRequired, 1u> auto operator()(
173 T_Acc const& acc,
174 ALPAKA_TYPEOF(origin::grid),
175 ALPAKA_TYPEOF(unit::warps)) const
176 {
177 std::integral auto linearNumWarpsInBlock
178 = acc.getExtentsOf(onAcc::origin::block, onAcc::unit::warps).product();
179 std::integral auto linearNumBlocks
180 = acc.getExtentsOf(onAcc::origin::grid, onAcc::unit::blocks).product();
181 return Vec{linearNumBlocks * linearNumWarpsInBlock};
182 }
183 };
184
185 template<concepts::Acc T_Acc>
186 struct GetExtentsOf::Op<T_Acc, ALPAKA_TYPEOF(origin::grid), ALPAKA_TYPEOF(unit::threads)>
187 {
188 constexpr alpaka::concepts::Vector auto operator()(
189 T_Acc const& acc,
190 ALPAKA_TYPEOF(origin::grid),
191 ALPAKA_TYPEOF(unit::threads)) const
192 {
193 return acc[layer::block].count() * acc[layer::thread].count();
194 }
195 };
196
197 template<concepts::Acc T_Acc>
198 struct GetExtentsOf::Op<T_Acc, ALPAKA_TYPEOF(origin::thread), ALPAKA_TYPEOF(unit::threads)>
199 {
200 /** The identity of the thread.
201 *
202 * @return One for all components of the extent.
203 */
204 constexpr alpaka::concepts::Vector auto operator()(
205 T_Acc const& acc,
206 ALPAKA_TYPEOF(origin::thread),
207 ALPAKA_TYPEOF(unit::threads)) const
208 {
209 using ExtentType = ALPAKA_TYPEOF(acc[layer::thread].count());
210 using ValueType = typename ExtentType::type;
211 constexpr uint32_t dim = ExtentType::dim();
212
214 }
215 };
216 } // namespace internalCompute
217} // namespace alpaka::onAcc
#define ALPAKA_TYPEOF(...)
Get the type of instance.
Definition common.hpp:154
constexpr auto block
Definition tag.hpp:259
constexpr auto thread
Definition tag.hpp:253
constexpr auto linearThreadsInBlock
Definition range.hpp:24
constexpr Block block
Definition scope.hpp:51
functionality which is usable on the accelerator compute device from within a kernel.
Definition executor.hpp:38
typename GetValueType< T >::type GetValueType_t
Definition trait.hpp:65
ALPAKA_FN_HOST_ACC constexpr auto divCeil(Integral a, Integral b) -> Integral
Returns the ceiling of a / b, as integer.
Definition utility.hpp:34
constexpr T_IntegralType linearize(Vec< T_IntegralType, T_dim - 1u, T_Storage > const &dim, Vec< T_IntegralType, T_dim, T_OtherStorage > const &idx)
Give the linear index of an N-dimensional index within an N-dimensional index space.
Definition Vec.hpp:839
Vec< T, sizeof...(T_values), detail::CVec< T, T_values... > > CVec
A vector with compile-time known values.
Definition CVec.hpp:31
ALPAKA_FN_HOST_ACC Vec(T_1, T_Args...) -> Vec< T_1, uint32_t(sizeof...(T_Args)+1u), ArrayStorage< T_1, uint32_t(sizeof...(T_Args)+1u)> >
consteval auto fillCVec()
Create and return a CVector of some length, filled with the given value.
Definition CVec.hpp:153