This is an archive of the discontinued LLVM Phabricator instance.

[mlir][tosa] Remove redundant "tosa.transpose" operations
ClosedPublic

Authored by AviadCo on Dec 21 2022, 1:09 AM.

Details

Summary

We can fold redundant Tosa::TransposeOp actions like identity tranpose/transpose(traspose).

Diff Detail

Event Timeline

AviadCo created this revision.Dec 21 2022, 1:09 AM
AviadCo requested review of this revision.Dec 21 2022, 1:09 AM
AviadCo edited the summary of this revision. (Show Details)Dec 21 2022, 1:20 AM
AviadCo updated this revision to Diff 484739.Dec 21 2022, 11:00 PM

Seperated change into NFC part and FC part.

AviadCo updated this revision to Diff 484740.Dec 21 2022, 11:03 PM

Seperate change into to commits - NFC part and FC part.

AviadCo updated this revision to Diff 484743.Dec 21 2022, 11:18 PM

Seperate change into 2 to commits - NFC part and FC part.

rsuderman requested changes to this revision.Jan 3 2023, 12:04 PM

Overall move the double tosa.transpose pattern to a TOSA canonicalization pattern, then replace with a
new tosa.transpose op. We can leverage the existing tosa.transpose folder to remove the extra operation
if it is a standard version.

mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
970

Breaking this out to a separate function is unnecessary as the folder should focus on the simple case.

994

This is better handled by adding a TransposeOp + TransposeOp -> TransposeOp canonicalization pattern. This allows multiple transposes to merge together, then reuse the existing folder to remove the noop version.

996

We avoid putting multi-op folders together as folding patterns should avoid becoming cumbersome. These kind of operations should stick to canonicalizers.

This revision now requires changes to proceed.Jan 3 2023, 12:04 PM
AviadCo updated this revision to Diff 486549.Jan 5 2023, 6:29 AM

[mlir][tosa] Remove redundant "tosa.transpose" operations

AviadCo marked 3 inline comments as done.Jan 5 2023, 6:35 AM

I appreciate your code review! Can you please review my new revision?

Thanks,
Aviad

mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
970

This function is still usefull both in TransposeOp::fold & in ConsolidateTransposeOptimization::matchAndRewrite , I think can usefull, can you check the new revision?

994

Good idea, adjusted the code according to your suggestion.

996

Ack.

rsuderman added inline comments.Jan 6 2023, 11:10 AM
mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
145

return rewriter.notifyMatchFailure(op, <error message>);

154

Include error message.

158

Use ++i instead of i++.

970

This function is still usefull both in TransposeOp::fold & in ConsolidateTransposeOptimization::matchAndRewrite , I think can usefull, can you check the new revision?

The problem is you have no way to discern if the perms is a constant value of size-0 or a non-constant value. Typically we avoid cases like returning an empty array as a failure sign to avoid ambiguous returns.

993

Missing newline.

mlir/test/IR/transpose-fold.mlir
45

Missing newline.

AviadCo updated this revision to Diff 487278.Jan 8 2023, 9:18 PM
AviadCo marked 3 inline comments as done.

[mlir][tosa] Remove redundant "tosa.transpose" operations

AviadCo marked 6 inline comments as done.Jan 8 2023, 9:27 PM

Hi Rob,

I fixed the adidiotnal comments.

Thanks,
Aviad Cohen

mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
145

Good point, updated to importmative error messages.

154

Updated to importmative error messages.

158

Ack.

970

Right. I updated the function to return a LogicalResult when failed.
In addition, I moved the function implementation to TosaOps.cpp as it seems better place for it.

993

Ack.

mlir/test/IR/transpose-fold.mlir
45

Ack.

rsuderman accepted this revision.Jan 10 2023, 11:47 AM
This revision is now accepted and ready to land.Jan 10 2023, 11:47 AM
This revision was automatically updated to reflect the committed changes.