Repository navigation
[STF] Formalize that parallel_for on the host requires nvcc or nvc++ - #10824
Conversation
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>
|
/ok to test 2c7e0c0 |
📝 WalkthroughSummary by CodeRabbit
WalkthroughHost-side ChangesHost
Suggested reviewers: Merge Risk: 🔵 Low · up to 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 |
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>
|
/ok to test 6e48f90 |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
cudax/examples/stf/frozen_data_init.cucudax/examples/stf/parallel_for_2D.cucudax/include/cuda/experimental/__stf/utility/core.cuhcudax/test/stf/parallel_for/parallel_for_host.cucudax/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
This comment has been minimized.
This comment has been minimized.
Per repository convention, flagged by review. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
/ok to test ab9e0f9 |
This comment has been minimized.
This comment has been minimized.
|
/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.
|
/ok to test e6f50ce |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
cudax/examples/stf/frozen_data_init.cucudax/examples/stf/parallel_for_2D.cucudax/include/cuda/experimental/__stf/utility/core.cuhcudax/test/stf/parallel_for/parallel_for_host.cucudax/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
⏱️ CCCL compile-time benchmark comparison: Public headers compile-time benchResult: 0 regression row(s), 2 improvement row(s) above threshold.
Artifacts: reports and traces Direct file processing
🟢 Direct file processing — Improvements
|
🥳 CI Workflow Results🟩 Finished in 1h 31m: Pass: 100%/63 | Total: 13h 09m | Max: 1h 06m | Hits: 99%/37005See results here. |
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>
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>
…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>
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_forstanza for nvcc/nvc++. The other branch holds a call that is declared but never defined, carrying the GNUerrorattribute — the Linux kernel's__compiletime_erroridiom. The attribute's diagnostic fires only at codegen, which produces exactly the desired split:-fsyntax-onlysweeps (the consumers the exception-escape series needs, Make eight STF tests and examples portable to clang-cuda #10793 Unpack launch()'s kernel arguments with cuda::std::apply #10796 Prepend to tuples without a deduction guide, so device code can too #10801 Record that ~while_graph_scope_guard terminates on purpose #10805) analyze the TU cleanly — verified with clang-tidy 21 runningbugprone-exception-escapeunder--cuda-host-only;call to 'parallel_for_on_the_host_requires_nvcc_or_nvcpp()' declared with 'error' attribute: parallel_for on exec_place::host() requires nvcc or nvc++;A subtlety worth its comment
The
noexcepton the poison declaration is load-bearing, and its absence was a bug during development: with a nontrivial destructor in scope (acontext, 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).noexceptremoves the landing pad and restores the diagnostic.Note
tiled_loops.cualso runsparallel_foron 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-onlyover all 283 STF tests and examples fails only on the six TUs of the upstream-disabledalgorithmconstruct (#4403) and the five deliberately-failingstatic_error_checks— i.e., the tree is clean for the clang-tidy work.Testing
-fsyntax-only(clang-cuda 21): clean on all four TUs.bugprone-exception-escape,--cuda-host-only: analyzes cleanly (only the known pre-LLVM-22CheckMainartifact, see Record that ~while_graph_scope_guard terminates on purpose #10805).Checklist
🤖 Generated with Claude Code