[PATCH] D75133: [mlir][DenseElementsAttr] Fix storage size for bfloat16 when parsing from hex.

River Riddle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 25 15:05:48 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGb3e6487f02ac: [mlir][DenseElementsAttr] Fix storage size for bfloat16 when parsing from hex. (authored by rriddle).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75133

Files:
  mlir/lib/Parser/Parser.cpp
  mlir/test/IR/dense-elements-hex.mlir


Index: mlir/test/IR/dense-elements-hex.mlir
===================================================================
--- mlir/test/IR/dense-elements-hex.mlir
+++ mlir/test/IR/dense-elements-hex.mlir
@@ -7,6 +7,9 @@
 // CHECK: dense<[1.000000e+01, 5.000000e+00]> : tensor<2xf64>
 "foo.op"() {dense.attr = dense<"0x00000000000024400000000000001440"> : tensor<2xf64>} : () -> ()
 
+// CHECK: dense<[1.000000e+01, 5.000000e+00]> : tensor<2xbf16>
+"foo.op"() {dense.attr = dense<"0x00000000000024400000000000001440"> : tensor<2xbf16>} : () -> ()
+
 // -----
 
 // expected-error at +1 {{elements hex string should start with '0x'}}
Index: mlir/lib/Parser/Parser.cpp
===================================================================
--- mlir/lib/Parser/Parser.cpp
+++ mlir/lib/Parser/Parser.cpp
@@ -2118,8 +2118,12 @@
 
   // Check that the size of the hex data correpsonds to the size of the type, or
   // a splat of the type.
+  // TODO: bf16 is currently stored as a double, this should be removed when
+  // APFloat properly supports it.
+  int64_t elementWidth =
+      elementType.isBF16() ? 64 : elementType.getIntOrFloatBitWidth();
   if (static_cast<int64_t>(data.size() * CHAR_BIT) !=
-      (type.getNumElements() * elementType.getIntOrFloatBitWidth())) {
+      (type.getNumElements() * elementWidth)) {
     p.emitError(loc) << "elements hex data size is invalid for provided type: "
                      << type;
     return nullptr;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75133.246584.patch
Type: text/x-patch
Size: 1438 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200225/eb3b6f5f/attachment.bin>


More information about the llvm-commits mailing list