Question on Vector API and MemorySegment

Paul Sandoz paul.sandoz at oracle.com
Fri May 3 22:12:31 UTC 2024


Hi Aurelian,

There was no explicit plan, but they should probably be added now that Foreign Function and Memory API is final (before that we were conservative adding memory segment access methods). Need a volunteer :-)

In theory we should be able to reuse the underlying storeWithMap intrinsic for indexed segment access. There is some degree of complexity wiring up segment accesses to be correctly scoped. Perhaps most of the work is adding tests. API-wise we would need to decide whether the index map should also be a segment with a long map offset, rather than an int[] array. I think it should be a segment, and it’s slightly more work to do that. 
 
Paul.


> On Apr 23, 2024, at 3:00 AM, Aurelian Tutuianu <padreati at yahoo.com> wrote:
> 
> Hi everybody,
> 
> I am using Vector API to manipulate arrays for linear algebra purposes with stride arrays. I was considering to use directly MemorySegment but I found some APIs that does not exist for MemorySegment, but there are for arrays. Those methods are for loading and storing from a MemorySegment using an index map. This is really useful for stride arrays. Below is an example of code:
> 
> VectorSpecies<Double> vsd = DoubleVector.SPECIES_PREFERRED;
> int[] indexes = new int[vsd.length()];
> for (int i = 0; i < indexes.length; i++) {
> indexes[i] = i * 2;
> }
> 
> double[] array = new double[1000];
> // read with index map elements 2 by 2
> DoubleVector.fromArray(vsd, array, 0, indexes, 0);
> 
> MemorySegment ms = MemorySegment.ofArray(array);
> // no possible to read with index map
> vsd.fromMemorySegment(ms, 0, ByteOrder.nativeOrder());
> 
> 
> Do you have in plan to implement those methods?
> 
> Thanks for everything. Best regards,
> Aurelian Tutuianu




More information about the panama-dev mailing list