Skip to content

fix[next]: set unit stride on horizontal dimensions only for unstructured programs - #3048

Open
edopao wants to merge 6 commits into
mainfrom
dace_fix_unit_stride_check
Open

edopao wants to merge 6 commits into
mainfrom
dace_fix_unit_stride_check

Conversation

@edopao

@edopao edopao commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

The unstructured_horizontal_has_unit_stride option assumes unit stride on the horizontal dimension of fields and connectivities. It should apply only to unstructured programs, and only to horizontal dimensions. On a Cartesian grid IDim/JDim are both horizontal, so applying it there gives fields with two unit-stride dimensions, which is wrong.

  • DaCe: find_constant_symbols sets the stride symbols to 1 only for the horizontal dimension, and only when the program is unstructured.
  • GTFN: the nanobind bindings already restricted unit stride to horizontal dimensions, but did not know the grid type. The grid type is kept within the GTFN toolchain, and the generic build infrastructure (ProgramSource, nanobind, compiledb) is unchanged:
    • GTFNTranslationStep emits a GTFNProgramSource, a ProgramSource subclass that carries the grid type of the program.
    • make_gtfn_bindings returns a GTFNBindings step, which enables unstructured_horizontal_has_unit_stride only for unstructured programs before calling the unchanged nanobind.ExtensionGenerator.

Tests

  • DaCe, test_dace_translation.py:
    • test_find_constant_symbols: on fields with a vertical dimension, unit stride is set on the horizontal dimension only (flag on/off, field origin on/off).
    • test_translation_grid_type (Cartesian and unstructured): runs the full translator and checks the strides of the emitted SDFG. The horizontal dimensions are unit stride for the unstructured program, and all strides stay symbolic for the Cartesian one.
  • GTFN:
    • test_codegen in test_gtfn_module.py (Cartesian and unstructured): the translation step emits a GTFNProgramSource with the grid type of the program.
    • test_bindings_static_strides in test_gtfn.py: checks the stride_spec generated by the GTFN bindings step for unstructured (flag on/off) and Cartesian programs.

…ured programs in gtfn

Add a required grid_type field to ProgramSource, filled by the gtfn and dace
translation steps, and use it in the nanobind bindings to apply
unstructured_horizontal_has_unit_stride only to unstructured programs.
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 1b78864)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
✅ Merge recommendation: No concerns found
🔎 Failure modes

What: Out-of-tree code that constructs `ProgramSource` (custom backends implemented as OTF translation steps) now fails with a `TypeError` about the missing required `grid_type` argument, since the new field has no default value.
Where: src/gt4py/next/otf/artifacts.py:ProgramSource
Trigger: Any external or user-defined translation step building a `ProgramSource` without the new field, e.g. on the first compilation after upgrading gt4py.
Detected by: mypy or a TypeError at first compile in downstream code; nothing in this repo's CI exercises out-of-tree constructors.
Covered in this PR: No

What: If `ir_misc.grid_type_from_program` misclassifies a program shape not covered by the new tests (e.g. a Cartesian program whose domain is not expressed via the standard `cartesian_domain`/`get_field_domain` forms), the dace path constant-folds horizontal strides to 1 that are actually non-unit, silently producing wrong numerical results. Note: the helper is pre-existing and not part of this diff, so this remains uncertain; the standard shapes are covered by the new tests.
Where: src/gt4py/next/program_processors/runners/dace/workflow/translation.py:find_constant_symbols
Trigger: A compiled Cartesian program that `grid_type_from_program` classifies as UNSTRUCTURED.
Detected by: test_translation_grid_type covers the standard Cartesian and unstructured domain forms; numerical verification in feature tests would catch other shapes.
Covered in this PR: No

What: Adding `grid_type` changes the fingerprint of `ProgramSource`, so persistent build caches (`.gt4py_cache`) miss for every previously compiled program after upgrade, causing a one-time full recompilation, with stale cache folders lingering until `GT4PY_BUILD_CACHE_LIFETIME` cleanup.
Where: src/gt4py/next/otf/artifacts.py:ProgramSource
Trigger: First compilation of any previously cached program with the new version.
Detected by: Build-cache miss / longer first-run compile time; no test asserts fingerprint stability across versions.
Covered in this PR: No

🏅 Score: 91
🧪 PR contains tests
🔒 No security concerns identified
🔀 No multiple PR themes
⚡ No major issues detected

⚙️ Agent run details
  • Model: openai/zai-org/GLM-5.3-Flash
  • Tokens: 16,270 in / 15,411 out / 31,681 total
  • Time cost: 321.9s
  • AI calls: 1
✅ Resolved findings

src/gt4py/next/program_processors/codegens/gtfn/gtfn_module.py:227

Test coverage gap

The gtfn translation step now fills ProgramSource.grid_type via ir_misc.grid_type_from_program(program), and the dace translation step does the same, but no test asserts the emitted value. Per the repo rule that tests are the spec for changed code paths: if the helper misclassifies the grid type on the transformed IR, unit stride is silently dropped for unstructured programs (performance regression) or wrongly applied to Cartesian programs, reintroducing the multi-unit-stride bug this PR fixes. A small unit test asserting the grid_type stored on the emitted ProgramSource for one representative unstructured and one Cartesian program would pin this behaviour down.

@edopao

edopao commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

/review

Parametrize test_codegen (gtfn) and test_translation_grid_type (dace) over
cartesian and unstructured programs. The dace test also checks the strides
of the emitted SDFG, which makes the cartesian find_constant_symbols test
redundant.
@edopao

edopao commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

/review

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

The dace changes look ok, but the gtfn changes can't be in the generic build infrastructure.

Comment thread src/gt4py/next/otf/artifacts.py Resolved
…cture

Address review: revert grid_type on ProgramSource, compiledb and nanobind.
GTFNTranslationStep now emits a GTFNProgramSource, a ProgramSource subclass
with the grid type, and make_gtfn_bindings returns a GTFNBindings step that
enables unstructured_horizontal_has_unit_stride only for unstructured
programs before calling the unchanged nanobind.ExtensionGenerator.
@edopao

edopao commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

The dace changes look ok, but the gtfn changes can't be in the generic build infrastructure.

I've reverted the changes to ProgramSource, compiledb and nanobind. The grid type now lives only in gtfn: GTFNTranslationStep emits a GTFNProgramSource (a ProgramSource subclass with grid_type), and make_gtfn_bindings returns a GTFNBindings step that enables unstructured_horizontal_has_unit_stride only for unstructured programs before calling the unchanged nanobind.ExtensionGenerator. The generic build infrastructure is now identical to main.

@edopao
edopao requested a review from havogt November 26, 2026 13:19

This branch was successfully deployed

1 active (outdated) deployment
pr-agent — 8aee26d0 Deployed Nov 26, 2026 by edopao via pr-agent / pr-agent #216
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.

2 participants