llvm-project/llvm/lib
Stella Laurenzo 2dc68b5398 Add APFloat and MLIR type support for fp8 (e5m2).
This is a first step towards high level representation for fp8 types
that have been built in to hardware with near term roadmaps. Like the
BFLOAT16 type, the family of fp8 types are inspired by IEEE-754 binary
floating point formats but, due to the size limits, have been tweaked in
various ways in order to maximally use the range/precision in various
scenarios. The list of variants is small/finite and bounded by real
hardware.

This patch introduces the E5M2 FP8 format as proposed by Nvidia, ARM,
and Intel in the paper: https://arxiv.org/pdf/2209.05433.pdf

As the more conformant of the two implemented datatypes, we are plumbing
it through LLVM's APFloat type and MLIR's type system first as a
template. It will be followed by the range optimized E4M3 FP8 format
described in the paper. Since that format deviates further from the
IEEE-754 norms, it may require more debate and implementation
complexity.

Given that we see two parts of the FP8 implementation space represented
by these cases, we are recommending naming of:

* `F8M<N>` : For FP8 types that can be conceived of as following the
  same rules as FP16 but with a smaller number of mantissa/exponent
  bits. Including the number of mantissa bits in the type name is enough
  to fully specify the type. This naming scheme is used to represent
  the E5M2 type described in the paper.
* `F8M<N>F` : For FP8 types such as E4M3 which only support finite
  values.

The first of these (this patch) seems fairly non-controversial. The
second is previewed here to illustrate options for extending to the
other known variant (but can be discussed in detail in the patch
which implements it).

Many conversations about these types focus on the Machine-Learning
ecosystem where they are used to represent mixed-datatype computations
at a high level. At that level (which is why we also expose them in
MLIR), it is important to retain the actual type definition so that when
lowering to actual kernels or target specific code, the correct
promotions, casts and rescalings can be done as needed. We expect that
most LLVM backends will only experience these types as opaque `I8`
values that are applicable to some instructions.

MLIR does not make it particularly easy to add new floating point types
(i.e. the FloatType hierarchy is not open). Given the need to fully
model FloatTypes and make them interop with tooling, such types will
always be "heavy-weight" and it is not expected that a highly open type
system will be particularly helpful. There are also a bounded number of
floating point types in use for current and upcoming hardware, and we
can just implement them like this (perhaps looking for some cosmetic
ways to reduce the number of places that need to change). Creating a
more generic mechanism for extending floating point types seems like it
wouldn't be worth it and we should just deal with defining them one by
one on an as-needed basis when real hardware implements a new scheme.
Hopefully, with some additional production use and complete software
stacks, hardware makers will converge on a set of such types that is not
terribly divergent at the level that the compiler cares about.

(I cleaned up some old formatting and sorted some items for this case:
If we converge on landing this in some form, I will NFC commit format
only changes as a separate commit)

Differential Revision: https://reviews.llvm.org/D133823
2022-10-02 17:17:08 -07:00
..
Analysis [ValueTracking] peek through fpext in isKnownNeverInfinity() 2022-10-02 11:20:23 -04:00
AsmParser [IR] Don't allow DLL storage-class and local linkage 2022-09-30 00:26:01 +01:00
BinaryFormat [NFC] Refactor DXContainer to support more parts 2022-09-29 11:59:52 -05:00
Bitcode [IR] Don't allow DLL storage-class and local linkage 2022-09-30 00:26:01 +01:00
Bitstream
CodeGen [ARM][DAG] BF16 constant handling. 2022-10-02 11:51:08 +01:00
DWARFLinker [DWARFLinker][NFC] Set the target DWARF version explicitly. 2022-09-15 16:06:10 +03:00
DWP [llvm-dwp] Report the filename if it cannot be found 2022-09-14 11:32:41 +08:00
DebugInfo [NFC] [Object] Create library to fetch debug info by build ID. 2022-09-28 13:35:35 -07:00
Debuginfod [NFC] [Object] Create library to fetch debug info by build ID. 2022-09-28 13:35:35 -07:00
Demangle Make demangler independent of LLVM again 2022-08-15 11:44:28 +02:00
ExecutionEngine [JITLink] Update external symbol scopes to reflect scopes of resolved defs. 2022-09-29 20:32:46 -07:00
Extensions
FileCheck [llvm][FileCheck] Fix unit tests failures with EXPENSIVE_CHECKS 2022-07-25 08:19:28 +00:00
Frontend LoopUnroll: Pass through AssumptionCache (NFC) 2022-09-26 14:52:59 -04:00
FuzzMutate
Fuzzer
IR [DebugInfo][LICM] Drop DebugLoc from IntrinsicInst when hoisting 2022-09-30 09:12:35 +00:00
IRReader
InterfaceStub [llvm] Use value instead of getValue (NFC) 2022-07-13 23:11:56 -07:00
LTO [LTO][AIX] Invoking AIX System Assembler in LTO CodeGen 2022-09-28 14:26:50 -04:00
LineEditor [llvm] Use range-based for loops (NFC) 2022-09-03 11:17:40 -07:00
Linker [llvm] Qualify auto in range-based for loops (NFC) 2022-08-13 12:55:42 -07:00
MC [PowerPC] XCOFF exception section support on the direct assembler path 2022-09-26 22:24:20 -04:00
MCA [MCA] Correctly check pipeline availability for partially overlapping resource groups. 2022-09-07 12:17:59 +01:00
ObjCopy [llvm-objcopy] --compress-debug-sections: remove tail padding for ELFCLASS32 2022-09-22 10:26:47 -07:00
Object [DX] [ObjectYAML] Support DX shader feature flags 2022-09-29 12:37:11 -05:00
ObjectYAML [DX] [ObjectYAML] Support DX shader feature flags 2022-09-29 12:37:11 -05:00
Option [llvm] Qualify auto in range-based for loops (NFC) 2022-08-28 23:29:00 -07:00
Passes [llvm] Migrate PAEval to new pass manager 2022-10-01 16:41:58 -07:00
ProfileData [llvm] Don't including SetVector.h (NFC) 2022-09-17 12:36:43 -07:00
Remarks Remove redundant initialization of Optional (NFC) 2022-08-20 21:18:28 -07:00
Support Add APFloat and MLIR type support for fp8 (e5m2). 2022-10-02 17:17:08 -07:00
TableGen [TableGen] Add div bang operator 2022-09-30 12:08:28 -07:00
Target [ARM] Add lowering for bf16 neon vtrn, vzup and vuzp. 2022-10-02 15:34:37 +01:00
Testing [Support] Provide access to the full mapping in llvm::Annotations 2022-09-20 11:06:21 -04:00
TextAPI [llvm][TextAPI] add driverkit as supported platform for older tbd 2022-09-19 15:08:29 -07:00
ToolDrivers [llvm-lib] Ignore /VERBOSE flag 2022-07-21 10:06:13 -07:00
Transforms [InstCombine] convert mul by negative-pow2 to negate and shift 2022-10-02 12:22:25 -04:00
WindowsDriver
WindowsManifest
XRay [XRay] Remove XRayRecordStorage 2022-09-11 16:11:41 -07:00
CMakeLists.txt