[Mlir-commits] [mlir] a4803d8 - [mlir][Tosa] Fix Clamp verifier to handle quantized types.

Adrian Kuegel llvmlistbot at llvm.org
Fri Oct 20 03:54:53 PDT 2023


Author: Adrian Kuegel
Date: 2023-10-20T10:53:59Z
New Revision: a4803d8a77c6a343a41511b16f643b0793bebfad

URL: https://github.com/llvm/llvm-project/commit/a4803d8a77c6a343a41511b16f643b0793bebfad
DIFF: https://github.com/llvm/llvm-project/commit/a4803d8a77c6a343a41511b16f643b0793bebfad.diff

LOG: [mlir][Tosa] Fix Clamp verifier to handle quantized types.

Added: 
    

Modified: 
    mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
    mlir/test/Dialect/Tosa/ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
index 2e9339c0ca2edc5..2b7f5bee6b7dcad 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
@@ -312,10 +312,18 @@ LogicalResult tosa::AvgPool2dOp::verify() {
 LogicalResult tosa::ClampOp::verify() {
   mlir::Type inputETy =
       llvm::cast<ShapedType>(getInput().getType()).getElementType();
+  if (auto quantType =
+          llvm::dyn_cast<mlir::quant::UniformQuantizedType>(inputETy)) {
+    inputETy = quantType.getStorageType();
+  }
   mlir::Type maxFpType = getMaxFpAttr().getType();
   mlir::Type minFpType = getMinFpAttr().getType();
   mlir::Type outputETy =
       llvm::cast<ShapedType>(getOutput().getType()).getElementType();
+  if (auto quantType =
+          llvm::dyn_cast<mlir::quant::UniformQuantizedType>(outputETy)) {
+    outputETy = quantType.getStorageType();
+  }
   unsigned dataTypeBitWidth = inputETy.getIntOrFloatBitWidth();
 
   if (inputETy != outputETy)

diff  --git a/mlir/test/Dialect/Tosa/ops.mlir b/mlir/test/Dialect/Tosa/ops.mlir
index 064c9160480fdcb..a3e2b66e0305281 100644
--- a/mlir/test/Dialect/Tosa/ops.mlir
+++ b/mlir/test/Dialect/Tosa/ops.mlir
@@ -152,6 +152,13 @@ func.func @test_clamp_bf16(%arg0: tensor<13x21x3xbf16>) -> tensor<13x21x3xbf16>
   return %0 : tensor<13x21x3xbf16>
 }
 
+// -----
+// CHECK-LABEL: clamp_quantized
+func.func @test_clamp_quantized(%arg0: tensor<13x21x3x!quant.uniform<i8:f32, 1.000000e-01:-127>>) -> tensor<13x21x3x!quant.uniform<i8:f32, 1.000000e-01:-127>> {
+  %0 = tosa.clamp %arg0 {min_fp = 0.0 : f32, max_fp = 1.0: f32, min_int = 0 : i64, max_int = 1 : i64} : (tensor<13x21x3x!quant.uniform<i8:f32, 1.000000e-01:-127>>) -> tensor<13x21x3x!quant.uniform<i8:f32, 1.000000e-01:-127>>
+  return %0 : tensor<13x21x3x!quant.uniform<i8:f32, 1.000000e-01:-127>>
+}
+
 // -----
 // CHECK-LABEL: sigmoid
 func.func @test_sigmoid(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> {


        


More information about the Mlir-commits mailing list