cubecl_core/frontend/
topology.rs1use cubecl_ir::{Instruction, Operator, Scope};
5
6use crate::prelude::CubePrimitive;
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: &Scope) -> NativeExpand<u32> {
22 let out = scope.create_value(u32::__expand_as_type(scope));
23 scope.register(Instruction::new(Operator::ReadBuiltin($var), out));
24 out.into()
25 }
26 }
27 };
28}
29
30macro_rules! constant_usize {
31 ($ident:ident, $var:expr, $doc:expr) => {
32 #[doc = $doc]
33 pub const $ident: usize = 2;
34
35 #[allow(non_snake_case)]
36 #[doc = $doc]
37 pub mod $ident {
38 use super::*;
39
40 pub fn expand(scope: &Scope) -> NativeExpand<usize> {
42 let out = scope.create_value(usize::__expand_as_type(scope));
43 scope.register(Instruction::new(Operator::ReadBuiltin($var), out));
44 out.into()
45 }
46 }
47 };
48}
49
50constant!(
51 PLANE_DIM,
52 crate::ir::Builtin::PlaneDim,
53 r"
54The total amount of working units in a plane.
55"
56);
57
58constant!(
59 PLANE_POS,
60 crate::ir::Builtin::PlanePos,
61 r"
62The position of the plane within the cube (plane/warp/subgroup index).
63"
64);
65
66constant!(
67 UNIT_POS_PLANE,
68 crate::ir::Builtin::UnitPosPlane,
69 r"
70The relative position of the working unit inside the plane, without regards to cube dimensions.
71"
72);
73
74constant!(
75 UNIT_POS,
76 crate::ir::Builtin::UnitPos,
77 r"
78The position of the working unit inside the cube, without regards to axis.
79"
80);
81
82constant!(
83 UNIT_POS_X,
84 crate::ir::Builtin::UnitPosX,
85 r"
86The position of the working unit inside the cube along the X axis.
87"
88);
89
90constant!(
91 UNIT_POS_Y,
92 crate::ir::Builtin::UnitPosY,
93 r"
94The position of the working unit inside the cube along the Y axis.
95"
96);
97
98constant!(
99 UNIT_POS_Z,
100 crate::ir::Builtin::UnitPosZ,
101 r"
102The position of the working unit inside the cube along the Z axis.
103"
104);
105
106constant!(
107 CUBE_CLUSTER_DIM,
108 crate::ir::Builtin::CubeClusterDim,
109 r"
110The total amount of cubes in a cluster.
111"
112);
113
114constant!(
115 CUBE_CLUSTER_DIM_X,
116 crate::ir::Builtin::CubeClusterDimX,
117 r"
118The dimension of the cluster along the X axis.
119"
120);
121
122constant!(
123 CUBE_CLUSTER_DIM_Y,
124 crate::ir::Builtin::CubeClusterDimY,
125 r"
126The dimension of the cluster along the Y axis.
127"
128);
129
130constant!(
131 CUBE_CLUSTER_DIM_Z,
132 crate::ir::Builtin::CubeClusterDimZ,
133 r"
134The dimension of the cluster along the Z axis.
135"
136);
137
138constant!(
139 CUBE_DIM,
140 crate::ir::Builtin::CubeDim,
141 r"
142The total amount of working units in a cube.
143"
144);
145
146constant!(
147 CUBE_DIM_X,
148 crate::ir::Builtin::CubeDimX,
149 r"
150The dimension of the cube along the X axis.
151"
152);
153
154constant!(
155 CUBE_DIM_Y,
156 crate::ir::Builtin::CubeDimY,
157 r"
158The dimension of the cube along the Y axis.
159"
160);
161
162constant!(
163 CUBE_DIM_Z,
164 crate::ir::Builtin::CubeDimZ,
165 r"
166The dimension of the cube along the Z axis.
167"
168);
169
170constant_usize!(
171 CUBE_POS,
172 crate::ir::Builtin::CubePos,
173 r"
174The cube position, without regards to axis.
175"
176);
177
178constant!(
179 CUBE_POS_X,
180 crate::ir::Builtin::CubePosX,
181 r"
182The cube position along the X axis.
183"
184);
185
186constant!(
187 CUBE_POS_Y,
188 crate::ir::Builtin::CubePosY,
189 r"
190The cube position along the Y axis.
191"
192);
193
194constant!(
195 CUBE_POS_Z,
196 crate::ir::Builtin::CubePosZ,
197 r"
198The cube position along the Z axis.
199"
200);
201
202constant!(
203 CUBE_POS_CLUSTER,
204 crate::ir::Builtin::CubePosCluster,
205 r"
206The cube position within the cluster.
207"
208);
209
210constant!(
211 CUBE_POS_CLUSTER_X,
212 crate::ir::Builtin::CubePosClusterX,
213 r"
214The cube position in the cluster along the X axis.
215"
216);
217
218constant!(
219 CUBE_POS_CLUSTER_Y,
220 crate::ir::Builtin::CubePosClusterY,
221 r"
222The cube position in the cluster along the Y axis.
223"
224);
225
226constant!(
227 CUBE_POS_CLUSTER_Z,
228 crate::ir::Builtin::CubePosClusterZ,
229 r"
230The cube position in the cluster along the Z axis.
231"
232);
233
234constant_usize!(
235 CUBE_COUNT,
236 crate::ir::Builtin::CubeCount,
237 r"
238The number of cubes launched.
239"
240);
241
242constant!(
243 CUBE_COUNT_X,
244 crate::ir::Builtin::CubeCountX,
245 r"
246The number of cubes launched along the X axis.
247"
248);
249
250constant!(
251 CUBE_COUNT_Y,
252 crate::ir::Builtin::CubeCountY,
253 r"
254The number of cubes launched along the Y axis.
255"
256);
257
258constant!(
259 CUBE_COUNT_Z,
260 crate::ir::Builtin::CubeCountZ,
261 r"
262The number of cubes launched along the Z axis.
263"
264);
265
266constant_usize!(
267 ABSOLUTE_POS,
268 crate::ir::Builtin::AbsolutePos,
269 r"
270The position of the working unit in the whole cube kernel, without regards to cubes and axis.
271"
272);
273
274constant!(
275 ABSOLUTE_POS_X,
276 crate::ir::Builtin::AbsolutePosX,
277 r"
278The index of the working unit in the whole cube kernel along the X axis, without regards to cubes.
279"
280);
281
282constant!(
283 ABSOLUTE_POS_Y,
284 crate::ir::Builtin::AbsolutePosY,
285 r"
286The index of the working unit in the whole cube kernel along the Y axis, without regards to cubes.
287"
288);
289
290constant!(
291 ABSOLUTE_POS_Z,
292 crate::ir::Builtin::AbsolutePosZ,
293 r"
294The index of the working unit in the whole cube kernel along the Z axis, without regards to cubes.
295"
296);