38. Fused Multiply Add

The mathematical computation (a * b) + c is heavily exploited in matrix multiplications, which are frequently used in High-Performance Computing (HPC), AI applications, machine learning, deep learning, neural networks, and so on.

The simplest way to implement this computation relies directly on the * and + operators, as follows:

double x = 49.29d;
double y = -28.58d;
double z = 33.63d;
double q = (x * y) + z;

The main problem of this implementation consists of low accuracy and performance caused by two rounding errors (one for the multiply operation and one for the addition operation).

But thanks to Intel AVX's instructions for performing SIMD operations and to JDK 9, which added the Math.fma() method, this computation can be boosted. By relying on Math.fma(), the rounding is done only once using the round to nearest even rounding mode:

double fma = Math.fma(x, y, z);

Notice that this improvement is available for modern Intel processors, so it is not enough to just have JDK 9 in place.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.36.194