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

bug[next]: Fix CSE inside stencil #1793

Merged
merged 10 commits into from
Jan 14, 2025

Conversation

tehrengruber
Copy link
Contributor

@tehrengruber tehrengruber commented Jan 10, 2025

The common subexpression elimination did not work at all inside of stencils due to a typo. Fixed & added a test to cover this.

@@ -26,17 +26,9 @@ def offset_provider_type(request):


def test_trivial():
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a cleanup, not important for this PR.

@tehrengruber tehrengruber requested a review from havogt January 10, 2025 14:06
Copy link
Contributor

@havogt havogt left a comment

Choose a reason for hiding this comment

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

Your decision to change or keep the is_call_to parameter order.

@@ -429,9 +429,9 @@ def apply(
return cls().visit(node, within_stencil=within_stencil)

def generic_visit(self, node, **kwargs):
if cpm.is_call_to("as_fieldop", node):
if cpm.is_call_to(node, "as_fieldop"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about the interface, I think the other version would make more sense, because a curried version makes more sense (and therefore works nicer with functools.partial).

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can use the __getattr__ to implement cpm.is_call_to.as_fieldop(node)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Obviously given my typo I find the other way (node last) also natural (even though that is different day-to-day). However I would argue that the existing ordering is the correct one in python since isinstance and issubclass also use this ordering.

isinstance(obj, type)

The reasoning, I assume, comes from the ordering in natural language: is OBJ of kind KIND -> function is called is_obj_kind. With respect to the cpm.is_call_to.as_fieldop, I think this is a violation of KISS.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, the missing placeholder <>_is_call_to(<>) in the beginning is the part that makes it ambiguous, and it's just a convention. Following isinstance makes sense.
I thought we cannot easily detect the error because I thought we also accept str as node and promote it to a Sym, like in im, but since that is not the case an assert isinstance(node, itir.Node) is probably good enough.

src/gt4py/next/iterator/transforms/cse.py Show resolved Hide resolved
@tehrengruber tehrengruber merged commit 8346bcd into GridTools:main Jan 14, 2025
21 checks passed
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