Skip to content

[cuda.compute]: Fix segmented sort selector race - #10024

Merged
NaderAlAwar merged 2 commits into
NVIDIA:mainfrom
NaderAlAwar:fix-segmented-sort-selector-race
Jul 20, 2026
Merged

[cuda.compute]: Fix segmented sort selector race#10024
NaderAlAwar merged 2 commits into
NVIDIA:mainfrom
NaderAlAwar:fix-segmented-sort-selector-race

Conversation

@NaderAlAwar

Copy link
Copy Markdown
Contributor

Description

This separates the race fix found by TSan in #9986 into it's own PR (and removes some redundant std::free calls)

The selector state is now per-call (stack-local), so the build-owned
selector ops carry state=nullptr. Drop the now-dead std::free(op.state)
calls in the destructor, cleanup path, and deserialize error handlers
(free(nullptr) is a harmless no-op but misleads readers into thinking the
build op still owns state), and fix the two comments accordingly. Every
op.code free is preserved.
@NaderAlAwar
NaderAlAwar requested a review from a team as a code owner July 20, 2026 18:25
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jul 20, 2026
@copy-pr-bot

copy-pr-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@NaderAlAwar

Copy link
Copy Markdown
Contributor Author

/ok to test 33c0a35

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved segmented sorting stability and reliability by managing selector operation state independently for each sort execution.
    • Updated serialized segmented-sort operations to restore correctly without retaining unnecessary runtime state.
  • Performance

    • Reduced persistent memory usage associated with compiled selector operations.
    • Simplified cleanup during segmented-sort execution and deserialization.

Walkthrough

Changes

Segmented sort selector state

Layer / File(s) Summary
Selector operation contract
c/parallel/src/segmented_sort.cu
Generated selector operations now return state = nullptr; ownership and compilation wiring no longer manage persistent selector state.
Per-dispatch selector state
c/parallel/src/segmented_sort.cu
Selector functors receive per-call state pointers, while dispatch creates stack-local large and small selector states and passes them into the kernel source.
Serialization and cleanup alignment
c/parallel/src/segmented_sort.cu
Deserialization restores selector operations without state and updates failure and cleanup paths to release only selector code buffers.

Suggested reviewers: oleksandr-pavlyk


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

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
c/parallel/src/segmented_sort.cu (1)

269-320: 🩺 Stability & Availability | 🔵 Trivial

Confirm regression test coverage for the fixed race.

The PR comments note testing was requested for the commit fixing this race. No test changes are included in this file/batch. Given the C API path instructions call for coverage of public C parallel APIs, and this is specifically a concurrency fix (hardest class of bug to regress-test), it's worth confirming a test exercising concurrent cccl_device_segmented_sort builds/dispatches on a shared build result exists (e.g. under a ThreadSanitizer-enabled CI job), per the referenced .agent/skills/cccl-test/SKILL.md guidance for this file type. Happy to help draft such a test if none exists yet.

As per coding guidelines, "When writing, updating, reviewing, or validating tests, follow the applicable guidance in .agent/skills/cccl-test/SKILL.md" and per path instructions, "Focus on ... coverage for public C parallel APIs" for c/**/*.

Also applies to: 904-925

Sources: Coding guidelines, Path instructions


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 91076c03-f3f8-49c8-a1be-ea379b940949

📥 Commits

Reviewing files that changed from the base of the PR and between 73a1a4b and 33c0a35.

📒 Files selected for processing (1)
  • c/parallel/src/segmented_sort.cu

@NaderAlAwar
NaderAlAwar enabled auto-merge (squash) July 20, 2026 19:01
@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 44m: Pass: 100%/20 | Total: 6h 03m | Max: 49m 14s | Hits: 98%/1515

See results here.

@NaderAlAwar
NaderAlAwar merged commit 6190044 into NVIDIA:main Jul 20, 2026
42 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants