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

8322768: Optimize non-subword vector compress and expand APIs for AVX2 target. #17261

Closed
wants to merge 10 commits into from

Conversation

jatin-bhateja
Copy link
Member

@jatin-bhateja jatin-bhateja commented Jan 4, 2024

Hi,

Patch optimizes non-subword vector compress and expand APIs for x86 AVX2 only targets.
Upcoming E-core Xeons (Sierra Forest) and Hybrid CPUs only support AVX2 instruction set.
These are very frequently used APIs in columnar database filter operation.

Implementation uses a lookup table to record permute indices. Table index is computed using
mask argument of compress/expand operation.

Following are the performance number of JMH micro included with the patch.

System : Intel(R) Xeon(R) Platinum 8480+ (Sapphire Rapids)

Baseline:
Benchmark                                 (size)   Mode  Cnt    Score   Error   Units
ColumnFilterBenchmark.filterDoubleColumn    1024  thrpt    2  142.767          ops/ms
ColumnFilterBenchmark.filterDoubleColumn    2047  thrpt    2   71.436          ops/ms
ColumnFilterBenchmark.filterDoubleColumn    4096  thrpt    2   35.992          ops/ms
ColumnFilterBenchmark.filterFloatColumn     1024  thrpt    2  182.151          ops/ms
ColumnFilterBenchmark.filterFloatColumn     2047  thrpt    2   91.096          ops/ms
ColumnFilterBenchmark.filterFloatColumn     4096  thrpt    2   44.757          ops/ms
ColumnFilterBenchmark.filterIntColumn       1024  thrpt    2  184.099          ops/ms
ColumnFilterBenchmark.filterIntColumn       2047  thrpt    2   91.981          ops/ms
ColumnFilterBenchmark.filterIntColumn       4096  thrpt    2   45.170          ops/ms
ColumnFilterBenchmark.filterLongColumn      1024  thrpt    2  148.017          ops/ms
ColumnFilterBenchmark.filterLongColumn      2047  thrpt    2   73.516          ops/ms
ColumnFilterBenchmark.filterLongColumn      4096  thrpt    2   36.844          ops/ms

Withopt:
Benchmark                                 (size)   Mode  Cnt     Score   Error   Units
ColumnFilterBenchmark.filterDoubleColumn    1024  thrpt    2  2051.707          ops/ms
ColumnFilterBenchmark.filterDoubleColumn    2047  thrpt    2   914.072          ops/ms
ColumnFilterBenchmark.filterDoubleColumn    4096  thrpt    2   489.898          ops/ms
ColumnFilterBenchmark.filterFloatColumn     1024  thrpt    2  5324.195          ops/ms
ColumnFilterBenchmark.filterFloatColumn     2047  thrpt    2  2587.229          ops/ms
ColumnFilterBenchmark.filterFloatColumn     4096  thrpt    2  1278.665          ops/ms
ColumnFilterBenchmark.filterIntColumn       1024  thrpt    2  4149.384          ops/ms
ColumnFilterBenchmark.filterIntColumn       2047  thrpt    2  1791.170          ops/ms
ColumnFilterBenchmark.filterIntColumn       4096  thrpt    2   974.888          ops/ms
ColumnFilterBenchmark.filterLongColumn      1024  thrpt    2  1128.281          ops/ms
ColumnFilterBenchmark.filterLongColumn      2047  thrpt    2   686.334          ops/ms
ColumnFilterBenchmark.filterLongColumn      4096  thrpt    2   337.170          ops/ms

Kindly review and share your feedback.

