Skip to content

feat/fix[cartesian]: Do not merge: working PR for NASA crew#2595

Open
romanc wants to merge 32 commits into
GridTools:mainfrom
romanc:romanc/fix-log10-precision
Open

feat/fix[cartesian]: Do not merge: working PR for NASA crew#2595
romanc wants to merge 32 commits into
GridTools:mainfrom
romanc:romanc/fix-log10-precision

Conversation

@romanc

@romanc romanc commented May 8, 2026

Copy link
Copy Markdown
Contributor

Description

Update This branch is clean except for the original math functions. DaCe math functions require spcl/dace#2418 to be merged first and then DaCe to be released such that it can be updated in GT4Py (to the newest alpha).

🧱 In short, this is blocked by spcl/dace#2418 and a subsequent DaCe release.


🐉 ⚠️
Temporary working branch of gt4py.cartesian for the NASA crew. To be properly integrated in July.

Several math functions, e.g. log10(x), do not respect GT4Py_LITERAL_FLOAT_PRECISION in the dace backend.

The issue is caused by a combination of dace's code generation and the C/C++ standard library history. In C, log10(x) is defined to operate in double precision. The single-precision equivalent is called log10f(x), see here.

In C++, there is std::log10(x), which is a templated version that computes in either single- or double-precision depending on the argument. DaCe exposes access to those templated versions through dace/math.h. Some function were missing and are being patched with spcl/dace#2364. Building on that PR in DaCe, this PR uses the newly exposed fuctions in the cartesian DaCe backends.

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.
    N/A

`log10(x)` will always be in double precision, regardless of
`GT4PY_LITERAL_FLOAT_PRECISION`. With this PR, we are deferring to
`dace.math.log10`, which is a templated version that respects the
floating point precision.
@romanc
romanc force-pushed the romanc/fix-log10-precision branch from 00a7a94 to 901b57e Compare May 11, 2026 08:03
@romanc
romanc marked this pull request as ready for review May 11, 2026 08:04
@romanc
romanc requested a review from FlorianDeconinck May 11, 2026 08:04
@romanc
romanc marked this pull request as draft May 11, 2026 10:41
@romanc

romanc commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

wait - there's more. In particular, I stumbled across atan in GFDL_1M's PhaseChange ...

@romanc
romanc force-pushed the romanc/fix-log10-precision branch from 170a1a7 to 91de511 Compare May 11, 2026 13:17
@romanc
romanc force-pushed the romanc/fix-log10-precision branch from 91de511 to 1abd6c7 Compare May 11, 2026 13:30
@romanc romanc changed the title fix[cartesian]: log10 percision issue fix[cartesian]: percision issue with dace math functions May 11, 2026
@romanc
romanc marked this pull request as ready for review May 11, 2026 17:56
@romanc

This comment was marked as outdated.

this allows us (the cartesian team) to continue using our test branch of
dace while we keep pushing for the presentation in june.
@romanc

romanc commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

Note: I've restored the cartesian/next separation of DaCe versions. This allows us to keep our current working branch of DaCe in this working branch of GT4Py.

@romanc romanc changed the title fix[cartesian]: percision issue with dace math functions feat/fix[cartesian]: Do not merge: working PR for NASA crew Jun 9, 2026
twicki pushed a commit that referenced this pull request Jun 10, 2026
## Description

Small cleanup to remove an unused function argument in
`get_dace_shape()` of `oir_to_treeir.py`.

Pulled out from #2595.

## Requirements

- [x] All fixes and/or new features come with corresponding tests.
  Covered by existing tests.
romanc added 6 commits June 17, 2026 18:26
The conditionals for regions were generated in the form of
`{axis_bound} + {offset}`. This would lead to conditionals like

```cpp
if (((__i >= (0 + -1)) && (__i < (0 + 0)))) { ... }
```

in generated code. While we could expect compilers to handle this, it's
also ugly to work with in the intermediate representations.

This PR suggests - as a first, easy step - to detect `0` and not write
them.
romanc added a commit that referenced this pull request Jul 8, 2026
## Description

The pipeline of representations (truncated) for the cartesian dace
backend is as follows:

```none
... > oir -> treeir (gt4py) -> schedule tree (dace) -> SDFG (dace)
```

In this PR, we change the names of map/loop in the schedule tree
representation. The map/loop names in that representation are just names
(that can more or less be anything). We had a rather general description
and replace it with a more descriptive one, which includes the name of
the stencil where the horizontal/vertical loop (sections) come from.
This allows easier debugging and profiling. Nothing (except names)
changes in the generated code. Thus no tests have been added.

This PR contains an unrelated commit removing unused imports from dace
backend tests.


This PR is part of cleaning up our "working branch", i.e.
#2595, which accumulated a couple
of changes over the last month.

## Requirements

- [ ] All fixes and/or new features come with corresponding tests.
  N/A
- [ ] Important design decisions have been documented in the appropriate
ADR inside the [docs/development/ADRs/](docs/development/ADRs/README.md)
folder.
  N/A
romanc added a commit that referenced this pull request Jul 8, 2026
…#2682)

## Description

In oir -> treeir, avoid inserting artificial `x + 0` or `0 + x`
calculations when translating axis bounds. In the end, this makes for
cleaner generated code, which is easier to read and doesn't rely on
general compilers to remove the calculation as part of their
optimization pipeline.

This PR is part of cleaning up our "working branch", i.e.
#2595, which accumulated a couple
of changes over the last month.

## Requirements

- [x] 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/](docs/development/ADRs/README.md)
folder.
  N/A
romanc added a commit that referenced this pull request Jul 8, 2026
## Description

This fix comes from running GFDL_1M in KJI-layout where - in NDSL -
there's no extra point allocated in the vertical (to be able to directly
copy the Fortran data).

This commit freezes origin and `domain` (not `shape`) in the K-axis of
the stencil. `shape` and `domain` agree most of the time, but can differ
if - for example - the stencil is configured on `K_INTERFACE_DIM` and
the field of size `K_DIM`. Depending on the combination, this can lead
to out of bound reads where we were previously saved by the extra point
allocated in the back (but in KJI since we don't have this point, we
crash).

I am not touching the horizontal axes in this commit. We probably
should, but we haven't seen any crashes (probably due to the fact that
we can't currently run dynamics in KJI (i.e. without the extra point)).
I'd argue we should tackle this in a follow-up when we also look at the
"potential out of bounds" memlet warnings that we get from dace (mainly
when running dynamics).


This PR is part of cleaning up our "working branch", i.e.
#2595, which accumulated a couple
of changes over the last month.

## Requirements

- [ ] All fixes and/or new features come with corresponding tests.
  N/A
- [ ] Important design decisions have been documented in the appropriate
ADR inside the [docs/development/ADRs/](docs/development/ADRs/README.md)
folder.
  N/A
romanc added 4 commits July 8, 2026 14:34
This update the cartesian version of dace to the latest version and
fixes the next version of dace to be the correct one (i.e. latest
release instead of pulling from their index).
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