File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -983,6 +983,10 @@ LogicalResult tosa::TransposeOp::inferReturnTypeComponents(
983
983
ShapeAdaptor inputShape (adaptor.getInput1 ().getType ());
984
984
ShapeAdaptor permsShape (adaptor.getPerms ().getType ());
985
985
986
+ // We cannot infer anything from a rank-0 "permutation" tensor.
987
+ if (permsShape.hasRank () && permsShape.getRank () == 0 )
988
+ return failure ();
989
+
986
990
// If input rank and permutation length is unknown, the output rank is
987
991
// unknown.
988
992
if (!inputShape.hasRank () || !permsShape.hasRank () ||
@@ -997,15 +1001,7 @@ LogicalResult tosa::TransposeOp::inferReturnTypeComponents(
997
1001
return failure ();
998
1002
}
999
1003
1000
- // Without the input dims we cannot determine the output dim sizes but we
1001
- // can determine the output rank.
1002
1004
SmallVector<int64_t > outputShape;
1003
- if (!inputShape.hasRank ()) {
1004
- outputShape.resize (permsShape.getDimSize (0 ), ShapedType::kDynamic );
1005
- inferredReturnShapes.push_back (ShapedTypeComponents (outputShape));
1006
- return success ();
1007
- }
1008
-
1009
1005
// Rank-0 means no permutations matter.
1010
1006
if (inputShape.getRank () == 0 ) {
1011
1007
inferredReturnShapes.push_back (ShapedTypeComponents (outputShape));
Original file line number Diff line number Diff line change @@ -1310,3 +1310,14 @@ func.func @test_large_constant_permutation() {
1310
1310
return
1311
1311
}
1312
1312
1313
+ // -----
1314
+
1315
+ // CHECK-LABEL: test_rank0_transpose_perms
1316
+ // Fail to infer the shape but not crash.
1317
+ func.func @test_rank0_transpose_perms () {
1318
+ %14 = tensor.empty () : tensor <5 x27 xi64 >
1319
+ %cst = tensor.empty () : tensor <i32 >
1320
+ // CHECK: tosa.transpose
1321
+ %72 = tosa.transpose %14 , %cst : (tensor <5 x27 xi64 >, tensor <i32 >) -> tensor <?x?xi64 >
1322
+ return
1323
+ }
You can’t perform that action at this time.
0 commit comments