ruda_kernel/dsl/frontend/
topology.rs1use ruda_core::ir::{ManagedVariable, Scope};
5
6use crate::dsl::prelude::RudaPrimitive;
7
8use super::NativeExpand;
9
10macro_rules! constant {
11 ($ident:ident, $var:expr, $doc:expr) => {
12 #[doc = $doc]
13 pub const $ident: u32 = 2;
14
15 #[allow(non_snake_case)]
16 #[doc = $doc]
17 pub mod $ident {
18 use super::*;
19
20 pub fn expand(scope: &mut Scope) -> NativeExpand<u32> {
22 NativeExpand::new(ManagedVariable::Plain(crate::dsl::ir::Variable::builtin(
23 $var,
24 u32::as_type(scope).storage_type(),
25 )))
26 }
27 }
28 };
29}
30
31macro_rules! constant_usize {
32 ($ident:ident, $var:expr, $doc:expr) => {
33 #[doc = $doc]
34 pub const $ident: usize = 2;
35
36 #[allow(non_snake_case)]
37 #[doc = $doc]
38 pub mod $ident {
39 use super::*;
40
41 pub fn expand(scope: &mut Scope) -> NativeExpand<usize> {
43 NativeExpand::new(ManagedVariable::Plain(crate::dsl::ir::Variable::builtin(
44 $var,
45 usize::as_type(scope).storage_type(),
46 )))
47 }
48 }
49 };
50}
51
52constant!(
53 PLANE_DIM,
54 crate::dsl::ir::Builtin::PlaneDim,
55 r"
56The total amount of working units in a plane.
57"
58);
59
60constant!(
61 PLANE_POS,
62 crate::dsl::ir::Builtin::PlanePos,
63 r"
64The position of the plane within the ruda (plane/warp/subgroup index).
65"
66);
67
68constant!(
69 PLANE_COUNT,
70 crate::dsl::ir::Builtin::PlaneCount,
71 r"
72The number of planes in the current ruda.
73"
74);
75
76constant!(
77 UNIT_POS_PLANE,
78 crate::dsl::ir::Builtin::UnitPosPlane,
79 r"
80The relative position of the working unit inside the plane, without regards to ruda dimensions.
81"
82);
83
84constant!(
85 UNIT_POS,
86 crate::dsl::ir::Builtin::UnitPos,
87 r"
88The position of the working unit inside the ruda, without regards to axis.
89"
90);
91
92constant!(
93 UNIT_POS_X,
94 crate::dsl::ir::Builtin::UnitPosX,
95 r"
96The position of the working unit inside the ruda along the X axis.
97"
98);
99
100constant!(
101 UNIT_POS_Y,
102 crate::dsl::ir::Builtin::UnitPosY,
103 r"
104The position of the working unit inside the ruda along the Y axis.
105"
106);
107
108constant!(
109 UNIT_POS_Z,
110 crate::dsl::ir::Builtin::UnitPosZ,
111 r"
112The position of the working unit inside the ruda along the Z axis.
113"
114);
115
116constant!(
117 RUDA_CLUSTER_DIM,
118 crate::dsl::ir::Builtin::ClusterDim,
119 r"
120The total amount of rudas in a cluster.
121"
122);
123
124constant!(
125 RUDA_CLUSTER_DIM_X,
126 crate::dsl::ir::Builtin::ClusterDimX,
127 r"
128The dimension of the cluster along the X axis.
129"
130);
131
132constant!(
133 RUDA_CLUSTER_DIM_Y,
134 crate::dsl::ir::Builtin::ClusterDimY,
135 r"
136The dimension of the cluster along the Y axis.
137"
138);
139
140constant!(
141 RUDA_CLUSTER_DIM_Z,
142 crate::dsl::ir::Builtin::ClusterDimZ,
143 r"
144The dimension of the cluster along the Z axis.
145"
146);
147
148constant!(
149 RUDA_DIM,
150 crate::dsl::ir::Builtin::RudaDim,
151 r"
152The total amount of working units in a ruda.
153"
154);
155
156constant!(
157 RUDA_DIM_X,
158 crate::dsl::ir::Builtin::RudaDimX,
159 r"
160The dimension of the ruda along the X axis.
161"
162);
163
164constant!(
165 RUDA_DIM_Y,
166 crate::dsl::ir::Builtin::RudaDimY,
167 r"
168The dimension of the ruda along the Y axis.
169"
170);
171
172constant!(
173 RUDA_DIM_Z,
174 crate::dsl::ir::Builtin::RudaDimZ,
175 r"
176The dimension of the ruda along the Z axis.
177"
178);
179
180constant_usize!(
181 RUDA_POS,
182 crate::dsl::ir::Builtin::RudaPos,
183 r"
184The ruda position, without regards to axis.
185"
186);
187
188constant!(
189 RUDA_POS_X,
190 crate::dsl::ir::Builtin::RudaPosX,
191 r"
192The ruda position along the X axis.
193"
194);
195
196constant!(
197 RUDA_POS_Y,
198 crate::dsl::ir::Builtin::RudaPosY,
199 r"
200The ruda position along the Y axis.
201"
202);
203
204constant!(
205 RUDA_POS_Z,
206 crate::dsl::ir::Builtin::RudaPosZ,
207 r"
208The ruda position along the Z axis.
209"
210);
211
212constant!(
213 RUDA_POS_CLUSTER,
214 crate::dsl::ir::Builtin::RudaPosCluster,
215 r"
216The ruda position within the cluster.
217"
218);
219
220constant!(
221 RUDA_POS_CLUSTER_X,
222 crate::dsl::ir::Builtin::RudaPosClusterX,
223 r"
224The ruda position in the cluster along the X axis.
225"
226);
227
228constant!(
229 RUDA_POS_CLUSTER_Y,
230 crate::dsl::ir::Builtin::RudaPosClusterY,
231 r"
232The ruda position in the cluster along the Y axis.
233"
234);
235
236constant!(
237 RUDA_POS_CLUSTER_Z,
238 crate::dsl::ir::Builtin::RudaPosClusterZ,
239 r"
240The ruda position in the cluster along the Z axis.
241"
242);
243
244constant_usize!(
245 RUDA_COUNT,
246 crate::dsl::ir::Builtin::RudaCount,
247 r"
248The number of rudas launched.
249"
250);
251
252constant!(
253 RUDA_COUNT_X,
254 crate::dsl::ir::Builtin::RudaCountX,
255 r"
256The number of rudas launched along the X axis.
257"
258);
259
260constant!(
261 RUDA_COUNT_Y,
262 crate::dsl::ir::Builtin::RudaCountY,
263 r"
264The number of rudas launched along the Y axis.
265"
266);
267
268constant!(
269 RUDA_COUNT_Z,
270 crate::dsl::ir::Builtin::RudaCountZ,
271 r"
272The number of rudas launched along the Z axis.
273"
274);
275
276constant_usize!(
277 ABSOLUTE_POS,
278 crate::dsl::ir::Builtin::AbsolutePos,
279 r"
280The position of the working unit in the whole ruda kernel, without regards to rudas and axis.
281"
282);
283
284constant!(
285 ABSOLUTE_POS_X,
286 crate::dsl::ir::Builtin::AbsolutePosX,
287 r"
288The index of the working unit in the whole ruda kernel along the X axis, without regards to rudas.
289"
290);
291
292constant!(
293 ABSOLUTE_POS_Y,
294 crate::dsl::ir::Builtin::AbsolutePosY,
295 r"
296The index of the working unit in the whole ruda kernel along the Y axis, without regards to rudas.
297"
298);
299
300constant!(
301 ABSOLUTE_POS_Z,
302 crate::dsl::ir::Builtin::AbsolutePosZ,
303 r"
304The index of the working unit in the whole ruda kernel along the Z axis, without regards to rudas.
305"
306);