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

feat[next]: Refactor CSE pass to support ITIR.Program (GTIR branch) #1579

Merged
merged 15 commits into from
Jul 24, 2024

Conversation

tehrengruber
Copy link
Contributor

@tehrengruber tehrengruber commented Jul 17, 2024

Extends the common subexpression elimination to support the new itir.Program node and pushes the intermediate Fencil -> Program conversion upwards the pass manager. The CSE pass now uses the type inference such that only field expressions or composites thereof are collected in field-view context (i.e. outside of as_fieldop).

@tehrengruber tehrengruber changed the base branch from main to gtir July 17, 2024 09:33
@tehrengruber tehrengruber changed the title feat[next]: Refactor CSE pass to support ITIR.Program feat[next]: Refactor CSE pass to support ITIR.Program (GTIR branch) Jul 17, 2024
@@ -264,25 +264,23 @@ def visit_FunCall(self, node: gtfn_ir.FunCall, **kwargs: Any) -> gtfn_ir_common.
self.imp_list_ir.append(InitStmt(lhs=gtfn_ir_common.Sym(id=f"{lam_idx}"), rhs=node))
return gtfn_ir_common.SymRef(id=f"{lam_idx}")
if isinstance(node.fun, gtfn_ir.Lambda):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The scoping here was completely broken leading to multiple SymbolName's with the same id being declared in InitStmt. The fix is ok, but not great.

Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

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

It looks good. I have mostly questions and optional suggestions.

src/gt4py/next/iterator/ir_utils/ir_makers.py Outdated Show resolved Hide resolved
src/gt4py/next/iterator/transforms/pass_manager.py Outdated Show resolved Hide resolved
src/gt4py/next/iterator/transforms/cse.py Outdated Show resolved Hide resolved
src/gt4py/next/iterator/transforms/cse.py Outdated Show resolved Hide resolved
@@ -365,10 +371,10 @@ class CommonSubexpressionElimination(PreserveLocationVisitor, NodeTranslator):
Perform common subexpression elimination.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you briefly outline here the algorithm and the used tools (e.g. other visitors, functions, ...)

@@ -116,15 +116,17 @@ def _(lhs: ts.ScalarType, rhs: ts.ScalarType) -> ts.ScalarType | ts.TupleType:


@_register_builtin_type_synthesizer
def deref(it: it_ts.IteratorType) -> ts.DataType:
def deref(it: it_ts.IteratorType) -> ts.DataType | ts.DeferredType:
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a question: is the type annotation for it correct? Shouldn't it be a union with DeferredType? If that is the case, why is not type checker complaining here?

Suggested change
def deref(it: it_ts.IteratorType) -> ts.DataType | ts.DeferredType:
def deref(it: it_ts.IteratorType| ts.DeferredType) -> ts.DataType | ts.DeferredType:

@tehrengruber tehrengruber requested a review from egparedes July 23, 2024 08:50
Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

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

LGTM

@tehrengruber tehrengruber merged commit e48d8c3 into GridTools:gtir Jul 24, 2024
28 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