RFR: 8315024: Vector API FP reduction tests should not test for exact equality

Gergö Barany gbarany at openjdk.org
Thu Oct 5 14:27:51 UTC 2023


On Wed, 4 Oct 2023 09:47:55 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

> Are we making sure the float/double reductions do not degenerate to either zero or infinity?

You're right. We're currently getting "lucky" here because we reduce individual vectors of 4, 8, or 16 elements inside a loop. So even if the array contains a zero, or the product of the entire array is infinite, individual blocks inside it will have finite, non-zero products. This will change when https://bugs.openjdk.org/browse/JDK-8309647 is addressed. I'll try to put together a generator that also works nicely for multiplications over a whole array.

> test/jdk/jdk/incubator/vector/Double128VectorTests.java line 64:
> 
>> 62: 
>> 63:     // for floating point reduction ops that may introduce rounding errors
>> 64:     private static final double RELATIVE_ROUNDING_ERROR = (double)0.01;
> 
> It seems a bit large. Have you tried to make it smaller? Or what is your justification for this value?

With the current version of the test, a value as small as 0.000001 seems to be fine, one more zero is too small. This will probably have to be adjusted in the future for larger tests.

> test/jdk/jdk/incubator/vector/Double128VectorTests.java line 150:
> 
>> 148:         }
>> 149:     }
>> 150: 
> 
> Optional: reduce code duplication. Call `assertReductionArraysEquals` with `relativeError = 0` in pre-existing method.

Good idea, thanks.

> test/jdk/jdk/incubator/vector/Double128VectorTests.java line 1117:
> 
>> 1115:                 return fill(s * BUFFER_REPS,
>> 1116:                             i -> (double)(i / (double) 10.0 + 0.1));
>> 1117:             }),
> 
> Did this generate rounding issues for addition?
> Another option would be random values that make sure to fill the whole mantissa with random information.
> Of course the tricky part is to keep them within reasonable bounds so that on multiplication they do not degenerate to zero or infinity.
> Also: it would be nice to have some cases with extreme values (infinity, NaN, etc).

Yes, this generator generates a rounding issue for addition:

test FloatMaxVectorTests.ADDReduceFloatMaxVectorTests(float[i / 10.0 + 0.1]): failure
java.lang.AssertionError: at index #16 expected [39.2] but found [39.199997]

-------------

PR Comment: https://git.openjdk.org/jdk/pull/16024#issuecomment-1748963277
PR Review Comment: https://git.openjdk.org/jdk/pull/16024#discussion_r1347474114
PR Review Comment: https://git.openjdk.org/jdk/pull/16024#discussion_r1347474207
PR Review Comment: https://git.openjdk.org/jdk/pull/16024#discussion_r1347474261


More information about the hotspot-compiler-dev mailing list