Skip to content

Refactor CUB DeviceFind::{Lower,Upper}BoundSortedValues two-phase… - #11234

Merged
bernhardmgruber merged 7 commits into
NVIDIA:mainfrom
nfcalabria:cub-device-find-env
Nov 18, 2026
Merged

bernhardmgruber merged 7 commits into
NVIDIA:mainfrom
nfcalabria:cub-device-find-env

Conversation

@nfcalabria

@nfcalabria nfcalabria commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

…overloads to accept environments

Description

Fixes: #11703 (Part of #9875)

Refactors the two-phase cub::DeviceFind::LowerBoundSortedValues and cub::DeviceFind::UpperBoundSortedValues overloads to accept an execution environment instead of a cudaStream_t.

Changes

  • Replaces the explicit cudaStream_t argument in the two-phase overloads with the templated argument const EnvT& env.
  • Adds tests covering user-provided temporary storage with the supported environment forms.

Testing

All tests pass locally.

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@nfcalabria
nfcalabria requested a review from a team as a code owner September 6, 2026 23:06
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Sep 6, 2026
@copy-pr-bot

copy-pr-bot Bot commented Sep 6, 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.

@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Sep 6, 2026
@coderabbitai

coderabbitai Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview 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

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Improvements
    • Sorted lower-bound and upper-bound searches now provide clearer compile-time validation for comparison operations.
    • Environment-based execution options remain supported, including CUDA streams, stream references, GPU-specific policies, and default execution.
    • Search operations continue to support caller-provided temporary storage and consistent CUDA error reporting.
  • Tests
    • Expanded coverage for lower- and upper-bound searches across execution environments, tuning options, synchronization, temporary storage, and result validation.

LowerBoundSortedValues and UpperBoundSortedValues now accept execution environments and require strict weak ordering. Their dispatch paths select environment-specific policies. Tests cover environment forms, temporary storage, and block-size tuning.

Changes: Sorted-value execution environments

Layer / File(s) Summary
Update sorted-value API contracts
cub/cub/device/device_find.cuh
Both APIs add EnvT, document the environment parameter, and require cuda::std::strict_weak_order for the range and value iterator element types.
Route searches through environment-aware dispatch
cub/cub/device/device_find.cuh
Both implementations select an environment-based policy and pass it to sorted-value dispatch.
Validate execution environment coverage
cub/test/catch2_test_device_find_bound_sorted_values_env.cu
Tests cover lower-bound and upper-bound searches with automatic and caller-provided temporary storage, configured block sizes, CUDA status, synchronization, and expected results.

Suggested reviewers: bernhardmgruber, miscco

Merge Risk: Minimal · previous review 1e7cb

The sorted-bound APIs now support execution environments with coverage for tuning and temporary storage. No actionable merge-blocking risk remains.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
ℹ️ Recent review info

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 0ab2f74b-4dbc-4619-83da-2978d9947658

📥 Commits

Reviewing files that changed from the base of the PR and between 11d1a15 and 1e7cb58.

📒 Files selected for processing (1)

  • cub/cub/device/device_find.cuh

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

@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 (2)
cub/test/catch2_test_device_find_bound_sorted_values_env.cu (2)

156-156: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Verify the selected stream for each non-default stream environment. cudaDeviceSynchronize() waits for work on all streams. A dispatch that ignores env and uses the default stream still passes these checks. Use the capture-based assertion in cub/test/catch2_test_env_launch_helper.h, or an equivalent stream-specific check.

  • cub/test/catch2_test_device_find_bound_sorted_values_env.cu#L156-L156: add a stream-specific assertion for LowerBoundSortedValues.
  • cub/test/catch2_test_device_find_bound_sorted_values_env.cu#L287-L287: add a stream-specific assertion for UpperBoundSortedValues.

Sources: Coding guidelines, Path instructions


108-111: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Declare read-only test values const. The inputs, expected outputs, and test lambdas are not reassigned. Keep d_output and temporary storage mutable.

  • cub/test/catch2_test_device_find_bound_sorted_values_env.cu#L108-L111: declare d_range, d_values, and expected const.
  • cub/test/catch2_test_device_find_bound_sorted_values_env.cu#L127-L127: declare test_lower_bound_sorted_values const.
  • cub/test/catch2_test_device_find_bound_sorted_values_env.cu#L239-L242: declare d_range, d_values, and expected const.
  • cub/test/catch2_test_device_find_bound_sorted_values_env.cu#L258-L258: declare test_upper_bound_sorted_values const.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f5fe3c04-8393-4793-a494-b5a484f1fa78

📥 Commits

Reviewing files that changed from the base of the PR and between 825d4c2 and e172043.

📒 Files selected for processing (2)
  • cub/cub/device/device_find.cuh
  • cub/test/catch2_test_device_find_bound_sorted_values_env.cu

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

@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 (3)
cub/cub/device/device_find.cuh (1)

865-865: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Declare immutable callback parameters const. policy_selector, storage, and stream are not reassigned before dispatch in either callback. As per coding guidelines, “All variables that are not modified must be declared const.”

Also applies to: 1117-1117

Source: Coding guidelines

cub/test/catch2_test_device_find_bound_sorted_values_env.cu (2)

110-113: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Declare the immutable input fixtures const. d_range, d_values, and expected are not modified in either test. Keep d_output mutable because the algorithm writes through its iterator. As per coding guidelines, “All variables that are not modified must be declared const.”

