Skip to content

fix[cartesian]: Scalarization of temporaries#2558

Merged
romanc merged 2 commits into
GridTools:mainfrom
romanc:romanc/fix-write-before-read-scalarization
Mar 31, 2026
Merged

fix[cartesian]: Scalarization of temporaries#2558
romanc merged 2 commits into
GridTools:mainfrom
romanc:romanc/fix-write-before-read-scalarization

Conversation

@romanc
Copy link
Copy Markdown
Contributor

@romanc romanc commented Mar 30, 2026

Description

Scalarization of read after write temporaries was eagerly scalarizing too many temporaries. If temporaries were written conditionaly, but read unconditionaly, the temporaries were still scalarized, leading to reads of undefined memory in case the condition for writing wasn't true.

This PR changes WriteBeforeReadTemporariesToScalars to never scalarize if the write is conditional. This is defensive in the sense that if the read had the same condition, we could still scalarize. That functionality can be added later if deemed necessary.

/cc @FlorianDeconinck

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

Scalarization of read after write temporaries was eagerly scalarizing
too many temporaries. If temporaries were written conditionaly, but read
unconditionaly, the temporaries were still scalarized, leading to reads
of undefined memory in case the condition for writing wasn't true.

This PR changes `WriteBeforeReadTemporariesToScalars` to never scalarize
if the write is conditional. This is defensive in the sense that if the
read had the same condition, we could still scalarize. That
functionality can be added later if deemed necessary.
@romanc romanc requested a review from twicki March 30, 2026 16:12
@romanc
Copy link
Copy Markdown
Contributor Author

romanc commented Mar 31, 2026

FYI: The failing jobs on the GH box are due to ongoing maintenance.

Copy link
Copy Markdown
Contributor

@twicki twicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty clean already. I think I would change the default behavior to not error unless there is a compelling reason for it?

Comment thread src/gt4py/cartesian/gtc/passes/oir_optimizations/utils.py
@romanc
Copy link
Copy Markdown
Contributor Author

romanc commented Mar 31, 2026

cscs-ci run

@romanc romanc merged commit 43df726 into GridTools:main Mar 31, 2026
20 checks passed
@romanc romanc deleted the romanc/fix-write-before-read-scalarization branch March 31, 2026 15:06
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