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

Use cudf::thread_index_type in cuIO to prevent overflow in row indexing #13910

Merged
merged 18 commits into from
Aug 23, 2023

Conversation

vuule
Copy link
Contributor

@vuule vuule commented Aug 17, 2023

Description

Use wider type for indexing when rows are indexed in pattern

for (auto row = start_row; row < num_rows; row += block_size) {
if (is_within_bounds) ...
}

or

auto t = threadIdx.x;
auto row = block_start + t;
if (is_within_bounds) ...

Overflow can happen when the number of rows is so close to max<size_type> that adding block size pushes the index over the max.

Also sprinkled auto where increased size is not needed.
Also removed a few redundant conditions.

Checklist

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

@vuule vuule added bug Something isn't working cuIO cuIO issue non-breaking Non-breaking change labels Aug 17, 2023
@vuule vuule self-assigned this Aug 17, 2023
@github-actions github-actions bot added the libcudf Affects libcudf (C++/CUDA) code. label Aug 17, 2023
Comment on lines 219 to -220
while (cur_row < end_row) {
auto const is_valid = cur_row < col.size() and col.is_valid(cur_row);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

redundant check with cur_row < end_row

@@ -317,8 +316,8 @@ __global__ void __launch_bounds__(csvparse_block_dim)
auto const raw_csv = data.data();
// thread IDs range per block, so also need the block id.
// this is entry into the field array - tid is an elements within the num_entries array
long const rec_id = threadIdx.x + (blockDim.x * blockIdx.x);
long const rec_id_next = rec_id + 1;
auto const rec_id = cudf::thread_index_type{threadIdx.x} + (blockDim.x * blockIdx.x);
Copy link
Contributor

Choose a reason for hiding this comment

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

Promoting just the threadId.x does not appear to be enough to promote the multiplication
https://godbolt.org/z/coqPKqfWe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved the promotion to the multiplication

@vuule vuule marked this pull request as ready for review August 22, 2023 18:16
@vuule vuule requested a review from a team as a code owner August 22, 2023 18:16
@vuule vuule requested review from harrism and davidwendt August 22, 2023 18:16
cpp/include/cudf/detail/utilities/cuda.cuh Outdated Show resolved Hide resolved
cpp/src/io/orc/dict_enc.cu Outdated Show resolved Hide resolved
Copy link
Member

@harrism harrism 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, just a couple of comments.

cpp/include/cudf/detail/utilities/cuda.cuh Outdated Show resolved Hide resolved
cpp/include/cudf/detail/utilities/cuda.cuh Outdated Show resolved Hide resolved
cpp/include/cudf/detail/utilities/cuda.cuh Outdated Show resolved Hide resolved
cpp/src/io/orc/stripe_data.cu Outdated Show resolved Hide resolved
@vuule vuule requested review from harrism and PointKernel August 22, 2023 23:14
Copy link
Member

@PointKernel PointKernel left a comment

Choose a reason for hiding this comment

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

Looks great!

@vuule
Copy link
Contributor Author

vuule commented Aug 23, 2023

/merge

@rapids-bot rapids-bot bot merged commit 2700111 into rapidsai:branch-23.10 Aug 23, 2023
@vuule vuule deleted the bug-prevent-overflow-tidx branch August 23, 2023 17:52
rapids-bot bot pushed a commit that referenced this pull request Sep 1, 2023
This PR adds `grid_1d::grid_stride()` and uses it in a handful of kernels. Follow-up to #13910, which added a `grid_1d::global_thread_id()`. We'll need to do a later PR that catches any missing instances where this should be used, since there are a large number of PRs in flight touching thread indexing code in various files. See #10368.

Authors:
  - Bradley Dice (https://github.com/bdice)

Approvers:
  - Yunsong Wang (https://github.com/PointKernel)
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #13996
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cuIO cuIO issue libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants