-
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.
refactor[next]: Fencil to itir.Program for gtfn (#1524)
First PR for preparing itir for a combined field view + iterator representation. Adds new nodes: - itir.Program (to replace itir.FencilDefinition) - itir.SetAt (to replace itir.StencilClosure) and a new builtin `as_fieldop`. The semantic of `SetAt` is that the `expr` is directly computed into the `target` field. `as_fieldop` aka map, takes an itir stencil (a function from iterators to values) and promotes it to a field_operator, i.e. a function from fields to fields. The idea for `itir.Program` is to align and ultimately merge with `past.Program`. In this PR, the transition from Fencil to Program is implemented only for GTFN with a separate pass before lowering to gtfn. Additionally the pretty_printer/parser is extended with the new nodes/builtin. --------- Co-authored-by: Till Ehrengruber <[email protected]>
- Loading branch information
1 parent
d5d59d2
commit a603bfe
Showing
16 changed files
with
414 additions
and
138 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
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,46 @@ | ||
# GT4Py - GridTools Framework | ||
# | ||
# Copyright (c) 2014-2023, ETH Zurich | ||
# All rights reserved. | ||
# | ||
# This file is part of the GT4Py project and the GridTools framework. | ||
# GT4Py is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License as published by the | ||
# Free Software Foundation, either version 3 of the License, or any later | ||
# version. See the LICENSE.txt file at the top-level directory of this | ||
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>. | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from gt4py import eve | ||
from gt4py.next.iterator import ir as itir | ||
from gt4py.next.iterator.ir_utils import ir_makers as im | ||
from gt4py.next.iterator.transforms import global_tmps | ||
|
||
|
||
class FencilToProgram(eve.NodeTranslator): | ||
@classmethod | ||
def apply(cls, node: itir.FencilDefinition | global_tmps.FencilWithTemporaries) -> itir.Program: | ||
return cls().visit(node) | ||
|
||
def visit_StencilClosure(self, node: itir.StencilClosure) -> itir.SetAt: | ||
as_fieldop = im.call(im.call("as_fieldop")(node.stencil, node.domain))(*node.inputs) | ||
return itir.SetAt(expr=as_fieldop, domain=node.domain, target=node.output) | ||
|
||
def visit_FencilDefinition(self, node: itir.FencilDefinition) -> itir.Program: | ||
return itir.Program( | ||
id=node.id, | ||
function_definitions=node.function_definitions, | ||
params=node.params, | ||
declarations=[], | ||
body=self.visit(node.closures), | ||
) | ||
|
||
def visit_FencilWithTemporaries(self, node: global_tmps.FencilWithTemporaries) -> itir.Program: | ||
return itir.Program( | ||
id=node.fencil.id, | ||
function_definitions=node.fencil.function_definitions, | ||
params=node.params, | ||
declarations=node.tmps, | ||
body=self.visit(node.fencil.closures), | ||
) |
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
Oops, something went wrong.