[mlir][linalg] Treat quant dialect type as unsupported in named conversion
authorKai Sasaki <lewuathe@gmail.com>
Thu, 25 May 2023 00:19:32 +0000 (09:19 +0900)
committerKai Sasaki <lewuathe@gmail.com>
Thu, 25 May 2023 00:35:23 +0000 (09:35 +0900)
Since the tosa-to-linalg conversion does not support the quant dialect type, we can treat it as unsupported instead of crash.  Issue was reported https://github.com/llvm/llvm-project/issues/62367

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D151296

mlir/lib/Conversion/TosaToLinalg/TosaToLinalgNamed.cpp
mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-invalid.mlir [new file with mode: 0644]

index 4f9ea7c..62ec44b 100644 (file)
@@ -766,6 +766,9 @@ public:
     llvm::append_range(pad, op.getPad());
     pad.resize(pad.size() + 2, 0);
     TypedAttr padAttr = rewriter.getZeroAttr(inElementTy);
+    // Unsupported element type
+    if (!padAttr)
+      return failure();
     Value paddedInput = applyPad(loc, input, pad, padAttr, rewriter);
 
     auto initialAttr = rewriter.getZeroAttr(accETy);
diff --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-invalid.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-invalid.mlir
new file mode 100644 (file)
index 0000000..2310ba9
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: mlir-opt --split-input-file -pass-pipeline="builtin.module(func.func(tosa-to-linalg-named))" %s -verify-diagnostics
+
+// CHECK-LABEL: @avg_pool2d_with_unsupported_quant_type
+func.func @avg_pool2d_with_unsupported_quant_type(%arg0: tensor<1x7x7x9x!quant.uniform<i8:f32, 0.01>>) -> tensor<1x7x7x9x!quant.uniform<i8:f32, 0.01>> {
+  // expected-error@+1 {{failed to legalize operation 'tosa.avg_pool2d'}}
+  %0 = "tosa.avg_pool2d"(%arg0) {acc_type = i32, kernel = array<i64: 2, 2>, pad = array<i64: 0, 1, 0, 1>, stride = array<i64: 1, 1>} : (tensor<1x7x7x9x!quant.uniform<i8:f32, 0.01>>) -> tensor<1x7x7x9x!quant.uniform<i8:f32, 0.01>>
+  return %0 : tensor<1x7x7x9x!quant.uniform<i8:f32, 0.01>>
+}