Skip to content

[CUB] Support stream-aware two-phase launch wrappers - #12379

Merged
oleksandr-pavlyk merged 19 commits into
NVIDIA:mainfrom
oleksandr-pavlyk:launch-helper-and-tests
Nov 10, 2026
Merged

oleksandr-pavlyk merged 19 commits into
NVIDIA:mainfrom
oleksandr-pavlyk:launch-helper-and-tests

Conversation

@oleksandr-pavlyk

@oleksandr-pavlyk oleksandr-pavlyk commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR is a focused part of #11374 that modifies launch helper macros to support passing execution stream as last argument of two-phase API.

Infer trailing stream-like arguments through cuda::get_stream and preserve ordering with test setup across all launch modes:

  • TEST_LAUNCH=0: forward the supplied stream to the host API and synchronize it before returning. Preserve omitted stream arguments.
  • TEST_LAUNCH=1: enqueue the parent kernel on the supplied host stream, preserving ordering with preparation work; invoke the API on the device side default stream; and wait for the parent and its child kernels to complete before returning.
  • TEST_LAUNCH=2: capture on the supplied non-default stream, or a temporary stream when the default stream is requested. Launch the graph on the requested stream and synchronize it before returning.

Use checked C2H buffers for temporary storage and scalar results. Fix the device-side memory resource to return the allocation's starting offset.

Add stream-forwarding and explicit default-stream tests, and update the launch-wrapper usage documentation.

Expand catch2_test_launch_wrapper.cu to test both two-phase and environment-based wrappers using
a shared synthetic CUB-style algorithm. Both interfaces reuse storage sizing, execution and stream validation,
graph-capture checks, and kernel dispatch.

Environment-wrapper tests cover host, device, and graph launches with a non-default stream or no stream property,
plus explicit default streams for host and device launches. They exercise ordinary and templated wrappers,
allocation accounting, and execution across multiple blocks.

Replace device vectors and Thrust-based result verification with checked C2H device buffers and host-side
comparisons. Factor allocation and asynchronous preparation into a shared fixture, centralize result checks,
and restore expected-stream state with a scope guard. Check stream completion before readback so verification does not mask incomplete work.

Checklist

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

Infer trailing stream-like arguments through cuda::get_stream and preserve
ordering with test setup across all launch modes:

- TEST_LAUNCH=0: forward the supplied stream to the host API and synchronize
  it before returning. Preserve omitted stream arguments.
- TEST_LAUNCH=1: synchronize the supplied host stream before launching the
  parent kernel, invoke the API on the device-side default stream, and
  wait for device execution to complete.
- TEST_LAUNCH=2: capture on the supplied non-default stream, or a temporary
  stream when the default stream is requested. Launch the graph on the
  requested stream and synchronize it before returning.

Use checked C2H buffers for temporary storage and scalar results. Fix the
device-side memory resource to return the allocation's starting offset.

Add stream-forwarding and explicit default-stream tests, and update the
launch-wrapper usage documentation.
@oleksandr-pavlyk
oleksandr-pavlyk requested review from a team as code owners November 2, 2026 19:07
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Nov 2, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Nov 2, 2026
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Documentation
    • Updated test-launch guidance for stream selection and ordering across host, device, and graph launches. Clarified environment-based memory resources, allocation sizing, wrapper completion, and input-preparation ordering when an environment does not provide a stream.
  • Tests
    • Expanded coverage of stream and environment forwarding, default-stream behavior, launch ordering, memory allocation, completion, and output validation across wrapper variants. Added checks for stream-capture errors and preparation/completion ordering.

Launch helpers now forward optional stream or environment arguments and coordinate ordinary, device-side, graph, and environment launches. Tests cover stream selection, completion, and output. The memory-resource allocation offset and launch-wrapper guidance are also updated.

Changes: Stream-aware launch behavior

