This is an archive of the discontinued LLVM Phabricator instance.

Add f16 type support in math.erf op.
ClosedPublic

Authored by pashu123 on Oct 12 2022, 5:42 AM.

Details

Summary

f16 type support was missing in the math.erf op.

Diff Detail

Event Timeline

pashu123 created this revision.Oct 12 2022, 5:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 12 2022, 5:42 AM
pashu123 requested review of this revision.Oct 12 2022, 5:42 AM
sogartar added inline comments.
mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
173

You could use

FloatAttr Builder::getFloatAttr(Type type, double value)

to avoid branching.

775

If this check fails wouldn't it let someone else handle math.erf down the line. Isn't it desirable for example if you have also f64 that has to be calculated in some other manner?
I think we should not handle all float types here because this approximation may not be precise enough for f64. It will be difficult to track the source of the imprecision.

sogartar added inline comments.Oct 12 2022, 9:28 AM
mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
171

This assert can be removed if you use Builder::getFloatAttr.

283

This assert can be removed if you use Builder::getFloatAttr.

@ezhulenev IIRC you added these. Please take a look.

ezhulenev accepted this revision.Oct 12 2022, 7:42 PM
This revision is now accepted and ready to land.Oct 12 2022, 7:42 PM
pashu123 updated this revision to Diff 467431.Oct 13 2022, 3:58 AM

use the getFloatAttr function and remove the branches

pashu123 added inline comments.Oct 13 2022, 3:59 AM
mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
171

assert is still needed to check for f64 cases though removing the branches makes sense. Thanks.

283

This assert is needed here. There is no support for f64.

775

I am asserting for f32 and f16 below.

sogartar added inline comments.Oct 13 2022, 3:25 PM
mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
775

Asserting is different. This will return a match failure, allowing others to handle the lowering.
The assert will not be there in a release build. In that case the lowering will silently succeed even though it should be avoided for f64.

pashu123 updated this revision to Diff 467740.Oct 14 2022, 4:43 AM

instead of assert notifiy match failure.

mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
775

Makes sense.

This revision was automatically updated to reflect the committed changes.