Skip to content

Commit 9d6286e

Browse files
authored
[MLIR] Add f8E3M4 IEEE 754 type (#101230)
This PR adds `f8E3M4` type to mlir. `f8E3M4` type follows IEEE 754 convention ```c f8E3M4 (IEEE 754) - Exponent bias: 3 - Maximum stored exponent value: 6 (binary 110) - Maximum unbiased exponent value: 6 - 3 = 3 - Minimum stored exponent value: 1 (binary 001) - Minimum unbiased exponent value: 1 − 3 = −2 - Precision specifies the total number of bits used for the significand (mantissa), including implicit leading integer bit = 4 + 1 = 5 - Follows IEEE 754 conventions for representation of special values - Has Positive and Negative zero - Has Positive and Negative infinity - Has NaNs Additional details: - Max exp (unbiased): 3 - Min exp (unbiased): -2 - Infinities (+/-): S.111.0000 - Zeros (+/-): S.000.0000 - NaNs: S.111.{0,1}⁴ except S.111.0000 - Max normal number: S.110.1111 = +/-2^(6-3) x (1 + 15/16) = +/-2^3 x 31 x 2^(-4) = +/-15.5 - Min normal number: S.001.0000 = +/-2^(1-3) x (1 + 0) = +/-2^(-2) - Max subnormal number: S.000.1111 = +/-2^(-2) x 15/16 = +/-2^(-2) x 15 x 2^(-4) = +/-15 x 2^(-6) - Min subnormal number: S.000.0001 = +/-2^(-2) x 1/16 = +/-2^(-2) x 2^(-4) = +/-2^(-6) ``` Related PRs: - [PR-99698](llvm/llvm-project#99698) [APFloat] Add support for f8E3M4 IEEE 754 type - [PR-97118](llvm/llvm-project#97118) [MLIR] Add f8E4M3 IEEE 754 type
1 parent 4a96e8d commit 9d6286e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

IRTypes.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,26 @@ class PyFloat8E5M2FNUZType
246246
}
247247
};
248248

249+
/// Floating Point Type subclass - Float8E3M4Type.
250+
class PyFloat8E3M4Type : public PyConcreteType<PyFloat8E3M4Type, PyFloatType> {
251+
public:
252+
static constexpr IsAFunctionTy isaFunction = mlirTypeIsAFloat8E3M4;
253+
static constexpr GetTypeIDFunctionTy getTypeIdFunction =
254+
mlirFloat8E3M4TypeGetTypeID;
255+
static constexpr const char *pyClassName = "Float8E3M4Type";
256+
using PyConcreteType::PyConcreteType;
257+
258+
static void bindDerived(ClassTy &c) {
259+
c.def_static(
260+
"get",
261+
[](DefaultingPyMlirContext context) {
262+
MlirType t = mlirFloat8E3M4TypeGet(context->get());
263+
return PyFloat8E3M4Type(context->getRef(), t);
264+
},
265+
py::arg("context") = py::none(), "Create a float8_e3m4 type.");
266+
}
267+
};
268+
249269
/// Floating Point Type subclass - BF16Type.
250270
class PyBF16Type : public PyConcreteType<PyBF16Type, PyFloatType> {
251271
public:
@@ -864,6 +884,7 @@ void mlir::python::populateIRTypes(py::module &m) {
864884
PyFloat8E4M3FNUZType::bind(m);
865885
PyFloat8E4M3B11FNUZType::bind(m);
866886
PyFloat8E5M2FNUZType::bind(m);
887+
PyFloat8E3M4Type::bind(m);
867888
PyBF16Type::bind(m);
868889
PyF16Type::bind(m);
869890
PyTF32Type::bind(m);

0 commit comments

Comments
 (0)