From d72d48803921551604f49db1ee72aa0ae9e57611 Mon Sep 17 00:00:00 2001 From: lewuathe Date: Sat, 25 Jun 2022 08:27:38 +0900 Subject: [PATCH] [mlir][quant] output spec verification check for quant.region We can have validation test for quant.region having incompatible output spec. Reviewed By: stellaraccident Differential Revision: https://reviews.llvm.org/D128245 --- mlir/test/Dialect/Quant/quant_region.mlir | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/mlir/test/Dialect/Quant/quant_region.mlir b/mlir/test/Dialect/Quant/quant_region.mlir index 8c7d6c4..437edf8 100644 --- a/mlir/test/Dialect/Quant/quant_region.mlir +++ b/mlir/test/Dialect/Quant/quant_region.mlir @@ -70,6 +70,36 @@ func.func @unmatched_primitive(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>, %arg2 // ----- +func.func @unmatched_quantize(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>, %arg2: tensor<4xf32>) -> (tensor<4xf32>) { + // @expected-error @+1 {{'quant.region' op has incompatible specification !quant.uniform and output type 'tensor<4xf32>'}} + %0 = "quant.region"(%arg0, %arg1, %arg2) ({ + ^bb0(%10: tensor<4xf32>, %11: tensor<4xf32>, %12: tensor<4xf32>): + %13 = "foo"(%10, %11) : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32> + %14 = "bar"(%13, %12) : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32> + "quant.return"(%14) : (tensor<4xf32>) -> () + }) {input_specs = [!quant.uniform, !quant.uniform, !quant.uniform], + output_specs = [!quant.uniform], logical_kernel = "xyz"} + : (tensor<4xf32>, tensor<4xf32>, tensor<4xf32>) -> (tensor<4xf32>) + return %0 : tensor<4xf32> +} + +// ----- + +func.func @unmatched_primitive(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>, %arg2: tensor<4xf32>) -> (tensor<4xf32>) { + // @expected-error @+1 {{'quant.region' op has incompatible specification i32 and output type 'tensor<4xf32>'}} + %0 = "quant.region"(%arg0, %arg1, %arg2) ({ + ^bb0(%10: tensor<4xf32>, %11: tensor<4xf32>, %12: tensor<4xf32>): + %13 = "foo"(%10, %11) : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32> + %14 = "bar"(%13, %12) : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32> + "quant.return"(%14) : (tensor<4xf32>) -> () + }) {input_specs = [!quant.uniform, !quant.uniform, !quant.uniform], + output_specs = [i32], logical_kernel = "xyz"} + : (tensor<4xf32>, tensor<4xf32>, tensor<4xf32>) -> (tensor<4xf32>) + return %0 : tensor<4xf32> +} + +// ----- + func.func @unmatched_number(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>, %arg2: tensor<4xf32>) -> (tensor<4xf32>) { // @expected-error @+1 {{'quant.region' op has unmatched operands/results number and spec attributes number}} %0 = "quant.region"(%arg0, %arg1, %arg2) ({ -- 2.7.4