Skip to content

Commit 51c847d

Browse files
authored
[mlir][tosa]-Edit the verifier of tosa constShapeOp (#126962)
Add verification for rank 1 for the elements' attribute of the tosa const_shape operation.
1 parent 5953e5a commit 51c847d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,6 +2618,10 @@ OpTrait::tosa::verifyTosaShapeOperatorWithSameRanks(Operation *op) {
26182618
//===----------------------------------------------------------------------===//
26192619

26202620
LogicalResult tosa::ConstShapeOp::verify() {
2621+
// check one dimensional rank
2622+
auto valuesRank = getValue().getType().getRank();
2623+
if (valuesRank != 1)
2624+
return emitOpError("expect elements in attribute value with rank 1");
26212625
// check that number of elements in value attr equal to rank of result shape
26222626
auto count = getValue().getNumElements();
26232627
auto rank = (cast<tosa::shapeType>(getResult().getType())).getRank();

mlir/test/Dialect/Tosa/invalid.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,14 @@ func.func @test_const_shape_value() -> !tosa.shape<5> {
10871087

10881088
// -----
10891089

1090+
func.func @test_const_shape_value() -> !tosa.shape<4> {
1091+
// expected-error@+1 {{'tosa.const_shape' op expect elements in attribute value with rank 1}}
1092+
%cst = tosa.const_shape {value = dense<[[1, 2], [3, 4]]> : tensor<2x2xindex>} : () -> !tosa.shape<4>
1093+
return %cst : !tosa.shape<4>
1094+
}
1095+
1096+
// -----
1097+
10901098
func.func @test_sub_with_unequal_operand_ranks(%arg0: tensor<1x21x3xf32>, %arg1: tensor<1x13x21x3xf32>) -> tensor<1x13x21x3xf32> {
10911099
// expected-error@+1 {{'tosa.sub' op operands don't have matching ranks}}
10921100
%0 = tosa.sub %arg0, %arg1 : (tensor<1x21x3xf32>, tensor<1x13x21x3xf32>) -> tensor<1x13x21x3xf32>

0 commit comments

Comments
 (0)