Skip to content

Unpack launch()'s kernel arguments with cuda::std::apply - #10796

Merged
andralex merged 3 commits into
mainfrom
work/stf-launch-kernel-cuda-tuple
Aug 13, 2026
Merged

andralex merged 3 commits into
mainfrom
work/stf-launch-kernel-cuda-tuple

Conversation

@andralex

Copy link
Copy Markdown
Contributor

Second step toward building STF with clang-cuda, so that bugprone-exception-escape can eventually run over STF (ci/build_tidy.sh still sets -Dcudax_ENABLE_CUDASTF=OFF). Follows #10793, which fixed portability slips in the tests; this one is in the library.

launch_kernel took a std::tuple by value and unpacked it with std::apply. libstdc++ declares std::apply host-only, so device code has no business calling it. nvcc lets it pass because --expt-relaxed-constexpr admits host constexpr functions in device code; clang-cuda has no such escape hatch and rejects every ctx.launch in the tree.

The kernel now receives a cuda::std::tuple and unpacks it with cuda::std::apply. A small reserved::__make_kernel_args helper builds it at the two launch sites (launch_impl and graph_launch_impl) and is named by the two occupancy queries, so the instantiation whose occupancy is queried stays the one that gets launched. data2inst keeps producing a std::tuple: the helper is precisely the boundary where host plumbing turns into a kernel argument, so nothing else has to change.

Validation

A clang-cuda -fsyntax-only sweep (clang 21, CTK 12, sm_75) over all 283 STF tests and examples goes from 50 failures to 33, with no regressions. The 17 that flip are every ctx.launch user plus the standalone reserved::launch, across both the stream and graph backends.

nvcc 13.2 still compiles the launch path (C++17, sm_90), and four representative tests covering launch_impl and graph_launch_impl build and run correctly on an RTX 3070: 01-axpy-launch, launch_sum, standalone-launches, and graph/many. pre-commit passes.

What the remaining 33 are

Only five still need real work, so this is close to the end of the road for the source fixes:

  • 8 are fixed by #10793 (missing <unistd.h>, unqualified min).
  • 9 are artifacts of my local toolkit, which has no cuBLAS, cuSOLVER, or NVTX headers.
  • 6 exercise algorithm.cuh, whose include in stf.cuh is commented out, so they do not compile with nvcc either.
  • 5 are the static_error_checks xfail tests, which are supposed to fail to compile. Two of them fail on the wrong diagnostic under clang (a deleted copy constructor rather than the expected static_assert), which the xfail regex would need to accommodate.
  • 5 are genuine: launch_scan.cu reaches core.cuh's tuple_prepend from device code through thread_hierarchy::apply_partition, which needs the same treatment as this PR one level down; parallel_for_2D.cu, parallel_for_host.cu, and test2_parallel_for_context.cu call a host operator() from host-device code; and frozen_data_init.cu does the same with operator->*.

launch_kernel received a std::tuple and unpacked it with std::apply, which
libstdc++ declares host-only. nvcc lets that slide because
--expt-relaxed-constexpr admits host constexpr functions in device code;
clang-cuda has no such escape hatch and rejects every launch() in the tree.

Hand the kernel a cuda::std::tuple instead, built by a small helper at the two
launch sites and named by the two occupancy queries, so the type the kernel is
instantiated with still matches the one launched. data2inst keeps building a
std::tuple: the helper is the boundary where host plumbing becomes a kernel
argument.
@andralex
andralex requested a review from a team as a code owner August 13, 2026 19:54
@andralex
andralex requested a review from caugonnet August 13, 2026 19:54
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Aug 13, 2026
@copy-pr-bot

copy-pr-bot Bot commented Aug 13, 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.

@andralex

Copy link
Copy Markdown
Contributor Author

/ok to test 9e1f736

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

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Refactor
    • Updated CUDA kernel argument handling for improved compatibility with CUDA’s standard tuple utilities.
    • Standardized kernel argument unpacking and thread-hierarchy handling across launch paths.

Walkthrough

Changes

Kernel argument migration

Layer / File(s) Summary
Tuple helper and kernel unpacking
cudax/include/cuda/experimental/__stf/internal/launch.cuh
suggestion: The launch header adds CUDA tuple utilities, introduces reserved::__make_kernel_args, and changes kernel argument unpacking to cuda::std::apply.
Launch path integration
cudax/include/cuda/experimental/__stf/internal/launch.cuh
suggestion: Direct launches, graph launches, and argument-type deduction now use __make_kernel_args instead of tuple_prepend.

