Repository navigation
Conversation
Port the NCAR/SWM shallow water benchmark to a single gt4py.next notebook, alongside a NumPy reference and the 16x16 reference state after the full 4000-step run. Periodicity is applied outside GT4Py for now, which keeps the example free of any src/ changes.
The scheme is verified against Sadourny (1975) Eq. 4 -- cu, cv, h, z are his U, V, H and eta term for term. The constants are not from the paper, and the 'Swarztrauber 1984' attribution came from a code comment in NCAR/SWM rather than from any reference, so point at the benchmark repo instead.
Cartesian shift offsets had to be literals, which meant a periodic wrap by a runtime grid size could not be written in the DSL. Relax the frontend to accept a non-literal integral offset, lower it, and canonicalize the resulting literal to an OffsetLiteral so domain inference sees a real offset rather than the unknown-access sentinel. Uses it in the shallow water example, whose halo update moves from NumPy into the field operator. Updates test_premap_cartesian_non_literal_offset, which pinned the old rejection, and adds the SUB and non-integral cases.
# Conflicts: # src/gt4py/next/ffront/foast_to_gtir.py
Port of the periodicity change to the example as merged in #3038: a make_periodic field operator with runtime shifts f(I + m), a program with per-output domains, m and n as static parameters so that the jit backends can shift by them, and no halo refresh on the host. The comparison now times complete steps. The top-level copies of the example from #2749 are removed.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moves the halo update of the shallow water example (
examples/swm/, added in #3038) into the DSL, replacing the halo refresh on the host that #3038 uses to stay free ofsrc/changes.The example side
timestepnow returns the wrapped prognostic fields, and the time loop touches no halo at all. The prognostic outputs are written over the full domain while the filtered levels only need the interior, so aprogramsupplies a per-outputdomain=.The rebinding order is load-bearing: each
concat_wherefeeds the next, so thejpass sees the already-i-corrected field and the corners come out right. A simultaneous formulation would leave them wrong.mandnare static parameters of the program (with_static_params("m", "n")): the jit backends of #3027 trace scalars, so they need the shift distance as a constant, and the compiled backends then see it as a literal. The opt-in performance comparison now times complete steps, halo included, instead of skipping the halo refresh.Why this needs frontend changes
The shift distance is
m, a program argument rather than a literal, and the frontend rejects that at FOAST construction:with_static_argscannot substitute — the check fires when the decorator runs at import, long beforecompile(m=[M])exists.Four files, and an ablation confirms none is redundant. Each row was measured (in August, on #2749's branch) by reverting that change alone and running all three backends:
ffront/foast_passes/type_deduction.pyffront/foast_to_gtir.pyiterator/transforms/normalize_shifts.py—CanonicalizeShiftOffsetspass_manager.py, wiring inapply_common_transformspass_manager.py, wiring inapply_fieldview_transformsThe last two lines are the non-obvious part: the two backends traverse different pass managers, so each wiring serves exactly one. Dropping either gives
AttributeError: 'DomainAccessDescriptor' object has no attribute 'grid_type'on the corresponding backend.CanonicalizeShiftOffsetsexists because our own lowering emits a shift whose offset is a runtime expression; oncemis inlined as a static argument it becomes anir.Literal, but domain inference expects anir.OffsetLiteraland otherwise yields the unknown-access sentinel.Validation
After merging
main(with #3027 and #3038):pytest --nbmake examples/swm/swm.ipynbpasses, including the full 4000 steps againstswm_reference.npz(NCAR data)swm_numpy, with the halo now filled in the field operator:gtfn_cpuandembedded_numpyare bit-for-bit equal,dace_cpuandjax_jit(CPU) differ by at most 2e-13 inu,vand 8e-11 inp, within the notebook's tolerancestests/next_tests/unit_tests/ffront_tests/test_foast_to_gtir.pypassesMerging
mainconflicted infoast_to_gtir.py, wheremainnow lowers literalDim + idxshifts viaconnectivity_for_cartesian_shiftfor staggered dimensions. The runtime-offset case is kept after it, unchanged: an integral runtime offset stays within its dimension, asconnectivity_for_cartesian_shiftdoes for integral literals.Unit suite (August, before merging
main)pytest tests/next_tests/unit_tests/compared against the same suite on #2749's branch, sincemainalready carries pre-existing failures:The one difference was
test_foast_to_gtir.py::test_premap_cartesian_non_literal_offset, which asserted thatinp(TDim + i)raises. That is the behaviour this PR deliberately changes, so the test is updated rather than silenced — it now pins the lowering, plus two new cases: theSUBform (negapplied to the offset) and that a non-literal float offset still errors, since a runtime offset has no fractional part to resolve to a staggered dimension.Failure sets are otherwise identical (
common the sorted lists shows no other difference in either direction).Note
An alternative that needs no
src/changes is to hardcode the wrap distance as a literal. I measured it and rejected it: it silently miscomputes at any--Mother than the default, because the domain follows the grid size but the wrap does not.