<div dir="ltr">Hi Eric,<div><br></div><div>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.</div><div><br></div><div>Michaël</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Oct 16, 2022 at 9:16 PM Eric Liu <<a href="mailto:eric.c.liu@arm.com">eric.c.liu@arm.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div class="msg8066975436461169920">





<div lang="EN-US" style="overflow-wrap: break-word;">
<div class="m_8066975436461169920WordSection1">
<p class="MsoNormal"><span style="font-family:"Courier New"">Hi Michaël,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">Thanks for you feedback.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">> it's currently possible to know for a given type which VectorSpecies is preferred<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">> on the current platform.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">I think the preferred species is usually the largest available species.
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">> an application developer would want to know which Operator will be preferred (i.e.
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">> backed by an appropriate SIMD instruction) on a targeted platform. Similarly, a<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">> library developer would want to be able to pick at runtime between different<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">> implementations of an algorithm.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">Usually, the larger species would have better performance since more data could be<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">handled in just one time. That’s true that it’s architecture dependent. Even though<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">some instructions have low throughput in a larger size, a well implemented backend<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">should choose the optimal instructions and should not trouble the Java developers.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">Have you ever found a case that has better performance but with a smaller species on<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">any platform? If there is, perhaps some micro-architecture optimizations should be done.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">- Eric<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<div style="border-style:solid none none;border-top-width:1pt;border-top-color:rgb(225,225,225);padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> panama-dev <<a href="mailto:panama-dev-retn@openjdk.org" target="_blank">panama-dev-retn@openjdk.org</a>> <b>On Behalf Of
</b>Michaël Figuière<br>
<b>Sent:</b> Saturday, October 15, 2022 1:56 AM<br>
<b>To:</b> <a href="mailto:panama-dev@openjdk.org" target="_blank">panama-dev@openjdk.org</a><br>
<b>Subject:</b> [Vector API] Missing a way to know which operators are preferred<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Hello,<br>
<br>
A suggestion based on my small experience with the Vector API: it's currently possible to know for<u></u><u></u></p>
<div>
<p class="MsoNormal">a given type which VectorSpecies is preferred on the current platform, but it's not the case for<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Operator. As the Vector API is all about improved performance, an application developer would<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">want to know which Operator will be preferred (i.e. backed by an appropriate SIMD instruction) on<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">a targeted platform. Similarly, a library developer would want to be able to pick at runtime between<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">different implementations of an algorithm.<u></u><u></u></p>
<div>
<p class="MsoNormal"><br>
That could look like:<br>
<br>
boolean VectorOperators.Operator#isPreferredWith(VectorSpecies)<br>
<br>
I haven't looked at the implementation details but I assume that it would be doable as the Operator<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">actual implementation is already picked based on CPU instructions availability.<br>
<br>
Thanks,<br>
Michaël<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>

</div></blockquote></div>