Skip to content

Commit f43ec6f

Browse files
committed
[mlir][Tosa] Fix attr type of out_shape for tosa.transpose_conv2d
This patch fixes attr type of out_shape, which is i64 dense array attribute with exactly 4 elements. - Fix description of DenseArrayMaxCt - Add DenseArrayMinCt and move it to CommonAttrConstraints.td - Change type of out_shape to Tosa_IntArrayAttr4
1 parent e982d7f commit f43ec6f

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def Tosa_TransposeConv2DOp : Tosa_InferShapedTypeOp<"transpose_conv2d"> {
352352

353353
Tosa_IntArrayAttr4:$out_pad,
354354
Tosa_IntArrayAttr2:$stride,
355-
Tosa_IntArrayAttrUpto4:$out_shape,
355+
Tosa_IntArrayAttr4:$out_shape,
356356
OptionalAttr<Tosa_ConvOpQuantizationAttr>:$quantization_info,
357357
DefaultValuedOptionalAttr<BoolAttr, "false">:$local_bound
358358
);

mlir/include/mlir/Dialect/Tosa/IR/TosaTypesBase.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,6 @@ def Tosa_Int8Like : Tosa_TypeLike<[Tosa_Int8], "signless-integer-8-bit-like">;
151151
//===----------------------------------------------------------------------===//
152152
// Attribute predicates and classes.
153153
//===----------------------------------------------------------------------===//
154-
class DenseArrayMaxCt<int n> : AttrConstraint<
155-
CPred<"::llvm::cast<::mlir::DenseArrayAttr>($_self).size() <= " # n>,
156-
"with at least " # n # " elements">;
157154

158155
def Tosa_Fp32ArrayAttr2 : ConfinedAttr<DenseF32ArrayAttr, [DenseArrayCount<2>]>;
159156
def Tosa_Fp32ArrayAttr3 : ConfinedAttr<DenseF32ArrayAttr, [DenseArrayCount<3>]>;

mlir/include/mlir/IR/CommonAttrConstraints.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,14 @@ class DenseArrayCount<int n> : AttrConstraint<
789789
CPred<"::llvm::cast<::mlir::DenseArrayAttr>($_self).size() == " #n>,
790790
"with exactly " # n # " elements">;
791791

792+
class DenseArrayMaxCt<int n> : AttrConstraint<
793+
CPred<"::llvm::cast<::mlir::DenseArrayAttr>($_self).size() <= " # n>,
794+
"with at most " # n # " elements">;
795+
796+
class DenseArrayMinCt<int n> : AttrConstraint<
797+
CPred<"::llvm::cast<::mlir::DenseArrayAttr>($_self).size() >= " # n>,
798+
"with at least " # n # " elements">;
799+
792800
class DenseArrayStrictlyPositive<DenseArrayAttrBase arrayType> : AttrConstraint<
793801
CPred<"::llvm::all_of(::llvm::cast<" # arrayType #">($_self).asArrayRef(), "
794802
"[&](auto v) { return v > 0; })">,

mlir/test/Dialect/Tosa/invalid.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,3 +526,12 @@ func.func @test_table_io_shape_mismatch(%arg0: tensor<?x16xi16>, %arg1: tensor<6
526526
%0 = tosa.table %arg0, %arg1 : (tensor<?x16xi16>, tensor<6xi16>) -> tensor<?x15xi16>
527527
return
528528
}
529+
530+
// -----
531+
532+
// CHECK-LABEL: test_transpose_conv2d_invalid_outshape
533+
func.func @test_transpose_conv2d_invalid_outshape(%arg0: tensor<1x32x32x8xf32>, %arg1: tensor<16x1x1x8xf32>, %arg2: tensor<16xf32>) -> tensor<1x32x32x16xf32> {
534+
// expected-error@+1 {{'tosa.transpose_conv2d' op attribute 'out_shape' failed to satisfy constraint: i64 dense array attribute with exactly 4 elements}}
535+
%0 = tosa.transpose_conv2d %arg0, %arg1, %arg2 {out_pad = array<i64: 0, 0, 0, 0>, out_shape = array<i64: 1, 32, 32>, stride = array<i64: 1, 1>} : (tensor<1x32x32x8xf32>, tensor<16x1x1x8xf32>, tensor<16xf32>) -> tensor<1x32x32x16xf32>
536+
return %0 : tensor<1x32x32x16xf32>
537+
}

0 commit comments

Comments
 (0)