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

Gui Cao gcao at openjdk.org
Mon Aug 21 02:08:45 UTC 2023


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 rvv vector length is set 256 bit):


zifeihan at plct-c8:~/jdk-rvv/build/linux-riscv64-server-fastdebug/jdk/bin$ ./java -XX:MaxVectorSize=16 -XX:+UnlockExperimentalVMOptions -XX:+UseRVV --add-exports java.base/jdk.internal.vm.vector=ALL-UNNAMED  GetMaxVectorSizeTest
maxLaneCount:32



AArch64 without the -XX:MaxVectorSize=16 has the following execution results(aarch64 sve vector length is set 256 bit):

zifeihan at d915263bc793:~/jdk/build/linux-aarch64-server-fastdebug/jdk/bin$ ./java --add-exports java.base/jdk.internal.vm.vector=ALL-UNNAMED  GetMaxVectorSizeTest
maxLaneCount:32


AArch64 using the -XX:MaxVectorSize=16 results in the following(aarch64 sve vector length is set 256 bit):

zifeihan at d915263bc793:~/jdk/build/linux-aarch64-server-fastdebug/jdk/bin$ ./java  -XX:MaxVectorSize=16  --add-exports java.base/jdk.internal.vm.vector=ALL-UNNAMED  GetMaxVectorSizeTest
maxLaneCount:16


X86 without the -XX:MaxVectorSize=16 has the following execution results(x86 avx512, vector length is set 512 bit):


zifeihan at plct-c8:~/jdk/build/linux-riscv64-server-fastdebug/jdk/bin$ java --add-exports java.base/jdk.internal.vm.vector=ALL-UNNAMED  GetMaxVectorSizeTest
maxLaneCount:64


X86 using the -XX:MaxVectorSize=16 results in the following(x86 avx512, vector length is set 512 bit):


zifeihan at plct-c8:~/jdk/build/linux-riscv64-server-fastdebug/jdk/bin$ java  -XX:MaxVectorSize=16  --add-exports java.base/jdk.internal.vm.vector=ALL-UNNAMED  GetMaxVectorSizeTest
maxLaneCount:16

Testing:
qemu with UseRVV:

- [x] Tier1 tests (release)
- [ ] Tier2 tests (release)
- [ ] Tier3 tests (release)
- [x] test/jdk/jdk/incubator/vector (fastdebug)

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

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

Changes: https://git.openjdk.org/jdk/pull/15356/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=15356&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8314618
  Stats: 4 lines in 2 files changed: 1 ins; 1 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/15356.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/15356/head:pull/15356

PR: https://git.openjdk.org/jdk/pull/15356


More information about the hotspot-dev mailing list