RFR: 8353786: Migrate Vector API math library support to FFM API [v5]
Xiaohong Gong
xgong at openjdk.org
Wed Apr 16 02:16:55 UTC 2025
On Fri, 11 Apr 2025 21:23:52 GMT, Vladimir Ivanov <vlivanov at openjdk.org> wrote:
>> Migrate Vector API math library (SVML and SLEEF) linkage from native code (in JVM) to Java FFM API.
>>
>> Since FFM API doesn't support vector calling conventions yet, migration affects only symbol lookup for now. But it still enables significant simplifications on JVM side.
>>
>> The patch consists of the following parts:
>> * on-demand symbol lookup in Java code replaces eager lookup from native code during JVM startup;
>> * 2 new VM intrinsics for vector calls (support unary and binary shapes) (code separated from unary/binary vector operations);
>> * new internal interface to query supported CPU ISA extensions (`jdk.incubator.vector.CPUFeatures`) used for CPU dispatching.
>>
>> `java.lang.foreign` API is used to perform symbol lookup in vector math library, then the address is cached and fed into corresponding JVM intrinsic, so C2 can turn it into a direct vector call in generated code.
>>
>> Once `java.lang.foreign` supports vectors & vector calling conventions, VM intrinsics can go away.
>>
>> Performance is on par with original implementation (tested with microbenchmarks on linux-x64 and macosx-aarch64).
>>
>> Testing: hs-tier1 - hs-tier6, microbenchmarks (on linux-x64 and macosx-aarch64)
>>
>> Thanks!
>
> Vladimir Ivanov has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 19 additional commits since the last revision:
>
> - Merge branch 'master' into vector.math.01.java
> - RVV and SVE adjustments
> - Merge branch 'master' into vector.math.01.java
> - Fix windows-aarch64 build failure
> - features_string -> cpu_info_string
> - Reviews and Float64Vector-related fix
> - Misc fixes and cleanups
> - CPU features support
> - Cleanup
> - TODO list
> - ... and 9 more: https://git.openjdk.org/jdk/compare/d3c46607...0ffed12f
src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorMathLibrary.java line 240:
> 238: if (isAARCH64() && vspecies.vectorBitSize() > 128) {
> 239: return false; // FIXME: SVE support only for MAX shapes
> 240: }
SVE also supports operations for partial vector size, which means the vector size is smaller than MAX size. For example, if the max vector size of a SVE architecture is 512-bit, the FP vector operations with `VectorShape.S_256_BIT` are also supported. They are implemented with the same scalable math functions in SLEEF.
Hence, I think this check and the assertion in line-198 can be removed. Thanks!
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24462#discussion_r2045871389
More information about the hotspot-compiler-dev
mailing list