Layer / File(s) Summary
Argument forwarding and stream selection
cub/test/catch2_test_launch_helper.h
Wrapper call operators forward arguments. Dispatch identifies stream or environment arguments and selects a fallback stream when needed.
Ordinary, device, and graph launches
cub/test/catch2_test_launch_helper.h
Launch paths invoke APIs with selected streams and check completion. Graph launches execute and destroy graph handles through a shared helper.
Environment launch ordering and allocation tracking
cub/test/catch2_test_launch_helper.h, cub/test/catch2_test_memory_resources.h
Environment launches use existing or fallback streams and retain allocation tracking. The device-side memory resource returns allocations at the counter’s previous offset.
Stream-aware wrapper validation
cub/test/catch2_test_launch_wrapper.cu, docs/cub/developer/test_overview.rst
Tests cover stream forwarding, launch targets, environment wrappers, completion, and output. The documentation describes stream handling, launch ordering, and allocation requirements.

Possibly related issues

  • NVIDIA/cccl#11613: The documentation adds the expected_allocation_size(...) requirement for device-launch tests.
  • NVIDIA/cccl#9875: The changes add and test environment-aware launch wrapper behavior, including stream handling.

Suggested reviewers: jacobfaib

Change: Feature

Merge Risk: Low · up to 10b50

Custom dual-interface environments may lose properties or fail to compile. The change is mergeable with awareness of this narrow regression.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: NVIDIA/cccl
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 852f506
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: f65d4539-7f4c-4a24-bce7-133cae3dfb5f
Commits

Reviewing files that changed from the base of the PR and between a2bef4a and 10b5013.

Files selected for processing: 1

  • cub/test/catch2_test_launch_helper.h

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

Comment thread docs/cub/developer/test_overview.rst Resolved
@github-actions

This comment has been minimized.

@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_launch_wrapper.cu: 1

279-322: Trivial · Functional Correctness · Quick win

suggestion: Reject default-stream capture in the graph test.

The explicit-default test does not enforce the documented temporary non-default capture stream. Add a focused check that rejects a default stream in the graph-mode API call.

Suggested fix
         const bool skip_check = (TEST_LAUNCH == 2) && expected_host_stream == cudaStream_t{};
+        if (skip_check && stream == cudaStream_t{})
+        {
+          return cudaErrorInvalidResourceHandle;
+        }
         if (!skip_check && stream != expected_host_stream)

Review info
Run configuration
  • Source mode: Auto
  • Repository: NVIDIA/cccl
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 852f506
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: b7a6d4da-84b4-4aaa-975e-c94e3ba1b22d
Commits

Reviewing files that changed from the base of the PR and between e4e7d3c and 4c1b48e.

Files selected for processing: 1
  • docs/cub/developer/test_overview.rst

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

@github-actions

This comment has been minimized.

Comment thread cub/test/catch2_test_launch_helper.h Resolved
1. since capture_stream is always non-default, make_device_buffer
   on it needs no device specified and capture_stream.device()
   can be used in simpler API
2. Use nameless template parameter in launch_impl in Graph Mode,
   as HasStream template parameter is unused there.
3. Improve readability by replacing capture_stream.get() with
   use of `capture_sh` variable populated with capture stream handle
We had a work-around specifically for earlier versions of clang
that do not support CUDA dynamic parallelism. Since we have been
using clang-22 for a while now, removed that work-around
@github-actions

This comment has been minimized.

1. Launch wrappers for DeviceLaunch (TEST_LAUNCH == 1) enqueue
   device_side_api_launcher_kernel using cuda::launch on
   the supplied stream avoiding call to `stream.sync()`;

   Both for two-phase invocation as well as for _ENV single
   phase invocation.

2. Documentation is updated.
… algorithm

Add environment overloads to the synthetic CUB-style algorithm and exercise
their wrappers across host, device, and graph launches.

Share storage sizing, validation, and kernel dispatch between API forms.
Use checked device buffers, common preparation and result-checking helpers,
and scoped stream expectations. Check stream completion before readback.
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

