1use cubecl_ir::ExpandValue;
2use half::{bf16, f16};
3
4use super::{CubePrimitive, Vector};
5use crate::prelude::*;
6use crate::{
7 ir::{Scope, attributes::IndexAttr, dialect::plane::*},
8 unexpanded,
9};
10
11pub trait PlaneNumeric {
12 fn __expand_native_sum(scope: &Scope, value: ExpandValue) -> ExpandValue;
13 fn __expand_native_inclusive_sum(scope: &Scope, value: ExpandValue) -> ExpandValue;
14 fn __expand_native_exclusive_sum(scope: &Scope, value: ExpandValue) -> ExpandValue;
15
16 fn __expand_native_prod(scope: &Scope, value: ExpandValue) -> ExpandValue;
17 fn __expand_native_inclusive_prod(scope: &Scope, value: ExpandValue) -> ExpandValue;
18 fn __expand_native_exclusive_prod(scope: &Scope, value: ExpandValue) -> ExpandValue;
19
20 fn __expand_native_plane_min(scope: &Scope, value: ExpandValue) -> ExpandValue;
21 fn __expand_native_plane_max(scope: &Scope, value: ExpandValue) -> ExpandValue;
22}
23
24macro_rules! plane_numeric {
25 ($($ty: ty),*; $sum: ty, $inc_sum: ty, $exc_sum: ty, $prod: ty, $inc_prod: ty, $exc_prod: ty, $min: ty, $max: ty) => {
26 $(impl PlaneNumeric for $ty {
27 fn __expand_native_sum(scope: &Scope, value: ExpandValue) -> ExpandValue {
28 unary_expand(scope, value, <$sum>::new)
29 }
30 fn __expand_native_inclusive_sum(scope: &Scope, value: ExpandValue) -> ExpandValue {
31 unary_expand(scope, value, <$inc_sum>::new)
32 }
33 fn __expand_native_exclusive_sum(scope: &Scope, value: ExpandValue) -> ExpandValue {
34 unary_expand(scope, value, <$exc_sum>::new)
35 }
36
37 fn __expand_native_prod(scope: &Scope, value: ExpandValue) -> ExpandValue {
38 unary_expand(scope, value, <$prod>::new)
39 }
40 fn __expand_native_inclusive_prod(scope: &Scope, value: ExpandValue) -> ExpandValue {
41 unary_expand(scope, value, <$inc_prod>::new)
42 }
43 fn __expand_native_exclusive_prod(scope: &Scope, value: ExpandValue) -> ExpandValue {
44 unary_expand(scope, value, <$exc_prod>::new)
45 }
46
47 fn __expand_native_plane_min(scope: &Scope, value: ExpandValue) -> ExpandValue {
48 unary_expand(scope, value, <$min>::new)
49 }
50 fn __expand_native_plane_max(scope: &Scope, value: ExpandValue) -> ExpandValue {
51 unary_expand(scope, value, <$max>::new)
52 }
53 })*
54 };
55}
56
57plane_numeric!(i8, i16, i32, i64, isize; ISumOp, InclusiveISumOp, ExclusiveISumOp, IProdOp, InclusiveIProdOp, ExclusiveIProdOp, SMinOp, SMaxOp);
58plane_numeric!(u8, u16, u32, u64, usize; ISumOp, InclusiveISumOp, ExclusiveISumOp, IProdOp, InclusiveIProdOp, ExclusiveIProdOp, UMinOp, UMaxOp);
59plane_numeric!(f16, bf16, f32, flex32, tf32, f64; FSumOp, InclusiveFSumOp, ExclusiveFSumOp, FProdOp, InclusiveFProdOp, ExclusiveFProdOp, FMinOp, FMaxOp);
60
61pub fn plane_elect() -> bool {
63 unexpanded!()
64}
65
66pub mod plane_elect {
68 use super::*;
69
70 pub fn expand(scope: &Scope) -> NativeExpand<bool> {
72 let op = ElectOp::new(scope.ctx_mut());
73 scope.register_with_result(&op).into()
74 }
75}
76
77#[allow(unused_variables)]
81pub fn plane_broadcast<E: CubePrimitive>(value: E, index: u32) -> E {
82 unexpanded!()
83}
84
85pub mod plane_broadcast {
87 use super::*;
88
89 pub fn expand<E: CubePrimitive>(
91 scope: &Scope,
92 value: NativeExpand<E>,
93 id: u32,
94 ) -> NativeExpand<E> {
95 let value = value.read_value(scope);
96 let op = BroadcastOp::new(scope.ctx_mut(), value, IndexAttr::new(id as usize));
97 scope.register_with_result(&op).into()
98 }
99}
100
101#[allow(unused_variables)]
108pub fn plane_shuffle<E: CubePrimitive>(value: E, src_lane: u32) -> E {
109 unexpanded!()
110}
111
112pub mod plane_shuffle {
114 use super::*;
115
116 pub fn expand<E: CubePrimitive>(
118 scope: &Scope,
119 value: NativeExpand<E>,
120 src_lane: NativeExpand<u32>,
121 ) -> NativeExpand<E> {
122 let value = value.read_value(scope);
123 let src_lane = src_lane.read_value(scope);
124 let op = ShuffleOp::new(scope.ctx_mut(), value, src_lane);
125 scope.register_with_result(&op).into()
126 }
127}
128
129#[allow(unused_variables)]
139pub fn plane_shuffle_xor<E: CubePrimitive>(value: E, mask: u32) -> E {
140 unexpanded!()
141}
142
143pub mod plane_shuffle_xor {
145 use super::*;
146
147 pub fn expand<E: CubePrimitive>(
149 scope: &Scope,
150 value: NativeExpand<E>,
151 mask: NativeExpand<u32>,
152 ) -> NativeExpand<E> {
153 let value = value.read_value(scope);
154 let mask = mask.read_value(scope);
155 let op = ShuffleXorOp::new(scope.ctx_mut(), value, mask);
156 scope.register_with_result(&op).into()
157 }
158}
159
160#[allow(unused_variables)]
167pub fn plane_shuffle_up<E: CubePrimitive>(value: E, delta: u32) -> E {
168 unexpanded!()
169}
170
171pub mod plane_shuffle_up {
173 use super::*;
174
175 pub fn expand<E: CubePrimitive>(
177 scope: &Scope,
178 value: NativeExpand<E>,
179 delta: NativeExpand<u32>,
180 ) -> NativeExpand<E> {
181 let value = value.read_value(scope);
182 let delta = delta.read_value(scope);
183 let op = ShuffleUpOp::new(scope.ctx_mut(), value, delta);
184 scope.register_with_result(&op).into()
185 }
186}
187
188#[allow(unused_variables)]
195pub fn plane_shuffle_down<E: CubePrimitive>(value: E, delta: u32) -> E {
196 unexpanded!()
197}
198
199pub mod plane_shuffle_down {
201 use super::*;
202
203 pub fn expand<E: CubePrimitive>(
205 scope: &Scope,
206 value: NativeExpand<E>,
207 delta: NativeExpand<u32>,
208 ) -> NativeExpand<E> {
209 let value = value.read_value(scope);
210 let delta = delta.read_value(scope);
211 let op = ShuffleDownOp::new(scope.ctx_mut(), value, delta);
212 scope.register_with_result(&op).into()
213 }
214}
215
216#[allow(unused_variables)]
218pub fn plane_sum<E: CubePrimitive<Scalar: PlaneNumeric>>(value: E) -> E {
219 unexpanded!()
220}
221
222pub mod plane_sum {
224 use super::*;
225
226 pub fn expand<E: CubePrimitive<Scalar: PlaneNumeric>>(
228 scope: &Scope,
229 elem: NativeExpand<E>,
230 ) -> NativeExpand<E> {
231 E::Scalar::__expand_native_sum(scope, elem.into()).into()
232 }
233}
234
235#[allow(unused_variables)]
242pub fn plane_inclusive_sum<E: CubePrimitive<Scalar: PlaneNumeric>>(value: E) -> E {
243 unexpanded!()
244}
245
246pub mod plane_inclusive_sum {
248 use super::*;
249
250 pub fn expand<E: CubePrimitive<Scalar: PlaneNumeric>>(
252 scope: &Scope,
253 elem: NativeExpand<E>,
254 ) -> NativeExpand<E> {
255 E::Scalar::__expand_native_inclusive_sum(scope, elem.into()).into()
256 }
257}
258
259#[allow(unused_variables)]
267pub fn plane_exclusive_sum<E: CubePrimitive<Scalar: PlaneNumeric>>(value: E) -> E {
268 unexpanded!()
269}
270
271pub mod plane_exclusive_sum {
273 use super::*;
274
275 pub fn expand<E: CubePrimitive<Scalar: PlaneNumeric>>(
277 scope: &Scope,
278 elem: NativeExpand<E>,
279 ) -> NativeExpand<E> {
280 E::Scalar::__expand_native_exclusive_sum(scope, elem.into()).into()
281 }
282}
283
284pub fn plane_prod<E: CubePrimitive<Scalar: PlaneNumeric>>(_elem: E) -> E {
286 unexpanded!()
287}
288
289pub mod plane_prod {
291 use super::*;
292
293 pub fn expand<E: CubePrimitive<Scalar: PlaneNumeric>>(
295 scope: &Scope,
296 elem: NativeExpand<E>,
297 ) -> NativeExpand<E> {
298 E::Scalar::__expand_native_prod(scope, elem.into()).into()
299 }
300}
301
302#[allow(unused_variables)]
309pub fn plane_inclusive_prod<E: CubePrimitive<Scalar: PlaneNumeric>>(value: E) -> E {
310 unexpanded!()
311}
312
313pub mod plane_inclusive_prod {
315 use super::*;
316
317 pub fn expand<E: CubePrimitive<Scalar: PlaneNumeric>>(
319 scope: &Scope,
320 elem: NativeExpand<E>,
321 ) -> NativeExpand<E> {
322 E::Scalar::__expand_native_inclusive_prod(scope, elem.into()).into()
323 }
324}
325
326#[allow(unused_variables)]
334pub fn plane_exclusive_prod<E: CubePrimitive<Scalar: PlaneNumeric>>(value: E) -> E {
335 unexpanded!()
336}
337
338pub mod plane_exclusive_prod {
340 use super::*;
341
342 pub fn expand<E: CubePrimitive<Scalar: PlaneNumeric>>(
344 scope: &Scope,
345 elem: NativeExpand<E>,
346 ) -> NativeExpand<E> {
347 E::Scalar::__expand_native_exclusive_prod(scope, elem.into()).into()
348 }
349}
350
351pub fn plane_max<E: CubePrimitive<Scalar: PlaneNumeric>>(_elem: E) -> E {
353 unexpanded!()
354}
355
356pub mod plane_max {
358 use super::*;
359
360 pub fn expand<E: CubePrimitive<Scalar: PlaneNumeric>>(
362 scope: &Scope,
363 elem: NativeExpand<E>,
364 ) -> NativeExpand<E> {
365 E::Scalar::__expand_native_plane_max(scope, elem.into()).into()
366 }
367}
368
369pub fn plane_min<E: CubePrimitive<Scalar: PlaneNumeric>>(_elem: E) -> E {
371 unexpanded!()
372}
373
374pub mod plane_min {
376 use super::*;
377
378 pub fn expand<E: CubePrimitive<Scalar: PlaneNumeric>>(
380 scope: &Scope,
381 elem: NativeExpand<E>,
382 ) -> NativeExpand<E> {
383 E::Scalar::__expand_native_plane_min(scope, elem.into()).into()
384 }
385}
386
387pub fn plane_all(_elem: bool) -> bool {
389 unexpanded!()
390}
391
392pub mod plane_all {
394 use super::*;
395
396 pub fn expand(scope: &Scope, elem: NativeExpand<bool>) -> NativeExpand<bool> {
398 let value = elem.read_value(scope);
399 let op = AllOp::new(scope.ctx_mut(), value);
400 scope.register_with_result(&op).into()
401 }
402}
403
404pub fn plane_any(_elem: bool) -> bool {
406 unexpanded!()
407}
408
409pub mod plane_any {
411 use super::*;
412
413 pub fn expand(scope: &Scope, elem: NativeExpand<bool>) -> NativeExpand<bool> {
415 let value = elem.read_value(scope);
416 let op = AnyOp::new(scope.ctx_mut(), value);
417 scope.register_with_result(&op).into()
418 }
419}
420
421pub fn plane_ballot(_elem: bool) -> Vector<u32, Const<4>> {
427 unexpanded!()
428}
429
430pub mod plane_ballot {
432 use super::*;
433
434 pub fn expand(scope: &Scope, elem: NativeExpand<bool>) -> NativeExpand<Vector<u32, Const<4>>> {
436 let value = elem.read_value(scope);
437 let op = BallotOp::new(scope.ctx_mut(), value);
438 scope.register_with_result(&op).into()
439 }
440}