Suggested reviewers: caugonnet

Mergeability Score: 🔵 Low · up to 9e1f7

The change is localized and well validated, but merge should include owner follow-up to mark the host-only tuple helper explicitly and add its direct standard-library header dependencies.


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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
cudax/include/cuda/experimental/__stf/internal/launch.cuh (1)

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

suggestion: Add direct host tuple headers.

__make_kernel_args now names ::std::tuple, ::std::apply, and ::std::forward, but these lines add only the cuda::std tuple headers. Add direct <tuple> and <utility> includes so launch.cuh does not depend on transitive STF includes.

As per coding guidelines, “Include all headers needed by the symbols being used; do not rely on transitive includes.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 93120744-4813-43cc-ada6-2bc7f47c52e3

📥 Commits

Reviewing files that changed from the base of the PR and between 43b7e4d and 9e1f736.

📒 Files selected for processing (1)
  • cudax/include/cuda/experimental/__stf/internal/launch.cuh

@caugonnet caugonnet added the stf Sequential Task Flow programming model label Aug 13, 2026
@andralex
andralex enabled auto-merge (squash) August 13, 2026 20:30
@andralex

Copy link
Copy Markdown
Contributor Author

/ok to test b1f55be

@github-actions

This comment has been minimized.

@andralex

Copy link
Copy Markdown
Contributor Author

/ok to test 7f9f534

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

⏱️ CCCL compile-time benchmark comparison: Public headers compile-time bench

Result: 0 regression row(s), 2 improvement row(s) above threshold.

Run Value
Config public-headers-gcc13
Baseline origin/main
Preset all-dev
Targets cub.headers.base, thrust.cpp.cuda.headers.base, libcudacxx.test.public_headers
GPU / launch args rtx2080 / --cuda 13.3 --host gcc13

Artifacts: reports and traces

Direct file processing

-f file-processing exclusive --sort total

🟢 Direct file processing — Improvements
Rank Improvement impact Selected Δ Baseline Current Event Matched traces
1 0.639133 -0.639133 5.389950 4.750817 Processing Header File: libcudacxx/include/cuda/std/__cccl/prologue.h 552
2 0.205083 -0.205083 1.657974 1.452891 Processing Header File: libcudacxx/include/cuda/std/__cccl/epilogue.h 552

@github-actions

github-actions Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 1h 42m: Pass: 100%/63 | Total: 10h 01m | Max: 1h 01m | Hits: 98%/37556

See results here.

AI failure analysis

1. CUDA 13.3 rejects RAFT kernel argument address conversion · 1 job

Explanation: While compiling cuML, NVCC rejects RAFT's conversion of kernel-parameter addresses to `void*` in `raft::detail::dispatch`. The same template defect appears across several TSNE and UMAP instantiations and stops the cuML build.

Evidence:

Build RAPIDS (optional) / rmm ucxx raft cuvs nvforest cuml, step 6

2026-08-13T21:13:31.3841653Z FAILED: CMakeFiles/cuml_objs.dir/src/tsne/tsne.cu.o 
2026-08-13T21:13:31.3870962Z /home/coder/raft/cpp/include/raft/util/kernel_launch.hpp(81): error: invalid type conversion
2026-08-13T21:13:31.3872367Z       {const_cast<void*>(static_cast<void const*>(std::addressof(params)))...}};

Root cause: The floating RAPIDS dependencies contain a RAFT kernel-launch implementation whose `std::addressof(params)` conversion is not accepted by NVCC 13.3 for qualified parameter types. The PR changes only the CUDA STF launch header and does not appear in the failing instantiation chain; a base-commit comparison or RAFT history is needed to identify the exact upstream regression. Sources: ci/rapids/cuda13.3-conda/devcontainer.json:17, ci/rapids/post-create-command.sh:141.

Suggested next steps: Reproduce with `RAPIDS_LIBS='rmm ucxx raft cuvs nvforest cuml' .devcontainer/launch.sh -d -c 13.3 -H rapids-conda -- ./ci/rapids/rapids-entrypoint.sh /bin/bash -li -c 'uninstall-all -j -qqq && clean-all -j && build-all -j0 -v'`, then compare the base commit using the same RAPIDS revisions. If confirmed external, consume or pin a RAFT revision that uses a CUDA-13.3-safe kernel-argument pointer conversion.

