[vectorIntrinsics] RFR: 8287289: Gather/Scatter with Index Vector
John R Rose
jrose at openjdk.java.net
Wed Jun 1 17:35:49 UTC 2022
On Wed, 25 May 2022 08:35:53 GMT, Joshua Zhu <jzhu at openjdk.org> wrote:
> When I assist engineers to apply VectorAPI in real business scenarios, I realize that Gather/Scatter APIs depend on indexMap residing in memory.
>
> When an index map is acquired by vector operations, it is represented by IntVector. To do Gather/Scatter operations, an extra integer array must be introduced and an explicit vector store is also required ahead of each Gather/Scatter. Furthermore, the redundant memory store may cause a performance penalty.
>
> Hence I submit this change for discussion. I propose to provide Gather/Scatter API supporting index vector. This patch only includes the change for Gather API.
> It passed the jtreg tests for VectorAPI.
P.S. As long as I'm talking about scatter and gather, I should also point out that the above APIs (as well as the existing proof-of-concept APIs) do not support scatter or gather to/from more than one Java object at a time. This is another limitation I'd like to eventually remove.
An API which could do this looks like 2-D scatter/gathers where the first dimension is an index (a real `int`) into a Java array of multiple objects. Panama lets us declare that this array can be of type `MemorySegment[]` and that's all you need.
FloatVector fromArrays(
VectorSpecies<Float> species,
MemorySegment[] as,
IntVector indexVector1,
IntVector indexVector2);
FloatVector fromArrays(
VectorSpecies<Float> species,
MemorySegment[] as,
IntVector indexVector1,
LongVector indexVector2);
// and for constant second index:
FloatVector fromArrays(
VectorSpecies<Float> species,
MemorySegment[] as,
IntVector indexVector1,
int index2);
FloatVector fromArrays(
VectorSpecies<Float> species,
MemorySegment[] as,
IntVector indexVector1,
long index2);
P.P.S. I suppose that the word `Array` in all of the above should be called `Memory` if embrace Panama. It's not really an array, except in a logical sense. Also I have omitted any discussion of index scaling and alignment. There might be more to say about those issues.
-------------
PR: https://git.openjdk.java.net/panama-vector/pull/201
More information about the panama-dev
mailing list