Skip to content

[STF] Formalize that parallel_for on the host requires nvcc or nvc++ - #10824

Merged
andralex merged 5 commits into
NVIDIA:mainfrom
andralex:work/stf-host-pfor-clang-guard
Aug 14, 2026
Merged

andralex merged 5 commits into
NVIDIA:mainfrom
andralex:work/stf-host-pfor-clang-guard

Conversation

@andralex

Copy link
Copy Markdown
Contributor

Description

The tactical third option alongside #10814 and #10815, agreed with @caugonnet: the codebase does not support clang-cuda today, and the current failure mode for parallel_for(exec_place::host(), ...) is an explosion several template levels deep inside the device kernel. This PR formalizes the limitation instead of letting the instantiation explain it — a step forward regardless of how the #10814/#10815 design discussion resolves, and severable from both (#10815 would delete these guards; #10814 rewrites these stanzas anyway).

Mechanism

The four affected tests/examples guard the host-parallel_for stanza for nvcc/nvc++. The other branch holds a call that is declared but never defined, carrying the GNU error attribute — the Linux kernel's __compiletime_error idiom. The attribute's diagnostic fires only at codegen, which produces exactly the desired split:

A subtlety worth its comment

The noexcept on the poison declaration is load-bearing, and its absence was a bug during development: with a nontrivial destructor in scope (a context, say), the call is emitted as an invoke, and clang silently skips the error-attribute diagnostic on invokes (observed with clang 21, plain C++ and CUDA alike — arguably a clang bug worth reporting upstream). noexcept removes the landing pad and restores the diagnostic.

Note tiled_loops.cu also runs parallel_for on the host but needs no guard: its unannotated lambda is implicitly __host__ __device__ under clang and its body is device-legal, so it compiles and dispatches dynamically — supported semantics on every compiler. The guard marks exactly the unsupported combination (a host-only callable), nothing more.

Effect on the clang-cuda sweep

