This is an archive of the discontinued LLVM Phabricator instance.

[mlir][tosa] Prefer tosa.transpose composition canonicalization to reshape
ClosedPublic

Authored by rsuderman on Jan 10 2023, 2:22 PM.

Details

Summary

It is preferred to merge tosa.transpose operations together rather than convert
one to a tosa.reshape. This is to leverage the tosa.transpose -> tosa.transpose
merging canonicalization.

Diff Detail

Event Timeline

rsuderman created this revision.Jan 10 2023, 2:22 PM
rsuderman requested review of this revision.Jan 10 2023, 2:22 PM

This is good idea!
I am wondering if we can use the "benefit" (https://mlir.llvm.org/docs/PatternRewriter/#benefit) mechnism here of Pattern Rewriting, something like:

enum TransposeRewriteBenefit : uint8_t {
  None = 0,
  ReshapeTranspose,
  ConsolidateTransposes,
} TransposeBenefit;

And then use is in c'tors:

TransposeIsReshape(MLIRContext *context)
    : OpRewritePattern(context, ReshapeTranspose) {}

ConsolidateTransposeOptimization(MLIRContext *context)
    : OpRewritePattern(context, ConsolidateTransposes) {}

More at: https://mlir.llvm.org/docs/DeclarativeRewrites/#adjusting-benefits

rsuderman updated this revision to Diff 489985.Jan 17 2023, 4:51 PM

Moved transpose-fold.mlir to the correct folder

This is good idea!
I am wondering if we can use the "benefit" (https://mlir.llvm.org/docs/PatternRewriter/#benefit) mechnism here of Pattern Rewriting, something like:

enum TransposeRewriteBenefit : uint8_t {
  None = 0,
  ReshapeTranspose,
  ConsolidateTransposes,
} TransposeBenefit;

And then use is in c'tors:

TransposeIsReshape(MLIRContext *context)
    : OpRewritePattern(context, ReshapeTranspose) {}

ConsolidateTransposeOptimization(MLIRContext *context)
    : OpRewritePattern(context, ConsolidateTransposes) {}

More at: https://mlir.llvm.org/docs/DeclarativeRewrites/#adjusting-benefits

Unfortunately benefit cannot be used to target the beneficial pattern as the transpose-transpose case depends on the interaction of two operations. Depending on the processing order it is possible for the top-most case to canonicalize to a reshape and be unable to merge with the consuming transpose. It may be possible to rearrange whether a consumer/producer is checked for being a transpose allowing the benefit pattern to be used however if a pattern used the canonicalization patterns but processed it in the opposite ordering it would then fail.

AviadCo accepted this revision.Jan 18 2023, 1:26 AM

I see, good point.

This revision is now accepted and ready to land.Jan 18 2023, 1:26 AM