[Vector API] Missing a way to know which operators are preferred

Michaël Figuière michael.figuiere at gmail.com
Wed Oct 19 01:01:54 UTC 2022


Hi Eric,

I was thinking of the POPCNT example that was discussed recently on this
mailing list, where it couldn't be optimized on an AVX2-only CPU because
the POPCNT operator relies on AVX512 instructions. In this case, even if
the developer picks the preferred species for the targeted platform, it
wouldn't be possible to know if the POPCNT operator will be leveraging
efficient SIMD instructions or just rely on a default scalar implementation
without digging into the produced assembly, which kills the purpose of such
a higher level, platform independent API. Hence my suggestion to be able to
programmatically test if the POPCNT operator itself can be SIMD optimized /
preferred on the current platform or if an alternative logic without a
POPCNT operator should be used if possible.

Michaël

On Sun, Oct 16, 2022 at 9:16 PM Eric Liu <eric.c.liu at arm.com> wrote:

> Hi Michaël,
>
>
>
> Thanks for you feedback.
>
>
>
> > it's currently possible to know for a given type which VectorSpecies is
> preferred
>
> > on the current platform.
>
>
>
> I think the preferred species is usually the largest available species.
>
>
>
> > an application developer would want to know which Operator will be
> preferred (i.e.
>
> > backed by an appropriate SIMD instruction) on a targeted platform.
> Similarly, a
>
> > library developer would want to be able to pick at runtime between
> different
>
> > implementations of an algorithm.
>
>
>
> Usually, the larger species would have better performance since more data
> could be
>
> handled in just one time. That’s true that it’s architecture dependent.
> Even though
>
> some instructions have low throughput in a larger size, a well implemented
> backend
>
> should choose the optimal instructions and should not trouble the Java
> developers.
>
>
>
> Have you ever found a case that has better performance but with a smaller
> species on
>
> any platform? If there is, perhaps some micro-architecture optimizations
> should be done.
>
>
>
>
>
> - Eric
>
>
>
> *From:* panama-dev <panama-dev-retn at openjdk.org> *On Behalf Of *Michaël
> Figuière
> *Sent:* Saturday, October 15, 2022 1:56 AM
> *To:* panama-dev at openjdk.org
> *Subject:* [Vector API] Missing a way to know which operators are
> preferred
>
>
>
> Hello,
>
> A suggestion based on my small experience with the Vector API: it's
> currently possible to know for
>
> a given type which VectorSpecies is preferred on the current platform, but
> it's not the case for
>
> Operator. As the Vector API is all about improved performance, an
> application developer would
>
> want to know which Operator will be preferred (i.e. backed by an
> appropriate SIMD instruction) on
>
> a targeted platform. Similarly, a library developer would want to be able
> to pick at runtime between
>
> different implementations of an algorithm.
>
>
> That could look like:
>
> boolean VectorOperators.Operator#isPreferredWith(VectorSpecies)
>
> I haven't looked at the implementation details but I assume that it would
> be doable as the Operator
>
> actual implementation is already picked based on CPU instructions
> availability.
>
> Thanks,
> Michaël
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20221018/e75b6a51/attachment-0001.htm>


More information about the panama-dev mailing list