Vector API performance

Eric Liu eric.c.liu at arm.com
Mon May 29 02:27:29 UTC 2023


Hi Bruno, 


> In addition to that, I have one more question. When I'm using the IntVector.fromArray method
passing an array with length less than 16 I get an IndexOutOfBoundsException. Why is that?

One reason is that the offset + N > a.length, where N is the vector lane count [1]. 

Vector lane count also related to the VectorSpecies. "SPECIES_PREFERRED" usually chooses the max
species which fits in the hardware vector register. E.g., on 512-bit vector size machine,
SPECIES_512 can pack bytes into 64 lanes or pack ints into 16 lanes. So, I guess your code was
running on a 512-bit SIMD hardware so that array length less than 16 would cause this exception.

Usually we can use " int upperBound = SPECIES.loopBound(a.length);" to get the largest multiple
of vector lane count [2] for the given array length. JEP 426 also explains VectorSpecies and
shows a typical case [3].

[1] https://github.com/openjdk/jdk/blob/master/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java#L2941
[2] https://github.com/openjdk/jdk/blob/master/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorSpecies.java#L159
[3] https://openjdk.org/jeps/426



- Eric


More information about the panama-dev mailing list