[STF] Support compound while-loop conditions in the C API#10006
Conversation
The built-in while-loop condition helper stf_stackable_while_cond_scalar() can only express a single comparison, so a loop guarded by, e.g., a convergence test AND an iteration cap forces callers to allocate a synthetic condition scalar and schedule an extra task that combines the subconditions on the device. Add stf_stackable_while_cond_multi(): a single condition task that reads up to STF_WHILE_COND_MAX_TERMS scalar logical data, evaluates each (*ld <op> threshold) term (with optional negation) and folds the results with an ALL (AND) or ANY (OR) combiner before updating the conditional handle. The term pack is passed by value through kernel parameters, so the kernel remains a single-thread launch with no device allocation, and duplicate logical data across terms share one read dependency. stf_stackable_while_cond_scalar() now delegates to the multi-term path, leaving a single condition kernel. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
/ok to test b0cc738 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughChangesThe stackable while-condition API now supports up to eight compound scalar terms with ALL/ANY combination, per-term comparison and negation, deduplicated dependencies, packed CUDA evaluation, scalar compatibility delegation, and regression tests. Compound while condition
Suggested reviewers: Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
c/experimental/stf/src/stf.cu (2)
1587-1635: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winsuggestion:
cond_handle(1587) andstream(1635) are never reassigned; declare themconst.As per coding guidelines: "All variables that are not modified must be declared
const, including cast results, function return values, and loop-invariant computations."Source: Coding guidelines
1637-1650: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low valuesuggestion: mark
cond_handleandstreamconst; they are never reassigned.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: a6743cc8-39f3-43d9-9df3-67872f61a0b7
📒 Files selected for processing (3)
c/experimental/stf/include/cccl/c/experimental/stf/stf.hc/experimental/stf/src/stf.cuc/experimental/stf/test/test_stackable.cu
This comment has been minimized.
This comment has been minimized.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
/ok to test 9bcd17d |
🥳 CI Workflow Results🟩 Finished in 48m 45s: Pass: 100%/7 | Total: 1h 02m | Max: 48m 45s | Hits: 98%/786See results here. |
Description
Extracted from #5315 (see this review thread).
The built-in while-loop condition helper
stf_stackable_while_cond_scalar()can only express a single comparison, so a loop guarded by, e.g., a convergence test and an iteration cap forces callers to allocate a synthetic condition scalar and schedule an extra task that combines the subconditions on the device.This PR adds
stf_stackable_while_cond_multi(): a single condition task that reads up toSTF_WHILE_COND_MAX_TERMS(8) scalar logical data, evaluates each(*ld <op> threshold)term (with optional negation) and folds the results with an ALL (AND) or ANY (OR) combiner before updating the conditional handle:Implementation notes:
stf_stackable_while_cond_scalar()now delegates to the multi-term path, leaving a single condition kernel.Motivation: Python compound while conditions
This entry point is the lowering target for the compound condition expressions of the Python STF bindings (#5315). Each flat
&-chain or|-chain of comparisons maps 1:1 onto onestf_stackable_while_cond_multi()call, so e.g. a BiCGSTAB solver expresses its loop guard directly:instead of allocating a condition scalar and spending a dedicated task fusing the two tests on the device. The flat
terms[] + combinerABI keeps that lowering (and code generators targeting the C API directly) trivial while the kernel stays a single tiny launch regardless of the number of terms.Testing
New
C2H_TEST("stackable: while compound condition")intest_stackable.cucovering the ALL combiner with an iteration cap, the ANY combiner with a negated term, and duplicate-logical-data dependency sharing. Built with--preset cccl-c-stfand run on an RTX 3080 Ti (CUDA 13.0): all assertions pass.Checklist
stf.h).🤖 Generated with Claude Code