Skip to content

Commit 590a988

Browse files
committed
Revert "[TOSA] bug fix infer shape for slice (llvm#113497)"
This reverts commit 7986e0c. Reason for revert: This shape inference si not following tosa spec and causing problems when lowering from onnx to tosa
1 parent ec5f5e6 commit 590a988

File tree

2 files changed

+2
-76
lines changed

2 files changed

+2
-76
lines changed

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

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -926,40 +926,8 @@ LogicalResult tosa::SliceOp::inferReturnTypeComponents(
926926
MLIRContext *context, ::std::optional<Location> location,
927927
SliceOp::Adaptor adaptor,
928928
SmallVectorImpl<ShapedTypeComponents> &inferredReturnShapes) {
929-
auto start = adaptor.getStart();
930-
auto size = adaptor.getSize();
931-
932-
// if size[i] is -1, all remaining elements in dimension i are included
933-
// in the slice, similar to TF.
934-
ShapeAdaptor inputShape(adaptor.getInput1().getType());
935-
// initialize outputShape to all unknown
936-
SmallVector<int64_t> outputShape(size.size(), ShapedType::kDynamic);
937-
if (inputShape.hasRank()) {
938-
for (size_t i = 0; i < size.size(); i++) {
939-
if (size[i] != 0 && size[i] >= -1 && start[i] >= 0 &&
940-
(ShapedType::isDynamic(inputShape.getDimSize(i)) ||
941-
start[i] < inputShape.getDimSize(i))) {
942-
// size[i] is not 0 and not < -1, and start[i] is in valid range
943-
if (ShapedType::isDynamic(inputShape.getDimSize(i))) {
944-
// input shape has unknown dim[i] - only valid if size[i] > 0
945-
if (size[i] > 0) {
946-
outputShape[i] = size[i];
947-
}
948-
} else {
949-
// input shape has known dim[i]
950-
if (size[i] == -1) {
951-
outputShape[i] = inputShape.getDimSize(i) - start[i];
952-
} else if (start[i] + size[i] <= inputShape.getDimSize(i)) {
953-
// start[i] + size[i] is within bound of input shape's dim[i]
954-
outputShape[i] = size[i];
955-
}
956-
}
957-
}
958-
}
959-
} else {
960-
outputShape = convertToMlirShape(size);
961-
}
962-
inferredReturnShapes.push_back(ShapedTypeComponents(outputShape));
929+
inferredReturnShapes.push_back(
930+
ShapedTypeComponents(convertToMlirShape(adaptor.getSize())));
963931
return success();
964932
}
965933

mlir/test/Dialect/Tosa/tosa-infer-shapes.mlir

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -524,48 +524,6 @@ func.func @test_slice(%arg0 : tensor<?xi32>) -> () {
524524

525525
// -----
526526

527-
// CHECK-LABEL: @test_slice_size_minus_one
528-
func.func @test_slice_size_minus_one(%arg0 : tensor<?x8x8x8xi32>) -> () {
529-
// CHECK: tosa.slice %arg0 {size = array<i64: -1, -1, -1, -1>, start = array<i64: 0, 1, -1, 8>} : (tensor<?x8x8x8xi32>) -> tensor<?x7x?x?xi32>
530-
// this checks following
531-
// dim 0: size=-1, input dim=? => inferred output dim is ?
532-
// dim 1: size=-1 => inferred output dim is input_dim - start
533-
// dim 2: size=-1, start=-1 => inferred output dim is ?
534-
// dim 3: size=-1, start=8 => inferred output dim is ? because start is out of bound
535-
%2= tosa.slice %arg0 { start = array<i64: 0, 1, -1, 8>, size = array<i64: -1, -1, -1, -1> } : (tensor<?x8x8x8xi32>) -> tensor<?x?x?x?xi32>
536-
return
537-
}
538-
539-
// -----
540-
// COM: AMD: disabled, input is invalid
541-
// // COM-LABEL: @test_slice_size_out_of_bound
542-
// func.func @test_slice_size_out_of_bound(%arg0 : tensor<8x8x8x?xi32>) -> () {
543-
// // COM: tosa.slice %arg0 {size = array<i64: 0, -2, 9, 4>, start = array<i64: 0, 0, 0, 0>} : (tensor<8x8x8x?xi32>) -> tensor<?x?x?x4xi32>
544-
// // this checks following
545-
// // dim 0: size=0 => inferred output dim is ?
546-
// // dim 1: size=-2 => inferred output dim is ?
547-
// // dim 3: start+size out of bound because size too big: inferred output dim is ?
548-
// // dim 4: size=4, input dim=? => inferred output dim is 4
549-
// %2= tosa.slice %arg0 { start = array<i64: 0, 0, 0, 0>, size = array<i64: 0, -2, 9, 4> } : (tensor<8x8x8x?xi32>) -> tensor<?x?x?x?xi32>
550-
// return
551-
// }
552-
553-
// -----
554-
// COM: AMD: disabled, input is invalid
555-
// // COM-LABEL: @test_slice_start_out_of_bound
556-
// func.func @test_slice_start_out_of_bound(%arg0 : tensor<8x8x8x?xi32>) -> () {
557-
// // COM: tosa.slice %arg0 {size = array<i64: 1, 1, 3, 4>, start = array<i64: -1, 8, 6, 8000000>} : (tensor<8x8x8x?xi32>) -> tensor<?x?x?x4xi32>
558-
// // this checks following
559-
// // dim 0: start=-1 => inferred output dim is ?
560-
// // dim 1: start=8 => inferred output dim is ?
561-
// // dim 2: start+size out of bound: inferred output dim is ?
562-
// // dim 3: start=8000000, size=4, input dim=? => inferred output dim is 4
563-
// %2= tosa.slice %arg0 { start = array<i64: -1, 8, 6, 8000000>, size = array<i64: 1, 1, 3, 4> } : (tensor<8x8x8x?xi32>) -> tensor<?x?x?x?xi32>
564-
// return
565-
// }
566-
567-
// -----
568-
569527
// CHECK-LABEL: @test_slice_dynamic
570528
func.func @test_slice_dynamic(%arg0 : tensor<10x?x2xf32>) -> () {
571529
// CHECK: tosa.slice %arg0 {size = array<i64: 7, -1, 1>, start = array<i64: 1, 0, 0>} : (tensor<10x?x2xf32>) -> tensor<7x?x1xf32>

0 commit comments

Comments
 (0)