Repository navigation
Optimize sort-merge join data passes - #23532
Conversation
|
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. |
|
/ok to test 64f4023 |
NVBench comparison (1/2): scalar row comparatorsReference: Coverage: Command: sort_merge_inner_join[0] NVIDIA GH200 480GB
Summary
|
NVBench comparison (2/2): string and nested row comparatorsReference: Coverage: Across both comments, 358 of 378 measured cases are meaningfully faster, 15 are within threshold/noise, and 5 are slower. The five slower cases are nullable, Command: sort_merge_inner_join[0] NVIDIA GH200 480GB
Summary
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe sort-merge join now indexes right-side key runs and uses bulk lower-bound searches to create per-row match ranges. Inner and left joins generate output directly from those ranges in probe-row order. Public APIs no longer require left-side sortedness. ChangesSort-merge join execution
Estimated code review effort: 4 (Complex) | ~60 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (3)
cpp/src/join/sort_merge_join.hpp (1)
220-222: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueClarify the valid extent of the two run vectors.
Both vectors are allocated with the right table row count, but only a prefix is meaningful.
right_run_rowsholdsnum_right_runsvalid entries.right_run_offsetsholdsnum_right_runs + 1valid entries, where the last entry is the row count sentinel. The current descriptions do not state this, so a reader could index either vector bysize(). Extend the///<comments to record the valid extent.As per coding guidelines: "Use doxygen as a documentation generator and linter for C++ and CUDA code."📝 Proposed documentation update
- std::unique_ptr<rmm::device_uvector<size_type>> right_run_rows; ///< First row of each key run - std::unique_ptr<rmm::device_uvector<size_type>> right_run_offsets; ///< Sorted run boundaries + std::unique_ptr<rmm::device_uvector<size_type>> + right_run_rows; ///< First row of each key run; only the first `num_right_runs` entries + ///< are valid + std::unique_ptr<rmm::device_uvector<size_type>> + right_run_offsets; ///< Start position of each run in sorted order; the first + ///< `num_right_runs + 1` entries are valid and the last is the row count🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cpp/src/join/sort_merge_join.hpp` around lines 220 - 222, Update the documentation comments for right_run_rows and right_run_offsets to state their valid extents: right_run_rows contains num_right_runs entries, while right_run_offsets contains num_right_runs + 1 entries including the row-count sentinel. Leave the allocation and num_right_runs declaration unchanged.Source: Coding guidelines
cpp/src/join/sort_merge_join.cu (2)
130-134: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdd doxygen comments for the new file-local types.
right_run_index,build_right_run_index, and the range functors on Lines 190-272 have no doxygen comments. The neighboring functors in the same anonymous namespace (index_mapping,list_nonnull_filter,is_row_valid,is_row_null) all document their purpose and members. Add brief@briefblocks and member descriptions for consistency, in particular for the semantics ofoffsets(run start positions plus a trailingnum_rowssentinel) andnum_runs.As per coding guidelines: "Use doxygen as a documentation generator and linter for C++ and CUDA code."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cpp/src/join/sort_merge_join.cu` around lines 130 - 134, Add brief Doxygen documentation for the file-local symbols right_run_index, build_right_run_index, and the range functors in the indicated anonymous namespace, matching neighboring functor style. Document right_run_index members, explicitly describing offsets as run-start positions with a trailing num_rows sentinel and num_runs as the number of runs, and include `@brief` descriptions of each symbol’s purpose.Source: Coding guidelines
291-293: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider
device_spaninstead of raw pointer plus count.
unique_smaller_rows,smaller_run_offsets, andnum_smaller_runsform a pointer-plus-size pair.device_span<size_type const>carries the size with the data and keeps the run count and the offsets array consistent at the call site.As per coding guidelines: "Prefer span parameters over pointer-plus-size pairs".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cpp/src/join/sort_merge_join.cu` around lines 291 - 293, Replace the raw pointer and count representation for unique_smaller_rows, smaller_run_offsets, and num_smaller_runs with an appropriate device_span<size_type const> parameter or member. Update all construction and call sites to pass the span directly, preserving the existing run count and offsets data consistently.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cpp/src/join/sort_merge_join.cu`:
- Around line 767-770: Document is_left_sorted as ignored in the public
declarations of inner_join, left_join, and inner_join_match_context, using
consistent wording. In cpp/src/join/sort_merge_join.cu lines 767-770, retain the
explanatory comment and define/reuse a named skip_probe_sort constant instead of
passing cudf::sorted::YES; apply that same constant at lines 800-803 and
890-893. Update the corresponding header declarations’ doxygen, with no direct
header changes beyond documenting the parameter’s ignored status.
- Around line 288-314: Reorder the member initializers in the merge constructor
so larger is initialized immediately after smaller, matching the declaration
order before sorted_smaller_order_begin and the remaining members.
- Around line 970-975: Update the DeviceTransform in the preprocessed-left-index
rebasing logic to add null_processed_table_start_idx rather than
left_partition_start_idx, ensuring UNEQUAL nested-null indices map from the
filtered slice to the correct rows. Declare the device lambda’s return type as
size_type, and add coverage for a nonzero partition with nested nulls.
---
Nitpick comments:
In `@cpp/src/join/sort_merge_join.cu`:
- Around line 130-134: Add brief Doxygen documentation for the file-local
symbols right_run_index, build_right_run_index, and the range functors in the
indicated anonymous namespace, matching neighboring functor style. Document
right_run_index members, explicitly describing offsets as run-start positions
with a trailing num_rows sentinel and num_runs as the number of runs, and
include `@brief` descriptions of each symbol’s purpose.
- Around line 291-293: Replace the raw pointer and count representation for
unique_smaller_rows, smaller_run_offsets, and num_smaller_runs with an
appropriate device_span<size_type const> parameter or member. Update all
construction and call sites to pass the span directly, preserving the existing
run count and offsets data consistently.
In `@cpp/src/join/sort_merge_join.hpp`:
- Around line 220-222: Update the documentation comments for right_run_rows and
right_run_offsets to state their valid extents: right_run_rows contains
num_right_runs entries, while right_run_offsets contains num_right_runs + 1
entries including the row-count sentinel. Leave the allocation and
num_right_runs declaration unchanged.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 029281af-489d-42ba-88b9-1645b04f3a04
📒 Files selected for processing (2)
cpp/src/join/sort_merge_join.cucpp/src/join/sort_merge_join.hpp
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
cpp/src/join/sort_merge_join.cu (2)
160-161: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick winAvoid signed overflow when adding sentinel elements.
Each site adds one to a signed
cudf::size_typebefore conversion. A table withINT32_MAXrows overflows before the allocator or span receives the length.
cpp/src/join/sort_merge_join.cu#L160-L161: usestatic_cast<std::size_t>(num_rows) + 1foroffsets.cpp/src/join/sort_merge_join.cu#L380-L382: usestatic_cast<std::size_t>(larger_numrows) + 1formatch_counts.cpp/src/join/sort_merge_join.cu#L769-L770: castnum_right_runsbefore adding the sentinel for the span length.Proposed fix
- auto offsets = std::make_unique<rmm::device_uvector<size_type>>(num_rows + 1, stream, temp_mr); + auto offsets = std::make_unique<rmm::device_uvector<size_type>>( + static_cast<std::size_t>(num_rows) + 1, stream, temp_mr); - cudf::detail::make_zeroed_device_uvector_async<size_type>(larger_numrows + 1, stream, mr); + cudf::detail::make_zeroed_device_uvector_async<size_type>( + static_cast<std::size_t>(larger_numrows) + 1, stream, mr); - right_run_offsets->data(), static_cast<std::size_t>(num_right_runs + 1)}; + right_run_offsets->data(), static_cast<std::size_t>(num_right_runs) + 1};As per coding guidelines,
cudf::size_typeis signed 32-bit and requires correct boundary handling.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cpp/src/join/sort_merge_join.cu` around lines 160 - 161, Prevent signed overflow when adding sentinel elements: in cpp/src/join/sort_merge_join.cu lines 160-161, size offsets with static_cast<std::size_t>(num_rows) + 1; at lines 380-382, use static_cast<std::size_t>(larger_numrows) + 1 for match_counts; and at lines 769-770, cast num_right_runs to std::size_t before adding one for the span length.Source: Coding guidelines
858-902: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy liftPreserve original probe-row order for filtered null rows.
For
null_equality::UNEQUALwith nested nulls, Line 881 copies all valid probe-row results first. Lines 885-898 then append all filtered null rows. If a null row precedes a valid row, the returned index columns no longer follow original probe-row order.Generate
JoinNoMatchentries at each filtered row's original position. Add a regression case with interleaved valid and nested-null probe rows.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cpp/src/join/sort_merge_join.cu` around lines 858 - 902, Update the filtered-null result construction around preprocessed_left_indices so JoinNoMatch entries are placed at each null probe row’s original position rather than appended after valid results. Preserve the original probe-row order in both result index vectors, and add a regression case covering interleaved valid and nested-null probe rows.
🧹 Nitpick comments (1)
cpp/tests/join/join_tests.cpp (1)
1163-1186: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winMake this test distinguish
null_equality::UNEQUAL.The only null left key is row 1, but the partition covers rows 2 and 3 (
[2, 4)). The right table has no null key. Therefore, the expected indices remain unchanged if nested-null comparison is incorrect. Add a matching null key on the right and include row 1 in the partition, or assert the full match-count vector before partitioning.As per coding guidelines:
cpp/**/*_test.{cpp,cu}tests must cover nulls; this test should assert the nested-null result.Suggested test data change
- column_wrapper<int32_t> right_child{{30, 40, 50, 10}}; + column_wrapper<int32_t> right_child{{30, 40, 50, 10, 20}, + {true, true, true, true, false}}; ... - auto partition_context = cudf::join_partition_context{std::move(match_context), 2, 4}; + auto partition_context = cudf::join_partition_context{std::move(match_context), 1, 4};🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cpp/tests/join/join_tests.cpp` around lines 1163 - 1186, Update JoinTest.PartitionedInnerJoinWithNestedNullsUnequal so the test exercises null_equality::UNEQUAL: add a null key to the right nested column and include the left null row in the partition range, then assert that the null rows do not match while preserving the existing non-null matches.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@cpp/src/join/sort_merge_join.cu`:
- Around line 160-161: Prevent signed overflow when adding sentinel elements: in
cpp/src/join/sort_merge_join.cu lines 160-161, size offsets with
static_cast<std::size_t>(num_rows) + 1; at lines 380-382, use
static_cast<std::size_t>(larger_numrows) + 1 for match_counts; and at lines
769-770, cast num_right_runs to std::size_t before adding one for the span
length.
- Around line 858-902: Update the filtered-null result construction around
preprocessed_left_indices so JoinNoMatch entries are placed at each null probe
row’s original position rather than appended after valid results. Preserve the
original probe-row order in both result index vectors, and add a regression case
covering interleaved valid and nested-null probe rows.
---
Nitpick comments:
In `@cpp/tests/join/join_tests.cpp`:
- Around line 1163-1186: Update
JoinTest.PartitionedInnerJoinWithNestedNullsUnequal so the test exercises
null_equality::UNEQUAL: add a null key to the right nested column and include
the left null row in the partition range, then assert that the null rows do not
match while preserving the existing non-null matches.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: a817a048-2504-428b-adcf-fc0098f1658a
📒 Files selected for processing (8)
cpp/benchmarks/join/join_on_int32.cucpp/benchmarks/join/multiplicity_join.cppcpp/benchmarks/join/sort_merge_join.cppcpp/include/cudf/join/sort_merge_join.hppcpp/src/join/sort_merge_join.cucpp/src/join/sort_merge_join.hppcpp/tests/join/join_tests.cppcpp/tests/streams/join_test.cpp
shrshi
left a comment
There was a problem hiding this comment.
Very clever idea! The speedup is remarkable 🚀
|
/merge |
Fixes #5107. This [cuDF PR](NVIDIA/cudf#23985) removed the `-Wno-error=deprecated-declarations` compile flag so all warnings are errors in C++ builds. This PR fixes the deprecation error for inner-join, and adds an overloaded function for the java cudf-spark interface that doesn't have the parameter. That way this doesn't break the cudf-spark build while we change it there, and can come back and delete the extra function here afterwards. [This cuDF PR](NVIDIA/cudf#23532) is the inner-join change. It changes the algorithm such that the probe (left) table no longer needs to be sorted, so this extra parameter is irrelevant. --------- Signed-off-by: Paul Mattione <[email protected]>
…#24202) This PR removes the deprecated `cudf::sort_merge_join::inner_join`, `left_join`, and `inner_join_match_context` overloads that take an ignored `sorted is_left_sorted` parameter. These were deprecated in 26.10 by #23532. Authors: - Yunsong Wang (https://github.com/PointKernel) Approvers: - Bradley Dice (https://github.com/bdice) - Nghia Truong (https://github.com/ttnghia) - Vyas Ramasubramani (https://github.com/vyasr) URL: #24202
Description
This PR reduces sort-merge join data passes by building a compact right-side run index, probing it with one bulk lower-bound operation that emits match starts and counts together, scanning those counts once, and using CUB batched copy to materialize both output index columns. The probe table no longer needs to be sorted.
The right-side run index computes the expensive row-comparator result once as byte flags. A separate flag-only CUB selection kernel consumes those values, keeping the heavy row operator out of the selection kernel and reducing its register usage from 120–255 registers per thread to 48. All new direct CUB calls use the environment-based one-phase APIs.
Checklist