Skip to content

Prepend to tuples without a deduction guide, so device code can too - #10801

Merged
andralex merged 2 commits into
mainfrom
work/stf-core-tuple-ctad
Aug 13, 2026
Merged

andralex merged 2 commits into
mainfrom
work/stf-core-tuple-ctad

Conversation

@andralex

@andralex andralex commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Third 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 (portability slips in the tests) and #10796 (launch()'s kernel arguments).

reserved::tuple_prepend built its result with CTAD. That was the one piece of the helper device code could not use: a deduction guide is not a constexpr function, so clang-cuda keeps it host-only, while it treats the rest of libstdc++'s constexpr tuple machinery -- std::apply, std::get, std::make_tuple, std::tuple_cat -- as implicitly __host__ __device__. Isolated, the diagnostic is exactly that:

error: reference to __host__ function '<deduction guide for tuple><int, double, char>' in
       __host__ __device__ function

std::tuple_cat avoids the guide, and it lets the apply and the lambda go too, so the body is now one line and the helper is usable from device code. That makes thread_hierarchy::apply_partition compile, and with it every launch() that partitions a shape.

Element types are preserved, which is what the documented return type std::tuple<T, P...> promises. std::make_tuple would also have fixed the build and read a little shorter, but it decays what it is handed: a tail holding int& comes back holding int, so writing through the result would quietly update a copy. Details in the review thread. Only the prefix has its type named, since that is where the guide was.

Worth noting what this replaces: my first instinct was to convert tuple_prepend, reserved::make_tuple, and make_tuple_indexwise to cuda::std::tuple, which would have rippled through stream_task, graph_task, task_dep, and parallel_for. None of that is needed -- the deduction guide was the only host-only element in the chain.

Validation

launch_scan.cu is the only file in the tree that reaches tuple_prepend from device code, and it needs #10796 as well, so on top of main alone this change flips nothing in the sweep. With #10796 applied, a clang-cuda -fsyntax-only sweep (clang 21, CTK 12, sm_75) over all 283 STF tests and examples goes from 33 failures to 24, with no regressions: the eight #10793 fixes, plus launch_scan.cu for this one. I verified separately that the explicit-type, make_tuple, and tuple_cat spellings all instantiate from a __global__ under clang-cuda, and that CTAD does not.

tuple_prepend is used by the stream, graph, host-launch, and launch paths, so nvcc 13.2 (C++17, sm_86) builds a representative spread of all four, and they run correctly on an RTX 3070: 01-axpy, 02-axpy-host_launch, 01-axpy-parallel_for, launch_scan, graph/many, and standalone-launches. The header unit tests for core.cuh, context.cuh (which covers make_tuple_indexwise) and thread_hierarchy.cuh (which covers apply_partition) build and pass. pre-commit passes.

What the remaining 24 are

The source fixes are done. Nothing left is mechanical:

  • 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 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.
  • 4 are one design question, not a bug: parallel_for_2D.cu, parallel_for_host.cu, test2_parallel_for_context.cu, and frozen_data_init.cu run parallel_for on exec_place::host() with lambdas that call host-only code such as EXPECT. parallel_for picks the host branch at run time, so the device branch is instantiated regardless, and clang compiles it. nvcc is spared because an unannotated lambda is host-only there, so __nv_is_extended_host_device_lambda_closure_type is false and the device branch is discarded. Clang has no equivalent trait and, per its maintainers, treats every lambda as __host__ __device__ -- "all lambdas in clang are extended lambdas in NVCC's terms" -- so STF cannot tell a host-only lambda from a device-capable one. Making the device branch's instantiation depend on the execution place being known at compile time would fix it; short of that, those four are a documented limitation. I would rather settle that in its own PR than smuggle it in here.

tuple_prepend built its result with CTAD. A deduction guide is not a constexpr
function, so clang-cuda leaves it host-only even though it treats the rest of
libstdc++'s constexpr tuple machinery, std::apply and std::get included, as
implicitly __host__ __device__. Device code that reaches the helper therefore
fails to compile: thread_hierarchy::apply_partition takes that route, and with
it every launch() that partitions a shape.

Naming the type keeps the previous behavior, since CTAD deduced the prefix by
value just as decay_t spells it here, and matches what libcudacxx already asks
for next door.
@andralex
andralex requested a review from a team as a code owner August 13, 2026 21:04
@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.

@github-project-automation github-project-automation Bot moved this to Todo in CCCL Aug 13, 2026
@andralex

Copy link
Copy Markdown
Contributor Author

/ok to test 6332d4d

@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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d23ad365-017e-4e7f-8aca-664e6aa692e7

📥 Commits

