Querying for best shape or species

Vladimir Ivanov vladimir.x.ivanov at oracle.com
Tue Nov 21 16:45:28 UTC 2017


Here you go:
   http://cr.openjdk.java.net/~vlivanov/panama/vector.max_vec_size/

Sample output:

command: main -XX:UseAVX=2 panama.vector.MaxVectorSize
----------System.out:(8/92)----------
boolean: 32
byte:    32
short:   16
char:    16
int:     8
long:    4
float :  8
double:  4

command: main -XX:UseAVX=1 panama.vector.MaxVectorSize
----------System.out:(8/90)----------
boolean: 16
byte:    16
short:   8
char:    8
int:     4
long:    2
float :  8
double:  4

command: main -XX:UseAVX=0 panama.vector.MaxVectorSize
----------System.out:(8/90)----------
boolean: 16
byte:    16
short:   8
char:    8
int:     4
long:    2
float :  4
double:  2

command: main -XX:UseAVX=0 -XX:UseSSE=2 panama.vector.MaxVectorSize
----------System.out:(8/90)----------
boolean: 16
byte:    16
short:   8
char:    8
int:     4
long:    2
float :  4
double:  2

Best regards,
Vladimir Ivanov

On 11/17/17 11:09 PM, Paul Sandoz wrote:
> 
> 
>> 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