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 some possible thread-id overflow calculations #17473

Merged
merged 13 commits into from
Dec 11, 2024

Conversation

davidwendt
Copy link
Contributor

Description

Fixes some possible thread-id calculations or usages that may possibly overflow int32 type or size_type.
Reference #10368

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@davidwendt davidwendt added bug Something isn't working 2 - In Progress Currently a work in progress libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change labels Dec 2, 2024
@davidwendt davidwendt self-assigned this Dec 2, 2024
Copy link

copy-pr-bot bot commented Dec 2, 2024

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@davidwendt
Copy link
Contributor Author

/ok to test

@@ -413,7 +413,7 @@ CUDF_KERNEL void compute_segment_sizes(device_span<column_device_view const> col
size_type max_branch_depth)
{
extern __shared__ row_span thread_branch_stacks[];
int const tid = threadIdx.x + blockIdx.x * blockDim.x;
auto const tid = static_cast<size_type>(cudf::detail::grid_1d::global_thread_id());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Merely for clarity. Prefer the type be size_type rather than int.

thread_index_type const stride = blockDim.x * gridDim.x;
auto const block_size = static_cast<thread_index_type>(blockDim.x);
thread_index_type const start = threadIdx.x + blockIdx.x * block_size;
thread_index_type const stride = block_size * gridDim.x;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is explicit up-casting for multiplication.

@@ -138,7 +138,7 @@ CUDF_KERNEL void compute_row_partition_numbers(row_hasher_t the_hasher,
auto const stride = cudf::detail::grid_1d::grid_stride();

// Initialize local histogram
size_type partition_number = threadIdx.x;
thread_index_type partition_number = threadIdx.x;
while (partition_number < num_partitions) {
shared_partition_sizes[partition_number] = 0;
partition_number += blockDim.x;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If num_partitions is close to max<size_type> then partition_number += blockDim.x could overlfow size_type.

@davidwendt
Copy link
Contributor Author

/ok to test

@davidwendt
Copy link
Contributor Author

/ok to test

@davidwendt
Copy link
Contributor Author

/ok to test

@davidwendt
Copy link
Contributor Author

/ok to test

@davidwendt
Copy link
Contributor Author

/ok to test

@davidwendt davidwendt added 3 - Ready for Review Ready for review by team and removed 2 - In Progress Currently a work in progress labels Dec 6, 2024
@davidwendt davidwendt marked this pull request as ready for review December 9, 2024 18:59
@davidwendt davidwendt requested a review from a team as a code owner December 9, 2024 18:59
@davidwendt davidwendt requested a review from shrshi December 9, 2024 18:59
@davidwendt davidwendt requested a review from vuule December 9, 2024 18:59
Copy link
Contributor

@shrshi shrshi 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 to me!

@davidwendt
Copy link
Contributor Author

/merge

@rapids-bot rapids-bot bot merged commit 63c5a38 into rapidsai:branch-25.02 Dec 11, 2024
105 checks passed
@davidwendt davidwendt deleted the tid-overflow branch December 11, 2024 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review Ready for review by team bug Something isn't working libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants