[vectorapi] Shape of the preferred species with UseAVX=0
Chris Hegarty
chegar999 at gmail.com
Wed May 24 11:39:21 UTC 2023
Hi,
Over in Lucene-land we're experimenting with the Vector API, and ran
into an issue when testing against different environments. We're
effectively simulating different environments with Hotspot's command
line flags, and see an issue with `-XX:UseAVX=0`. With this option we
expect the shape of the preferred species to fallback to 64 bits, but it
is actually 128.
Trivial reproducer that just prints the preferred int species:
$ java -version
openjdk version "21-ea" 2023-09-19
OpenJDK Runtime Environment (build 21-ea+23-1988)
OpenJDK 64-Bit Server VM (build 21-ea+23-1988, mixed mode, sharing)
$ cat PrintPreferredVectorSize.java
import jdk.incubator.vector.*;
public class PrintPreferredVectorSize {
public static void main(String... args) {
System.out.println(IntVector.SPECIES_PREFERRED);
}
}
// Start with the default - no flags, then downsize with MaxVectorSize.
// All looks good.
$ java --add-modules jdk.incubator.vector PrintPreferredVectorSize
WARNING: Using incubator modules: jdk.incubator.vector
Species[int, 16, S_512_BIT]
$ java --add-modules jdk.incubator.vector -XX:MaxVectorSize=64
PrintPreferredVectorSize
WARNING: Using incubator modules: jdk.incubator.vector
Species[int, 16, S_512_BIT]
$ java --add-modules jdk.incubator.vector -XX:MaxVectorSize=32
PrintPreferredVectorSize
WARNING: Using incubator modules: jdk.incubator.vector
Species[int, 8, S_256_BIT]
$ java --add-modules jdk.incubator.vector -XX:MaxVectorSize=16
PrintPreferredVectorSize
WARNING: Using incubator modules: jdk.incubator.vector
Species[int, 4, S_128_BIT]
$ java --add-modules jdk.incubator.vector -XX:MaxVectorSize=8
PrintPreferredVectorSize
WARNING: Using incubator modules: jdk.incubator.vector
Species[int, 2, S_64_BIT]
^^^ this all is as expected ^^^
Now do similar(ish) with UseAVX
$ java --add-modules jdk.incubator.vector -XX:UseAVX=3
PrintPreferredVectorSize
WARNING: Using incubator modules: jdk.incubator.vector
Species[int, 16, S_512_BIT]
$ java --add-modules jdk.incubator.vector -XX:UseAVX=2
PrintPreferredVectorSize
WARNING: Using incubator modules: jdk.incubator.vector
Species[int, 8, S_256_BIT]
$ java --add-modules jdk.incubator.vector -XX:UseAVX=1
PrintPreferredVectorSize
WARNING: Using incubator modules: jdk.incubator.vector
Species[int, 4, S_128_BIT]
$ java --add-modules jdk.incubator.vector -XX:UseAVX=0
PrintPreferredVectorSize
WARNING: Using incubator modules: jdk.incubator.vector
Species[int, 4, S_128_BIT]
It is this last one that is surprising to us. We expect similar
-XX:MaxVectorSize=8, which is Species[int, 2, S_64_BIT]
Firstly, is this a bug? Is our expectation correct? If not, then I'm
failing to understand something.
If I'm not mistaken, then I can see that the
Matcher::vector_width_in_bytes assumes a minimum of 16 regardless of
whether UseAVX is < 1. Trivially, and as a hack, I just retrofitted
vector_width_in_bytes to return 0 if UseAVX < 1. And we get
Species[int, 2, S_64_BIT].
The layer of these flags is not straightforward, so I won't pretend that
my hack is the right way to fix this, but I just wanted to ensure that I
was looking in the correct general area.
Thanks,
-Chris.
More information about the panama-dev
mailing list