Page MenuHomePhabricator

[mlir][tosa] Fix tosa.cast semantics to perform rounding/clipping
ClosedPublic

Authored by rsuderman on May 12 2021, 3:26 PM.

Details

Summary

Rounding to integers requires rounding (for floating points) and clipping
to the min/max values of the destination range. Added this behavior and
updated tests appropriately.

Diff Detail

Event Timeline

rsuderman created this revision.May 12 2021, 3:26 PM
rsuderman requested review of this revision.May 12 2021, 3:26 PM
silvas accepted this revision.May 12 2021, 4:33 PM

Code looks fine. Will let @sjarus review the rounding algorithm details.

This revision is now accepted and ready to land.May 12 2021, 4:33 PM
sjarus added inline comments.May 12 2021, 5:38 PM
mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
517–518

Would be cleaner to integer clip in the integer domain here instead of the seemingly awkward expression of intMin and intMax and F32Attrs and then doing an integer range clamping in the fp Domain ?

This could then reuse the intMin/intMax further below (they'd be common for all dstTy.isa<IntegerType>() ) and swap the last two ops around - FPtoSI(rounded) followed by CmpIOp ?

rsuderman added inline comments.May 12 2021, 6:39 PM
mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
517–518

That doesn't work. To clip in the integer domain we would need to type-convert to integer, then perform the clip. F32 range exceeds i32 (and even i64), so converting type to an integer type, then clipping, would fail.

sjarus accepted this revision.May 12 2021, 7:15 PM
sjarus added inline comments.
mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
517–518

Right, realized that on second thought.

rsuderman marked 2 inline comments as done.May 12 2021, 9:47 PM