Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mlir][tosa]-Edit the verifier of tosa constShapeOp #126962

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2618,6 +2618,10 @@ OpTrait::tosa::verifyTosaShapeOperatorWithSameRanks(Operation *op) {
//===----------------------------------------------------------------------===//

LogicalResult tosa::ConstShapeOp::verify() {
// check one dimensional rank
auto valuesRank = getValue().getType().getRank();
if (valuesRank != 1)
return emitOpError("expect elements in attribute value with rank 1");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great! thank you. I was just about to work on similar checks.
if you don't mind, would you please add an additional check that
the getValue().getType() has element type which is an index type?

Copy link
Contributor Author

@amirBish amirBish Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already being validated with the type of value being declared in the td file.

take a look at mlir/include/mlir/Dialect/Tosa/IR/TosaShapeOps.td line 70:
let arguments = (ins IndexElementsAttr : $value);

// check that number of elements in value attr equal to rank of result shape
auto count = getValue().getNumElements();
auto rank = (cast<tosa::shapeType>(getResult().getType())).getRank();
Expand Down
8 changes: 8 additions & 0 deletions mlir/test/Dialect/Tosa/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,14 @@ func.func @test_const_shape_value() -> !tosa.shape<5> {

// -----

func.func @test_const_shape_value() -> !tosa.shape<4> {
// expected-error@+1 {{'tosa.const_shape' op expect elements in attribute value with rank 1}}
%cst = tosa.const_shape {value = dense<[[1, 2], [3, 4]]> : tensor<2x2xindex>} : () -> !tosa.shape<4>
return %cst : !tosa.shape<4>
}

// -----

func.func @test_sub_with_unequal_operand_ranks(%arg0: tensor<1x21x3xf32>, %arg1: tensor<1x13x21x3xf32>) -> tensor<1x13x21x3xf32> {
// expected-error@+1 {{'tosa.sub' op operands don't have matching ranks}}
%0 = tosa.sub %arg0, %arg1 : (tensor<1x21x3xf32>, tensor<1x13x21x3xf32>) -> tensor<1x13x21x3xf32>
Expand Down