When two-phase launch wrappers are given an environment, the
wrapper would only override stream for device launchers and
for temporary graph captures.

A test is added for property preservation for two-phase launch
wrappers.

Documentation is updated as well
@github-actions

This comment has been minimized.

Comment thread cub/test/catch2_test_launch_helper.h Resolved
Comment thread cub/test/catch2_test_launch_helper.h Resolved
Comment thread docs/cub/developer/test_overview.rst Resolved
Comment thread docs/cub/developer/test_overview.rst Resolved
Comment thread docs/cub/developer/test_overview.rst Resolved
Comment thread docs/cub/developer/test_overview.rst Resolved
Also got rid of cudaStreamCreate single usage by factoring
out make_owning_stream utility and reusing it in launch and
launch_env to create stream as needed.

@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

  • Source mode: Auto
  • Repository: NVIDIA/cccl
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 852f506
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 20dc6178-1288-4e5f-a813-1c831f19b597
Commits

Reviewing files that changed from the base of the PR and between 2bebb86 and 6784178.

Files selected for processing: 2

  • cub/test/catch2_test_launch_helper.h
  • docs/cub/developer/test_overview.rst

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

Comment thread docs/cub/developer/test_overview.rst Resolved
…pers

Add tests that reproduce failure before the fix. Add the fix by making
wrapped API arguments signature part of wrapper's signature with use
of trailing return type. This permits use of is_invocable_v on the
ActionT to distinguish whether wrapped API would accept supplied
arguments `args...` followed by stream handle.

If it does not, we override_stream in the last argument instead of
appending it after `args...` pack.
@github-actions

This comment has been minimized.

Comment thread cub/test/catch2_test_launch_helper.h Resolved
Comment thread cub/test/catch2_test_launch_helper.h Resolved
Comment thread cub/test/catch2_test_launch_helper.h Resolved
Comment thread cub/test/catch2_test_launch_helper.h Resolved
Comment thread cub/test/catch2_test_launch_helper.h Resolved
Comment thread cub/test/catch2_test_launch_wrapper.cu Resolved
Comment thread cub/test/catch2_test_launch_wrapper.cu Resolved
Comment thread cub/test/catch2_test_launch_wrapper.cu Resolved
Comment thread cub/test/catch2_test_launch_wrapper.cu Resolved
Comment thread cub/test/catch2_test_launch_wrapper.cu Resolved

@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

  • Source mode: Auto
  • Repository: NVIDIA/cccl
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 852f506
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: c1a49a6f-3d21-4cce-bb4a-d6ce9b7e0ce2
Commits

Reviewing files that changed from the base of the PR and between 77451a5 and a2bef4a.

Files selected for processing: 3

  • cub/test/catch2_test_launch_helper.h
  • cub/test/catch2_test_launch_wrapper.cu
  • docs/cub/developer/test_overview.rst

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

Comment thread cub/test/catch2_test_launch_helper.h Resolved
@github-actions

This comment has been minimized.

Passing cuda::stream_ref{stream} ended up passing that type to wrapped
API which expected cudaStream_t. With no implicit conversion defined
that broken the build.
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 05m: Pass: 100%/141 | Total: 3d 05h | Max: 1h 39m | Hits: 44%/283269

See results here.

@oleksandr-pavlyk oleksandr-pavlyk changed the title Launch helper and tests [CUB] Support stream-aware launch wrappers Nov 10, 2026
@oleksandr-pavlyk oleksandr-pavlyk changed the title [CUB] Support stream-aware launch wrappers [CUB] Support stream-aware two-phase launch wrappers Nov 10, 2026
@oleksandr-pavlyk
oleksandr-pavlyk merged commit 86b3f6a into NVIDIA:main Nov 10, 2026
166 checks passed
@oleksandr-pavlyk
oleksandr-pavlyk deleted the launch-helper-and-tests branch November 10, 2026 14:21
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Nov 10, 2026
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.

2 participants