llvm-project/llvm/unittests
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
..
ADT Add APFloat and MLIR type support for fp8 (e5m2). 2022-10-02 17:17:08 -07:00
Analysis [LazyCallGraph] Handle spurious ref edges when deleting a dead function 2022-09-22 15:01:15 -07:00
AsmParser [AsmParserTest] Avoid pointer element type accesses (NFC) 2022-01-25 14:31:51 +01:00
BinaryFormat [llvm] Use has_value instead of hasValue (NFC) 2022-07-12 22:25:42 -07:00
Bitcode [X86][MS] Change the alignment of f80 to 16 bytes on Windows 32bits to match with ICC 2022-01-23 09:58:46 +08:00
Bitstream
CodeGen [GlobalISel] Add isConstFalseVal helper to Utils 2022-09-28 15:44:26 -07:00
DebugInfo Change isLittleEndian to follow llvm style and add an accessor 2022-09-20 17:00:47 -07:00
Debuginfod [llvm] [Debuginfod] Add HTTP Server to Debuginfod library. 2022-07-06 18:56:54 +00:00
Demangle [demangler] No need to space adjacent template closings 2022-05-09 06:14:44 -07:00
ExecutionEngine [ORC] Update LinkGraph unit tests for API change in 75404e9ef8. 2022-09-25 22:02:15 -07:00
FileCheck [llvm] Use value instead of getValue (NFC) 2022-07-13 23:11:56 -07:00
Frontend [OpenMP][IRBuilder] Added if clause to task 2022-09-23 01:39:41 +00:00
FuzzMutate Revert "[FuzzMutate] Don't insert instructions after musttail call" 2022-03-16 17:29:27 +01:00
IR [VP][RISCV] Add vp.copysign and RISC-V support. 2022-10-01 10:19:10 +08:00
InterfaceStub [llvm] Use value instead of getValue (NFC) 2022-07-13 23:11:56 -07:00
LineEditor
Linker Revert "[OpenMP][NFC] Add missing virtual destructor to silence warning" 2022-03-25 16:07:11 -05:00
MC [MCDwarf] Use emplace to avoid move assignment. NFC 2022-08-12 05:05:49 +00:00
MI [LiveIntervals] Find better anchoring end points when repairing ranges 2022-07-18 19:34:43 +01:00
MIR Use llvm::sort instead of std::sort where possible 2022-07-23 15:19:05 +02:00
ObjCopy Fix for buildbot failure: https://lab.llvm.org/buildbot#builders/110/builds/11051 2022-03-09 14:26:46 +03:00
Object [LoongArch] Define the new-style reloc types 2022-08-11 10:37:30 +08:00
ObjectYAML [llvm] Use value instead of getValue (NFC) 2022-07-13 23:11:56 -07:00
Option [OptTable] Reapply Improve error message output for grouped short options 2021-09-03 11:13:52 +01:00
Passes Remove unnecessary includes of ManagedStatic.h 2022-07-07 14:29:20 +02:00
ProfileData [llvm] Use std::size instead of llvm::array_lengthof 2022-09-08 09:01:53 -06:00
Remarks Cleanup includes: DebugInfo & CodeGen 2022-03-12 17:26:40 +01:00
Support [Support] Class for response file expansion (NFC) 2022-09-29 19:15:01 +07:00
TableGen [llvm] Use value instead of getValue (NFC) 2022-07-13 23:11:56 -07:00
Target [DirectX backend] Support global ctor for DXILBitcodeWriter. 2022-09-30 11:27:23 -07:00
Testing [llvm][Testing/ADT] Implement `IsStringMapEntry` testing matcher for verifying the entries in a `StringMap`. 2022-09-01 17:30:41 +00:00
TextAPI Use the range-based overload of llvm::sort where possible 2022-07-23 15:13:25 +02:00
Transforms [IntegerDivision][AMDGPU] Use CreateLogicalOr to block poison propagation. 2022-09-15 09:38:02 -07:00
XRay
tools Re-land "[llvm-exegesis] Support analyzing results from a different target." 2022-09-22 11:39:52 +02:00
CMakeLists.txt [test-suite][cmake] sort unit test targets 2022-05-16 16:55:40 -07:00
unittest.cfg.in