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

Fix overflow bug for >2^32 elements in thrust::shuffle #1074

Merged
merged 2 commits into from
Nov 17, 2023

Conversation

djns99
Copy link
Contributor

@djns99 djns99 commented Nov 9, 2023

Description

closes #1073

This fixes an integer overflow bug caused by an incorrect cast in the thrust::shuffle() Philox implementation. It also optimises the TestFunctionIsBijection() test to not sort large arrays on the host

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@djns99 djns99 requested review from a team as code owners November 9, 2023 03:49
@djns99 djns99 requested review from miscco and alliepiper and removed request for a team November 9, 2023 03:49
Copy link

copy-pr-bot bot commented Nov 9, 2023

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Copy link
Collaborator

@gevtushenko gevtushenko left a comment

Choose a reason for hiding this comment

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

Thank you for fixing this!

@@ -69,7 +69,7 @@ class feistel_bijection {
state[1] = lo & right_side_mask;
}
// Combine the left and right sides together to get result
return static_cast<std::uint64_t>(state[0] << right_side_bits) | static_cast<std::uint64_t>(state[1]);
return (static_cast<std::uint64_t>(state[0]) << right_side_bits) | static_cast<std::uint64_t>(state[1]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

remark: right_side_bits is equal to half of problem size. When problem size exceeds 2^31 elements, we used to shift state out of 32 bits, potentially returning 0 instead of state[0] in high 32 bits of 64 bit value. This change fixes the issue by casting the state to 64-bit value first.

@gevtushenko
Copy link
Collaborator

/ok to test

@gevtushenko
Copy link
Collaborator

/ok to test

@gevtushenko gevtushenko merged commit aeaa3d3 into NVIDIA:main Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[BUG]: thrust::shuffle gives incorrect results for size 2^32
3 participants