Skip to main content

cubecl_core/frontend/element/float/
fp6.rs

1use cubecl_common::{e2m3, e3m2};
2use cubecl_ir::{
3    ConstantValue, ElemType, FloatKind, Scope,
4    types::scalar::{Float6E2M3Type, Float6E3M2Type},
5};
6use pliron::r#type::TypeHandle;
7
8use crate::prelude::*;
9
10impl CubeType for e2m3 {
11    type ExpandType = NativeExpand<e2m3>;
12}
13
14impl CubeDebug for e2m3 {}
15impl Scalar for e2m3 {
16    fn elem_type_native() -> ElemType {
17        FloatKind::E2M3.into()
18    }
19}
20impl CubePrimitive for e2m3 {
21    type Scalar = Self;
22    type Size = Const<1>;
23    type WithScalar<S: Scalar> = S;
24
25    fn from_const_value(_value: ConstantValue) -> Self {
26        unimplemented!("e2m3 doesn't yet support conversion");
27    }
28}
29impl ConstantTyped for e2m3 {
30    fn __expand_as_type(scope: &Scope) -> TypeHandle {
31        Float6E2M3Type::get(scope.ctx()).into()
32    }
33}
34
35impl IntoRuntime for e2m3 {
36    fn __expand_runtime_method(self, _scope: &Scope) -> NativeExpand<Self> {
37        self.into()
38    }
39}
40impl IntoExpand for e2m3 {
41    type Expand = NativeExpand<e2m3>;
42    fn into_expand(self, _scope: &Scope) -> Self::Expand {
43        self.into()
44    }
45}
46
47impl NativeAssign for e2m3 {}
48
49impl CubeType for e3m2 {
50    type ExpandType = NativeExpand<e3m2>;
51}
52
53impl CubeDebug for e3m2 {}
54impl Scalar for e3m2 {
55    fn elem_type_native() -> ElemType {
56        FloatKind::E3M2.into()
57    }
58}
59impl CubePrimitive for e3m2 {
60    type Scalar = Self;
61    type Size = Const<1>;
62    type WithScalar<S: Scalar> = S;
63
64    fn from_const_value(_value: ConstantValue) -> Self {
65        unimplemented!("e3m2 doesn't yet support conversion");
66    }
67}
68impl ConstantTyped for e3m2 {
69    fn __expand_as_type(scope: &Scope) -> TypeHandle {
70        Float6E3M2Type::get(scope.ctx()).into()
71    }
72}
73
74impl IntoRuntime for e3m2 {
75    fn __expand_runtime_method(self, _scope: &Scope) -> NativeExpand<Self> {
76        self.into()
77    }
78}
79impl IntoExpand for e3m2 {
80    type Expand = NativeExpand<e3m2>;
81    fn into_expand(self, _scope: &Scope) -> Self::Expand {
82        self.into()
83    }
84}
85
86impl NativeAssign for e3m2 {}