Querying for best shape or species

Paul Sandoz paul.sandoz at oracle.com
Fri Nov 17 20:09:21 UTC 2017



> On 17 Nov 2017, at 05:59, Vladimir Ivanov <vladimir.x.ivanov at oracle.com> wrote:
> 
> 
> 
> On 11/17/17 4:35 AM, Paul Sandoz wrote:
>> We need a method on Vector for a given type to either return a shape or species for the maximum shape supported by the hardware e.g.
>> static <E> Vector.Species<E, ?> getOptimalSpecies(Class<E> c)
>> There has gotta be logic we can reuse with the VM and expose via a native method from which we can derive the species e.g. on VectorIntrinsics or Unsafe
>> // Return the maximum register size that can be used to pack, lane-wise, values of type c.
>> int getMaxRegisterSize(Class<?> c)
>> Vladimir, WDYT, is this easy to expose out?
> 
> It's doable, but may be a bit tricky. There are multiple sources of information in the JVM:
>  (1) MaxVectorSize
>  (2) Matcher::max_vector_size(const BasicType bt)
>  (3) Matcher::match_rule_supported_vector(int opcode, int vlen)
> 
> The closest to what you are asking for is (2) [1], but it's somewhat C2-centric: it determines the max vector size with all necessary operations natively supported (e.g., it differentiates AVX & AVX2 w.r.t. integral types), but with some exceptions (e.g. some operations on 256-bit vectors of shorts are supported only in AVX512BW [2], but max_vector_size(T_SHORT) will return 32 on AVX2-capable hardware).
> 
> Does it suit your needs as is?
> 

I think so, as long as we are fuzzy by what “Optimal” or “Best” is, and we can tweak later.


> MaxVectorSize provides the upper bound on max vector size available and match_rule_supported_vector() allows to query individual operation support.
> 
> There's nothing unsafe in querying such info, so VectorIntrinsics (or another place for VM-specific stuff) looks fine.
> 

Right, but it’s so much easier to add a native method to Unsafe than create new JNI boiler plate and compilation targets for VectorIntrinsics :-) but maybe we will need other native methods...

Thanks,
Paul.

> Best regards,
> Vladimir Ivanov
> 
> [1] http://hg.openjdk.java.net/jdk/hs/file/cde4a65ba47d/src/hotspot/cpu/x86/x86.ad#l1342
> 
> [2] http://hg.openjdk.java.net/jdk/hs/file/cde4a65ba47d/src/hotspot/cpu/x86/x86.ad#l1297



More information about the panama-dev mailing list