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

refact[next][dace]: split handling of let-statement lambdas from stencil body #1781

Merged
merged 5 commits into from
Dec 16, 2024

Conversation

edopao
Copy link
Contributor

@edopao edopao commented Dec 11, 2024

This is a refactoring of the code to lower lambda nodes: it splits the lowering of let-statements from the lowering of stencil expressions.

Copy link
Contributor

@philip-paul-mueller philip-paul-mueller left a comment

Choose a reason for hiding this comment

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

There are some aspects that needs some changes but it looks not bad.

@@ -1309,3 +1320,38 @@ def visit_SymRef(self, node: gtir.SymRef) -> IteratorExpr | MemletExpr | SymbolE
# if not in the lambda symbol map, this must be a symref to a builtin function
assert param in gtir_python_codegen.MATH_BUILTINS_MAPPING
return SymbolExpr(param, dace.string)

def apply(
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't remember that there is a call to apply().
As far as I can tell apply is only called in this function, so it is a recursive function.
However, it does some highly non trivial pre and post processing.
So I think that:

  • This function needs a better name, apply is just too generic.
  • This function needs a doc string.
  • This function needs comment that explain why the pre and post processing is needed and how it is done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like to keep the name apply for the entry point of this visitor class, since it is consistent with other visitor classes in GT4Py. However, I agree on the rest so I will write some documentation.

Copy link
Contributor

Choose a reason for hiding this comment

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

I still think that apply() is the wrong name. If it is for compatibility, then why was it there before?
_vistit_let() should be the much better name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have now made a code change in this direction.

Copy link
Contributor

@philip-paul-mueller philip-paul-mueller left a comment

Choose a reason for hiding this comment

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

There are some small points, but there is nothing serious.

@@ -1309,3 +1320,38 @@ def visit_SymRef(self, node: gtir.SymRef) -> IteratorExpr | MemletExpr | SymbolE
# if not in the lambda symbol map, this must be a symref to a builtin function
assert param in gtir_python_codegen.MATH_BUILTINS_MAPPING
return SymbolExpr(param, dace.string)

def apply(
Copy link
Contributor

Choose a reason for hiding this comment

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

I still think that apply() is the wrong name. If it is for compatibility, then why was it there before?
_vistit_let() should be the much better name.

Comment on lines 1351 to 1352
prev_symbol_map = self.symbol_map
self.symbol_map = self.symbol_map.copy()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
prev_symbol_map = self.symbol_map
self.symbol_map = self.symbol_map.copy()
prev_symbol_map = self.symbol_map.copy()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking to save the self.symbol_map object as prev_symbol_map, just to be on the safe side.

Copy link
Contributor

Choose a reason for hiding this comment

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

In my view this is indicating that you have some big problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see what you mean, side effects. Luckily I do not have such problems: I can do the change you propose.
However, in my opinion, I still prefer the original version where I added/removed items from always the same dictionary object, without copying it.

Copy link
Contributor

@philip-paul-mueller philip-paul-mueller left a comment

Choose a reason for hiding this comment

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

I still think that apply() is not needed.
It is not an entry point because it was not needed before (as visit() was used).

@edopao
Copy link
Contributor Author

edopao commented Dec 16, 2024

I still think that apply() is not needed. It is not an entry point because it was not needed before (as visit() was used).

That is true. I will make another change in this direction.

@edopao edopao merged commit 06b398a into GridTools:main Dec 16, 2024
31 checks passed
@edopao edopao deleted the dace-refact-lambda branch December 16, 2024 14:32
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