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

8275821: Optimize random number generators developed in JDK-8248862 using Math.unsignedMultiplyHigh() #6206

Closed
wants to merge 8 commits into from

Conversation

vamsi-parasa
Copy link
Contributor

@vamsi-parasa vamsi-parasa commented Nov 2, 2021

This change optimizes random number generators using Math.unsignedMultiplyHigh()


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8275821: Optimize random number generators developed in JDK-8248862 using Math.unsignedMultiplyHigh()

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/6206/head:pull/6206
$ git checkout pull/6206

Update a local copy of the PR:
$ git checkout pull/6206
$ git pull https://git.openjdk.java.net/jdk pull/6206/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 6206

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/6206.diff

@vamsi-parasa
Copy link
Contributor Author

vamsi-parasa commented Nov 2, 2021

/covered

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 2, 2021

👋 Welcome back vamsi-parasa! 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.

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 2, 2021

You are already a known contributor!

@openjdk
Copy link

openjdk bot commented Nov 2, 2021

@vamsi-parasa The following label will be automatically applied to this pull request:

  • core-libs

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

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Nov 2, 2021
@vamsi-parasa vamsi-parasa marked this pull request as ready for review Nov 2, 2021
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 2, 2021
@mlbridge
Copy link

mlbridge bot commented Nov 2, 2021

Webrevs

@openjdk openjdk bot removed the rfr Pull request is ready for review label Nov 5, 2021
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 5, 2021
@vamsi-parasa
Copy link
Contributor Author

vamsi-parasa commented Dec 2, 2021

The following speedups were observed for the JMH benchmarks. L128X128MixRandom shows 8% improvement, L128x256MixRandom shows 6% improvement and L128X1024MixRandom shows 14% improvement. (Another micro workload shows 10% improvement for both L128X128MixRandom and L128x256MixRandom while L128X1024MixRandom shows 25% improvement in performance.)

@vamsi-parasa
Copy link
Contributor Author

vamsi-parasa commented Dec 2, 2021

@JimLaskey Could you please review this PR which optimizes three of the Pseudo-Random Number Generators you implemented in https://bugs.openjdk.java.net/browse/JDK-8248862 ?

@sviswa7
Copy link

sviswa7 commented Dec 2, 2021

@PaulSandoz Could you please also review this small PR.

Copy link
Member

@PaulSandoz PaulSandoz left a comment

Looks good. Some comments on the benchmark.

rngL128X128MixRandom = RandomGeneratorFactory.of("L128X128MixRandom").create(42);
rngL128X256MixRandom = RandomGeneratorFactory.of("L128X256MixRandom").create(174);
rngL128X1024MixRandom = RandomGeneratorFactory.of("L128X1024MixRandom").create(308);
Copy link
Member

@PaulSandoz PaulSandoz Dec 2, 2021

Choose a reason for hiding this comment

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

You can declare parameters:

@Param({"L128X128MixRandom", "L128X256MixRandom", "L128X1024MixRandom"})
String randomGeneratorName;

@Param("1024")
int size;

long[] buffer;
RandomGenerator randomGenerator;


@Setup
public void setup() {
    buffer = new long[size];
    randomGenerator = RandomGeneratorFactory.of(randomGeneratorName)
        .create(randomGeneratorName.hashCode());
}

Then you can simplify to just two benchmark methods. Further, the benchmark can be used for other PRNGs.

Copy link
Contributor Author

@vamsi-parasa vamsi-parasa Dec 2, 2021

Choose a reason for hiding this comment

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

Thank you Paul! Will make the necessary changes and update the benchmark...

Copy link
Contributor Author

@vamsi-parasa vamsi-parasa Dec 3, 2021

Choose a reason for hiding this comment

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

@PaulSandoz Implemented the changes you suggested for the benchmark. Tested it on my side and ensured that it's working as expected...

Copy link
Member

@PaulSandoz PaulSandoz left a comment

Very nice, much neater, just a few more minor comments.

