Hello.

Le mer. 18 août 2021 à 09:44, Erik Svensson <erik.svens...@nasdaq.com> a écrit :
>
> Hi all!
>
>
>
> To recap, we use Apache-commons math extensively and we would like to improve 
> performance by improving performance in the FastMath (now named AccurateMath) 
> class by using
>
> Java.lang.Math methods where those are annotated with the 
> HotSpotIntrinsicCandidate/IntrinsicCandidate annotation.
>
> One problem is that FM/AM is not a drop-in replacement for jlM as of java 9. 
> I could add the methods needed easily (if we ignore the performance penalty 
> for the FMA operation when using BigDecimal) so I could get on with the 
> actual performance work (NB that FMA is marked as IntrinsicCandidate and that 
> modern intel cpu:s have integral support for FMA).
>
> If FM/AM is NOT to be a drop-in replacement for jlM, then I can get on with 
> finding a solution that enables users to select a math provider for the math 
> lib, thus being able to select jlM if the additional performance is desired.

I never quite understood the qualification of "drop-in" replacement as
switching from "java.lang.Math" to "Fastmath" requires source change
and recompilation.
A runtime switch would be an interesting feature, but it might have a
large adverse effect on performance...

>
> On another note, FM/AM is advertised as being more accurate than jlM.

A unit test[1] compares results from Fastmath with computations that use
40 decimal digits (see "Dfp" class[2]).  It ensures that FastMath is within
0.5 ULPs of the high-precision value but does not check whether "Math"
is also within that boundary.

> Anybody knows if this applies to methods using intrinsics as well?

You are welcome to provide benchmark code (to be located in the
"commons-math-examples" module where each "sub-module" can
require a different version of the JDK), that would give up-to-date
answers to those questions with different combinations of JDK
version (with/without the annotation):
  * Accuracy (perhaps using "BigDecimal" instead of "Dfp")
  * Speed (using JMH)
This would be crucial information for selecting the way forward
(including whether "AccurateMath" support should be dropped
entirely!).

Regards,
Gilles

[1] 
https://gitbox.apache.org/repos/asf?p=commons-math.git;a=blob;f=commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java;h=6cddff2306a9f429c6f8f58d2827bc4a1f35911d;hb=HEAD
[2] 
https://gitbox.apache.org/repos/asf?p=commons-math.git;a=blob;f=commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java;h=41f15c91151b16b8005da376e9c3aff54229b967;hb=HEAD

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to