Skip to content

Commit 72b7eaf

Browse files
sjarusJerry-Ge
authored andcommitted
[mlir][tosa] Fix ability to expand ranks with dynamic shape support
- The use of != 1 accommodates the use of kDynamicDim - Simplified the for loop to iterate only on lowerRank and access the higherRank dim by using the rankDiff Signed-off-by: Suraj Sudhir <[email protected]> Change-Id: I0f223f335667b2e32c43d4370f0a4b11b0617694
1 parent 8bea511 commit 72b7eaf

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

mlir/lib/Dialect/Tosa/Utils/ConversionUtils.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,21 @@ computeReshapeOutput(ArrayRef<int64_t> higherRankShape,
7777
// Initialize new shapes with [1] * higherRank.
7878
int64_t higherRank = higherRankShape.size();
7979
int64_t lowerRank = lowerRankShape.size();
80-
8180
reshapeOutputShape.assign(higherRank, 1);
8281

8382
int64_t higherRankDim;
8483
int64_t lowerRankDim;
84+
const int64_t rankDiff = higherRank - lowerRank;
85+
86+
for (int64_t i = lowerRank - 1; i >= 0; i--) {
87+
higherRankDim = higherRankShape[i + rankDiff];
88+
lowerRankDim = lowerRankShape[i];
8589

86-
for (int64_t i = higherRank - 1, j = lowerRank - 1; i >= 0 && j >= 0;
87-
i--, j--) {
88-
higherRankDim = higherRankShape[i];
89-
lowerRankDim = lowerRankShape[j];
90-
91-
if (lowerRankDim == 1 && higherRankDim > 1)
92-
reshapeOutputShape[i] = 1;
93-
else if ((lowerRankDim > 1 && higherRankDim == 1) ||
94-
(lowerRankDim == higherRankDim))
95-
reshapeOutputShape[i] = lowerRankDim;
96-
else if (higherRankDim != lowerRankDim)
90+
if (lowerRankDim != 1 && higherRankDim != 1 &&
91+
lowerRankDim != higherRankDim)
9792
return failure();
93+
94+
reshapeOutputShape[i + rankDiff] = lowerRankDim == 1 ? 1 : lowerRankDim;
9895
}
9996
return success();
10097
}

0 commit comments

Comments
 (0)