Querying for best shape or species

Vladimir Ivanov vladimir.x.ivanov at oracle.com
Fri Nov 17 13:59:37 UTC 2017



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?

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.

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