summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Dialect/QuantOps/Utils/QuantizeUtils.cpp
diff options
context:
space:
mode:
authorRiver Riddle <riverriddle@google.com>2019-06-18 18:26:26 -0700
committerMehdi Amini <joker.eph@gmail.com>2019-06-19 23:07:34 -0700
commit30bbd910565a1319bf121b0ef87031b8217cf1c2 (patch)
tree71c44332f8984385c2d6d573e69fffe60d11828c /mlir/lib/Dialect/QuantOps/Utils/QuantizeUtils.cpp
parent18743a33ac0caf08b69f097383c176a8a653e4f5 (diff)
downloadbcm5719-llvm-30bbd910565a1319bf121b0ef87031b8217cf1c2.tar.gz
bcm5719-llvm-30bbd910565a1319bf121b0ef87031b8217cf1c2.zip
Simplify usages of SplatElementsAttr now that it inherits from DenseElementsAttr.
PiperOrigin-RevId: 253910543
Diffstat (limited to 'mlir/lib/Dialect/QuantOps/Utils/QuantizeUtils.cpp')
-rw-r--r--mlir/lib/Dialect/QuantOps/Utils/QuantizeUtils.cpp38
1 files changed, 1 insertions, 37 deletions
diff --git a/mlir/lib/Dialect/QuantOps/Utils/QuantizeUtils.cpp b/mlir/lib/Dialect/QuantOps/Utils/QuantizeUtils.cpp
index 850f1224cbb..7cfedf9412d 100644
--- a/mlir/lib/Dialect/QuantOps/Utils/QuantizeUtils.cpp
+++ b/mlir/lib/Dialect/QuantOps/Utils/QuantizeUtils.cpp
@@ -69,36 +69,6 @@ convertDenseFPElementsAttr(DenseFPElementsAttr realFPElementsAttr,
/// Converts a real expressed SplatElementsAttr to a corresponding
/// SplatElementsAttr containing quantized storage values assuming the given
/// quantizedElementType and converter.
-static SplatElementsAttr
-convertSplatElementsAttr(SplatElementsAttr realSplatAttr,
- QuantizedType quantizedElementType,
- const UniformQuantizedValueConverter &converter) {
- // Since the splat just references a single primitive value, use the
- // function for converting primitives.
- // NOTE: When implementing per-channel, we will need to promote the
- // splat to a dense and handle channels individually.
- Type unusedPrimitiveType;
- auto elementAttr =
- convertPrimitiveValueAttr(realSplatAttr.getValue(), quantizedElementType,
- converter, unusedPrimitiveType);
- if (!elementAttr) {
- return nullptr;
- }
-
- // Cast from an expressed-type-based type to storage-type-based type,
- // preserving the splat shape (i.e. tensor<4xf32> -> tensor<4xi8>).
- ShapedType newSplatType =
- quantizedElementType.castExpressedToStorageType(realSplatAttr.getType())
- .dyn_cast_or_null<ShapedType>();
- if (!newSplatType) {
- return nullptr;
- }
- return SplatElementsAttr::get(newSplatType, elementAttr);
-}
-
-/// Converts a real expressed SplatElementsAttr to a corresponding
-/// SplatElementsAttr containing quantized storage values assuming the given
-/// quantizedElementType and converter.
static SparseElementsAttr
convertSparseElementsAttr(SparseElementsAttr realSparseAttr,
QuantizedType quantizedElementType,
@@ -134,13 +104,7 @@ Attribute quantizeAttrUniform(Attribute realValue,
const UniformQuantizedValueConverter &converter,
Type &outConvertedType) {
// Fork to handle different variants of constants supported.
- if (realValue.isa<SplatElementsAttr>()) {
- // Splatted tensor or vector constant.
- auto converted = convertSplatElementsAttr(
- realValue.cast<SplatElementsAttr>(), quantizedElementType, converter);
- outConvertedType = converted.getType();
- return converted;
- } else if (realValue.isa<DenseFPElementsAttr>()) {
+ if (realValue.isa<DenseFPElementsAttr>()) {
// Dense tensor or vector constant.
auto converted = convertDenseFPElementsAttr(
realValue.cast<DenseFPElementsAttr>(), quantizedElementType, converter);
OpenPOWER on IntegriCloud