llvm-project/llvm/lib/Support
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
..
BLAKE3 [Support/BLAKE3] Fix error in prior commit, apply `-mavx512vl` for `blake3_avx512_x86-64_unix.S` when including it 2022-06-22 10:51:19 -07:00
Unix Revert "Support: Add mapped_file_region::sync(), equivalent to msync" 2022-09-08 12:49:52 -04:00
Windows Revert "Support: Add mapped_file_region::sync(), equivalent to msync" 2022-09-08 12:49:52 -04:00
AArch64TargetParser.cpp [AArch64] Add all predecessor archs in target info 2022-09-27 10:23:21 +02:00
ABIBreak.cpp
AMDGPUMetadata.cpp
APFixedPoint.cpp [iwyu] Move <cmath> out of llvm/Support/MathExtras.h 2022-09-28 20:49:01 +02:00
APFloat.cpp Add APFloat and MLIR type support for fp8 (e5m2). 2022-10-02 17:17:08 -07:00
APInt.cpp [ISel] Match all bits when merge undefs for DAG combine 2022-07-01 09:09:43 +08:00
APSInt.cpp
ARMAttributeParser.cpp [llvm] Remove includes of `llvm/Support/STLArrayExtras.h` 2022-09-09 17:44:00 -06:00
ARMBuildAttrs.cpp Ensure newlines at the end of files (NFC) 2022-08-20 21:18:23 -07:00
ARMTargetParser.cpp [LLVM][ARM] Remove options for armv2, 2A, 3 and 3M 2022-09-08 09:49:48 +00:00
ARMWinEH.cpp [llvm-readobj] Improve printing of Windows ARM packed unwind info 2022-05-18 21:33:08 +03:00
AddressRanges.cpp [Reland][DebugInfo][llvm-dwarfutil] Combine overlapped address ranges. 2022-07-21 14:15:39 +03:00
Allocator.cpp
Atomic.cpp
AutoConvert.cpp
Base64.cpp An upcoming patch to LLDB will require the ability to decode base64. This patch adds support for decoding base64 and adds tests. 2022-08-30 15:52:08 -07:00
BinaryStreamError.cpp [NFC] Additional header dependency cleanup LLVMSupport 2022-01-26 11:16:15 +01:00
BinaryStreamReader.cpp [Support] Convert BinaryStream class zoo to 64-bit offsets 2021-09-16 19:14:52 -04:00
BinaryStreamRef.cpp [Support] Convert BinaryStream class zoo to 64-bit offsets 2021-09-16 19:14:52 -04:00
BinaryStreamWriter.cpp [iwyu] Handle regressions in libLLVM header include 2022-05-26 08:12:34 +02:00
BlockFrequency.cpp [llvm] Cleanup header dependencies in ADT and Support 2022-01-21 13:54:49 +01:00
BranchProbability.cpp
BuryPointer.cpp
CMakeLists.txt use LLVM_USE_STATIC_ZSTD 2022-09-02 21:00:38 +00:00
COM.cpp
COPYRIGHT.regex
CRC.cpp
CSKYAttributeParser.cpp Use range-based for loops (NFC) 2022-08-20 21:18:32 -07:00
CSKYAttributes.cpp [Support] Add CSKY target parser and attributes parser 2022-02-28 11:35:07 +08:00
CSKYTargetParser.cpp [CSKY] Fix the conflict of default fpu features and -mfpu option 2022-05-23 10:44:55 +08:00
CachePruning.cpp
Caching.cpp [Support] [DebugInfo] Lazily create cache dir. 2022-01-20 19:27:15 +00:00
Chrono.cpp
CodeGenCoverage.cpp [llvm] Use = default (NFC) 2022-02-06 22:18:35 -08:00
CommandLine.cpp [Support] Class for response file expansion (NFC) 2022-09-29 19:15:01 +07:00
Compression.cpp [Object] Add zstd decompression support to Decompressor 2022-09-19 11:41:16 -07:00
ConvertUTF.cpp Update license on Unicode.org's ConvertUTF code. 2022-08-12 16:51:08 +00:00
ConvertUTFWrapper.cpp Re-land c346068928 with fixes 2022-03-23 08:13:17 -04:00
CrashRecoveryContext.cpp [llvm] Use std::size instead of llvm::array_lengthof 2022-09-08 09:01:53 -06:00
DAGDeltaAlgorithm.cpp [llvm] Cleanup header dependencies in ADT and Support 2022-01-21 13:54:49 +01:00
DJB.cpp
DataExtractor.cpp [llvm] Cleanup header dependencies in ADT and Support 2022-01-21 13:54:49 +01:00
Debug.cpp Revert "[Support] Remove redundant declaration setCurrentDebugTypes (NFC)" 2022-07-16 17:19:27 -07:00
DebugCounter.cpp Revert "ManagedStatic: remove from DebugCounter" 2022-08-26 11:02:58 +02:00
DebugOptions.h Ensure newlines at the end of files (NFC) 2021-10-23 08:45:29 -07:00
DeltaAlgorithm.cpp [llvm] Use = default (NFC) 2022-02-06 22:18:35 -08:00
DivisionByConstantInfo.cpp [Support][CodeGen] Fix spelling Divison->Division. NFC 2022-07-17 23:16:29 -07:00
DynamicLibrary.cpp ManagedStatic: remove from DynamicLibrary 2022-08-25 17:06:43 +02:00
ELFAttributeParser.cpp [ARM] Fix bug in also_compatible_with attribute parser 2022-08-22 09:40:37 +01:00
ELFAttributes.cpp
Errno.cpp Cleanup include: TableGen 2022-03-11 11:41:32 +01:00
Error.cpp ManagedStatic: remove many straightforward uses in llvm 2022-07-10 10:29:15 +02:00
ErrorHandling.cpp fix tests after my commit 80b3dcc045 2022-05-30 19:44:06 +01:00
ExtensibleRTTI.cpp [llvm][clang][NFC] updates inline licence info 2021-08-11 02:48:53 +00:00
FileCollector.cpp
FileOutputBuffer.cpp [llvm] Cleanup header dependencies in ADT and Support 2022-01-21 13:54:49 +01:00
FileUtilities.cpp Include <cmath> in FileUtilities.cpp for std:abs(double) 2022-09-29 15:33:49 -07:00
FoldingSet.cpp [llvm] LLVM_FALLTHROUGH => [[fallthrough]]. NFC 2022-08-08 11:24:15 -07:00
FormatVariadic.cpp [llvm] Don't use Optional::hasValue (NFC) 2022-06-20 10:38:12 -07:00
FormattedStream.cpp [llvm] LLVM_FALLTHROUGH => [[fallthrough]]. NFC 2022-08-08 11:24:15 -07:00
GlobPattern.cpp [llvm] LLVM_FALLTHROUGH => [[fallthrough]]. NFC 2022-08-08 11:24:15 -07:00
GraphWriter.cpp [llvm] LLVM_FALLTHROUGH => [[fallthrough]]. NFC 2022-08-08 11:24:15 -07:00
Hashing.cpp
Host.cpp [AArch64] Add Neoverse V2 CPU support 2022-09-27 07:56:08 +00:00
InitLLVM.cpp Add ms-specific missing header in Support/InitLLVM.cpp 2022-01-21 14:28:47 +01:00
InstructionCost.cpp
IntEqClasses.cpp
IntervalMap.cpp
ItaniumManglingCanonicalizer.cpp Revert "Use std::is_same_v instead of std::is_same (NFC)" 2022-08-20 23:00:39 -07:00
JSON.cpp [llvm][json] Fix UINT64 json parsing 2022-05-17 09:11:45 -07:00
KnownBits.cpp [llvm] Don't use Optional::getValue (NFC) 2022-06-20 22:45:45 -07:00
LEB128.cpp
LineIterator.cpp [Support] Use default member initialization (NFC) 2022-06-18 15:46:09 -07:00
Locale.cpp
LockFileManager.cpp [libc++] Remove unused macro in __config 2021-09-23 13:09:32 -04:00
LowLevelType.cpp [MachineValueType] Don't allow MVT::getVectorNumElements() to be called for scalable vectors. 2022-01-13 09:16:25 -08:00
MD5.cpp [Support/Hash functions] Change the `final()` and `result()` of the hashing functions to return an array of bytes 2022-04-05 21:38:06 -07:00
MSP430AttributeParser.cpp [llvm] Cleanup header dependencies in ADT and Support 2022-01-21 13:54:49 +01:00
MSP430Attributes.cpp [llvm-readobj] Support dumping of MSP430 ELF attributes 2021-09-28 00:56:11 +03:00
ManagedStatic.cpp
MathExtras.cpp Cleanup include: TableGen 2022-03-11 11:41:32 +01:00
MemAlloc.cpp [Support] #include <new> for std::align_val_t 2022-01-25 19:40:00 +01:00
Memory.cpp Cleanup include: TableGen 2022-03-11 11:41:32 +01:00
MemoryBuffer.cpp Fix issing header on z/OS 2022-03-14 17:29:08 +01:00
MemoryBufferRef.cpp
NativeFormatting.cpp [iwyu] Move <cmath> out of llvm/Support/MathExtras.h 2022-09-28 20:49:01 +02:00
OptimizedStructLayout.cpp Fix a bug in OptimizedStructLayout when filling gaps before 2021-07-21 15:47:18 -04:00
Optional.cpp
Parallel.cpp [Support] Access threadIndex via a wrapper function 2022-09-14 09:19:27 +03:00
Path.cpp LLVM Driver Multicall tool 2022-06-06 04:27:32 +00:00
PluginLoader.cpp ManagedStatic: remove from PluginLoader 2022-08-03 10:41:58 +02:00
PrettyStackTrace.cpp Add apple-specific missing include 2022-01-21 14:18:29 +01:00
Process.cpp [llvm] Use value instead of getValue (NFC) 2022-07-13 23:11:56 -07:00
Program.cpp Cleanup include: TableGen 2022-03-11 11:41:32 +01:00
RISCVAttributeParser.cpp Use range-based for loops (NFC) 2022-08-20 21:18:32 -07:00
RISCVAttributes.cpp Use ManagedStatic and lazy initialization of cl::opt in libSupport to make it free of global initializer 2021-07-16 07:38:16 +00:00
RISCVISAInfo.cpp [RISCV] Remove support for the unratified Zbe, Zbf, and Zbm extensions. 2022-09-22 13:04:41 -07:00
RWMutex.cpp
RandomNumberGenerator.cpp Use ManagedStatic and lazy initialization of cl::opt in libSupport to make it free of global initializer 2021-07-16 07:38:16 +00:00
Regex.cpp [llvm] Use range-based for loops (NFC) 2021-12-02 09:27:47 -08:00
SHA1.cpp Drop empty string literals from static_assert (NFC) 2022-09-03 11:17:47 -07:00
SHA256.cpp Drop empty string literals from static_assert (NFC) 2022-09-03 11:17:47 -07:00
ScaledNumber.cpp
ScopedPrinter.cpp Replace to_hexString by touhexstr [NFC] 2022-06-16 17:29:50 +02:00
Signals.cpp [iwyu] Move <cmath> out of llvm/Support/MathExtras.h 2022-09-28 20:49:01 +02:00
Signposts.cpp Change the LLVM signpost category 2022-04-05 12:18:31 -07:00
SmallPtrSet.cpp [llvm] Cleanup header dependencies in ADT and Support 2022-01-21 13:54:49 +01:00
SmallVector.cpp [Support] Use std::clamp (NFC) 2022-08-27 21:21:08 -07:00
SourceMgr.cpp [PDLL] Add support for tablegen includes and importing ODS information 2022-03-03 16:14:03 -08:00
SpecialCaseList.cpp [llvm] Use = default (NFC) 2022-02-06 22:18:35 -08:00
Statistic.cpp [Timer][Statistics] Make global constructor ordering more robust 2022-08-25 19:09:49 +02:00
StringExtras.cpp [llvm] Use range-based for loops (NFC) 2021-12-02 09:27:47 -08:00
StringMap.cpp [NFC][llvm][StringMap]Extract createTable and getHashTable functions and add the inline attribute to the getMinBucketToReserveForEntries function. 2022-03-23 10:09:59 +08:00
StringRef.cpp [ADT] Add edit_distance_insensitive to StringRef 2022-06-05 12:03:09 +01:00
StringSaver.cpp
SuffixTree.cpp
SymbolRemappingReader.cpp [llvm] Cleanup header dependencies in ADT and Support 2022-01-21 13:54:49 +01:00
SystemUtils.cpp
TarWriter.cpp
TargetParser.cpp [RISCV] Change how mtune aliases are implemented. 2022-08-18 16:22:25 -07:00
ThreadLocal.cpp
ThreadPool.cpp Revert "[llvm] Use llvm::is_contained (NFC)" 2022-08-28 18:52:49 -07:00
Threading.cpp Remove redundant initialization of Optional (NFC) 2022-08-20 21:18:28 -07:00
TimeProfiler.cpp [support] Prepare TimeProfiler for cross-thread support 2022-09-16 10:20:18 -06:00
Timer.cpp [Timer][Statistics] Make global constructor ordering more robust 2022-08-25 19:09:49 +02:00
ToolOutputFile.cpp [llvm] Cleanup header dependencies in ADT and Support 2022-01-21 13:54:49 +01:00
TrigramIndex.cpp TrigramIndex.h - move unnecessary StringRef include down to TrigramIndex.cpp 2022-02-02 16:29:47 +00:00
Triple.cpp [ARM64EC] Add arm64ec for getArchName 2022-09-29 09:05:17 +08:00
Twine.cpp Consolidate string types into ptr and length representations. 2021-07-20 13:29:57 -07:00
TypeSize.cpp Remove unneeded cl::ZeroOrMore for cl::opt/cl::list options 2022-06-05 01:07:51 -07:00
Unicode.cpp Update Unicode to 15.0 2022-09-22 05:03:01 +02:00
UnicodeCaseFold.cpp Update Unicode to 15.0 2022-09-22 05:03:01 +02:00
UnicodeNameToCodepoint.cpp Update Unicode to 15.0 2022-09-22 05:03:01 +02:00
UnicodeNameToCodepointGenerated.cpp Update Unicode to 15.0 2022-09-22 05:03:01 +02:00
Valgrind.cpp Work around a Clang modules build issue. 2022-01-31 12:03:00 -08:00
VersionTuple.cpp
VirtualFileSystem.cpp [llvm] LLVM_FALLTHROUGH => [[fallthrough]]. NFC 2022-08-08 11:24:15 -07:00
Watchdog.cpp
WithColor.cpp [Support] Allow the ability to change WithColor's auto detection function 2022-02-28 20:30:06 -08:00
X86TargetParser.cpp [llvm] Use std::size instead of llvm::array_lengthof 2022-09-08 09:01:53 -06:00
YAMLParser.cpp [llvm] LLVM_FALLTHROUGH => [[fallthrough]]. NFC 2022-08-08 11:24:15 -07:00
YAMLTraits.cpp [llvm][support] Replace `std::vector<bool>` use in YAMLTraits 2022-01-26 11:20:18 +01:00
Z3Solver.cpp [analyzer] Fix include typo introduced by e61a1a9 2022-03-11 16:09:25 +01:00
circular_raw_ostream.cpp
raw_os_ostream.cpp
raw_ostream.cpp [llvm] Remove includes of `llvm/Support/STLArrayExtras.h` 2022-09-09 17:44:00 -06:00
regcomp.c [Support] unsafe pointer arithmetic in llvm_regcomp() 2022-02-03 19:59:27 -05:00
regengine.inc [Support] Optimize (.*) regex matches 2022-04-19 09:55:21 +02:00
regerror.c
regex2.h
regex_impl.h
regexec.c
regfree.c
regstrlcpy.c
regutils.h
xxhash.cpp Cleanup include: TableGen 2022-03-11 11:41:32 +01:00