Skip to content

Reduce segmented sort template instantiations - #23733

Open
vyasr wants to merge 1 commit into
NVIDIA:mainfrom
vyasr:codex/libcudf-next-dup-kernel-reductions
Open

Reduce segmented sort template instantiations#23733
vyasr wants to merge 1 commit into
NVIDIA:mainfrom
vyasr:codex/libcudf-next-dup-kernel-reductions

Conversation

@vyasr

@vyasr vyasr commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Description

Reduce libcudf binary size by co-locating segmented sort and stable segmented sort wrapper definitions in the same translation unit. This avoids compiling the same segmented sort template instantiations through separate non-stable and stable segmented sort TUs.

This PR:

  • moves the stable segmented sort wrapper definitions into segmented_sort.cu alongside the corresponding non-stable wrappers.
  • removes stable_segmented_sort.cu from the libcudf source list.
  • keeps the public behavior unchanged while reducing the linked libcudf.so size.

Refs #23419.

Validation:

  • git diff --check
  • Commit hooks run by git commit -S.
  • A/B size comparison measured inside the CUDA 12.9 cudf devcontainer:
    • base branch (codex/libcudf-size-analysis): 1,071,116,104 bytes
    • this branch (codex/libcudf-next-dup-kernel-reductions): 1,051,837,536 bytes
    • reduction: 19,278,568 bytes (18.39 MiB, 1.80%)
  • Compile-time comparison bypassing sccache/sccache-dist:
    • measured the affected libcudf source object set using Ninja logs with compiler launchers disabled.
    • base affected TUs: 374.784s total (segmented_sort.cu.o 193.079s, stable_segmented_sort.cu.o 181.705s).
    • this branch affected TU: segmented_sort.cu.o 191.793s.
    • reduction: 182.991s (48.83%).
  • Full binary builds used distributed sccache:
    • base: 212 successful distributed compiles, 0 distributed failures.
    • this branch: 10 successful distributed compiles, 0 distributed failures.

Checklist

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

@copy-pr-bot

copy-pr-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

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.

@vyasr
vyasr force-pushed the codex/libcudf-next-dup-kernel-reductions branch from 77d621d to 1817601 Compare August 19, 2026 23:35
@github-actions github-actions Bot added libcudf Affects libcudf (C++/CUDA) code. CMake CMake build issue labels Aug 19, 2026
@vyasr vyasr added 3 - Ready for Review Ready for review by team improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Aug 20, 2026 — with ChatGPT Codex Connector
@vyasr
vyasr marked this pull request as ready for review August 20, 2026 00:07
@vyasr
vyasr requested review from a team as code owners August 20, 2026 00:07
@vyasr
vyasr requested review from bdice and qbacpey August 20, 2026 00:07
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 78ac7b4a-0f75-43a2-bcb6-a20929466b95

📥 Commits

Reviewing files that changed from the base of the PR and between bd37009 and 1817601.

📒 Files selected for processing (3)
  • cpp/CMakeLists.txt
  • cpp/src/sort/segmented_sort.cu
  • cpp/src/sort/stable_segmented_sort.cu
💤 Files with no reviewable changes (2)
  • cpp/CMakeLists.txt
  • cpp/src/sort/stable_segmented_sort.cu

Included review availability: Your plan provides up to 12 included reviews per hour; 10 remain after this review.


📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added stable segmented sorting for determining sorted row order.
    • Added stable segmented sort-by-key operations.
    • Sorting supports ascending and descending order, null placement preferences, CUDA streams, and custom memory resources.
    • Results preserve the relative order of equivalent values, providing deterministic behavior for stable sorting workflows.

Walkthrough

Changes

Stable segmented sort

Layer / File(s) Summary
Stable segmented sort APIs
cpp/src/sort/segmented_sort.cu, cpp/src/sort/stable_segmented_sort.cu, cpp/CMakeLists.txt
Stable segmented sorted-order and sort-by-key implementations now reside in segmented_sort.cu. The former source file was removed from the library source list and deleted.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 18176

The change co-locates existing segmented-sort wrappers to reduce build time and binary size without changing public behavior; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: bdice, qbacpey, wence-

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: reducing duplicate segmented sort template instantiations.
Description check ✅ Passed The description directly explains the translation-unit change, source removal, unchanged behavior, and measured size and compile-time reductions.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@davidwendt

Copy link
Copy Markdown
Contributor

I know these were originally split because the compile time was very large when they were together.

@vyasr

vyasr commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

I know these were originally split because the compile time was very large when they were together.

@davidwendt that's very possible. We've certainly chosen to do redundant compilation work in the past to improve parallelism since it improves end to end times. The approach I'm taking right now is systematically reducing duplicate kernel instantiations, which is a trivial optimization for an agent to do. I suggest that we continue with PRs like this until we've exhausted the improvements for per-TU (i.e. serial) compile time and binary size, then revisit if there are clear TUs that we should split. At that point we can also introduce helper TUs that just compile common shared templates to avoid duplicate instantiations.

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 CMake CMake build issue improvement Improvement / enhancement to an existing function 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