Slow Vectors?

Paul Sandoz paul.sandoz at oracle.com
Thu Jun 3 22:50:24 UTC 2021


Hi Remi,

In this case it's not related to blend, it's related to production of the mask, indexInRange, and use of the mask when storing. We have yet to focus on optimizing them, esp within loops. For storing we need to be especially careful when a mask bit is set and if ignored would result in an out-of-bounds array access.

There is ongoing work in the branch https://github.com/openjdk/panama-vector/tree/vectorIntrinsics+mask that should bring some improvements, esp. for architectures that support mask registers.

Paul.

> On Jun 3, 2021, at 9:33 AM, Remi Forax <forax at univ-mlv.fr> wrote:
> 
> ----- Mail original -----
>> De: "Mark Hammons" <markehammons at gmail.com>
>> À: "panama-dev at openjdk.java.net'" <panama-dev at openjdk.java.net>
>> Envoyé: Jeudi 3 Juin 2021 17:51:29
>> Objet: Slow Vectors?
> 
>> Hi all,
>> 
>> I tried testing the incubator vector api today with the following code in
>> JMH
>> 
>> val panamaIntVecAdder = (a: Array[Int], b: Array[Int]) => {
>>> var i = 0
>>> val nArr = Array.ofDim[Int](a.size)
>>> val species = IntVector.SPECIES_PREFERRED
>>> while i < a.size do
>>> val m = species.indexInRange(i, a.length)
>>> val va = IntVector.fromArray(species, a, i, m)
>>> val vb = IntVector.fromArray(species, b, i, m)
>>> 
>>> va.add(vb).intoArray(nArr, i, m)
>>> i += species.length
>>> ArraySeq.unsafeWrapArray(nArr)
>>> }
>>> 
>> 
>> It works, but it's very slow, averaging about  154.038 ns/op. The
>> simplistic vector addition implementation I wrote beats it very easily,
>> which I found very suprising. My current jdk is # VM version: JDK 16.0.1,
>> OpenJDK 64-Bit Server VM, 16.0.1+9-24.
>> 
>> Any idea what I'm doing wrong here?
> 
> reading and writing from a non constant mask is slow with Java 16,
> because it uses blend under the cover.
> 
> using JMH, you can use hsdis [1] + JMH perfasm profiler to get the generated assembly code
> 
> regards,
> Rémi
> 
> [1] https://www.morling.dev/blog/building-hsdis-for-openjdk-15/



More information about the panama-dev mailing list