Best Regards,
Jatin


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-8322768: Optimize non-subword vector compress and expand APIs for AVX2 target. (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/17261/head:pull/17261
$ git checkout pull/17261

Update a local copy of the PR:
$ git checkout pull/17261
$ git pull https://git.openjdk.org/jdk.git pull/17261/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 17261

View PR using the GUI difftool:
$ git pr show -t 17261

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/17261.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 4, 2024

👋 Welcome back jbhateja! 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 Jan 4, 2024
@openjdk
Copy link

openjdk bot commented Jan 4, 2024

@jatin-bhateja The following labels will be automatically applied to this pull request:

  • core-libs
  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added hotspot-compiler hotspot-compiler-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Jan 4, 2024
@mlbridge
Copy link

mlbridge bot commented Jan 4, 2024

Copy link
Contributor

@eme64 eme64 left a comment

Choose a reason for hiding this comment

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

@jatin-bhateja this looks like a great improvement!
I have a few questions and requests below.

FYI, this feels very inspiring. I'm dreaming of a day where we could do this filtering in the auto-vectorizer directly.

Copy link
Contributor

@eme64 eme64 left a comment

Choose a reason for hiding this comment

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

Thanks for the updates!

One more idea: Your AVX2 solution has a lot of cost for converting the mask to a permutation. Might it make sense to split this off into a separate vector-node, so that it can float out of a loop if the mask is invariant?

@jatin-bhateja
Copy link
Member Author

Thanks for the updates!

One more idea: Your AVX2 solution has a lot of cost for converting the mask to a permutation. Might it make sense to split this off into a separate vector-node, so that it can float out of a loop if the mask is invariant?

CompressV / ExpandV only accepts two inputs, vector to be operated on and mask under which operation is performed, permute table based implementation is specific to x86 backend implementation.

@merykitty
Copy link
Member

@jatin-bhateja I think you can expand them in the matcher into several MachNodes that will get scheduled separately.

Copy link
Contributor

@eme64 eme64 left a comment

Choose a reason for hiding this comment

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

Exactly, like @merykitty suggests: you can do a platform-dependent expansion.

@jatin-bhateja
Copy link
Member Author

jatin-bhateja commented Jan 9, 2024

Exactly, like @merykitty suggests: you can do a platform-dependent expansion.

Hi @merykitty , @eme64 , in principle platform specific lowering is a good idea where ever useful, our main concern here is to identify a loop invariant constant mask in matcher patterns and save the cost of re-loading from a permute table index. Existing loop invariant analysis moves invariant masks out of loop and GCM should be able to move expanded load from permute table out of loop.

But this looks very restrictive and will mainly be useful for constant one hot bit mask pattern. A constant mask may have more than one set bits and in such a case we will need to generate multiple loads from permute tables and handle multiple expansion scenarios. I think we can defer that complexity for the time being.

Copy link
Contributor

@eme64 eme64 left a comment

Choose a reason for hiding this comment

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

I think we are almost there! 😊

src/hotspot/cpu/x86/stubGenerator_x86_64.cpp Outdated Show resolved Hide resolved
src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp Outdated Show resolved Hide resolved
src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp Outdated Show resolved Hide resolved
@jatin-bhateja
Copy link
Member Author

jatin-bhateja commented Jan 10, 2024

Following are the performance numbers for existing Vector API JMH micro benchmark over Meteor Lake - Crestmont E-cores.
image

Copy link

@sviswa7 sviswa7 left a comment

Choose a reason for hiding this comment

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

Nice work! The patch looks good to me now.

@openjdk
Copy link

openjdk bot commented Jan 22, 2024

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

8322768: Optimize non-subword vector compress and expand APIs for AVX2 target.

Reviewed-by: epeter, sviswanathan

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 26 new commits pushed to the master branch:

  • 3059c3b: 8324242: Avoid null check for OopHandle::ptr_raw()
  • 929af9e: 8307788: vmTestbase/gc/gctests/LargeObjects/large003/TestDescription.java timed out
  • e7fdac9: 8324280: RISC-V: Incorrect implementation in VM_Version::parse_satp_mode
  • 3d32c46: 6503196: API doc for DecimalFormat::getMaximumIntegerDigits is unclear
  • 2d5cb97: 8324647: Invalid test group of lib-test after JDK-8323515
  • 6212264: 8320692: Null icon returned for .exe without custom icon
  • 32eb529: 8324553: Shenandoah: Move periodic tasks closer to their collaborators
  • c702dca: 8323815: Source launcher should find classes with $ in names
  • c432dc0: 8322149: ConcurrentHashMap smarter presizing for copy constructor and putAll
  • fb822e4: 8324514: ClassLoaderData::print_on should print address of class loader
  • ... and 16 more: https://git.openjdk.org/jdk/compare/5acd37fa9625fd53dd705ba536a8ae6c7e54ed7d...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 Jan 22, 2024
Copy link
Contributor

@eme64 eme64 left a comment

Choose a reason for hiding this comment

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

Looks good, except for one detail ;)

src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@eme64 eme64 left a comment

Choose a reason for hiding this comment

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

Ok, I'll just run the testing again, and then I will approve this :)

@jatin-bhateja
Copy link
Member Author

Hi @eme64 , let us know test results.

Best Regards

Copy link
Contributor

@eme64 eme64 left a comment

Choose a reason for hiding this comment

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

Testing passed, looks good now :)
Nice progress, the code now is simpler and much more understandable!

@jatin-bhateja
Copy link
Member Author

Thanks @eme64 and @sviswa7 for your comments.

@jatin-bhateja
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Jan 25, 2024

Going to push as commit 6d36eb7.
Since your change was applied there have been 27 commits pushed to the master branch:

  • 9d1a6d1: 8323645: Remove unused internal sun.net.www.protocol.jar.URLJarFileCallBack interface
  • 3059c3b: 8324242: Avoid null check for OopHandle::ptr_raw()
  • 929af9e: 8307788: vmTestbase/gc/gctests/LargeObjects/large003/TestDescription.java timed out
  • e7fdac9: 8324280: RISC-V: Incorrect implementation in VM_Version::parse_satp_mode
  • 3d32c46: 6503196: API doc for DecimalFormat::getMaximumIntegerDigits is unclear
  • 2d5cb97: 8324647: Invalid test group of lib-test after JDK-8323515
  • 6212264: 8320692: Null icon returned for .exe without custom icon
  • 32eb529: 8324553: Shenandoah: Move periodic tasks closer to their collaborators
  • c702dca: 8323815: Source launcher should find classes with $ in names
  • c432dc0: 8322149: ConcurrentHashMap smarter presizing for copy constructor and putAll
  • ... and 17 more: https://git.openjdk.org/jdk/compare/5acd37fa9625fd53dd705ba536a8ae6c7e54ed7d...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jan 25, 2024

@jatin-bhateja Pushed as commit 6d36eb7.

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

@jatin-bhateja jatin-bhateja deleted the JDK-8322768 branch August 1, 2024 08:54
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 hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

5 participants