Skip to content

Commit 48b573b

Browse files
committed
[AutoBump] Merge with fixes of 37263b6 (Sep 04)
2 parents 2fff529 + 37263b6 commit 48b573b

File tree

2 files changed

+25
-90
lines changed

2 files changed

+25
-90
lines changed

mlir/lib/Dialect/Tosa/IR/TosaOps.cpp

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -856,35 +856,17 @@ LogicalResult tosa::PadOp::inferReturnTypeComponents(
856856
return success();
857857
}
858858

859-
LogicalResult PadOp::verify() {
860-
ShapedType inputType = llvm::cast<ShapedType>(getInput1().getType());
861-
if (inputType.hasRank() && inputType.getRank() == 0) {
862-
return emitOpError() << "input tensor rank must not be 0";
863-
}
859+
LogicalResult tosa::PadOp::verify() {
860+
RankedTensorType inputType = getInput1().getType();
861+
RankedTensorType outputType = getOutput().getType();
862+
TensorType paddingType = getPadding().getType();
864863

865-
ShapedType paddingType = llvm::cast<ShapedType>(getPadding().getType());
866-
if (paddingType.hasRank()) {
867-
if (paddingType.getRank() != 2) {
868-
return emitOpError() << "paddings must be a tensor of rank 2";
869-
}
870-
if (inputType.hasRank() && !paddingType.isDynamicDim(0) &&
871-
inputType.getRank() != paddingType.getDimSize(0)) {
872-
return emitOpError() << "paddings must be a tensor of shape ["
873-
<< inputType.getRank() << ", 2]";
874-
}
875-
if (!paddingType.isDynamicDim(1) && paddingType.getDimSize(1) != 2) {
876-
return emitOpError() << "paddings must be a tensor of shape ["
877-
<< inputType.getRank() << ", 2]";
878-
}
864+
if (inputType.getRank() != outputType.getRank())
865+
return emitOpError() << "expect same input and output tensor rank.";
866+
867+
if (paddingType.hasRank() && paddingType.getRank() != 2)
868+
return emitOpError() << "expect 'padding' tensor rank equal to 2.";
879869

880-
DenseIntElementsAttr paddings;
881-
if (matchPattern(getPadding(), m_Constant(&paddings))) {
882-
if (llvm::any_of(paddings,
883-
[](auto val) { return val.getSExtValue() < 0; })) {
884-
return emitOpError() << "number of pad elements must be positive";
885-
}
886-
}
887-
}
888870
return success();
889871
}
890872

mlir/test/Dialect/Tosa/invalid.mlir

Lines changed: 16 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -105,83 +105,36 @@ func.func @test_pad_non_const(%arg0: tensor<13x21x3xf32>, %arg1: tensor<3x2xi32>
105105

106106
// -----
107107

108-
func.func @test_pad_non_const(%arg0: tensor<13x21x3xi8>, %arg1: tensor<i8>) -> tensor<?x?x?xi8> {
108+
func.func @test_pad_non_const(%arg0: tensor<13x21x3xi8>, %arg1: tensor<i8>) -> tensor<13x21x3xi8> {
109109
%0 = "tosa.const"() {value = dense<[[0, 0], [0, 1], [0, 1]]> : tensor<3x2xi32>} : () -> tensor<3x2xi32>
110110
// expected-error@+1 {{'tosa.pad' op pad_const of pad is not constant}}
111-
%1 = tosa.pad %arg0, %0, %arg1 : (tensor<13x21x3xi8>, tensor<3x2xi32>, tensor<i8>) -> tensor<?x?x?xi8>
112-
return %1 : tensor<?x?x?xi8>
111+
%1 = tosa.pad %arg0, %0, %arg1 : (tensor<13x21x3xi8>, tensor<3x2xi32>, tensor<i8>) -> tensor<13x21x3xi8>
112+
return %1 : tensor<13x21x3xi8>
113113
}
114114

115115
// -----
116116

117-
func.func @test_pad_output_shape_mismatch(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> {
118-
%0 = "tosa.const"() {value = dense<[[1, 1], [1, 1], [1, 1]]> : tensor<3x2xi32>} : () -> tensor<3x2xi32>
119-
// expected-error@+2 {{'tosa.pad' op failed to infer returned types}}
120-
// expected-error@+1 {{'tosa.pad' op inferred type(s) 'tensor<15x23x5xf32>' are incompatible with return type(s) of operation 'tensor<13x21x3xf32>}}
121-
%1 = tosa.pad %arg0, %0 : (tensor<13x21x3xf32>, tensor<3x2xi32>) -> tensor<13x21x3xf32>
122-
return %1 : tensor<13x21x3xf32>
123-
}
124-
125-
// -----
126-
127-
func.func @test_pad_type_mismatch(%arg0: tensor<13x21x3xf32>) -> tensor<15x23x5xi32> {
128-
%0 = "tosa.const"() {value = dense<[[1, 1], [1, 1], [1, 1]]> : tensor<3x2xi32>} : () -> tensor<3x2xi32>
129-
// expected-error@+2 {{'tosa.pad' op failed to infer returned types}}
130-
// expected-error@+1 {{'tosa.pad' op inferred type(s) 'tensor<15x23x5xf32>' are incompatible with return type(s) of operation 'tensor<15x23x5xi32>}}
131-
%1 = tosa.pad %arg0, %0 : (tensor<13x21x3xf32>, tensor<3x2xi32>) -> tensor<15x23x5xi32>
132-
return %1 : tensor<15x23x5xi32>
133-
}
134-
135-
// -----
136-
137-
func.func @test_pad_incorret_padding_rank(%arg0: tensor<13x21xf32>) -> tensor<13x21xf32> {
138-
%0 = "tosa.const"() {value = dense<[0, 1]> : tensor<2xi32>} : () -> tensor<2xi32>
139-
// expected-error@+1 {{'tosa.pad' op paddings must be a tensor of rank 2}}
140-
%1 = tosa.pad %arg0, %0 : (tensor<13x21xf32>, tensor<2xi32>) -> tensor<13x21xf32>
141-
return %1 : tensor<13x21xf32>
142-
}
143-
144-
// -----
145-
146-
func.func @test_pad_incorret_padding_shape(%arg0: tensor<13x21xf32>) -> tensor<13x21xf32> {
147-
%0 = "tosa.const"() {value = dense<[[0, 0], [0, 1], [0, 1], [1, 1]]> : tensor<4x2xi32>} : () -> tensor<4x2xi32>
148-
// expected-error@+1 {{'tosa.pad' op paddings must be a tensor of shape [2, 2]}}
149-
%1 = tosa.pad %arg0, %0 : (tensor<13x21xf32>, tensor<4x2xi32>) -> tensor<13x21xf32>
150-
return %1 : tensor<13x21xf32>
151-
}
152-
153-
// -----
154-
155-
func.func @test_pad_incorret_padding_shape(%arg0: tensor<13x21xf32>) -> tensor<13x21xf32> {
156-
%0 = "tosa.const"() {value = dense<[[0, 0, 0, 1], [0, 1, 1, 1]]> : tensor<2x4xi32>} : () -> tensor<2x4xi32>
157-
// expected-error@+1 {{'tosa.pad' op paddings must be a tensor of shape [2, 2]}}
158-
%1 = tosa.pad %arg0, %0 : (tensor<13x21xf32>, tensor<2x4xi32>) -> tensor<13x21xf32>
159-
return %1 : tensor<13x21xf32>
160-
}
161-
162-
// -----
163-
164-
func.func @test_pad_negative_padding(%arg0: tensor<13x21xf32>) -> tensor<?x?xf32> {
165-
%0 = "tosa.const"() {value = dense<[[0, 0], [0, -1]]> : tensor<2x2xi32>} : () -> tensor<2x2xi32>
166-
// expected-error@+1 {{'tosa.pad' op number of pad elements must be positive}}
167-
%1 = tosa.pad %arg0, %0 : (tensor<13x21xf32>, tensor<2x2xi32>) -> tensor<?x?xf32>
168-
return %1 : tensor<?x?xf32>
117+
func.func @test_pad_io_rank_mismatch(%arg0: tensor<13x21xf32>, %arg1: tensor<2x2xi32>) {
118+
// expected-error@+1 {{'tosa.pad' op expect same input and output tensor rank.}}
119+
%1 = tosa.pad %arg0, %arg1 : (tensor<13x21xf32>, tensor<2x2xi32>) -> tensor<13x21x3xf32>
120+
return
169121
}
170122

171123
// -----
172124

173-
func.func @test_pad_incorrect_input(%arg0: f32, %arg1: i32) -> f32 {
174-
// expected-error@+1 {{'tosa.pad' op operand #0 must be ranked tensor of number values, but got 'f32'}}
175-
%1 = tosa.pad %arg0, %arg1 : (f32, i32) -> f32
176-
return %1 : f32
125+
func.func @test_pad_invalid_padding_rank(%arg0: tensor<13x21xf32>, %arg1: tensor<2xi32>) {
126+
// expected-error@+1 {{'tosa.pad' op expect 'padding' tensor rank equal to 2.}}
127+
%1 = tosa.pad %arg0, %arg1 : (tensor<13x21xf32>, tensor<2xi32>) -> tensor<13x21xf32>
128+
return
177129
}
178130

179131
// -----
180132

181-
func.func @test_pad_zero_rank_input(%arg0: tensor<f32>, %arg1: tensor<i32>) -> tensor<f32> {
182-
// expected-error@+1 {{'tosa.pad' op input tensor rank must not be 0}}
183-
%1 = tosa.pad %arg0, %arg1 : (tensor<f32>, tensor<i32>) -> tensor<f32>
184-
return %1 : tensor<f32>
133+
func.func @test_pad_invalid_padConst_rank(%arg0: tensor<13x21xf32>, %arg1: tensor<2x2xi32>) {
134+
%0 = "tosa.const"() {value = dense<3.14> : tensor<1xf32>} : () -> tensor<1xf32>
135+
// expected-error@+1 {{'tosa.pad' op operand #2 must be 0D tensor of number values, but got 'tensor<1xf32>'}}
136+
%1 = tosa.pad %arg0, %arg1, %0 : (tensor<13x21xf32>, tensor<2x2xi32>, tensor<1xf32>) -> tensor<13x21xf32>
137+
return
185138
}
186139

187140
// -----

0 commit comments

Comments
 (0)