Skip to content

Add SUM_OVERFLOW in sort groupby - #22832

Merged
rapids-bot[bot] merged 28 commits into
mainfrom
enable-sum-with-overflow-sort-groupby
Jun 26, 2026
Merged

Add SUM_OVERFLOW in sort groupby#22832
rapids-bot[bot] merged 28 commits into
mainfrom
enable-sum-with-overflow-sort-groupby

Conversation

@PointKernel

@PointKernel PointKernel commented Jun 9, 2026

Copy link
Copy Markdown
Member

Description

Closes #22576

This PR adds support for SUM_OVERFLOW (previously SUM_WITH_OVERFLOW) in the sort-based groupby execution path.

Checklist

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

Wire SUM_WITH_OVERFLOW into the sort groupby path via a new
group_sum_with_overflow that reuses the reduction's overflow-aware sum
operator, promoted to cudf/reduction/detail/sum_with_overflow.cuh.
Previously the sort path threw for any co-requested sort-only
aggregation such as TDIGEST (#22576). Adds sort-path tests across the
supported signed integer and decimal types.
Deduplicate the "signed integral or decimal" predicate, previously
copied across the reduction dispatcher, reduction_function, target_type,
and the new sort groupby, into a single is_sum_with_overflow_supported
helper in cudf/detail/aggregation/aggregation.hpp. The hash device
aggregator keeps its own atomic-support-aware predicate. Also rename the
null-replacement reduction functor to null_replaced_to_sum_overflow to
match the existing null_replaced_value_accessor convention.
Bound both reduce_by_key calls in group_sum_with_overflow by
group_labels.end() instead of values.size(), and trim a redundant
supported-types comment on the target_type specialization.
@PointKernel
PointKernel requested review from a team as code owners June 9, 2026 23:53
@github-actions github-actions Bot added libcudf Affects libcudf (C++/CUDA) code. CMake CMake build issue labels Jun 9, 2026
@PointKernel PointKernel added feature request New feature or request non-breaking Non-breaking change CMake CMake build issue libcudf Affects libcudf (C++/CUDA) code. and removed libcudf Affects libcudf (C++/CUDA) code. CMake CMake build issue labels Jun 9, 2026
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds SUM_OVERFLOW as the overflow-sum kind, keeps SUM_WITH_OVERFLOW as a deprecated alias, wires sort-based groupby support through shared overflow helpers, and updates C++/Java tests.

Changes

Overflow-sum sort-path support

Layer / File(s) Summary
Public overflow-sum contract
cpp/include/cudf/aggregation.hpp, cpp/include/cudf/detail/aggregation/aggregation.hpp, cpp/src/aggregation/aggregation.cpp, cpp/include/cudf/reduction/detail/sum_overflow.cuh
Adds SUM_OVERFLOW, deprecates SUM_WITH_OVERFLOW as an alias, adds make_sum_overflow_aggregation(), centralizes the supported-type constraint, and introduces the overflow accumulator helpers.
Scalar sum-with-overflow dispatch
cpp/src/reductions/reductions.cpp, cpp/src/reductions/sum_with_overflow.cu
Rewrites the scalar reduction specialization constraint to use sum_overflow_supported and switches the null-handling path to null_replaced_to_sum_overflow.
Sort-groupby implementation
cpp/src/groupby/sort/group_reductions.hpp, cpp/src/groupby/sort/group_sum_overflow.cu, cpp/src/groupby/sort/aggregate.cpp, cpp/CMakeLists.txt
Declares and implements group_sum_overflow, routes SUM_WITH_OVERFLOW through sort aggregation, removes the sort-path rejection, and compiles the new CUDA source.
Sort-path tests
cpp/tests/groupby/sum_with_overflow_tests.cpp, java/src/test/java/ai/rapids/cudf/TableTest.java
C++ and Java tests now assert successful sort-based SUM_WITH_OVERFLOW execution, overflow detection, and STRUCT child outputs.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • rapidsai/cudf#22465: Adjusts supported Source constraints for SUM_WITH_OVERFLOW, which is the shared dispatch surface used here.
  • rapidsai/cudf#22696: Modifies cpp/src/reductions/sum_with_overflow.cu, the same scalar reduction implementation file updated here.
  • rapidsai/cudf#22404: Adds Java/JNI plumbing for make_sum_with_overflow_aggregation(), overlapping with the API and Java test surface touched here.

Suggested reviewers

  • pmattione-nvidia
  • mythrocks
  • bdice
  • ttnghia
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR also adds a new SUM_OVERFLOW public API and deprecates SUM_WITH_OVERFLOW, which is broader than fixing sort-groupby support. Move the API rename/deprecation to a separate PR, or document it as part of the issue scope if it is intended to ship together.
Docstring Coverage ⚠️ Warning Docstring coverage is 3.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR satisfies #22576 by removing the sort-path restriction, adding the implementation, and covering the new behavior with tests.
Title check ✅ Passed The title is concise and related to the main change: adding overflow-sum support in sort-based groupby.
Description check ✅ Passed The description clearly matches the changes by stating that sort-based groupby support for SUM_OVERFLOW/SUM_WITH_OVERFLOW is being added.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch enable-sum-with-overflow-sort-groupby

Comment @coderabbitai help to get the list of available commands.

Comment thread cpp/include/cudf/reduction/detail/sum_with_overflow.cuh Outdated
Comment thread cpp/include/cudf/reduction/detail/sum_overflow.cuh
Comment thread cpp/include/cudf/reduction/detail/sum_overflow.cuh
Comment on lines +89 to +92
thrust::reduce_by_key(
rmm::exec_policy_nosync(stream, cudf::get_current_device_resource_ref()),
group_labels.begin(),
group_labels.end(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we combine two reduce_by_key together, using zip_iterator input/output? They are operating on the same keys.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We need to do some benchmark to see how that combination will change performance.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I noticed this also and realized that the sort-based regular SUM follows the same pattern. I originally tried using a single reduce_by_key invocation, but ran into issues that I mistakenly attributed to the single-pass approach. Now that we know the root cause is a bug elsewhere, let me take a quick look and see whether we can apply the same change to the regular SUM path as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Benchmarked + profiled it: fusing the two reduce_by_key into one zip pass is consistently ~1.45x slower.

100M int64 rows, 90% valid, average of 50 iters:

groups two passes fused one pass
1 3.77 ms 5.52 ms
100 3.76 ms 5.51 ms
10K 3.78 ms 5.55 ms
1M 3.65 ms 5.36 ms
10M 3.93 ms 5.42 ms

Root cause is register pressure: carrying tuple<{int64 sum, int32 wraps}, valid> through the CUB scan pushes registers from 71 to 89, which drops occupancy from 37% to 24% and slows the kernel. It's not bandwidth, the fused kernel actually reads fewer bytes. Keeping the two passes.

Comment thread cpp/include/cudf/detail/aggregation/aggregation.hpp

@mhaseeb123 mhaseeb123 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Optional suggestion about using C++ concepts. Looks good otherwise

@PointKernel PointKernel changed the title Enable SUM_WITH_OVERFLOW in sort groupby Add SUM_OVERFLOW in sort groupby Jun 24, 2026
@PointKernel

Copy link
Copy Markdown
Member Author

@ttnghia Can you please take another pass at this? I've made some additional Java changes since it was last approved. Thanks!

@PointKernel

Copy link
Copy Markdown
Member Author

/merge

@rapids-bot
rapids-bot Bot merged commit 8d4ee62 into main Jun 26, 2026
136 checks passed
@PointKernel
PointKernel deleted the enable-sum-with-overflow-sort-groupby branch June 26, 2026 20:30
copy-pr-bot Bot pushed a commit that referenced this pull request Jun 29, 2026
Closes #22576

This PR adds support for `SUM_OVERFLOW` (previously `SUM_WITH_OVERFLOW`) in the sort-based groupby execution path.

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

Approvers:
  - Nghia Truong (https://github.com/ttnghia)
  - Muhammad Haseeb (https://github.com/mhaseeb123)

URL: #22832
rapids-bot Bot pushed a commit that referenced this pull request Jun 30, 2026
…e old APIs (#23014)

Followup of #22832.

This PR completes the migration of the "sum with overflow" aggregation to the `_overflow` naming so it is used consistently, and points the hash groupby and all remaining internal code at the canonical `SUM_OVERFLOW` kind. #22832 added `SUM_OVERFLOW` / `make_sum_overflow_aggregation()` for the sort path and left `SUM_WITH_OVERFLOW` / `make_sum_with_overflow_aggregation()` as deprecated aliases; this PR migrates everything else.

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

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Nghia Truong (https://github.com/ttnghia)

URL: #23014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CMake CMake build issue feature request New feature or request Java Affects Java cuDF API. libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] SUM_WITH_OVERFLOW unusable with sort agg

4 participants