Skip to content

fix[next-dace]: reject in-map global write racing with an independent read - #2815

Open
edopao wants to merge 2 commits into
GridTools:mainfrom
edopao:fix/map-buffer-elimination-war
Open

fix[next-dace]: reject in-map global write racing with an independent read#2815
edopao wants to merge 2 commits into
GridTools:mainfrom
edopao:fix/map-buffer-elimination-war

Conversation

@edopao

@edopao edopao commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Description

GT4PyMapBufferElimination inlines the write-back MapExit -> tmp -> G into the Map body, eliminating the transient buffer. When the Map also reads G through a branch that is independent of the branch producing the written value, the rewrite creates a write-after-read hazard: independent branches inside a Map scope can be scheduled in arbitrary (insertion) order, so the read may observe the newly written value instead of the old one, producing silently wrong results.

This showed up as wrong numerical output in the icon4py stencil tests with the dace backend (e.g. extrapolate_temporally_exner_pressure): a stencil computing an auxiliary field from a field it also updates in place read the already-overwritten value.

The fix adds a check to _perform_pointwise_test: the rewrite is rejected unless every read of G inside the Map is dataflow-ordered before the branch that produces the written value (new helper _map_reads_glob_before_write). Reads that feed the producing branch — in-place patterns of the form G[i] = f(G[i]) produced by a single branch — are ordered before the write by construction and remain admissible, so existing valid uses are unaffected.

A unit test reproducing the hazard pattern is added: without this fix the transformation is applied despite the hazard (test fails), and execution of the rewritten SDFG yields numerically wrong results.

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.

… read

GT4PyMapBufferElimination inlines the write-back 'MapExit -> tmp -> G'
into the Map body. When the Map also reads 'G' through a branch that is
independent of the branch producing the written value, the rewrite
creates a write-after-read hazard: independent branches inside a Map
scope can be scheduled in arbitrary (insertion) order, so the read may
observe the newly written value and produce silently wrong results.

Reject the rewrite unless every read of 'G' inside the Map is
dataflow-ordered before the branch that produces the written value.
Reads that feed the producing branch (in-place patterns such as
'G[i] = f(G[i])') remain admissible.

Observed as wrong numerical results in icon4py stencil tests with the
dace backend (e.g. 'extrapolate_temporally_exner_pressure'). The added
unit test fails without this fix because the transformation is applied
despite the hazard.
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