Skip to content

Conversation

@SF-N
Copy link
Contributor

@SF-N SF-N commented Jul 25, 2025

This new pass checks within a SetAt if any fields that are written are also read with an offset and raises a ValueError in case.
It should run before create_global_tmps, since the shifts of the temporary targets are not forwarded.

Motivation: Warn user if he uses an in-out field

@gtx.field_operator
def field_op(v_field):
    return v_field(e2v[0])

@gtx.program
def program(v_field):
    field_op(v_field, out=v_field)

TODOs:

  • Mechanism to also warn if inputs are aliased, e.g. for the case where the field operator is called directly -> New PR
  • Fix tests

@SF-N SF-N requested a review from tehrengruber July 25, 2025 17:34
@havogt
Copy link
Contributor

havogt commented Jul 28, 2025

It should run before create_global_tmps, since the shifts of the temporary targets are not forwarded.

This is actually an interesting observation: it it find a problem before tmp creation, but not after the program is actually ok, but only because we did optimization in a way that makes it correct. That mean for gtfn, we could warn before tmp creation and say: "You are violating ..., but if there is no error later, your program will working for now, but may break any time." and then check again after tmp creation with a hard error. Not sure if DaCe checks for race conditions when fusing currently, but if they do, we could also in that case only warn. I am not sure if I like it, but it's something to discuss.

def extract_subexprs(expr):
"""Return a list of all subexpressions in expr.args, including expr itself."""
subexprs = [expr]
if hasattr(expr, "args"):
Copy link
Contributor

Choose a reason for hiding this comment

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

What cases are these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make_tuple, tuple_get and all functions like plus, maximum, ...
I am checking for FunCall now.

@@ -0,0 +1,338 @@
# GT4Py - GridTools Framework
Copy link
Contributor

Choose a reason for hiding this comment

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

Without reading the tests, these cases come up to my mind:

{a, b} <- {as_fieldop(...), as_fieldop(...)}
{a, b} <- as_fieldop(...)
a[0] <- as_fieldop(...)
a[0] <- {as_fieldop(...), as_fieldop(...)}
{a[0], a[1]} <- as_fieldop(...)
{a[0], a[1]} <- {as_fieldop(...), as_fieldop(...)}
a <- {as_fieldop(...), as_fieldop(...)}

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.

3 participants