@State(Scope.Thread)
public class RandomGeneratorNext {

public RandomGenerator randomGenerator;
Copy link
Member

@PaulSandoz PaulSandoz Dec 3, 2021

Choose a reason for hiding this comment

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

Suggested change
public RandomGenerator randomGenerator;
RandomGenerator randomGenerator;

Copy link
Contributor Author

@vamsi-parasa vamsi-parasa Dec 3, 2021

Choose a reason for hiding this comment

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

Incorporated your suggestion in the recent commit...

@Param({"L128X128MixRandom", "L128X256MixRandom", "L128X1024MixRandom"})
String randomGeneratorName;

public static long[] buffer;
Copy link
Member

@PaulSandoz PaulSandoz Dec 3, 2021

Choose a reason for hiding this comment

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

Suggested change
public static long[] buffer;
long[] buffer;

Copy link
Contributor Author

@vamsi-parasa vamsi-parasa Dec 3, 2021

Choose a reason for hiding this comment

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

Incorporated your suggestion in the recent commit...


@Benchmark
@Fork(1)
public void testFillBufferWithNextLong() {
Copy link
Member

@PaulSandoz PaulSandoz Dec 3, 2021

Choose a reason for hiding this comment

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

Return buffer after the loop completes, just in case the JIT decides it is otherwise dead code

Copy link
Contributor Author

@vamsi-parasa vamsi-parasa Dec 3, 2021

Choose a reason for hiding this comment

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

Added the code to return buffer at the end of the loop...

}

@Benchmark
@Fork(1)
Copy link
Member

@PaulSandoz PaulSandoz Dec 3, 2021

Choose a reason for hiding this comment

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

Why is @Fork need here?

Copy link
Contributor Author

@vamsi-parasa vamsi-parasa Dec 3, 2021

Choose a reason for hiding this comment

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

Removed the @fork annotation...

@openjdk
Copy link

openjdk bot commented Dec 3, 2021

⚠️ @vamsi-parasa the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout rand_umulhigh
$ git commit -c user.name='Preferred Full Name' --allow-empty -m 'Update full name'
$ git push

@openjdk
Copy link

openjdk bot commented Dec 3, 2021

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

8275821: Optimize random number generators developed in JDK-8248862 using Math.unsignedMultiplyHigh()

Reviewed-by: psandoz, jlaskey

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

  • 678ac58: 8278240: ProblemList containers/docker/TestJcmd.java on linux-aarch64
  • 01cb2b9: 8277529: SIGSEGV in C2 CompilerThread Node::rematerialize() compiling Packet::readUnsignedTrint
  • 660f21a: 8278119: ProblemList few headful test failing in macosx12-aarch64 system
  • 2e30fa9: 8278171: [vectorapi] Mask incorrectly computed for zero extending cast
  • fbf096e: 8251400: Fix incorrect addition of library to test in JDK-8237858
  • 0a09092: 8268288: jdk/jfr/api/consumer/streaming/TestOutOfProcessMigration.java fails with "Error: ShouldNotReachHere()"
  • 0d938ce: 8278172: java/nio/channels/FileChannel/BlockDeviceSize.java should only run on Linux
  • 0e7b6bc: 8278141: LIR_OpLoadKlass::_info shadows the field of the same name from LIR_Op
  • 53a4342: 8278137: JFR: PrettyWriter uses incorrect year specifier
  • f723779: 8278079: C2: expand_dtrace_alloc_probe doesn't take effect in macro.cpp
  • ... and 448 more: https://git.openjdk.java.net/jdk/compare/2eafa036c03d3e8f3dba8f67dd37b484874dc3d3...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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@PaulSandoz, @JimLaskey) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 3, 2021
Copy link
Member

@JimLaskey JimLaskey left a comment

LGTM

@PaulSandoz
Copy link
Member

PaulSandoz commented Dec 3, 2021

@vamsi-parasa you can now integrate this and then I or someone else will sponsor it

@vamsi-parasa
Copy link
Contributor Author

vamsi-parasa commented Dec 3, 2021

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Dec 3, 2021
@openjdk
Copy link

openjdk bot commented Dec 3, 2021

@vamsi-parasa
Your change (at version cf68fe0) is now ready to be sponsored by a Committer.

@vamsi-parasa
Copy link
Contributor Author

vamsi-parasa commented Dec 3, 2021

Thank you @PaulSandoz and @JimLaskey for reviewing the PR!

@sviswa7
Copy link

sviswa7 commented Dec 3, 2021

/sponsor

@openjdk
Copy link

openjdk bot commented Dec 3, 2021

Going to push as commit 38f525e.
Since your change was applied there have been 459 commits pushed to the master branch:

  • 780b8b1: 8278179: Enable all doclint warnings for build of java.naming
  • 678ac58: 8278240: ProblemList containers/docker/TestJcmd.java on linux-aarch64
  • 01cb2b9: 8277529: SIGSEGV in C2 CompilerThread Node::rematerialize() compiling Packet::readUnsignedTrint
  • 660f21a: 8278119: ProblemList few headful test failing in macosx12-aarch64 system
  • 2e30fa9: 8278171: [vectorapi] Mask incorrectly computed for zero extending cast
  • fbf096e: 8251400: Fix incorrect addition of library to test in JDK-8237858
  • 0a09092: 8268288: jdk/jfr/api/consumer/streaming/TestOutOfProcessMigration.java fails with "Error: ShouldNotReachHere()"
  • 0d938ce: 8278172: java/nio/channels/FileChannel/BlockDeviceSize.java should only run on Linux
  • 0e7b6bc: 8278141: LIR_OpLoadKlass::_info shadows the field of the same name from LIR_Op
  • 53a4342: 8278137: JFR: PrettyWriter uses incorrect year specifier
  • ... and 449 more: https://git.openjdk.java.net/jdk/compare/2eafa036c03d3e8f3dba8f67dd37b484874dc3d3...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Dec 3, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Dec 3, 2021
@openjdk
Copy link

openjdk bot commented Dec 3, 2021

@sviswa7 @vamsi-parasa Pushed as commit 38f525e.

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

@vamsi-parasa vamsi-parasa deleted the rand_umulhigh branch Dec 3, 2021
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
4 participants