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 return linearBlockIdx + Vec{warp::internal::getWarpIdx(acc)};
78 }
79 };
80
81 template<concepts::Acc T_Acc>
82 struct GetIdxWithin::Op<T_Acc, ALPAKA_TYPEOF(origin::grid), ALPAKA_TYPEOF(unit::blocks)>
83 {
84 constexpr alpaka::concepts::Vector auto operator()(
85 T_Acc const& acc,
86 ALPAKA_TYPEOF(origin::grid),
87 ALPAKA_TYPEOF(unit::blocks)) const
88 {
89 return acc[layer::block].idx();
90 }
91 };
92
93 template<concepts::Acc T_Acc>
94 struct GetIdxWithin::Op<T_Acc, ALPAKA_TYPEOF(origin::thread), ALPAKA_TYPEOF(unit::threads)>
95 {
96 /** The identity of the thread.
97 *
98 * @return Zero for all components of the extent.
99 */
100 constexpr alpaka::concepts::Vector auto operator()(
101 T_Acc const& acc,
102 ALPAKA_TYPEOF(origin::thread),
103 ALPAKA_TYPEOF(unit::threads)) const
104 {
105 using ExtentType = ALPAKA_TYPEOF(acc[layer::thread].idx());
106
107 using ValueType = typename ExtentType::type;
108 constexpr uint32_t dim = ExtentType::dim();
109
111 }
112 };
113
114 template<concepts::Acc T_Acc>
115 struct GetExtentsOf::Op<T_Acc, ALPAKA_TYPEOF(origin::warp), ALPAKA_TYPEOF(unit::threads)>
116 {
117 constexpr alpaka::concepts::CVector<uint32_t> auto operator()(
118 T_Acc const& acc,
119 ALPAKA_TYPEOF(origin::warp),
120 ALPAKA_TYPEOF(unit::threads)) const
121 {
122 alpaka::unused(acc);
123 return alpaka::CVec<uint32_t, T_Acc::getWarpSize()>{};
124 }
125 };
126
127 template<concepts::Acc T_Acc>
128 struct GetExtentsOf::Op<T_Acc, ALPAKA_TYPEOF(origin::block), ALPAKA_TYPEOF(unit::threads)>
129 {
130 constexpr alpaka::concepts::Vector auto operator()(
131 T_Acc const& acc,
132 ALPAKA_TYPEOF(origin::block),
133 ALPAKA_TYPEOF(unit::threads)) const
134 {
135 return acc[layer::thread].count();
136 }
137 };
138
139 template<concepts::Acc T_Acc>
140 struct GetExtentsOf::Op<T_Acc, ALPAKA_TYPEOF(origin::block), ALPAKA_TYPEOF(unit::warps)>
141 {
142 constexpr alpaka::concepts::Vector<alpaka::NotRequired, 1u> auto operator()(
143 T_Acc const& acc,
144 ALPAKA_TYPEOF(origin::block),
145 ALPAKA_TYPEOF(unit::warps)) const
146 {
147 std::integral auto linearThreadsInBlock
148 = acc.getExtentsOf(onAcc::origin::block, onAcc::unit::threads).product();
149 using IndexType = alpaka::trait::GetValueType_t<ALPAKA_TYPEOF(linearThreadsInBlock)>;
150 return Vec{divCeil(linearThreadsInBlock, static_cast<IndexType>(T_Acc::getWarpSize()))};
151 }
152 };
153
154 template<concepts::Acc T_Acc>
155 struct GetExtentsOf::Op<T_Acc, ALPAKA_TYPEOF(origin::grid), ALPAKA_TYPEOF(unit::blocks)>
156 {
157 constexpr alpaka::concepts::Vector auto operator()(
158 T_Acc const& acc,
159 ALPAKA_TYPEOF(origin::grid),
160 ALPAKA_TYPEOF(unit::blocks)) const
161 {
162 return acc[layer::block].count();
163 }
164 };
165
166 template<concepts::Acc T_Acc>
167 struct GetExtentsOf::Op<T_Acc, ALPAKA_TYPEOF(origin::grid), ALPAKA_TYPEOF(unit::warps)>
168 {
169 constexpr alpaka::concepts::Vector<alpaka::NotRequired, 1u> auto operator()(
170 T_Acc const& acc,
171 ALPAKA_TYPEOF(origin::grid),
172 ALPAKA_TYPEOF(unit::warps)) const
173 {
174 std::integral auto linearNumWarpsInBlock
175 = acc.getExtentsOf(onAcc::origin::block, onAcc::unit::warps).product();
176 std::integral auto linearNumBlocks
177 = acc.getExtentsOf(onAcc::origin::grid, onAcc::unit::blocks).product();
178 return Vec{linearNumBlocks * linearNumWarpsInBlock};
179 }
180 };
181
182 template<concepts::Acc T_Acc>
183 struct GetExtentsOf::Op<T_Acc, ALPAKA_TYPEOF(origin::grid), ALPAKA_TYPEOF(unit::threads)>
184 {
185 constexpr alpaka::concepts::Vector auto operator()(
186 T_Acc const& acc,
187 ALPAKA_TYPEOF(origin::grid),
188 ALPAKA_TYPEOF(unit::threads)) const
189 {
190 return acc[layer::block].count() * acc[layer::thread].count();
191 }
192 };
193
194 template<concepts::Acc T_Acc>
195 struct GetExtentsOf::Op<T_Acc, ALPAKA_TYPEOF(origin::thread), ALPAKA_TYPEOF(unit::threads)>
196 {
197 /** The identity of the thread.
198 *
199 * @return One for all components of the extent.
200 */
201 constexpr alpaka::concepts::Vector auto operator()(
202 T_Acc const& acc,
203 ALPAKA_TYPEOF(origin::thread),
204 ALPAKA_TYPEOF(unit::threads)) const
205 {
206 using ExtentType = ALPAKA_TYPEOF(acc[layer::thread].count());
207 using ValueType = typename ExtentType::type;
208 constexpr uint32_t dim = ExtentType::dim();
209
211 }
212 };
213 } // namespace internalCompute
214} // namespace alpaka::onAcc
#define ALPAKA_TYPEOF(...)
Get the type of instance.
Definition common.hpp:153
constexpr auto block
Definition tag.hpp:261
constexpr auto thread
Definition tag.hpp:255
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:832
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