jdk
jdk copied to clipboard
8291118: [vectorapi] Optimize the implementation of lanewise FIRST_NONZERO
Vector API binary op "FIRST_NONZERO" represents the vector operation of "a != 0 ? a : b", which can be implemented with existing APIs like "compare + blend". The current implementation is more complex especially for the floating point type vectors. The main idea is:
1) mask = a.compare(0, ne);
2) b = b.blend(0, mask);
3) result = a | b;
And for the floating point types, it needs the vector reinterpretation between the floating point type and the relative integral type, since the final "OR" operation is only valid for bitwise integral types.
A simpler implementation is:
1) mask = a.compare(0, eq);
2) result = a.blend(b, mask);
This could save the final "OR" operation and the related reinterpretation between FP and integral types.
Here are the performance data of the "FIRST_NONZERO" benchmarks (please see the benchmark details for byte vector from [1]) on ARM NEON system:
Benchmark (size) Mode Cnt Before After Units
ByteMaxVector.FIRST_NONZERO 1024 thrpt 15 12107.422 18385.157 ops/ms
ByteMaxVector.FIRST_NONZEROMasked 1024 thrpt 15 9765.282 14739.775 ops/ms
DoubleMaxVector.FIRST_NONZERO 1024 thrpt 15 1798.545 2331.214 ops/ms
DoubleMaxVector.FIRST_NONZEROMasked 1024 thrpt 15 1211.838 1810.644 ops/ms
FloatMaxVector.FIRST_NONZERO 1024 thrpt 15 3491.924 4377.167 ops/ms
FloatMaxVector.FIRST_NONZEROMasked 1024 thrpt 15 2307.085 3606.576 ops/ms
IntMaxVector.FIRST_NONZERO 1024 thrpt 15 3602.727 5610.258 ops/ms
IntMaxVector.FIRST_NONZEROMasked 1024 thrpt 15 2726.843 4210.741 ops/ms
LongMaxVector.FIRST_NONZERO 1024 thrpt 15 1819.886 2974.655 ops/ms
LongMaxVector.FIRST_NONZEROMasked 1024 thrpt 15 1337.737 2315.094 ops/ms
ShortMaxVector.FIRST_NONZERO 1024 thrpt 15 6603.642 9586.320 ops/ms
ShortMaxVector.FIRST_NONZEROMasked 1024 thrpt 15 5222.006 7991.443 ops/ms
We can also observe the similar improvement on x86 system.
[1] https://github.com/openjdk/panama-vector/blob/vectorIntrinsics/test/micro/org/openjdk/bench/jdk/incubator/vector/operation/ByteMaxVector.java#L266
Progress
- [ ] Change must be properly reviewed (1 review required, with at least 1 Reviewer)
- [x] Change must not contain extraneous whitespace
- [x] Commit message must refer to an issue
Issue
- JDK-8291118: [vectorapi] Optimize the implementation of lanewise FIRST_NONZERO
Reviewers
- Eric Liu (@theRealELiu - Author)
Reviewing
Using git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/9683/head:pull/9683
$ git checkout pull/9683
Update a local copy of the PR:
$ git checkout pull/9683
$ git pull https://git.openjdk.org/jdk pull/9683/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 9683
View PR using the GUI difftool:
$ git pr show -t 9683
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/9683.diff
:wave: Welcome back xgong! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.
@XiaohongGong To determine the appropriate audience for reviewing this pull request, one or more labels corresponding to different subsystems will normally be applied automatically. However, no automatic labelling rule matches the changes in this pull request. In order to have an "RFR" email sent to the correct mailing list, you will need to add one or more applicable labels manually using the /label pull request command.
Applicable Labels
buildclientcompilercore-libshotspothotspot-compilerhotspot-gchotspot-jfrhotspot-runtimei18nide-supportjavadocjdkjmxkullanetniosecurityserviceabilityshenandoah
/label add core-libs
@XiaohongGong
The core-libs label was successfully added.
Hi, could anyone please take a look at this change? Thanks a lot!
Hi @PaulSandoz , could you please take a look at this simple change? Thanks a lot for your time!
Thanks for the review @theRealELiu !
ping again. Could anyone please take a look at this simple patch? Thanks so much for your time!
@XiaohongGong looking... (just back from vacation).
Looks good. Much better to flip the operation and the receiver + first arg to the blend.
Looks good.
Thanks for looking at this patch @PaulSandoz !
Much better to flip the operation and the receiver + first arg to the blend.
I'm not quite understand what the flip operation here mean. The current code is simple enough to me. Could you please show more details? Thanks a lot!
Much better to flip the operation and the receiver + first arg to the blend.
I'm not quite understand what the flip operation here mean. The current code is simple enough to me. Could you please show more details? Thanks a lot!
I mean to say your approach is much better: changing ne to eq and changing the arguments to the blend.
Much better to flip the operation and the receiver + first arg to the blend.
I'm not quite understand what the flip operation here mean. The current code is simple enough to me. Could you please show more details? Thanks a lot!
I mean to say your approach is much better: changing
netoeqand changing the arguments to the blend.
Oh, ok, thanks for the review!
Hi @PaulSandoz , may I get an approve from your side? Thanks so much!
@XiaohongGong This change now passes all automated pre-integration checks.
ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.
After integration, the commit message for the final commit will be:
8291118: [vectorapi] Optimize the implementation of lanewise FIRST_NONZERO
Reviewed-by: eliu, psandoz
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.
At the time when this comment was updated there had been 301 new commits pushed to the master branch:
- 45c3e898ed538545921395372fe507e9111401e1: 8292316: Tests should not rely on specific JAR file names (jpackage)
- db772276848f6ad2d4d13e892bcd0eb3123d030f: 8282684: Obsolete UseContainerCpuShares and PreferContainerQuotaForCPUCount flags
- 256b52387b7267c234f03aac19422e59a77d956f: 8292381: java/net/httpclient/SpecialHeadersTest.java fails with "ERROR: Shutting down connection: HTTP/2 client stopped"
- e561933907bbab0a42f1796fa12f582b3a347312: 8292623: Reduce runtime of java.io microbenchmarks
- dcd78020e4cd064061ac892c566c94fb744859c4: 8292708: Rename G1ParScanThreadState::flush to flush_stats
- 16593cf51c3d994ba4a6d28ab97e519dfd53f37b: 8292717: Clean up checking of testing requirements in configure
- c59f9b374b4497ab385675b0019c3647e6cddbbb: 8287828: Fix so that one can select jtreg test case by ID from make
- 476c484e3778dddf2fb71f83524e691ce262370d: 8292656: G1: Remove G1HotCardCache::_use_cache
- a17fce7507c7d485d51f98fadd444235ea31058d: 6445283: ProgressMonitorInputStream not large file aware (>2GB)
- 1ed03d82b221d6fa54b855070944aec52366c658: 8292226: Prepare make for better Link Time Optimization support
- ... and 291 more: https://git.openjdk.org/jdk/compare/0ca5cb13a38105a4334ac3508a9c7155fc00cac3...master
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.
➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.
Thanks for the review Paul!
/integrate
Going to push as commit 4da1745836550224306ca66201c35a5baaf30953.
Since your change was applied there have been 310 commits pushed to the master branch:
- 38a81913d33c856d64b7c26f934026815a482e43: 8290322: Optimize Vector.rearrange over byte vectors for AVX512BW targets.
- 27af0144ea57e86d9b81c2b328fad66e4a046f61: 8292743: Missing include resourceHash.hpp
- f58aaab4a40f09be03d77a8df8dfefa94e47b320: 8292262: adjust timeouts in several M&M tests
- ab6988599cded028ebfc4c958bc9e88d1b365ad7: 8292215: java/util/stream/boottest/java.base/java/util/stream/SpinedBufferTest.java times out with slowdebug
- 54843b700a463e75cd23a23df8ec5dc73b80f105: 8290211: jdk/internal/vm/Continuation/Fuzz.java failed with "AssertionError: Failed to compile int Fuzz.com_int(int,int) in 5000ms"
- 8a0c3e53d541395ac32d656ac64d20ca0b9a187c: 8292261: adjust timeouts in JLI GetObjectSizeIntrinsicsTest.java
- 8e8ee4b6f22657a7efba8d7998f3c309f334a086: 8292596: Make SymbolHashMap a ResourceHashtable
- aa9b8f04bf74d5fa00f2b27895e7369abea3a930: 8292043: Incorrect decoding near EOF for stateful decoders like UTF-16
- f95ee7960328410551a6948053d1ff0ec3d8c53d: 8292566: Add reference to the java.nio.file package in java.nio package documentation
- 45c3e898ed538545921395372fe507e9111401e1: 8292316: Tests should not rely on specific JAR file names (jpackage)
- ... and 300 more: https://git.openjdk.org/jdk/compare/0ca5cb13a38105a4334ac3508a9c7155fc00cac3...master
Your commit was automatically rebased without conflicts.
@XiaohongGong Pushed as commit 4da1745836550224306ca66201c35a5baaf30953.
:bulb: You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.