This is an archive of the discontinued LLVM Phabricator instance.

[mlir][tosa] Rework tosa.apply_scale lowering for 32-bit
ClosedPublic

Authored by rsuderman on May 13 2022, 1:36 PM.

Details

Summary

Added handling rounding behavior in 32-bits for when possible. This
avoids kernel compilation generating scalarized code on platforms where
64-bit vectors are not available.

As the 48-bit lowering requires 64-bit anyway, we added a full 64-bit
solution simplifying the old path.

Diff Detail

Event Timeline

rsuderman created this revision.May 13 2022, 1:36 PM
Herald added a project: Restricted Project. · View Herald Transcript
rsuderman requested review of this revision.May 13 2022, 1:36 PM
rsuderman updated this revision to Diff 429356.May 13 2022, 2:19 PM

Tweaked to clean up a bit.

rsuderman updated this revision to Diff 429363.May 13 2022, 2:59 PM

Tweaked the 64-bit path to slightly decrease the amount of IR.

Added different populate methods depending on the bitwith supported.

rsuderman updated this revision to Diff 429388.May 13 2022, 4:37 PM

Dag-ified the checks

mravishankar requested changes to this revision.May 15 2022, 9:03 PM

Dont have an opinion about the transformation itself, but more about expected usage.

mlir/lib/Conversion/TosaToArith/TosaToArith.cpp
61–62

Why is this ApplyScale48OpConverter?

270

This probably needs to be added with a higher benefit. If both this pattern and the non-32 bit patterns are added by a caller, then it is undefined which will trigger first. That can lead to strange compilation.

This revision now requires changes to proceed.May 15 2022, 9:03 PM

Thanks for working on this, Rob! I really can't comment on the actual implementation from the TOSA perspective. However, I would suggest not enabling this by default. Architectures with full 64-bit support should do better with the 64-bit lowering. I can follow up with a patch to enable this for the RISC-V specific cases.

mlir/lib/Conversion/TosaToArith/TosaToArith.cpp
270

+1.
Nit: Alternatively, we could have a single populate function with a flag to enable the 32-bit lowering. That would keep both related patterns and their priorities in a single function and avoid potential misuses.

rsuderman updated this revision to Diff 429841.May 16 2022, 1:59 PM

Updated for change how TosaToArith target 32-bit vs 64-bit.

rsuderman marked 3 inline comments as done.May 16 2022, 2:15 PM
rsuderman added inline comments.
mlir/lib/Conversion/TosaToArith/TosaToArith.cpp
61–62

48 meant that it was meant for 48-bit conversion. Because we want to use this for 32-bit operations in some cases I changed it to Generic.

270

Updated to include benefit values and just a bool to decide whether to include the 32-bit lowering path. Note that on llvm integrate we are going to need an integration fix.

mravishankar accepted this revision.May 16 2022, 5:50 PM

Removing my blocker, but I didnt check the math. Probably worth getting someone to review that.

mlir/lib/Conversion/TosaToArith/TosaToArithPass.cpp
40

You could set this to default false?

This revision is now accepted and ready to land.May 16 2022, 5:50 PM
rsuderman updated this revision to Diff 429914.May 16 2022, 5:54 PM
rsuderman marked 2 inline comments as done.

Added default 32-bit setting.

rsuderman marked an inline comment as done.May 16 2022, 5:55 PM
rsuderman added inline comments.
mlir/lib/Conversion/TosaToArith/TosaToArithPass.cpp
40

It is set to default to false in the Passes.td file. Added a default on the function definition as well.

rsuderman marked an inline comment as done.

Resyncing

rsuderman updated this revision to Diff 430181.May 17 2022, 1:53 PM

Update relative benefit

dcaballe accepted this revision.May 17 2022, 2:38 PM

Thanks for addressing the changes. LGTM but, as Mahesh mentioned, it's probably worth getting someone with experience in TOSA to take a look.