Skip to content

feat[next]!: required vertical range for the scan builtin - #3067

Draft
havogt wants to merge 3 commits into
havogt/scan-initfrom
havogt/scan-range
Draft

havogt wants to merge 3 commits into
havogt/scan-initfrom
havogt/scan-range

Conversation

@havogt

@havogt havogt commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Description

Stacked on #3066.

The scan builtin takes a required vertical range=(dim, start, stop) instead of axis:

return scan(add, range=(KDim, vertical_start, vertical_end), init=0.0)(a)
  • The interval is half-open. The carry starts from init at start (forward) or at stop - 1 (backward).
  • The result is only defined on the range, independent of the domain it is accessed on.
  • start and stop are integer scalars and may be runtime values.
  • @scan_operator is unchanged and keeps axis.

Changes:

  • Type deduction: checks range as (vertical dimension, integer, integer). The axis check is shared with the decorator, which still passes axis.
  • Lowering: the bounds go into the domain of the scan's as_fieldop, with (-inf, inf) on every other dimension. The bounds (and a runtime init) are bound outside the lambda over the scan pass's parameters, so a parameter named like a bound does not capture it.
  • Domain inference: keeps the vertical range of a scan's domain instead of the one demanded by its consumers.
  • Temporaries: where a scan's domain differs from what a set_at writes, the scan is materialized in a temporary and copied with clipping.
  • dace: concat_where clips a branch to its domain.
  • Embedded: the builtin scans its given range. Tuple outputs are written element by element on their own domains.

Behaviour changes in embedded execution: a @scan_operator with tuple outputs on different domains now raises instead of silently writing the intersection, and non-scan field operators with tuple outputs on different domains write each element in full, as the compiled backends do.

Requirements

  • All fixes and/or new features come with corresponding tests.
  • Important design decisions have been documented in the appropriate ADR inside the docs/development/ADRs/ folder.

The call-site `scan` takes `range=(dim, start, stop)` instead of `axis`: the carry
starts from `init` at the range boundary and the result is only defined on the range,
independent of the domain the result is accessed on. `@scan_operator` keeps `axis`.
The bounds are lowered into the scan's `as_fieldop` domain; domain inference keeps its
vertical range. Where the scan's domain differs from what a `set_at` or a
`concat_where` branch writes, the scan is read through a copy. Embedded call-site
scans use the range instead of the closure column range.
- global_tmps: materialize a scan in a temporary and copy the part each output
  element needs, one statement per element domain, clipped to the scan's range
- dace: clip scan branches of concat_where to their region instead of copying
- embedded: write each tuple output element on its own domain
- `cpm.is_applied_scan` replaces three local scan checks
@havogt

havogt commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Written by an agent on behalf of @havogt

# Conflicts:
#	src/gt4py/next/embedded/operators.py
#	src/gt4py/next/ffront/foast_to_gtir.py
#	src/gt4py/next/iterator/transforms/infer_domain.py
#	tests/next_tests/integration_tests/feature_tests/ffront_tests/test_scan.py
@havogt
havogt added this pull request to stack #3069 December 2, 2026 08:36

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant