Skip to content

[PSTL] Use env based overload for DeviceFindIf - #9318

Merged
miscco merged 6 commits into
NVIDIA:mainfrom
miscco:pstl_fake_resource
Jun 12, 2026
Merged

miscco merged 6 commits into
NVIDIA:mainfrom
miscco:pstl_fake_resource

Conversation

@miscco

@miscco miscco commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

We want to use env based API to ensure that we take advantage of user provided tunings

@miscco
miscco requested a review from a team as a code owner June 9, 2026 09:43
@miscco
miscco requested a review from gevtushenko June 9, 2026 09:43
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jun 9, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jun 9, 2026
@coderabbitai

coderabbitai Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Review 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

suggestion:

Walkthrough

Convert stream-based CUB dispatches to env-based APIs (const-ref), add dispatch overloads that accept caller-provided temporary storage, route DeviceFind through env dispatch helpers, update PSTL find_if to use choose_offset_t and detail::find::dispatch with policy, and extend tests to exercise sizing and user-provided temp storage across env variants.

Changes

env dispatch & DeviceFind migration

Layer / File(s) Summary
Env dispatch API changes
cub/cub/detail/env_dispatch.cuh
dispatch_with_env and dispatch_with_env_and_tuning now take const EnvT&; new overloads accept void* d_temp_storage, size_t& temp_storage_bytes and perform single-phase calls using stream+tuning resolved from the env.
DeviceFind env-based overloads and implementations
cub/cub/device/device_find.cuh
Introduce EnvT template for tuning overloads, replace cudaStream_t params with const EnvT& env, route FindIf through detail::dispatch_with_env_and_tuning and Lower/UpperBound through detail::dispatch_with_env; dispatch lambdas preserve sizing fast-paths and use env-resolved stream via ::cuda::stream_ref.
PSTL find_if -> detail::find::dispatch
libcudacxx/include/cuda/std/__pstl/cuda/find_if.h
PSTL find_if now uses CUB_NS_QUALIFIER::detail::choose_offset_t for offsets/results, queries temp storage via detail::find::dispatch with the policy/env, invokes cub::DeviceFind::FindIf with storage raw-pointer accessors, and uses __policy in the execution call.
Tests: env and user-temp-storage coverage
cub/test/catch2_test_device_find_env.cu
Add execution/env/stream headers; rewrite tests to exercise both sizing (temp_storage == nullptr) and execution with allocated temp storage across stream, cuda::stream_ref, stdexec::env, and cuda::execution::gpu variants for FindIf/LowerBound/UpperBound.

Possibly related issues

Suggested reviewers

  • gevtushenko
  • shwina

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

@github-actions

This comment has been minimized.

@miscco
miscco force-pushed the pstl_fake_resource branch from 26183bc to d1e6753 Compare June 10, 2026 13:10
@miscco
miscco requested a review from a team as a code owner June 10, 2026 13:10

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 165d6480-fc76-449e-ba17-fb2ac0a8b8da

📥 Commits

Reviewing files that changed from the base of the PR and between 26183bc and d1e6753.

📒 Files selected for processing (4)
  • cub/cub/detail/env_dispatch.cuh
  • cub/cub/device/device_find.cuh
  • cub/test/catch2_test_device_find_env.cu
  • libcudacxx/include/cuda/std/__pstl/cuda/find_if.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • libcudacxx/include/cuda/std/__pstl/cuda/find_if.h

Comment thread cub/test/catch2_test_device_find_env.cu Resolved
Comment thread cub/test/catch2_test_device_find_env.cu Resolved
@miscco
miscco force-pushed the pstl_fake_resource branch from d1e6753 to e512d5e Compare June 10, 2026 13:56

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 44be2432-1b4d-4cf9-9773-e9e5d50a9605

📥 Commits

Reviewing files that changed from the base of the PR and between d1e6753 and e512d5e.

📒 Files selected for processing (4)
  • cub/cub/detail/env_dispatch.cuh
  • cub/cub/device/device_find.cuh
  • cub/test/catch2_test_device_find_env.cu
  • libcudacxx/include/cuda/std/__pstl/cuda/find_if.h
🚧 Files skipped from review as they are similar to previous changes (3)
  • cub/test/catch2_test_device_find_env.cu
  • cub/cub/detail/env_dispatch.cuh
  • cub/cub/device/device_find.cuh

@miscco
miscco force-pushed the pstl_fake_resource branch 2 times, most recently from 88539e2 to 4b10484 Compare June 10, 2026 14:38
@github-actions

This comment has been minimized.

@gonidelis gonidelis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why are we substituting the stream overloads with env overloads? don't we already have existing env overloads at home?

@github-project-automation github-project-automation Bot moved this from In Review to In Progress in CCCL Jun 10, 2026
Comment on lines +118 to +130
template <typename InputIteratorT,
typename OutputIteratorT,
typename ScanOpT,
typename NumItemsT,
typename EnvT = ::cuda::std::execution::env<>>
CUB_RUNTIME_FUNCTION static cudaError_t FindIf(
void* d_temp_storage,
size_t& temp_storage_bytes,
InputIteratorT d_in,
OutputIteratorT d_out,
ScanOpT scan_op,
NumItemsT num_items,
cudaStream_t stream = nullptr)
const EnvT& 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.

Remark: Changing to an environment here would require several new tests to be added, not only about whether various stream types can be passed here, but also whether a tuning passed here would be applied. If we proceed with more such changes across the entire CUB device layer, we would need to write a TON of redundant tests.

I think we should try to move as much logic as possible into the dispatch function, so the device layer becomes so thin that we can reasonably only cover one of the overloads (e.g. the one without temp storage args) with all tests.

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.

The way the refactoring is structured is to just forward to the dispatch layer.

The forward is exactly the same as with the current env overloads, so I am not sure whether we would need any more testing.

My suggestion is be to split the effort in two. There is no reason why we need to block refactoring the top level APIs on the dispatch refactoring, given we only dispatch to the same function anyway.

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.

I will keep your reply in mind and send any resulting bugs your way ;)

@miscco
miscco force-pushed the pstl_fake_resource branch 2 times, most recently from 1acde58 to cf33786 Compare June 11, 2026 06:28

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c3cca406-9b61-49da-be5e-44cbfe674161

📥 Commits

Reviewing files that changed from the base of the PR and between 4b10484 and 1acde58.

📒 Files selected for processing (4)
  • cub/cub/detail/env_dispatch.cuh
  • cub/cub/device/device_find.cuh
  • cub/test/catch2_test_device_find_env.cu
  • libcudacxx/include/cuda/std/__pstl/cuda/find_if.h
🚧 Files skipped from review as they are similar to previous changes (3)
  • cub/test/catch2_test_device_find_env.cu
  • cub/cub/detail/env_dispatch.cuh
  • cub/cub/device/device_find.cuh

@github-actions

This comment has been minimized.

@miscco

miscco commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

why are we substituting the stream overloads with env overloads? don't we already have existing env overloads at home?

We have only those that take care of all the memory management. But we also need the env for those where the user provides memory

@github-actions

This comment has been minimized.

Comment thread cub/cub/detail/env_dispatch.cuh Resolved
Comment thread cub/cub/detail/env_dispatch.cuh Resolved
Comment thread cub/cub/detail/env_dispatch.cuh Resolved
temp_storage_bytes = 1;
return cudaSuccess;
}
return detail::dispatch_with_env(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

again thinking for future developers that will jump on CUB ship, our high level bodies start to look really ugly, no complain for now. just laying this one out in the field

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.

sad but true

Comment thread cub/test/catch2_test_device_find_env.cu Resolved
Comment thread cub/test/catch2_test_device_find_env.cu Resolved
@miscco
miscco force-pushed the pstl_fake_resource branch from 7ee7e13 to 0a5dcbd Compare June 12, 2026 06:59
@github-project-automation github-project-automation Bot moved this from In Progress to In Review in CCCL Jun 12, 2026
@miscco
miscco enabled auto-merge (squash) June 12, 2026 07:43
@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 1h 24m: Pass: 100%/343 | Total: 2d 16h | Max: 1h 08m | Hits: 99%/476366

See results here.

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.

4 participants