Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cartesian: re-evaluate InlineThreadLocalTransients in gt4py/dace bridge #1896

Open
romanc opened this issue Mar 3, 2025 · 0 comments
Open
Labels
gt4py.cartesian Issues concerning the current version with support only for cartesian grids. module: backend Related to analysis/backend subpackages triage: performance Performance related issues

Comments

@romanc
Copy link
Contributor

romanc commented Mar 3, 2025

Description

After exposing control flow elements to DaCe in the gt4py/DaCe bridge1, we had to temporarily deactivate InlineThreadLocalTransients because the pass would need to be adapted to the new expansion.

This PR is about re-evaluating the usefulness of the pass and if deemed useful re-activate the optimization pass. This might involve or be part of a bigger operation to re-think the CPU optimization strategy from scratch. Things will change anyway with "the schedule tree" aka

/cc @FlorianDeconinck @twicki as discussed

Footnotes

  1. https://github.com/GridTools/gt4py/pull/1894

@romanc romanc added module: backend Related to analysis/backend subpackages triage: performance Performance related issues gt4py.cartesian Issues concerning the current version with support only for cartesian grids. labels Mar 3, 2025
romanc added a commit that referenced this issue Mar 18, 2025
## Description

This PR refactors the GT4Py/DaCe bridge to expose control flow elements
(`if` statements and `while` loops) to DaCe. Previously, the whole
contents of a vertical loop was put in one big Tasklet. With this PR,
that Tasklet is broken apart in case control flow is found such that
control flow is visible in the SDFG. This allows DaCe to better analyze
code and will be crucial in future (within the current milestone)
performance optimization work.

The main ideas in this PR are the following

1. Introduce `oir.CodeBlock` to recursively break down
`oir.HorizontalExecution`s into smaller pieces that are either code flow
or evaluated in (smaller) Tasklets.
2. Introduce `dcir.Condition`and `dcir.WhileLoop` to represent if
statements and while loops that are translated into SDFG states. We keep
the current `dcir.MaskStmt` / `dcir.While` for if statements / while
loops inside horizontal regions, which aren't yet exposed to DaCe (see
#1900).
3. Add support for `if` statements and `while` loops in the state
machine of `sdfg_builder.py`
4. We are breaking up vertical loops inside stencils in multiple
Tasklets. It might thus happen that we write a "local" scalar in one
Tasklet and read it in another Tasklet (downstream). We thus create
output connectors for all scalar writes in a Tasklet and input
connectors for all reads (unless previously written in the same
Tasklet).
5. Memlets can't be generated per horizontal execution anymore and need
to be more fine grained. `TaskletAccessInfoCollector` does this work for
us, duplicating some logic in `AccessInfoCollector`. A refactor task has
been logged to fix/re-evaluate this later.

This PR depends on the following (downstream) DaCe fixes

- spcl/dace#1954
- spcl/dace#1955

which have been merged by now.

Follow-up issues

- unrelated changes have been moved to
#1895
- #1896
- #1898
- #1900

Related issue: GEOS-ESM/NDSL#53

## Requirements

- [x] All fixes and/or new features come with corresponding tests.
Added new tests and increased coverage of horizontal regions with PRs
#1807 and #1851.
- [ ] Important design decisions have been documented in the appropriate
ADR inside the [docs/development/ADRs/](docs/development/ADRs/Index.md)
folder.
Docs are [in our knowledge
base](https://geos-esm.github.io/SMT-Nebulae/technical/backend/dace-bridge/)
for now. Will be ported.

---------

Co-authored-by: Roman Cattaneo <>
Co-authored-by: Roman Cattaneo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gt4py.cartesian Issues concerning the current version with support only for cartesian grids. module: backend Related to analysis/backend subpackages triage: performance Performance related issues
Projects
None yet
Development

No branches or pull requests

1 participant