Reviewing files that changed from the base of the PR and between 6332d4d and 037f318.

📒 Files selected for processing (1)
  • cudax/include/cuda/experimental/__stf/utility/core.cuh
🚧 Files skipped from review as they are similar to previous changes (1)
  • cudax/include/cuda/experimental/__stf/utility/core.cuh

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved tuple handling in device code, preventing compilation issues in supported CUDA environments.

Walkthrough

Changes

The PR updates tuple_prepend to explicitly construct a decayed std::tuple type. This avoids host-only tuple deduction guides in device code.

Tuple construction

Layer / File(s) Summary
Explicit tuple result type
cudax/include/cuda/experimental/__stf/utility/core.cuh
tuple_prepend uses std::tuple<std::decay_t<T>, P...> construction and documents the device-code compatibility requirement.

Suggested reviewers: srinivasyadav18

Mergeability Score: ⚪ Minimal · up to 037f3

This localized change makes tuple construction usable in device code without changing behavior, and no actionable merge-blocking risk remains after normal checks and review.


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)
cudax/include/cuda/experimental/__stf/utility/core.cuh (1)

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

Use brace initialization for the explicit tuple construction to follow the project's uniform-initialization guideline; retain P... so the std::tuple<T, P...> contract remains unchanged.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 5f4fdb0e-18a0-45ee-b7c2-916d39fbc7bc

📥 Commits

Reviewing files that changed from the base of the PR and between 5274138 and 6332d4d.

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

Jacob asked why not make_tuple. It does compile in device code, but it decays
what it is handed, so a tail holding int& or reference_wrapper<int> comes back
holding int and int& respectively, quietly dropping the aliasing that the caller
passed in. tuple_cat keeps every element type, which is what the documented
return type std::tuple<T, P...> promises, and it drops the apply and the lambda
along the way. Only the prefix still needs its type named, for the same reason
as before.
@andralex

Copy link
Copy Markdown
Contributor Author

/ok to test 037f318

@andralex andralex changed the title Spell out tuple_prepend's result type instead of deducing it Prepend to tuples without a deduction guide, so device code can too Aug 13, 2026
@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.668495 -0.668495 5.388692 4.720197 Processing Header File: libcudacxx/include/cuda/std/__cccl/prologue.h 552
2 0.235691 -0.235691 1.670316 1.434625 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 26m: Pass: 100%/63 | Total: 1d 06h | Max: 59m 45s | Hits: 11%/201713

See results here.

AI failure analysis

1. RAPIDS build failure has no captured diagnostic · 1 job

Explanation: The rmm/ucxx/raft/cuvs/nvforest/cuml matrix failed in step 6, but no job log was collected, so the earliest failing library, command, and compiler diagnostic cannot be determined. The PR changes only `tuple_prepend`, making its new `std::tuple_cat` expression the primary suspect but not a confirmed cause.

Root cause: Unknown because `job-94599094848.log` is absent. Evidence is needed to distinguish a compilation regression caused by `std::tuple_cat` from a RAPIDS dependency, checkout, container, or infrastructure failure. Sources: cudax/include/cuda/experimental/__stf/utility/core.cuh:221.

Suggested next steps: Recover the step 6 log or reproduce the CUDA 13.3 matrix 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'`. Capture the first failing library and diagnostic before modifying code.

Copy this prompt into a coding agent
Repository: https://github.com/NVIDIA/cccl
Workflow run: https://github.com/NVIDIA/cccl/actions/runs/31745276448
Failure group: RAPIDS build failure has no captured diagnostic
Affected jobs:
- Build RAPIDS (optional) / rmm ucxx raft cuvs nvforest cuml: https://github.com/NVIDIA/cccl/actions/runs/31745276448/job/94599094848

Reproduce the CUDA 13.3 RAPIDS build narrowly and capture the first failure from rmm, ucxx, raft, cuvs, nvforest, or cuml. Verify whether `cudax/include/cuda/experimental/__stf/utility/core.cuh:221` fails because `std::tuple_cat` is unavailable or not device-callable in the affected compiler configuration. If confirmed, replace it with a direct tuple construction using an index-sequence expansion that explicitly returns `std::tuple<std::decay_t<T>, P...>`, preserves reference element types from the tail tuple, and avoids deduction guides, `std::apply`, and `std::tuple_cat`; add a focused test covering reference and move-only elements, then run the smallest relevant CUDASTF test and the failing RAPIDS library build.

Jobs:

@andralex
andralex merged commit 1de8499 into main Aug 13, 2026
89 of 90 checks passed
@andralex
andralex deleted the work/stf-core-tuple-ctad branch August 13, 2026 22:52
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Aug 13, 2026
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

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants