You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[REVIEW] Preserve infinities in compensated sum reductions - #3233
A column with one infinity and 31 ones sums to NaN in raft::stats::sum. The running sum already has the right sign, but the rounding correction computes inf - inf. Adding that correction back turns the result into NaN.
This skips the correction when the partial sum is already nonfinite. Finite partial sums still use the same correction, and a column containing both signs of infinity still produces NaN. The regression test covers both matrix layouts and the short, medium and long reduction paths in float and double.
On a GTX 1660 SUPER, all 82 tests in stats/sum.cu passed. On finite inputs, the largest increase in median time across two timing runs was 2.3%, for a long contiguous FP32 column. That same case measured 3.2% faster in the other run.
No actionable comments were generated in the recent review.
Summary
Summary by CodeRabbit
Bug Fixes
Corrected compensated summation so results involving positive or negative infinity, opposing infinities, and overflow are handled consistently across supported reduction paths.
Preserved accurate sums for unaffected columns when other columns contain non-finite values.
Tests
Added coverage for non-finite column sums across floating-point types, memory layouts, and input sizes.
Reduction kernels now suppress compensation when a partial sum is non-finite. New typed tests check infinity, NaN, and overflow results across data types, layouts, and row counts.
Added sum_correction. For types that support infinity, it returns zero when the sum is non-finite. For other types, it returns the correction unchanged.
Thin, medium, thick, and strided reduction paths use sum_correction when combining sums with compensation.
Non-finite sum tests cpp/tests/stats/sum.cu
Added float and double tests for both layouts and three row counts. The tests check infinity propagation, NaN results, overflow, and an unaffected column.
This change makes column sums with a single infinity return infinity instead of NaN, while opposing infinities still give NaN. Finite results are unchanged, and the author reports a small performance cost. No merge-blocking risk remains.
Security architecture risk: Minimal · up to 89ae6
The change prevents a rounding correction from turning a valid infinite sum into NaN. Finite partial sums still use the same correction, and the fix does not add a new way to invoke the reduction or access data.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: compensated sum reductions in raft::stats::sum now keep infinities instead of producing NaN. It matches the changeset and the linked objectives. It is specific and not…
Description check
The description states the bug (a column with one infinity and ones sums to NaN), the fix (skip the rounding correction when the partial sum is nonfinite), the regression test coverage, and the test a…
Linked Issues check
[#3232] The issue requires that a column with one positive infinity and otherwise ones sum to +inf, one negative infinity sum to -inf, and a column with both signs of infinity sum to NaN, for float an…
Out of Scope Changes check
All changed files relate to the fix. reduction.cuh adds the helper and its required <cuda/std/cmath> and <cuda/std/limits> includes. The two reduction kernels apply the helper at the compensatio…
Full details: Title check
Explanation
The title names the main change: compensated sum reductions in raft::stats::sum now keep infinities instead of producing NaN. It matches the changeset and the linked objectives. It is specific and not vague.
Full details: Description check
Explanation
The description states the bug (a column with one infinity and ones sums to NaN), the fix (skip the rounding correction when the partial sum is nonfinite), the regression test coverage, and the test and timing results. It directly describes the changeset.
Full details: Linked Issues check
Explanation
[#3232] The issue requires that a column with one positive infinity and otherwise ones sum to +inf, one negative infinity sum to -inf, and a column with both signs of infinity sum to NaN, for float and double. The PR adds raft::detail::sum_correction in cpp/include/raft/util/reduction.cuh. It returns the rounding correction only when the running sum is finite, and returns T{0} otherwise. The PR applies this helper in coalesced_reduction-inl.cuh (thin, medium, and thick add-reduction kernels) and in strided_reduction.cuh (stridedSummationKernel grid-reduction atomic add). With one infinity, the running sum stays infinite and the correction is skipped, so the result is +/-inf. With both signs, the running sum becomes NaN, so the result stays NaN. Finite sums keep the existing correction. The added tests in cpp/tests/stats/sum.cu cover float and double, row-major and column-major layouts, and 32, 1024, and 131072 rows, which map to the short, medium, and long paths. No coding requirement remains unmet. The issue's reproduction uses a 32-element float column, which the tests cover.
Full details: Out of Scope Changes check
Explanation
All changed files relate to the fix. reduction.cuh adds the helper and its required <cuda/std/cmath> and <cuda/std/limits> includes. The two reduction kernels apply the helper at the compensation points. The test file adds non-finite sum tests. The copyright line change in reduction.cuh is a minor, administrative edit to the same file. It does not change behavior and is low-risk. One behavior change is not covered by the issue: a finite input set that overflows to infinity now returns inf instead of NaN, because the correction is skipped. The issue does not require this case. The PR summary and test description do mention NaN for overflowing finite values, so the test expectations for that case should be checked against this behavior. This does not make a change out of scope.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Fix failing CI checks
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A column with one infinity and 31 ones sums to NaN in
raft::stats::sum. The running sum already has the right sign, but the rounding correction computesinf - inf. Adding that correction back turns the result into NaN.This skips the correction when the partial sum is already nonfinite. Finite partial sums still use the same correction, and a column containing both signs of infinity still produces NaN. The regression test covers both matrix layouts and the short, medium and long reduction paths in float and double.
On a GTX 1660 SUPER, all 82 tests in
stats/sum.cupassed. On finite inputs, the largest increase in median time across two timing runs was 2.3%, for a long contiguous FP32 column. That same case measured 3.2% faster in the other run.Fixes #3232.