RFR: 8314618: RISC-V: -XX:MaxVectorSize does not work as expected

Gui Cao gcao at openjdk.org
Tue Aug 22 02:47:37 UTC 2023


On Mon, 21 Aug 2023 02:29:10 GMT, Fei Yang <fyang at openjdk.org> wrote:

>> Hi all,  we found that when the specified -XX:MaxVectorSize=16 no bigger than the detected _initial_vector_length=32, it causes the MaxVectorSize to be set incorrectly. 
>> 
>> MaxVectorSize is updated in src/hotspot/cpu/riscv/vm_version_riscv.cpp#VM_Version::c2_initialize().
>> 
>> 
>>   if (UseRVV) {
>>     if (FLAG_IS_DEFAULT(MaxVectorSize)) {
>>       MaxVectorSize = _initial_vector_length;
>>     } else if (MaxVectorSize < 16) {
>>       warning("RVV does not support vector length less than 16 bytes. Disabling RVV.");
>>       UseRVV = false;
>>     } else if (is_power_of_2(MaxVectorSize)) {
>>       if (MaxVectorSize > _initial_vector_length) {
>>         warning("Current system only supports max RVV vector length %d. Set MaxVectorSize to %d",
>>                 _initial_vector_length, _initial_vector_length);
>>       }
>>       MaxVectorSize = _initial_vector_length;
>>     } else {
>>       vm_exit_during_initialization(err_msg("Unsupported MaxVectorSize: %d", (int)MaxVectorSize));
>>     }
>>   }
>> 
>> 
>> It's that RISC-V only supports max-width vectorization at first, so it's unconditionally set to hardware max-width here. However, after https://github.com/openjdk/jdk/commit/43c71ddf923d442499449948f4bf8a7c79249af0, vectors with small widths are supported, so here it needs to be adjusted accordingly. The correct should be If MaxVectorSize is less than _initial_vector_length, then MaxVectorSize should be used as the final value.
>> 
>> This issue affects C2 autovectorization and some specific Vector API interfaces such as VectorSupport.getMaxLaneCount.
>> 
>> We can verify the problem using the following test case:
>> 
>> 
>> import jdk.internal.vm.vector.VectorSupport;
>> 
>> public class GetMaxVectorSizeTest {
>>     public static void main(String[] args) {
>>         final int maxLaneCount = VectorSupport.getMaxLaneCount(byte.class);
>>         System.out.println("maxLaneCount:" + maxLaneCount);
>>     }
>> }
>> 
>> 
>> The compile command is as follows:
>> 
>> 
>> javac --add-exports java.base/jdk.internal.vm.vector=ALL-UNNAMED GetMaxVectorSizeTest.java
>> 
>> 
>> RISC-V without the -XX:MaxVectorSize=16 has the following execution results(risc-v rvv vector length is set 256 bit):
>> 
>> zifeihan at plct-c8:~/jdk-rvv/build/linux-riscv64-server-fastdebug/jdk/bin$ ./java -XX:+UnlockExperimentalVMOptions -XX:+UseRVV --add-exports java.base/jdk.internal.vm.vector=ALL-UNNAMED  GetMaxVectorSizeTest
>> maxLaneCount:32
>> 
>> 
>> RISC-V using the -XX:MaxVectorSize=16 results in the following(risc-v rv...
>
> Looks reasonable.

@RealFYang @DingliZhang Thanks for the review.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/15356#issuecomment-1687332499


More information about the hotspot-dev mailing list