Replace math::LogOp with an approximations from the the Julien Pommier's SSE math library
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Code LGTM, I didn't review carefully the numerics here, @asaadaldien is this something you'd like to look at?
LGTM, The log-approximation looks very similar to another implementation I am familiar with (https://github.com/halide/Halide/blob/master/src/IROperator.cpp#L1147)
Some (approximation precision - performance) trade off can be revisited later IMO.
mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp | ||
---|---|---|
305 | The shift adds more operations and still uses same 8-order polynomial as https://github.com/boulos/syrah/blob/master/src/include/syrah/FixedVectorMath.h#L460, I wonder does it add more precision? if yes Can we reach same precision as syrah's implementation with lower polynomial order ? |
mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp | ||
---|---|---|
146 | abs isn't needed here if we are using a strictly positive frexp which is useful in the log(x), x > 0 we have below. This requires using a different cstInvMantMask see (https://github.com/boulos/syrah/blob/master/src/include/syrah/FixedVectorMath.h#L426) |
mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp | ||
---|---|---|
146 | Added a flag to disable abs, it saved ~5% of cpu time in benchmarks. Re mask: didn't quite get it, I think it is irrelevant, and 0x807FFFF is exactly the inverse of 0x7f800000. | |
305 | Added a note to explore this option in the followup PRs. |
Hi @ezhulenev!
It looks like elementType and isI32 methods in PolynomialApproximation.cpp are not used. Would it be possible to remove them to avoid the warnings?
Thanks!
Diego
They are actually used but only inside assert, is it a release build when it is a warning?
Oh, yes, it looks like it's only for release build. Not sure about the guidelines for this case. We couldn't use #ifndef NDEBUG since asserts can also be enabled in release build. Could we introduce some dummy casting for them as we do for other variables that are only used inside asserts (https://llvm.org/docs/CodingStandards.html#id44)?
#ifndef NDEBUG works because this is exactly what is controlled by enabling/disabling assert in release mode.
abs isn't needed here if we are using a strictly positive frexp which is useful in the log(x), x > 0 we have below. This requires using a different cstInvMantMask see (https://github.com/boulos/syrah/blob/master/src/include/syrah/FixedVectorMath.h#L426)