[all-commits] [llvm/llvm-project] 88eb3c: Add FP8 E4M3 support to APFloat.

Reed via All-commits all-commits at lists.llvm.org
Tue Nov 15 11:27:24 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 88eb3c62f25d820a80bc73af786002e1fc4bbbba
      https://github.com/llvm/llvm-project/commit/88eb3c62f25d820a80bc73af786002e1fc4bbbba
  Author: Reed <reedwm at google.com>
  Date:   2022-11-15 (Tue, 15 Nov 2022)

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

  Log Message:
  -----------
  Add FP8 E4M3 support to APFloat.

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.

Reviewed By: bkramer

Differential Revision: https://reviews.llvm.org/D137760




More information about the All-commits mailing list