Skip to content

Commit

Permalink
add verifier for pad input rank
Browse files Browse the repository at this point in the history
  • Loading branch information
sayeddla committed Jan 17, 2024
1 parent 6412cf9 commit 6cd0a91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,10 @@ LogicalResult tosa::PadOp::inferReturnTypeComponents(

LogicalResult PadOp::verify() {
ShapedType inputType = llvm::cast<ShapedType>(getInput1().getType());
if (inputType.hasRank() && inputType.getRank() == 0) {
return emitOpError() << "input tensor rank must not be 0";
}

ShapedType paddingType = llvm::cast<ShapedType>(getPadding().getType());
if (paddingType.hasRank()) {
if (paddingType.getRank() != 2) {
Expand Down
16 changes: 16 additions & 0 deletions mlir/test/Dialect/Tosa/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,22 @@ func.func @test_pad_negative_padding(%arg0: tensor<13x21xf32>) -> tensor<?x?xf32

// -----

func.func @test_pad_incorrect_input(%arg0: f32, %arg1: i32) -> f32 {
// expected-error@+1 {{'tosa.pad' op operand #0 must be ranked tensor of number values, but got 'f32'}}
%1 = "tosa.pad"(%arg0, %arg1) : (f32, i32) -> f32
return %1 : f32
}

// -----

func.func @test_pad_zero_rank_input(%arg0: tensor<f32>, %arg1: tensor<i32>) -> tensor<f32> {
// expected-error@+1 {{'tosa.pad' op input tensor rank must not be 0}}
%1 = "tosa.pad"(%arg0, %arg1) : (tensor<f32>, tensor<i32>) -> tensor<f32>
return %1 : tensor<f32>
}

// -----

func.func @test_transpose_non_const(%arg0: tensor<13x21x3xf32>, %arg1: tensor<3xi32>) -> tensor<3x13x21xf32> {
// expected-error@+1 {{'tosa.transpose' op perms of transpose is not constant}}
%0 = "tosa.transpose"(%arg0, %arg1) : (tensor<13x21x3xf32>, tensor<3xi32>) -> tensor<3x13x21xf32>
Expand Down

0 comments on commit 6cd0a91

Please sign in to comment.