Copy this prompt into a coding agent
Repository: https://github.com/NVIDIA/cccl
Workflow run: https://github.com/NVIDIA/cccl/actions/runs/31743049673
Failure group: CUDA 13.3 rejects RAFT kernel argument address conversion
Affected jobs:
- Build RAPIDS (optional) / rmm ucxx raft cuvs nvforest cuml: https://github.com/NVIDIA/cccl/actions/runs/31743049673/job/94591596789

Verify this narrowly by building cuML with CUDA 13.3 against identical RAFT and cuML revisions on both the PR and its base commit. Inspect `raft/util/kernel_launch.hpp` around `raft::detail::dispatch`, especially the expansion `{const_cast<void*>(static_cast<void const*>(std::addressof(params)))...}`; determine which qualified parameter type NVCC rejects. If the failure reproduces on the base, do not modify the STF tuple change: pin RAPIDS RAFT to a known-good revision or update the dependency to an upstream fix. If RAFT must be patched, replace the conversion with a standards-correct CUDA-13.3-compatible way to form the `void*` kernel-argument array without changing parameter lifetimes, add a focused compile test covering `const __restrict__` pointer arguments, and rerun the smallest RAFT/cuML TSNE compilation before the RAPIDS job.

Jobs:

@andralex
andralex merged commit e3fdb62 into main Aug 13, 2026
88 of 89 checks passed
@andralex
andralex deleted the work/stf-launch-kernel-cuda-tuple branch August 13, 2026 22:38
andralex added a commit to andralex/cccl that referenced this pull request Sep 24, 2026
Drop the STF exclusion from the tidy build. STF compiles under clang-cuda
since the August portability series (NVIDIA#10612, NVIDIA#10793, NVIDIA#10796, NVIDIA#10801,
NVIDIA#10824), and its throw sites all go through _CCCL_THROW (NVIDIA#10826), so the
exception checks can see them. This first run measures the remaining tidy
backlog, including the test main() functions that clang-tidy 21 flags
because it ignores CheckMain. Places stays excluded here; NVIDIA#11626 handles it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
andralex added a commit to andralex/cccl that referenced this pull request Sep 24, 2026
Drop the STF exclusion from the tidy build. STF compiles under clang-cuda
since the August portability series (NVIDIA#10612, NVIDIA#10793, NVIDIA#10796, NVIDIA#10801,
NVIDIA#10824), and its throw sites all go through _CCCL_THROW (NVIDIA#10826), so the
exception checks can see them. The first run measured 1237 findings in
214 TUs; the follow-up commits on this branch work through them.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
andralex added a commit that referenced this pull request Sep 26, 2026
…11642)

* Run clang-tidy over CUDA STF

Drop the STF exclusion from the tidy build. STF compiles under clang-cuda
since the August portability series (#10612, #10793, #10796, #10801,
#10824), and its throw sites all go through _CCCL_THROW (#10826), so the
exception checks can see them. The first run measured 1237 findings in
214 TUs; the follow-up commits on this branch work through them.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [STF] clang-tidy batch 1: the mechanical findings, by script

From the first tidy run over STF (1237 findings, 214 TUs), the categories
that a script can apply from the reported location:

  misc-const-correctness            690  const at the declaration
  bugprone-narrowing-conversions    280  explicit static_cast of the operand
                                         (whole right-hand side for integral
                                         targets; the integer leaf inside a
                                         floating expression otherwise)
  cert-err34-c                       92  atoi/atol/atoll/atof -> std::sto*
  clang-diagnostic-braced-scalar-init 25 {N} -> N
  modernize-deprecated-headers       10  <stdio.h> -> <cstdio> etc.

plus four narrowing sites with dependent target types by hand.

Also: the negative-compile TUs under test/stf/static_error_checks are
marked NO_CLANG_TIDY (they fail to compile on purpose), and the
bugprone-exception-escape findings in exception_policy.cuh are
suppressed with a stated reason: clang-tidy's device pass compiles with
exceptions disabled, which makes every function implicitly non-throwing,
so the unit tests that throw on purpose and the ON_THROW(abort) runner
in invoke_nothrow are flagged for the throw the policy exists to catch.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [STF] clang-tidy batch 2: the findings that needed reading

The remaining ~110 findings from the first tidy run over STF, each by
hand or by an exact per-site substitution:

  modernize-loop-convert            20  range-for over the array being filled
  performance-inefficient-vector-op 11  reserve() before the push loop
  misc-predictable-rand              8  std::random_device for filenames and
                                        coin flips; a seeded std::mt19937 where
                                        the unseeded rand() was deterministic
  performance-unnecessary-copy-init  6  a const& where the copy was incidental;
                                        suppressed with a reason where the copy
                                        is what the test exercises
  performance-faster-string-find     5  (already absent after batch 1)
  bugprone-branch-clone              5  merged where the arms were both
                                        runtime; suppressed with a reason where
                                        one arm is constexpr
  bugprone-integer-division          5  floating divisor
  modernize-redundant-void-arg       4
  modernize-use-emplace              4
  modernize-min-max-use-init-list    4
  performance-noexcept-move          4  noexcept, conditional on the wrapped
                                        callable for the scope-guard results
  bugprone-unused-return-value       3  unique_ptr::release after ownership
                                        went to the host callback: suppressed
  google-global-names-in-headers     3  example headers: suppressed
  the rest                          ~15 one-liners: scoped_lock, = default,
                                        self-assignment guard, fseek for
                                        rewind, using for typedef, matching
                                        override visibility, and suppressions
                                        with a stated reason for the
                                        constrained forwarding constructor and
                                        the deliberately hash-named macros

One line in libcu++ (__variant/visit.h): __as_variant returns its const&
parameter by design; suppressed with a reason since the STF TUs are the
only ones that instantiate that overload under tidy.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [STF] clang-tidy batch 2 follow-up: one reserve per push loop, suppressions on the line they cover

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [STF] clang-tidy batch 1 corrections: three consts the check got wrong

- exception_policy.cuh: the retry counter is decremented in the catch
  arm; tidy only saw the instantiation where that arm is dead.
- source_location.cuh: the test binds the object to with_location<widget&>
  and mutates it through the reference.
- memory.cuh: cudaFreeHost takes void*, so a const pointee makes the
  introspected cuda_try form uncallable.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [STF] clang-tidy batch 1 corrections: no const on default-initialized objects, keep the captured test constant mutable

A const object of class type needs a user-provided default constructor
(GCC 15 rejects event_list, whose constructor is defaulted in-class), and
const buys nothing on a default-initialized handle or context anyway:
reverted at all eleven such sites. parallel_for_host.cu keeps its
captured constant non-const on purpose; a const literal makes the explicit
capture unused and Clang 14 warns.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [STF] restore the consts the previous correction removed from pre-existing declarations

The revert of const on default-initialized objects matched twelve lines
that predate the batch (members of exception_sink::sink_base, stored
source_locations, a dependencies pointer, a test fixture). Back to const.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [STF] restore sink_base's member block verbatim from trunk

The previous restore mis-paired two lines in this block.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [STF] clang-tidy corrections: keep CTAD test objects non-const where decltype(var) is asserted

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [STF] restore two as_expected test bindings that were const on trunk

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [libcu++] __as_variant: mark the parameter _CCCL_LIFETIMEBOUND instead of suppressing the check (review)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [STF] clang-tidy batch 3: the 58 findings of the second run

- bugprone-exception-escape (26): all reported at on_throw's operator<<,
  the noexcept runner, for its instantiations with test lambdas that throw.
  In clang-tidy's device pass _CCCL_TRY expands to no catch, so the check
  sees the callable's throw escape the runner. One NOLINT with the reason on
  the runner; the per-block suppressions in the tests, which addressed the
  wrong location, are removed.
- The runner's callable binding is back to trunk's non-const reference (a
  mutable callable, re-invoked by retry, needs it) and suppressed with the
  existing comment as the reason.
- const restored on default-initialized contexts/handles/hashtables (they
  compile; only event_list's defaulted constructor does not, suppressed).
- CTAD tests assert the const type; remaining narrowing, string-find,
  reserve() and branch-clone sites fixed or suppressed with a reason.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [STF] const only on the flagged default-initialized objects, not every same-named declaration in the file

Batch 3 restored const by matching the statement text, which also hit the
many other 'graph_ctx ctx;' / 'stream_ctx ctx;' / handle declarations in
those files whose objects are mutated. Keep const on the flagged lines only.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [STF] tidy: the reference-propagation test mutates its variable on purpose (trunk merge follow-up)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stf Sequential Task Flow programming model

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants