cubecl_core/frontend/element/float/
fp6.rs

1use cubecl_common::{e2m3, e3m2};
2use cubecl_ir::{ConstantScalarValue, ElemType, ExpandElement, FloatKind, Scope, StorageType};
3
4use crate::prelude::{
5    CubePrimitive, CubeType, ExpandElementIntoMut, ExpandElementTyped, IntoRuntime,
6    into_mut_expand_element, into_runtime_expand_element,
7};
8
9impl CubeType for e2m3 {
10    type ExpandType = ExpandElementTyped<e2m3>;
11}
12
13impl CubePrimitive for e2m3 {
14    /// Return the element type to use on GPU
15    fn as_type_native() -> Option<StorageType> {
16        Some(ElemType::Float(FloatKind::E2M3).into())
17    }
18
19    fn from_const_value(_value: ConstantScalarValue) -> Self {
20        unimplemented!("e2m3 doesn't yet support conversion");
21    }
22}
23
24impl IntoRuntime for e2m3 {
25    fn __expand_runtime_method(self, scope: &mut Scope) -> ExpandElementTyped<Self> {
26        let elem: ExpandElementTyped<Self> = self.into();
27        into_runtime_expand_element(scope, elem).into()
28    }
29}
30
31impl ExpandElementIntoMut for e2m3 {
32    fn elem_into_mut(scope: &mut Scope, elem: ExpandElement) -> ExpandElement {
33        into_mut_expand_element(scope, elem)
34    }
35}
36
37impl CubeType for e3m2 {
38    type ExpandType = ExpandElementTyped<e3m2>;
39}
40
41impl CubePrimitive for e3m2 {
42    /// Return the element type to use on GPU
43    fn as_type_native() -> Option<StorageType> {
44        Some(ElemType::Float(FloatKind::E3M2).into())
45    }
46
47    fn from_const_value(_value: ConstantScalarValue) -> Self {
48        unimplemented!("e3m2 doesn't yet support conversion");
49    }
50}
51
52impl IntoRuntime for e3m2 {
53    fn __expand_runtime_method(self, scope: &mut Scope) -> ExpandElementTyped<Self> {
54        let elem: ExpandElementTyped<Self> = self.into();
55        into_runtime_expand_element(scope, elem).into()
56    }
57}
58
59impl ExpandElementIntoMut for e3m2 {
60    fn elem_into_mut(scope: &mut Scope, elem: ExpandElement) -> ExpandElement {
61        into_mut_expand_element(scope, elem)
62    }
63}