[PATCH] D141432: Add two additional float8 types to MLIR and APFloat.

2023-01-10 Thread Jake Hall via Phabricator via cfe-commits
jakeh-gc created this revision.
Herald added subscribers: Moerafaat, zero9178, bzcheeseman, sdasgup3, 
wenzhicui, wrengr, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, 
Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, 
antiagainst, shauheen, rriddle, mehdi_amini, hiraditya.
Herald added a reviewer: rriddle.
Herald added a reviewer: antiagainst.
Herald added a project: All.
jakeh-gc requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, stephenneuendorffer, 
nicolasvasilache.
Herald added projects: clang, MLIR, LLVM.

Graphcore, AMD, and Qualcomm have proposed two new FP8 formats, Float8E4M3FZN 
and Float8E5M2FZN. These formats are presented in this paper: 
https://arxiv.org/abs/2206.02915. They are implemented in commercially 
available hardware and the ISA for this hardware is available here: 
https://docs.graphcore.ai/projects/isa-mk2-with-fp8/en/latest/_static/TileVertexISA-IPU21-1.3.1.pdf.

This patch adds support for these two types in MLIR and APFloat, alongside the 
previously added types Float8E4M3FN and Float8E5M2 (D133823 
, D137760 , 
RFC 
).

Following the naming scheme from those existing types, the suffix "FZN" here 
refers to the fact that these types support finite values, positive-only zero 
(no negative zero), and a NaN encoding. In both types NaN has exactly one 
encoding `0b1000`.

To support this behaviour I have added another value to the 
`fltNonfiniteBehavior` enum to represent this specific NaN encoding. I have 
also added a new field (`fltSignedZeroSupport`) to the `fltSemantics` struct to 
describe whether signed zero is supported.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141432

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  llvm/include/llvm/ADT/APFloat.h
  llvm/lib/Support/APFloat.cpp
  llvm/unittests/ADT/APFloatTest.cpp
  mlir/include/mlir-c/BuiltinTypes.h
  mlir/include/mlir/IR/Builders.h
  mlir/include/mlir/IR/BuiltinTypes.h
  mlir/include/mlir/IR/BuiltinTypes.td
  mlir/include/mlir/IR/OpBase.td
  mlir/include/mlir/IR/Types.h
  mlir/lib/AsmParser/TokenKinds.def
  mlir/lib/AsmParser/TypeParser.cpp
  mlir/lib/Bindings/Python/IRTypes.cpp
  mlir/lib/CAPI/IR/BuiltinTypes.cpp
  mlir/lib/IR/AsmPrinter.cpp
  mlir/lib/IR/Builders.cpp
  mlir/lib/IR/BuiltinTypes.cpp
  mlir/lib/IR/MLIRContext.cpp
  mlir/lib/IR/Types.cpp
  mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
  mlir/test/IR/attribute.mlir
  mlir/test/python/ir/builtin_types.py
  mlir/utils/lldb-scripts/mlirDataFormatters.py

Index: mlir/utils/lldb-scripts/mlirDataFormatters.py
===
--- mlir/utils/lldb-scripts/mlirDataFormatters.py
+++ mlir/utils/lldb-scripts/mlirDataFormatters.py
@@ -52,6 +52,8 @@
 "mlir::UnknownLoc": '"loc(unknown)"',
 "mlir::Float8E5M2Type": '"f8E5M2"',
 "mlir::Float8E4M3FNType": '"f8E4M3FN"',
+"mlir::Float8E4M3FZNType": '"f8E4M3FZN"',
+"mlir::Float8E5M2FZNType": '"f8E5M2FZN"',
 "mlir::BFloat16Type": '"bf16"',
 "mlir::Float16Type": '"f16"',
 "mlir::Float32Type": '"f32"',
Index: mlir/test/python/ir/builtin_types.py
===
--- mlir/test/python/ir/builtin_types.py
+++ mlir/test/python/ir/builtin_types.py
@@ -197,6 +197,10 @@
 print("float:", Float8E4M3FNType.get())
 # CHECK: float: f8E5M2
 print("float:", Float8E5M2Type.get())
+# CHECK: float: f8E4M3FZN
+print("float:", Float8E4M3FZNType.get())
+# CHECK: float: f8E5M2FZN
+print("float:", Float8E5M2FZNType.get())
 # CHECK: float: bf16
 print("float:", BF16Type.get())
 # CHECK: float: f16
Index: mlir/test/IR/attribute.mlir
===
--- mlir/test/IR/attribute.mlir
+++ mlir/test/IR/attribute.mlir
@@ -44,6 +44,14 @@
 // CHECK: float_attr = 2.00e+00 : f8E4M3FN
 float_attr = 2. : f8E4M3FN
   } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f8E4M3FZN
+float_attr = 2. : f8E4M3FZN
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f8E5M2FZN
+float_attr = 2. : f8E5M2FZN
+  } : () -> ()
   "test.float_attrs"() {
 // CHECK: float_attr = 2.00e+00 : f16
 float_attr = 2. : f16
Index: mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
===
--- mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
+++ mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
@@ -52,6 +52,8 @@
 "DictAttr",
 "Float8E4M3FNType",
 "Float8E5M2Type",
+"Float8E4M3FZNType",
+"Float8E5M2FZNType",
 "F16Type",
 "F32Type",
 "F64Type",
@@ -586,6 +588,20 @@
 @staticmethod
 def isinstance(arg: Any) -> bool: ...
 
+class Float8E5M2FZNType(Type):
+def __init_

[PATCH] D141432: Add two additional float8 types to MLIR and APFloat.

2023-01-11 Thread Jake Hall via Phabricator via cfe-commits
jakeh-gc added a comment.

The build failure is for clang-format on `APFloat.cpp`. That file has an 
unusual indentation, so I don't believe I can make that pass without 
reformatting the whole file. I believe doing that would make this diff harder 
to review.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141432/new/

https://reviews.llvm.org/D141432

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141432: Add two additional float8 types to MLIR and APFloat.

2023-01-25 Thread Jake Hall via Phabricator via cfe-commits
jakeh-gc abandoned this revision.
jakeh-gc added a comment.

I'm going to put up a narrower version of this based on D141863 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141432/new/

https://reviews.llvm.org/D141432

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits