Skip to content

Commit

Permalink
[util] Add serialization support for f64 resources (iree-org#17640)
Browse files Browse the repository at this point in the history
Serializing `f64` resources was strangely omitted from the logic while
`f32` and `f16` support is present. Running things with `f64` is
certainly not a good idea in general but relatively well-supported in
the LLVM backend. Our use-case is the bring-up of a custom compiler
backend where `f64` happens to be the most trivial element type to
support.

Signed-off-by: Markus Böck <[email protected]>
  • Loading branch information
zero9178 authored Jun 11, 2024
1 parent cda3ccb commit db7974c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/iree/compiler/Dialect/Util/IR/UtilAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,14 @@ static LogicalResult serializeGenericResourceElementData(
<< " for type " << resourceElementsAttr.getType();
}
} else if (auto floatType = llvm::dyn_cast<FloatType>(elementType)) {
// TODO(saienduri): implement float64 support (not necessary now)
unsigned bitWidth = floatType.getIntOrFloatBitWidth();
switch (bitWidth) {
case 16:
return serializeResourceRawData(loc, resourceElementsAttr, os);
case 32:
return serializeResourceRawData(loc, resourceElementsAttr, os);
case 64:
return serializeResourceRawData(loc, resourceElementsAttr, os);
default:
return emitError(loc) << "unhandled float element bit width " << bitWidth
<< " for type " << resourceElementsAttr.getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,32 @@ vm.module @constants {
// CHECK-NEXT: 1
// CHECK-NEXT: ]
vm.rodata private @byte_pattern_i2 #util.byte_pattern<1> : tensor<9xi2>

// CHECK: "embedded_data": [
// CHECK-NEXT: 0,
// CHECK-NEXT: 0,
// CHECK-NEXT: 0,
// CHECK-NEXT: 0,
// CHECK-NEXT: 0,
// CHECK-NEXT: 0,
// CHECK-NEXT: 240,
// CHECK-NEXT: 63,
// CHECK-NEXT: 0,
// CHECK-NEXT: 0,
// CHECK-NEXT: 0,
// CHECK-NEXT: 0,
// CHECK-NEXT: 0,
// CHECK-NEXT: 0,
// CHECK-NEXT: 0,
// CHECK-NEXT: 64,
// CHECK-NEXT: 0,
// CHECK-NEXT: 0,
// CHECK-NEXT: 0,
// CHECK-NEXT: 0,
// CHECK-NEXT: 0,
// CHECK-NEXT: 0,
// CHECK-NEXT: 8,
// CHECK-NEXT: 64
// CHECK-NEXT: ]
vm.rodata private @dense_f64 dense<[1.000000e+00, 2.000000e+00, 3.000000e+00]> : tensor<3xf64>
}

0 comments on commit db7974c

Please sign in to comment.