With this, -fsyntax-only over all 283 STF tests and examples fails only on the six TUs of the upstream-disabled algorithm construct (#4403) and the five deliberately-failing static_error_checks — i.e., the tree is clean for the clang-tidy work.

Testing

  • -fsyntax-only (clang-cuda 21): clean on all four TUs.
  • Real clang build: fails with the poison message on all four (verified per-TU).
  • clang-tidy 21, bugprone-exception-escape, --cuda-host-only: analyzes cleanly (only the known pre-LLVM-22 CheckMain artifact, see Record that ~while_graph_scope_guard terminates on purpose #10805).
  • nvcc 13.2: compiles unchanged; tests run green on an RTX 3070 (sm_86).
  • pre-commit passes.

Checklist

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

🤖 Generated with Claude Code

The four tests and examples that run parallel_for on
exec_place::host() fail to compile with clang-cuda, which cannot
classify lambdas for host/device execution and therefore compiles the
host lambda into the device kernel, where it explodes several levels
deep. Formalize the limitation instead of letting the instantiation
explain it.

Each site is now guarded for nvcc/nvc++, and the other branch holds a
call that is declared but never defined, carrying the GNU 'error'
attribute. That diagnostic fires only at codegen, which yields exactly
the desired split: clang-tidy and -fsyntax-only sweeps (the consumers
this series is for) analyze the file cleanly, while an attempt to
actually build states the limitation in one line at compile time --
and at link time, with the function name as the message, on compilers
without the attribute. Nothing anywhere compiles into wrong runtime
behavior.

The noexcept on the poison declaration is load-bearing and was a bug
once: with a nontrivial destructor in scope, the call is otherwise
emitted as an invoke, whose error-attribute diagnostic clang silently
skips (observed with clang 21, plain C++ and CUDA alike).

tiled_loops.cu also runs parallel_for on the host but needs no guard:
its unannotated lambda is implicitly host-device under clang and its
body is device-legal, so it compiles and dispatches dynamically --
supported semantics on every compiler.

With this, the clang-cuda sweep over all 283 STF tests and examples
fails only on the six disabled 'algorithm' TUs (NVIDIA#4403) and the five
deliberately-failing static_error_checks. Verified: -fsyntax-only
clean and real clang build poisoned with the message on all four TUs;
clang-tidy 21 (bugprone-exception-escape, --cuda-host-only) analyzes
cleanly; nvcc 13.2 compiles and the tests run green on an RTX 3070
(sm_86), byte-identical behavior.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@andralex
andralex requested review from a team as code owners August 14, 2026 15:28
@andralex
andralex requested a review from gonidelis August 14, 2026 15:28
@andralex
andralex requested a review from caugonnet August 14, 2026 15:28
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Aug 14, 2026
@copy-pr-bot

copy-pr-bot Bot commented Aug 14, 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 Aug 14, 2026
@andralex

Copy link
Copy Markdown
Contributor Author

/ok to test 2c7e0c0

@coderabbitai

coderabbitai Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved compiler diagnostics for host-side parallel_for usage.
    • NVCC and nvc++ continue to compile host execution paths normally.
    • Other compilers now receive a clear message indicating that host execution requires NVCC or nvc++.

Walkthrough

Host-side parallel_for validation now runs only with NVCC or NVHPC. Other compilers receive targeted diagnostics through CUDASTF_UNSUPPORTED or an equivalent undefined helper.

Changes

Host parallel_for diagnostics

Layer / File(s) Summary
Unsupported compiler diagnostic macro
cudax/include/cuda/experimental/__stf/utility/core.cuh
Defines _CCCL_UNSUPPORTED with optional compiler error attributes and an undefined noexcept function call.
Host validation compiler gating
cudax/examples/stf/*.cu, cudax/test/stf/parallel_for/*.cu
Host validation remains enabled for NVCC and NVHPC. Other compilers receive diagnostics stating that host execution requires NVCC or nvc++.

Suggested reviewers: gonidelis, bernhardmgruber, caugonnet

Merge Risk: 🔵 Low · up to e6f50

The PR adds compile-time diagnostics for unsupported host parallel_for usage, but the new declaration is missing the required host API annotation, which may cause compiler-specific integration issues. The change is otherwise bounded and mergeable with owner awareness or a follow-up fix.


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

One macro in core.cuh carries the idiom and its documentation (the
codegen-fire semantics, the link-time fallback, the load-bearing
noexcept); the four call sites shrink to a guard and one statement.

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

Copy link
Copy Markdown
Contributor Author

/ok to test 6e48f90

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: cfe8ac89-bb0c-492c-8fd6-86dc896e4667

📥 Commits

Reviewing files that changed from the base of the PR and between 2c7e0c0 and 6e48f90.

📒 Files selected for processing (5)
  • cudax/examples/stf/frozen_data_init.cu
  • cudax/examples/stf/parallel_for_2D.cu
  • cudax/include/cuda/experimental/__stf/utility/core.cuh
  • cudax/test/stf/parallel_for/parallel_for_host.cu
  • cudax/test/stf/parallel_for/test2_parallel_for_context.cu
🚧 Files skipped from review as they are similar to previous changes (4)
  • cudax/examples/stf/frozen_data_init.cu
  • cudax/test/stf/parallel_for/test2_parallel_for_context.cu
  • cudax/examples/stf/parallel_for_2D.cu
  • cudax/test/stf/parallel_for/parallel_for_host.cu

Comment thread cudax/examples/stf/frozen_data_init.cu Resolved
@github-actions

This comment has been minimized.

Per repository convention, flagged by review.

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

Copy link
Copy Markdown
Contributor Author

/ok to test ab9e0f9

@github-actions

This comment has been minimized.

@andralex

Copy link
Copy Markdown
Contributor Author

/ok to test 9a6680e

The poison macro is a general facility, not an STF-specific one, so it takes
the reserved _CCCL_ prefix the rest of the codebase uses.
@andralex

Copy link
Copy Markdown
Contributor Author

/ok to test e6f50ce

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 253a11d8-a235-40eb-8444-d9bf18a2621e

📥 Commits

Reviewing files that changed from the base of the PR and between ab9e0f9 and e6f50ce.

📒 Files selected for processing (5)
  • cudax/examples/stf/frozen_data_init.cu
  • cudax/examples/stf/parallel_for_2D.cu
  • cudax/include/cuda/experimental/__stf/utility/core.cuh
  • cudax/test/stf/parallel_for/parallel_for_host.cu
  • cudax/test/stf/parallel_for/test2_parallel_for_context.cu
🚧 Files skipped from review as they are similar to previous changes (4)
  • cudax/examples/stf/frozen_data_init.cu
  • cudax/test/stf/parallel_for/test2_parallel_for_context.cu
  • cudax/test/stf/parallel_for/parallel_for_host.cu
  • cudax/examples/stf/parallel_for_2D.cu

@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.662746 -0.662746 5.460691 4.797945 Processing Header File: libcudacxx/include/cuda/std/__cccl/prologue.h 552
2 0.223569 -0.223569 1.692049 1.468480 Processing Header File: libcudacxx/include/cuda/std/__cccl/epilogue.h 552

@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 1h 31m: Pass: 100%/63 | Total: 13h 09m | Max: 1h 06m | Hits: 99%/37005

See results here.

@andralex
andralex merged commit 7fe7d64 into NVIDIA:main Aug 14, 2026
95 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Aug 14, 2026
@andralex
andralex deleted the work/stf-host-pfor-clang-guard branch August 14, 2026 19:35
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