-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add EvalTranspose pattern to StablehloAggressiveFolder (#2570)
This patch folds `stablehlo.transpose` operation with constant operand into `stablehlo.constant`. I have considered doing this by iterating over source index space, i.e. ``` auto initialValue = *std::begin(data); SmallVector<ElementType> result(resultType.getNumElements(), initialValue); for (int64_t i = 0; i < operandType.getNumElements(); ++i) { auto srcDimIndex = delinearize(i, operandStrides); auto dstDimIndex = applyPermutation(srcDimIndex, permutation); auto dstLinearIndex = linearize(dstDimIndex, resultStrides); result[dstLinearIndex] = data[i]; } ``` but that requires preinitialization of result vector with some value, which is twice as slow on simple case: ``` func.func @eval_transpose() -> (tensor<5000x80x30xi32>) { %0 = stablehlo.iota dim = 0 : tensor<30x80x5000xi32> %1 = stablehlo.transpose %0, dims = [2, 1, 0] : (tensor<30x80x5000xi32>) -> tensor<5000x80x30xi32> func.return %1 : tensor<5000x80x30xi32> } ```
- Loading branch information
Showing
2 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters