kernel.workgroup.scan
← kernel dialect
Prefix-scan a scalar or rank-1 vector value across the current workgroup. Workitems are ordered by x + size_x * (y + size_y * z), independently of their physical subgroup or lane assignment. Forward scans use increasing order; reverse scans use decreasing order. Vector components scan independently. An exclusive scan's empty prefix has the combining kind's empty value, such as zero for addition or one for multiplication; that value is not an additional contribution to nonempty prefixes. Each active contribution participates once per component; association is unspecified. Floating sums and products default to native target arithmetic, which may change signed zeros, flush subnormals, or relax nonfinite handling. The optional preserve requirement instead evaluates each combine with the source format's arithmetic semantics. Neither mode promises serial-reference bits, reproducibility, or a correctly rounded real-number sum. Integer arithmetic and the selected floating-extremum kind keep their exact semantics.
Operation contract
| Property |
Value |
| Semantic phase |
executable |
| Traits |
Convergent, HasAnyAncestor(kernel.def, pipeline.strand) |
| Target contracts |
kernel.synchronization |
Signature
| Kind |
Name |
Type |
Cardinality |
Description |
| Operand |
value |
any |
required |
Per-invocation value to scan. |
| Result |
result |
any |
required |
Scanned value. |
| Attribute |
kind |
enum CombiningKind |
required |
Combining operation. |
| Attribute |
math |
flags CollectiveMathFlags |
optional |
Optional floating-point preservation requirement; omission selects native arithmetic. |
| Attribute |
mode |
enum KernelWorkgroupScanMode |
required |
Inclusive or exclusive scan. |
| Attribute |
direction |
enum KernelWorkgroupScanDirection |
required |
Workitem order to scan. |
Verification constraints
Examples
%prefix = kernel.workgroup.scan<addf> %v {direction = forward, mode = inclusive} : f32
%offset = kernel.workgroup.scan<addi> %count {direction = forward, mode = exclusive} : i32