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]: Lowering foast/past to GTIR #1569

Merged
merged 33 commits into from
Aug 26, 2024
Merged

Conversation

havogt
Copy link
Contributor

@havogt havogt commented Jul 3, 2024

Adds lowering of foast and past to GTIR.

The backend that goes through the new lowering is not enabled in this PR as it is missing the domain propagation pass which comes in a different PR. The lowering is tested with the test_foast_to_gtir (which is an extended duplication of test_foast_to_itir which will eventually be deleted).

Notes:

  • Lowering of scan is not yet implemented.

@tehrengruber tehrengruber changed the title feat[next] foast to gtir feat[next]: foast to gtir Jul 17, 2024
common_symbols: dict[str, foast.Symbol] = node.annex.propagated_symbols

if return_kind is foast_introspection.StmtReturnKind.NO_RETURN:
# TODO document why this case should be handled in this way, not by the more general CONDITIONAL_RETURN
Copy link
Contributor Author

Choose a reason for hiding this comment

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

question to @tehrengruber (probably smaller tree?)

@havogt havogt changed the title feat[next]: foast to gtir feat[next]: Lowering foast/past to GTIR Aug 15, 2024
@havogt havogt marked this pull request as ready for review August 15, 2024 10:25
@havogt havogt requested a review from tehrengruber August 15, 2024 10:25
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 overall good to me. Requested changes are mostly minor style issues.

@@ -1651,3 +1651,5 @@ def to_set(self) -> Set[T]:


xiter = XIterable

__all__ = ["toolz"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this has been added to avoid linter errors but I don't think it's the right solution (and additionally __all__ should always go at the top of the file).

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 don't remember. My question would be, do you think it's ok to import toolz from eve (to have the import check for the ctoolz not repeated everywhere).

src/gt4py/next/ffront/lowering_utils.py Outdated Show resolved Hide resolved
src/gt4py/next/ffront/lowering_utils.py Outdated Show resolved Hide resolved
src/gt4py/next/ffront/past_to_itir.py Outdated Show resolved Hide resolved
src/gt4py/next/ffront/past_to_itir.py Outdated Show resolved Hide resolved


def test_annotated_assignment():
pytest.xfail("Annotated assignments are not properly supported at the moment.")
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: why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's blindly copied, I can check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

First error "gtx not defined", after importing Field directly, I get "TDim not defined". Not sure if hard to fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(first part might be fixed by @nfarabullini 's work...)

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure, but I think the reason this doesn't work is because in a from __future__ import annotations file the annotations are no evaluated and hence don't land in the closure vars. This might be something to take into consideration in @nfarabullini works.

)


def test_copy_lowering(copy_program_def, gtir_identity_fundef):
Copy link
Contributor

Choose a reason for hiding this comment

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

Slightly outside of the scope of the PR and not strictly necessary, but in the spirit of the previous tests, I'd suggest to rename all the copy_ names (e.g. fixture, test_function, ...) should be renamed to something like identity or pass_through,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actually a copy, we use the identity fieldop but assign the result into another field.

@@ -1651,3 +1651,5 @@ def to_set(self) -> Set[T]:


xiter = XIterable

__all__ = ["toolz"]
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 don't remember. My question would be, do you think it's ok to import toolz from eve (to have the import check for the ctoolz not repeated everywhere).

common_symbols: dict[str, foast.Symbol] = node.annex.propagated_symbols

if return_kind is foast_introspection.StmtReturnKind.NO_RETURN:
# TODO document why this case should be handled in this way, not by the more general CONDITIONAL_RETURN
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is meant to be resolved in this PR, probably removed.

@@ -136,7 +136,6 @@ class TupleConstructorType(Protocol, Generic[_R]):
def __call__(self, *args: Any) -> _R: ...


# TODO(havogt): the complicated typing is a hint that this function needs refactoring
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the Till's tree_map version. this removal is acknowledging that the problem is not simple and typing is complicated for this kind of function.



def test_annotated_assignment():
pytest.xfail("Annotated assignments are not properly supported at the moment.")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's blindly copied, I can check

@@ -356,6 +363,18 @@ def lifted_neighbors(offset, it) -> itir.Expr:
return lift(lambda_("it")(neighbors(offset, "it")))(it)


def as_fieldop_neighbors(offset, it) -> itir.Expr:
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to also pass the optional domain of as_fieldop, at least for unit testing of gtir to SDFG. Anyway, I could also add it in my PR.

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 to me.

src/gt4py/next/ffront/foast_to_itir.py Show resolved Hide resolved
src/gt4py/next/ffront/past_to_itir.py Show resolved Hide resolved
src/gt4py/next/ffront/foast_to_gtir.py Show resolved Hide resolved
src/gt4py/next/ffront/foast_to_gtir.py Outdated Show resolved Hide resolved
src/gt4py/next/ffront/foast_to_gtir.py Outdated Show resolved Hide resolved
src/gt4py/next/ffront/foast_to_gtir.py Show resolved Hide resolved
src/gt4py/next/ffront/lowering_utils.py Show resolved Hide resolved
common_symbols: dict[str, foast.Symbol] = node.annex.propagated_symbols

if return_kind is foast_introspection.StmtReturnKind.NO_RETURN:
# FIXME[#1582](havogt): document why this case should be handled in this way, not by the more general CONDITIONAL_RETURN
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
# FIXME[#1582](havogt): document why this case should be handled in this way, not by the more general CONDITIONAL_RETURN
# FIXME[#1582](tehrengruber): document why this case should be handled in this way, not by the more general CONDITIONAL_RETURN

@havogt havogt requested a review from tehrengruber August 26, 2024 07:59
@havogt havogt merged commit 659c38c into GridTools:main Aug 26, 2024
31 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.

4 participants