This is an archive of the discontinued LLVM Phabricator instance.

[mlir][arith] Add expansion pattern for ext/trunc of bf16
ClosedPublic

Authored by rsuderman on Mar 28 2023, 2:52 PM.

Details

Summary

bf16 has a trivial truncation/extension behavior with F32 that
can be described in elementary arith operations. Include some
expansions to efficiently convert.

Diff Detail

Event Timeline

rsuderman created this revision.Mar 28 2023, 2:52 PM
rsuderman requested review of this revision.Mar 28 2023, 2:52 PM

Nice (sorry forgot to hit submit)

mlir/lib/Dialect/Arith/Transforms/ExpandOps.cpp
207

Could we do this before cloning?

305

rm ?

rsuderman updated this revision to Diff 509506.Mar 29 2023, 5:08 PM

Updated for jpienaar@ comments

rsuderman marked 2 inline comments as done.Mar 29 2023, 5:08 PM
jpienaar accepted this revision.Mar 29 2023, 5:35 PM

LG to me, and optionally done via populate, I'm not sure if always good idea vs letting lower level codegen handle it (seems direct). But given not supported on all backends, SGTM.

mlir/include/mlir/Dialect/Arith/Transforms/Passes.h
41

to lower level bitcasts and shifts ?

(something useful, is not too descriptive).

This revision is now accepted and ready to land.Mar 29 2023, 5:35 PM

LG to me, and optionally done via populate, I'm not sure if always good idea vs letting lower level codegen handle it (seems direct). But given not supported on all backends, SGTM.

I agree. It does not appear that anything depends on the pass specifically and we should be able to integrate via the populate command.

rsuderman updated this revision to Diff 509517.Mar 29 2023, 5:47 PM

Updated comment.

This revision was landed with ongoing or failed builds.Mar 29 2023, 5:59 PM
This revision was automatically updated to reflect the committed changes.
bkramer added a subscriber: bkramer.Apr 4 2023, 6:50 AM
bkramer added inline comments.
mlir/lib/Dialect/Arith/Transforms/ExpandOps.cpp
223

Sorry for being late, but this expansion is simply incorrect. converting from f32 to bf16 needs a rounding step.

Can this pattern be removed or at least pulled out into an opt-in pass. Having it on by default just gives us incorrect results.