This is an archive of the discontinued LLVM Phabricator instance.

[mlir][math] Expand math.exp2 to use math.exp.
ClosedPublic

Authored by bviyer on Apr 11 2023, 5:00 PM.

Details

Summary

Exp2 functions are pushed directly to libm. This is problematic for
situations where libm is not available. This patch will expand the exp2
function to use exp2 with the input multiplied by ln2 (natural log).

Diff Detail

Event Timeline

bviyer created this revision.Apr 11 2023, 5:00 PM
bviyer requested review of this revision.Apr 11 2023, 5:00 PM
rsuderman added inline comments.Apr 12 2023, 10:29 AM
mlir/lib/Dialect/Math/Transforms/ExpandPatterns.cpp
25

Rather than self defining we can just using stdlib's <numbers> library:

https://en.cppreference.com/w/cpp/header/numbers

mlir/test/Dialect/Math/expand-math.mlir
191

Missing newline at the end of the file.

mlir/test/mlir-cpu-runner/math-polynomial-approx.mlir
700

Could we check values that fall outside the boundaries? We should verify that the edgecase behavior is approximately correct (e.g. very negative or very positive numbers should have a reasonable behavior).

Also we could we include nan, inf, and -inf cases.

bviyer updated this revision to Diff 512948.Apr 12 2023, 1:07 PM
bviyer marked 3 inline comments as done.

Added all the changes requested by rsuderman

bviyer updated this revision to Diff 513250.Apr 13 2023, 8:31 AM

Moved the approximation tests to a new file.

rsuderman accepted this revision.Apr 13 2023, 8:53 AM
This revision is now accepted and ready to land.Apr 13 2023, 8:53 AM