[PATCH] D137760: Add FP8 E4M3 support to APFloat.

Reed Wanderman-Milne via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 9 20:28:08 PST 2022


reedwm created this revision.
reedwm added reviewers: stellaraccident, bkramer, rengolin, jpienaar.
Herald added subscribers: bzcheeseman, rriddle, hiraditya, kristof.beyls.
Herald added a project: All.
reedwm requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, stephenneuendorffer.
Herald added projects: clang, LLVM.

NVIDIA, ARM, and Intel recently introduced two new FP8 formats, as described in the paper: https://arxiv.org/abs/2209.05433. The first of the two FP8 dtypes, E5M2, was added in https://reviews.llvm.org/D133823. This change adds the second of the two: E4M3.

There is an RFC for adding the FP8 dtypes here: https://discourse.llvm.org/t/rfc-add-apfloat-and-mlir-type-support-for-fp8-e5m2/65279. I spoke with the RFC's author, Stella, and she gave me the go ahead to implement the E4M3 type. The name of the E4M3 type in APFloat is Float8E4M3FN, as discussed in the RFC. The "FN" means only Finite and NaN values are supported.

Unlike E5M2, E4M3 has different behavior from IEEE types in regards to Inf and NaN values. There are no Inf values, and NaN is represented when the exponent and mantissa bits are all 1s. To represent these differences in APFloat, I added an enum field, fltNonfiniteBehavior, to the fltSemantics struct. The possible enum values are IEEE754 and NanOnly. Only Float8E4M3FN has the NanOnly behavior.

After this change is submitted, I plan on adding the Float8E4M3FN type to MLIR, in the same way as E5M2 was added in https://reviews.llvm.org/D133823.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137760

Files:
  clang/include/clang/AST/Stmt.h
  clang/lib/AST/MicrosoftMangle.cpp
  llvm/include/llvm/ADT/APFloat.h
  llvm/lib/Support/APFloat.cpp
  llvm/unittests/ADT/APFloatTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137760.474421.patch
Type: text/x-patch
Size: 38249 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221110/db5c77dd/attachment-0001.bin>


More information about the cfe-commits mailing list