Usage:
The option “-XX:+UseFMA” enables hardware-based FMA intrinsics for hardware where FMA instructions are available (such as, Intel, SPARC, and ARM64).
Since:
Starting from JDK 9.
Syntax:
java -XX:+UseFMA MainClass
Description:
The FMA instruction set is and instruction to perform a Fused Multiply Add (FMA) operations. The FMA operation has the mathematical form “d = round(a * b + c)”, where the round is math rounding function to allow the result to fit within the destination register if there are too many significant bits to fit within the destination.
A good use to test FMA is DAXPY from Basic Linear Algebra (Check the related posts “Autovectorised FMA in JDK10” to know more about DAXPY and a benchmark of FMA in Java).
Hence, the flag “UseFMA” controls whether Fused Multiply Add (FMA) commands are enabled on hardware-based FMA intrinsics for hardware where FMA instructions are available (such as, Intel, SPARC, and ARM64). FMA intrinsics are generated for the java.lang.Math.fma(a, b, c) methods that calculate the value of (a * b + c) expressions.
Let’s look at the following code snippet:
public class FMATest {
public static void main(String[] args) {
double result = 0;
for (int i = 0; i < 100_000; ++i) {
result = result + fma(i);
}
System.out.println(result);
}
private static float fma(int x) {
return Math.fma(x, x, x);
}
}
We will run it with enabling and disabling FMA.
- Enabling FMA
We will use this options: -XX:+UnlockDiagnosticVMOptions -XX:+UseFMA -XX:+PrintInlining -XX:+PrintIntrinsics -XX:+PrintCompilation
When running those options with the above snippet code, we have this output:
As we can see, the call to “java.long.Math::fma” has used an intrinsic method for FMA instructions.
- Disabling FMA
We will use this options: -XX:+UnlockDiagnosticVMOptions -XX:-UseFMA -XX:+PrintInlining -XX:+PrintIntrinsics -XX:+PrintCompilation
When running the same snippet code with the options above, we will get this output:
As you can notice, the “java.lang.Math::fma” didn’t use any intrinsic method for FMA instructions and we can see the information that “Callee is too large”
Default Value:
This option is disabled by default. (can be enabled for newer version of JDK)
Errors:
None.
Related Posts:
Edit your Comment