Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8291118: [vectorapi] Optimize the implementation of lanewise FIRST_NONZERO #9683

Closed
wants to merge 1 commit into from

Conversation

XiaohongGong
Copy link

@XiaohongGong XiaohongGong commented Jul 29, 2022

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)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8291118: [vectorapi] Optimize the implementation of lanewise FIRST_NONZERO

Reviewers

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

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 29, 2022

👋 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.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 29, 2022
@openjdk
Copy link

openjdk bot commented Jul 29, 2022

@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
  • build
  • client
  • compiler
  • core-libs
  • hotspot
  • hotspot-compiler
  • hotspot-gc
  • hotspot-jfr
  • hotspot-runtime
  • i18n
  • ide-support
  • javadoc
  • jdk
  • jmx
  • kulla
  • net
  • nio
  • security
  • serviceability
  • shenandoah

@XiaohongGong
Copy link
Author

/label add core-libs

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Jul 29, 2022
@openjdk
Copy link

openjdk bot commented Jul 29, 2022

@XiaohongGong
The core-libs label was successfully added.

@mlbridge
Copy link

mlbridge bot commented Jul 29, 2022

Webrevs

@XiaohongGong
Copy link
Author

Hi, could anyone please take a look at this change? Thanks a lot!

@XiaohongGong
Copy link
Author

Hi @PaulSandoz , could you please take a look at this simple change? Thanks a lot for your time!

Copy link
Member

@e1iu e1iu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@XiaohongGong
Copy link
Author

Thanks for the review @theRealELiu !

@XiaohongGong
Copy link
Author

ping again. Could anyone please take a look at this simple patch? Thanks so much for your time!

@PaulSandoz
Copy link
Member

@XiaohongGong looking... (just back from vacation).

@PaulSandoz
Copy link
Member

Looks good. Much better to flip the operation and the receiver + first arg to the blend.

@XiaohongGong
Copy link
Author

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!

@PaulSandoz
Copy link
Member

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.

@XiaohongGong
Copy link
Author

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.

Oh, ok, thanks for the review!

@XiaohongGong
Copy link
Author

Hi @PaulSandoz , may I get an approve from your side? Thanks so much!

@openjdk
Copy link

openjdk bot commented Aug 22, 2022

@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:

  • 45c3e89: 8292316: Tests should not rely on specific JAR file names (jpackage)
  • db77227: 8282684: Obsolete UseContainerCpuShares and PreferContainerQuotaForCPUCount flags
  • 256b523: 8292381: java/net/httpclient/SpecialHeadersTest.java fails with "ERROR: Shutting down connection: HTTP/2 client stopped"
  • e561933: 8292623: Reduce runtime of java.io microbenchmarks
  • dcd7802: 8292708: Rename G1ParScanThreadState::flush to flush_stats
  • 16593cf: 8292717: Clean up checking of testing requirements in configure
  • c59f9b3: 8287828: Fix so that one can select jtreg test case by ID from make
  • 476c484: 8292656: G1: Remove G1HotCardCache::_use_cache
  • a17fce7: 6445283: ProgressMonitorInputStream not large file aware (>2GB)
  • 1ed03d8: 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.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 22, 2022
@XiaohongGong
Copy link
Author

Thanks for the review Paul!

@XiaohongGong
Copy link
Author

/integrate

@openjdk
Copy link

openjdk bot commented Aug 23, 2022

Going to push as commit 4da1745.
Since your change was applied there have been 310 commits pushed to the master branch:

  • 38a8191: 8290322: Optimize Vector.rearrange over byte vectors for AVX512BW targets.
  • 27af014: 8292743: Missing include resourceHash.hpp
  • f58aaab: 8292262: adjust timeouts in several M&M tests
  • ab69885: 8292215: java/util/stream/boottest/java.base/java/util/stream/SpinedBufferTest.java times out with slowdebug
  • 54843b7: 8290211: jdk/internal/vm/Continuation/Fuzz.java failed with "AssertionError: Failed to compile int Fuzz.com_int(int,int) in 5000ms"
  • 8a0c3e5: 8292261: adjust timeouts in JLI GetObjectSizeIntrinsicsTest.java
  • 8e8ee4b: 8292596: Make SymbolHashMap a ResourceHashtable
  • aa9b8f0: 8292043: Incorrect decoding near EOF for stateful decoders like UTF-16
  • f95ee79: 8292566: Add reference to the java.nio.file package in java.nio package documentation
  • 45c3e89: 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.

@openjdk openjdk bot added the integrated Pull request has been integrated label Aug 23, 2022
@openjdk openjdk bot closed this Aug 23, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Aug 23, 2022
@openjdk
Copy link

openjdk bot commented Aug 23, 2022

@XiaohongGong Pushed as commit 4da1745.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@XiaohongGong XiaohongGong deleted the JDK-8291118 branch September 16, 2022 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants