Skip to content
This repository was archived by the owner on Oct 11, 2025. It is now read-only.

Commit 221f9cb

Browse files
authored
[MLIR] Add f6E3M2FN type (#105573)
This PR adds `f6E3M2FN` type to mlir. `f6E3M2FN` 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 S1E3M2. Unlike IEEE-754 types, there are no infinity or NaN values. ```c f6E3M2FN - Exponent bias: 3 - Maximum stored exponent value: 7 (binary 111) - Maximum unbiased exponent value: 7 - 3 = 4 - Minimum stored exponent value: 1 (binary 001) - Minimum unbiased exponent value: 1 − 3 = −2 - Has Positive and Negative zero - Doesn't have infinity - Doesn't have NaNs Additional details: - Zeros (+/-): S.000.00 - Max normal number: S.111.11 = ±2^(4) x (1 + 0.75) = ±28 - Min normal number: S.001.00 = ±2^(-2) = ±0.25 - Max subnormal number: S.000.11 = ±2^(-2) x 0.75 = ±0.1875 - Min subnormal number: S.000.01 = ±2^(-2) x 0.25 = ±0.0625 ``` Related PRs: - [PR-94735](llvm/llvm-project#94735) [APFloat] Add APFloat support for FP6 data types - [PR-97118](llvm/llvm-project#97118) [MLIR] Add f8E4M3 type - was used as a template for this PR
1 parent 1aa854c commit 221f9cb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

mlir/lib/Bindings/Python/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 - Float6E3M2FNType.
128+
class PyFloat6E3M2FNType
129+
: public PyConcreteType<PyFloat6E3M2FNType, PyFloatType> {
130+
public:
131+
static constexpr IsAFunctionTy isaFunction = mlirTypeIsAFloat6E3M2FN;
132+
static constexpr GetTypeIDFunctionTy getTypeIdFunction =
133+
mlirFloat6E3M2FNTypeGetTypeID;
134+
static constexpr const char *pyClassName = "Float6E3M2FNType";
135+
using PyConcreteType::PyConcreteType;
136+
137+
static void bindDerived(ClassTy &c) {
138+
c.def_static(
139+
"get",
140+
[](DefaultingPyMlirContext context) {
141+
MlirType t = mlirFloat6E3M2FNTypeGet(context->get());
142+
return PyFloat6E3M2FNType(context->getRef(), t);
143+
},
144+
py::arg("context") = py::none(), "Create a float6_e3m2fn type.");
145+
}
146+
};
147+
127148
/// Floating Point Type subclass - Float8E4M3FNType.
128149
class PyFloat8E4M3FNType
129150
: public PyConcreteType<PyFloat8E4M3FNType, PyFloatType> {
@@ -880,6 +901,7 @@ void mlir::python::populateIRTypes(py::module &m) {
880901
PyIntegerType::bind(m);
881902
PyFloatType::bind(m);
882903
PyIndexType::bind(m);
904+
PyFloat6E3M2FNType::bind(m);
883905
PyFloat8E4M3FNType::bind(m);
884906
PyFloat8E5M2Type::bind(m);
885907
PyFloat8E4M3Type::bind(m);

0 commit comments

Comments
 (0)