-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[next]: Refactor CSE pass to support ITIR.Program (#1646)
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). This PR was initially meant to be merged into the temporary GTIR branch and reviewed by @egparedes here: #1570. The only change since then is to make dace tests pass (see commit 160a616). --------- Co-authored-by: edopao <[email protected]> Co-authored-by: Enrique González Paredes <[email protected]>
- Loading branch information
1 parent
c8822c0
commit 9328c50
Showing
11 changed files
with
256 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# GT4Py - GridTools Framework | ||
# | ||
# Copyright (c) 2014-2024, ETH Zurich | ||
# All rights reserved. | ||
# | ||
# Please, refer to the LICENSE file in the root directory. | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
from gt4py.next.iterator import ir as itir | ||
from gt4py.next.iterator.ir_utils import common_pattern_matcher as cpm | ||
|
||
|
||
def program_to_fencil(node: itir.Program) -> itir.FencilDefinition: | ||
assert not node.declarations | ||
closures = [] | ||
for stmt in node.body: | ||
assert isinstance(stmt, itir.SetAt) | ||
assert isinstance(stmt.expr, itir.FunCall) and cpm.is_call_to(stmt.expr.fun, "as_fieldop") | ||
stencil, domain = stmt.expr.fun.args | ||
inputs = stmt.expr.args | ||
assert all(isinstance(inp, itir.SymRef) for inp in inputs) | ||
closures.append( | ||
itir.StencilClosure(domain=domain, stencil=stencil, output=stmt.target, inputs=inputs) | ||
) | ||
|
||
return itir.FencilDefinition( | ||
id=node.id, | ||
function_definitions=node.function_definitions, | ||
params=node.params, | ||
closures=closures, | ||
) |
Oops, something went wrong.