Commit 2533c35
PR #19096: Add F4E2M1FN and F8E8M0FNU types
Imported from GitHub PR #19096
This PR adds F4E2M1FN primitive type (4-bit float with 2 bits exponent and 1 bit mantissa), F8E8M0FNU primitive type (8-bit float with 8 bits exponent, no mantissa and no sign) and enables loads/stores in the same way S4/U4 type is implemented.
This will enable using microscaling (MX) formats ([RFC](#18085)), such as MXFP4.
```c
F4E2M1FN
- Exponent bias: 1
- Maximum stored exponent value: 3 (binary 11)
- Maximum unbiased exponent value: 3 - 1 = 2
- Minimum stored exponent value: 1 (binary 01)
- Minimum unbiased exponent value: 1 − 1 = 0
- Has Positive and Negative zero
- Doesn't have infinity
- Doesn't have NaNs
Additional details:
- Zeros (+/-): S.00.0
- Max normal number: S.11.1 = ±2^(2) x (1 + 0.5) = ±6.0
- Min normal number: S.01.0 = ±2^(0) = ±1.0
- Min subnormal number: S.00.1 = ±2^(0) x 0.5 = ±0.5
F8E8M0FNU
- Exponent bias: 127
- Maximum stored exponent value: 254 (binary 1111'1110)
- Maximum unbiased exponent value: 254 - 127 = 127
- Minimum stored exponent value: 0 (binary 0000'0000)
- Minimum unbiased exponent value: 0 − 127 = -127
- Doesn't have zero
- Doesn't have infinity
- NaN is encoded as binary 1111'1111
Additional details:
- Zeros cannot be represented
- Negative values cannot be represented
- Mantissa is always 1
```
Related PRs:
- openxla/stablehlo#2582
- jax-ml/ml_dtypes#181
- llvm/llvm-project#95392
- llvm/llvm-project#108877
- jax-ml/ml_dtypes#166
- llvm/llvm-project#107127
- llvm/llvm-project#111028
The PR is split into multiple commits just to make the review easier, it is possible that some tests could fail if only some (i.e. not all) of these commits are applied.
Copybara import of the project:
--
f493e48 by Sergey Kozub <[email protected]>:
Add F4E2M1FN type: import mxfloat.h
--
87d0056 by Sergey Kozub <[email protected]>:
Add F4E2M1FN type: primitive type
--
70ca820 by Sergey Kozub <[email protected]>:
Add F4E2M1FN type: literal support
--
c479f09 by Sergey Kozub <[email protected]>:
Add F4E2M1FN type: conversion codegen
--
daaa3af by Sergey Kozub <[email protected]>:
Add F4E2M1FN type: python interface
--
1f0e19f by Sergey Kozub <[email protected]>:
Add F4E2M1FN type: FFI
--
999bf96 by Sergey Kozub <[email protected]>:
Add F4E2M1FN type: HLO evaluator
--
d7d5af7 by Sergey Kozub <[email protected]>:
Add F4E2M1FN type: add tests
--
9e8c7bc by Sergey Kozub <[email protected]>:
Add F8E8M0FNU type
--
1e34417 by Sergey Kozub <[email protected]>:
Addressing PR#19096 review comments
--
d4de0a3 by Sergey Kozub <[email protected]>:
Addressing PR#19096 review comments (round 2)
Merging this change closes #19096
COPYBARA_INTEGRATE_REVIEW=#19096 from openxla:skozub/e2m1 d4de0a3
PiperOrigin-RevId: 7083900611 parent fadc986 commit 2533c35
File tree
83 files changed
+1856
-367
lines changed- third_party/tsl/tsl/platform
- xla
- backends/gpu/codegen/transforms
- tests
- ffi
- api
- hlo
- builder/lib
- evaluator
- transforms
- expanders
- simplifiers
- translate
- hlo_to_mhlo
- tests
- mhlo_to_hlo
- tests
- mlir_hlo/tests/Dialect/mhlo
- mlir/utils
- pjrt/c
- python
- ifrt
- pjrt_ifrt
- xla_extension
- service
- cpu
- gpu
- fusions/triton
- tests
- llvm_ir
- stream_executor
- gpu
- rocm
- tests
- tools
- tsl
- framework
- protobuf
- python/lib/core
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
83 files changed
+1856
-367
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
985 | 985 | | |
986 | 986 | | |
987 | 987 | | |
| 988 | + | |
988 | 989 | | |
989 | 990 | | |
990 | 991 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| 32 | + | |
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
222 | 250 | | |
223 | 251 | | |
224 | 252 | | |
| |||
0 commit comments