Skip to content

Commit ae91cd9

Browse files
authored
[MLIR] Add f6E2M3FN type (#107999)
This PR adds `f6E2M3FN` type to mlir. `f6E2M3FN` type is proposed in [OpenCompute MX Specification](https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf). It defines a 6-bit floating point number with bit layout S1E2M3. Unlike IEEE-754 types, there are no infinity or NaN values. ```c f6E2M3FN - Exponent bias: 1 - Maximum stored exponent value: 3 (binary 11) - Maximum unbiased exponent value: 3 - 1 = 2 - Minimum stored exponent value: 1 (binary 01) - Minimum unbiased exponent value: 1 − 1 = 0 - Has Positive and Negative zero - Doesn't have infinity - Doesn't have NaNs Additional details: - Zeros (+/-): S.00.000 - Max normal number: S.11.111 = ±2^(2) x (1 + 0.875) = ±7.5 - Min normal number: S.01.000 = ±2^(0) = ±1.0 - Max subnormal number: S.00.111 = ±2^(0) x 0.875 = ±0.875 - Min subnormal number: S.00.001 = ±2^(0) x 0.125 = ±0.125 ``` Related PRs: - [PR-94735](llvm/llvm-project#94735) [APFloat] Add APFloat support for FP6 data types - [PR-105573](llvm/llvm-project#105573) [MLIR] Add f6E3M2FN type - was used as a template for this PR
1 parent 09e358d commit ae91cd9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

IRTypes.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,27 @@ class PyFloatType : public PyConcreteType<PyFloatType> {
124124
}
125125
};
126126

127+
/// Floating Point Type subclass - Float6E2M3FNType.
128+
class PyFloat6E2M3FNType
129+
: public PyConcreteType<PyFloat6E2M3FNType, PyFloatType> {
130+
public:
131+
static constexpr IsAFunctionTy isaFunction = mlirTypeIsAFloat6E2M3FN;
132+
static constexpr GetTypeIDFunctionTy getTypeIdFunction =
133+
mlirFloat6E2M3FNTypeGetTypeID;
134+
static constexpr const char *pyClassName = "Float6E2M3FNType";
135+
using PyConcreteType::PyConcreteType;
136+
137+
static void bindDerived(ClassTy &c) {
138+
c.def_static(
139+
"get",
140+
[](DefaultingPyMlirContext context) {
141+
MlirType t = mlirFloat6E2M3FNTypeGet(context->get());
142+
return PyFloat6E2M3FNType(context->getRef(), t);
143+
},
144+
py::arg("context") = py::none(), "Create a float6_e2m3fn type.");
145+
}
146+
};
147+
127148
/// Floating Point Type subclass - Float6E3M2FNType.
128149
class PyFloat6E3M2FNType
129150
: public PyConcreteType<PyFloat6E3M2FNType, PyFloatType> {
@@ -901,6 +922,7 @@ void mlir::python::populateIRTypes(py::module &m) {
901922
PyIntegerType::bind(m);
902923
PyFloatType::bind(m);
903924
PyIndexType::bind(m);
925+
PyFloat6E2M3FNType::bind(m);
904926
PyFloat6E3M2FNType::bind(m);
905927
PyFloat8E4M3FNType::bind(m);
906928
PyFloat8E5M2Type::bind(m);

0 commit comments

Comments
 (0)