Also applies to: 243-246

Source: Coding guidelines


158-158: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

suggestion: Synchronize the selected stream. The direct DeviceFind calls pass stream-bearing environments but then call cudaDeviceSynchronize(). A regression that ignores cuda::get_stream and launches on the default stream can still pass. Use a stream-specific completion check or event dependency for each selected stream.

Source: Path instructions


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 32eab430-ab35-4796-93dd-bd8c4184faf6

📥 Commits

Reviewing files that changed from the base of the PR and between e172043 and 52a8861.

📒 Files selected for processing (2)
  • cub/cub/device/device_find.cuh
  • cub/test/catch2_test_device_find_bound_sorted_values_env.cu

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

@miscco

miscco commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

/ok to test 52a8861

@miscco miscco 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.

This looks good. Thanks a lot 🎉

typename OutputIteratorT,
typename CompareOpT>
typename CompareOpT,
typename EnvT = ::cuda::std::execution::env<>>

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 will probably need an additional constraint that verifies that CompareOpT is a suitable binary predicate.
Otherwise there is a high chance of running into ambiguities with the single pass overload

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your comment: I just added a strict weak ordering constraint on CompareOpT for the two-phase overloads.

@miscco miscco 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.

Sorry missclick

@github-project-automation github-project-automation Bot moved this from In Review to In Progress in CCCL Sep 7, 2026

@bernhardmgruber bernhardmgruber 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.

Library changes LGTM, can you please also add a test that a tuning is successfully extracted?

@github-actions

This comment has been minimized.

@nfcalabria

nfcalabria commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Library changes LGTM, can you please also add a test that a tuning is successfully extracted?

Thanks for your comment, I added a tuning extraction test for both the one-phase and the two-phase overloads.

@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 (2)
cub/cub/device/device_find.cuh (1)

845-845: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Use ::cuda::std::strict_weak_order in both constraints. This preserves the required global namespace qualification in the CUB header.

As per path instructions, “qualify ::cuda namespace calls in headers according to CUB style.”

Also applies to: 1099-1099

Source: Path instructions

cub/test/catch2_test_device_find_bound_sorted_values_env.cu (1)

140-140: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Add a comment that explains why these tests require TEST_LAUNCH == 0. State the exact unsupported launch mode or test-harness limitation.

As per coding guidelines, “If a test is unsupported, expected to fail, disabled, or skipped on a platform, motivate it with a comment.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 0cf56eae-861b-44d2-add0-b09b83214c4d

📥 Commits

Reviewing files that changed from the base of the PR and between 52a8861 and 69ebdf0.

📒 Files selected for processing (2)
  • cub/cub/device/device_find.cuh
  • cub/test/catch2_test_device_find_bound_sorted_values_env.cu

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

@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)
cub/test/catch2_test_device_find_bound_sorted_values_env.cu (1)

136-136: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

suggestion: Declare expected as const.

The test does not modify expected. This declaration is also inconsistent with the adjacent lower-bound and user-provided-memory tests.

As per path instructions, “Keep non-modified variables const.”

Source: Path instructions


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 78f0a5a3-2509-416f-aff3-99c4d0ea3813

📥 Commits

Reviewing files that changed from the base of the PR and between 69ebdf0 and 8e164d5.

📒 Files selected for processing (1)
  • cub/test/catch2_test_device_find_bound_sorted_values_env.cu

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

@nfcalabria
nfcalabria force-pushed the cub-device-find-env branch 2 times, most recently from 11d1a15 to 1e7cb58 Compare September 10, 2026 14:37
@bernhardmgruber

Copy link
Copy Markdown
Contributor

@nfcalabria are you still working on this PR?

@nfcalabria

Copy link
Copy Markdown
Contributor Author

@nfcalabria are you still working on this PR?

I implemented the requested modifications and waiting for their review.

Comment thread cub/cub/device/device_find.cuh Resolved
Comment thread cub/cub/device/device_find.cuh Resolved
Comment thread cub/cub/device/device_find.cuh Resolved
Comment thread cub/cub/device/device_find.cuh Resolved
Comment thread cub/cub/device/device_find.cuh Resolved
nfcalabria and others added 4 commits November 18, 2026 12:04
Remove the strict_weak_order constraint, which rejects heterogeneous comparators,
share the dispatch between all overloads through select_tuning_and_dispatch,
and align the tests with the other two-phase environment migrations.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bernhardmgruber

Copy link
Copy Markdown
Contributor

@nfcalabria I had claude apply my suggestions now and rebase.

@github-project-automation github-project-automation Bot moved this from In Progress to In Review in CCCL Nov 18, 2026
@bernhardmgruber

Copy link
Copy Markdown
Contributor

/ok to test 14a48b4

@bernhardmgruber
bernhardmgruber enabled auto-merge (squash) November 18, 2026 16:11
@bernhardmgruber
bernhardmgruber merged commit 272c18a into NVIDIA:main Nov 18, 2026
241 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Nov 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 3h 26m: Pass: 100%/210 | Total: 9d 12h | Max: 3h 26m | Hits: 27%/1068953

See results here.

@bernhardmgruber

Copy link
Copy Markdown
Contributor

@nfcalabria thank you for the contribution!

@nfcalabria

nfcalabria commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

@nfcalabria thank you for the contribution!
@bernhardmgruber Thank you very much for your help!

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

DeviceFind: migrate two-phase overloads to Env

3 participants