Skip to content

Commit 6cd0a91

Browse files
committed
add verifier for pad input rank
1 parent 6412cf9 commit 6cd0a91

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,10 @@ LogicalResult tosa::PadOp::inferReturnTypeComponents(
682682

683683
LogicalResult PadOp::verify() {
684684
ShapedType inputType = llvm::cast<ShapedType>(getInput1().getType());
685+
if (inputType.hasRank() && inputType.getRank() == 0) {
686+
return emitOpError() << "input tensor rank must not be 0";
687+
}
688+
685689
ShapedType paddingType = llvm::cast<ShapedType>(getPadding().getType());
686690
if (paddingType.hasRank()) {
687691
if (paddingType.getRank() != 2) {

mlir/test/Dialect/Tosa/invalid.mlir

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,22 @@ func.func @test_pad_negative_padding(%arg0: tensor<13x21xf32>) -> tensor<?x?xf32
171171

172172
// -----
173173

174+
func.func @test_pad_incorrect_input(%arg0: f32, %arg1: i32) -> f32 {
175+
// expected-error@+1 {{'tosa.pad' op operand #0 must be ranked tensor of number values, but got 'f32'}}
176+
%1 = "tosa.pad"(%arg0, %arg1) : (f32, i32) -> f32
177+
return %1 : f32
178+
}
179+
180+
// -----
181+
182+
func.func @test_pad_zero_rank_input(%arg0: tensor<f32>, %arg1: tensor<i32>) -> tensor<f32> {
183+
// expected-error@+1 {{'tosa.pad' op input tensor rank must not be 0}}
184+
%1 = "tosa.pad"(%arg0, %arg1) : (tensor<f32>, tensor<i32>) -> tensor<f32>
185+
return %1 : tensor<f32>
186+
}
187+
188+
// -----
189+
174190
func.func @test_transpose_non_const(%arg0: tensor<13x21x3xf32>, %arg1: tensor<3xi32>) -> tensor<3x13x21xf32> {
175191
// expected-error@+1 {{'tosa.transpose' op perms of transpose is not constant}}
176192
%0 = "tosa.transpose"(%arg0, %arg1) : (tensor<13x21x3xf32>, tensor<3xi32>) -> tensor<3x13x21xf32>

0 commit comments

Comments
 (0)