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 __expand_as_type(scope: &Scope) -> TypeHandle {
26        Float6E2M3Type::get(scope.ctx()).into()
27    }
28
29    fn from_const_value(_value: ConstantValue) -> Self {
30        unimplemented!("e2m3 doesn't yet support conversion");
31    }
32}
33
34impl IntoRuntime for e2m3 {
35    fn __expand_runtime_method(self, _scope: &Scope) -> NativeExpand<Self> {
36        self.into()
37    }
38}
39impl IntoExpand for e2m3 {
40    type Expand = NativeExpand<e2m3>;
41    fn into_expand(self, _scope: &Scope) -> Self::Expand {
42        self.into()
43    }
44}
45
46impl NativeAssign for e2m3 {}
47
48impl CubeType for e3m2 {
49    type ExpandType = NativeExpand<e3m2>;
50}
51
52impl CubeDebug for e3m2 {}
53impl Scalar for e3m2 {
54    fn elem_type_native() -> ElemType {
55        FloatKind::E3M2.into()
56    }
57}
58impl CubePrimitive for e3m2 {
59    type Scalar = Self;
60    type Size = Const<1>;
61    type WithScalar<S: Scalar> = S;
62
63    fn __expand_as_type(scope: &Scope) -> TypeHandle {
64        Float6E3M2Type::get(scope.ctx()).into()
65    }
66
67    fn from_const_value(_value: ConstantValue) -> Self {
68        unimplemented!("e3m2 doesn't yet support conversion");
69    }
70}
71
72impl IntoRuntime for e3m2 {
73    fn __expand_runtime_method(self, _scope: &Scope) -> NativeExpand<Self> {
74        self.into()
75    }
76}
77impl IntoExpand for e3m2 {
78    type Expand = NativeExpand<e3m2>;
79    fn into_expand(self, _scope: &Scope) -> Self::Expand {
80        self.into()
81    }
82}
83
84impl NativeAssign for e3m2 {}