This is an archive of the discontinued LLVM Phabricator instance.

[mlir][tosa] Fold consecutive tosa.abs
ClosedPublic

Authored by Lewuathe on May 17 2023, 7:53 PM.

Details

Summary

Consecutive tosa.abs can be fold as single abs operation since the second one has no impact.

Diff Detail

Event Timeline

Lewuathe created this revision.May 17 2023, 7:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2023, 7:53 PM
Lewuathe requested review of this revision.May 17 2023, 7:53 PM

Looks good!

In general, MLIR could have an Idempotence trait on ops and then a general facility in the folder.
In TOSA specifically, I think also floor, ceil and clamp (with same min/max) are idempotent.

Looks good!

In general, MLIR could have an Idempotence trait on ops and then a general facility in the folder.
In TOSA specifically, I think also floor, ceil and clamp (with same min/max) are idempotent.

Funny you should mention that

https://mlir.llvm.org/doxygen/classmlir_1_1OpTrait_1_1IsIdempotent.html

Lewuathe added a comment.EditedMay 21 2023, 10:56 PM

Looks good!

In general, MLIR could have an Idempotence trait on ops and then a general facility in the folder.
In TOSA specifically, I think also floor, ceil and clamp (with same min/max) are idempotent.

@mgehre-amd @jpienarr Okay. I’ll add the IsIdempotent trait for these ops in a separate change. Thanks!

This revision was not accepted when it landed; it landed in state Needs Review.May 21 2023, 11:11 PM
This revision was automatically updated to reflect the committed changes.

In TOSA specifically, I think also floor, ceil and clamp (with same min/max) are idempotent.

Idempotent trait seems to expect the op not to change the type itself. They cannot be applied to these ops as it is.

static_assert failed due to requirement 'CeilOp::hasTrait()' "expected operation to preserve type"

@mgehre-amd

In TOSA specifically, I think also floor, ceil and clamp (with same min/max) are idempotent.

Idempotent trait seems to expect the op not to change the type itself. They cannot be applied to these ops as it is.

static_assert failed due to requirement 'CeilOp::hasTrait()' "expected operation to preserve type"

@mgehre-amd

I don't understand what you mean. How does floor for example change the type?

I think the issue is that floor/ceil/clamp don't have the SameOperandsAndResultType trait which is required by the Idempotent trait. It should be okay to add for floor/ceil/clamp as they shouldn't change type.

We can't add SameOperandsAndResultType to the TOSA elementwise binary operators because of the implicit broadcast in TOSA. In those cases the difference in shape between the input and output would cause failures. (Not a factor here, but noting it for reference)

We can't put Idempotent on clamp because the Idempotent fold operation doesn't check the attributes, so could potentially fold improperly. It likely needs an op specific folder.