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

feature[next]: ITIR Inline lift pass extension #1475

Closed
wants to merge 50 commits into from

Conversation

tehrengruber
Copy link
Contributor

@tehrengruber tehrengruber commented Feb 28, 2024

Blocked by #1455 (contained in this PR)

Still a draft. While refactoring I found a less complex way for this transformation.

@tehrengruber tehrengruber changed the base branch from main to inline_center_deref_lift_vars March 5, 2024 12:11
@tehrengruber tehrengruber marked this pull request as ready for review March 5, 2024 23:10
Copy link
Contributor

@havogt havogt left a comment

Choose a reason for hiding this comment

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

first round

@@ -96,6 +98,7 @@ def visit_FunCall(self, node: itir.FunCall, **kwargs):
eligible_params=eligible_params,
)
# TODO(tehrengruber): propagate let outwards
# todo: inherit recorded shifts
Copy link
Contributor

Choose a reason for hiding this comment

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

todo

Copy link
Contributor

Choose a reason for hiding this comment

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

why marked as resolved?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just forgot to remove the todo. The change is one line below.

src/gt4py/next/iterator/transforms/pass_manager.py Outdated Show resolved Hide resolved
flags=InlineLifts.Flag.INLINE_TRIVIAL_DEREF_LIFT
| InlineLifts.Flag.INLINE_DEREF_LIFT # some tuple exprs found in FVM don't work yet.
).visit(ir)
| InlineLifts.Flag.INLINE_LIFTED_ARGS,
inline_single_pos_deref_lift_args_only=True,
Copy link
Contributor

Choose a reason for hiding this comment

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

why not a flag

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 started with that approach, but it looked rather ugly. The inline_single_pos_deref_lift_args_only=True case is a strict subset of the default case so having both flags doesn't make sense from a user perspective -> already a hint that this is better merely an option to the transformation like it is now. Additionally making two flags means one would need two transform_... functions that then need to dispatch to a third function containing the actual implementation. This is already ugly for the INLINE_DEREF_LIFT, INLINE_TRIVIAL_DEREF_LIFT case and didn't feel right here.

Copy link
Contributor

Choose a reason for hiding this comment

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

but it's also not orthogonal to the flags, right? is it a subset of one of the flags?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what you mean with orthogonal. It as an option to the INLINE_LIFTED_ARGS flags, either inline all or only the ones that are dereferenced at the center. In that sense it is a subset of that flag.


import gt4py.eve as eve
from gt4py.eve import NodeTranslator, traits
from gt4py.next.iterator import ir
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.iterator.transforms.inline_lambdas import inline_lambda
from gt4py.next.iterator.transforms.trace_shifts import TraceShifts, copy_recorded_shifts
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
from gt4py.next.iterator.transforms.trace_shifts import TraceShifts, copy_recorded_shifts
from gt4py.next.iterator.transforms import trace_shifts

Copy link
Contributor Author

@tehrengruber tehrengruber Mar 7, 2024

Choose a reason for hiding this comment

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

Fixed, but good example for a case where I really dislike this because it does not increase readabilty at all:

trace_shifts.TraceShifts.apply(...)
trace_shifts.copy_recorded_shifts(...)

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe the fix would be TraceShifts.apply -> apply. Let's not change that now, but maybe in "workflowify more" project.

src/gt4py/next/iterator/transforms/inline_lifts.py Outdated Show resolved Hide resolved
src/gt4py/next/iterator/transforms/inline_lifts.py Outdated Show resolved Hide resolved
src/gt4py/next/iterator/transforms/inline_lifts.py Outdated Show resolved Hide resolved
src/gt4py/next/iterator/transforms/inline_lifts.py Outdated Show resolved Hide resolved
src/gt4py/next/iterator/transforms/inline_lifts.py Outdated Show resolved Hide resolved
src/gt4py/next/iterator/transforms/inline_lifts.py Outdated Show resolved Hide resolved
@tehrengruber tehrengruber changed the base branch from inline_center_deref_lift_vars to main March 8, 2024 20:36
@havogt havogt changed the title featue[next]: ITIR Inline lift pass extension feature[next]: ITIR Inline lift pass extension Mar 13, 2024
Comment on lines 397 to 404
for transformation in self.Flag:
if self.flags & transformation:
assert isinstance(transformation.name, str)
method = getattr(self, f"transform_{transformation.name.lower()}")
transformed_node = method(new_node, **kwargs)
# if the transformation returned `None` it did not apply and we continue.
if transformed_node is not None:
return transformed_node
Copy link
Contributor

Choose a reason for hiding this comment

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

I am a bit confused by this pattern. The first transformation that matches is applied? Because each transformation matches exactly once?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. This should continue transforming.

@tehrengruber tehrengruber requested a review from havogt March 20, 2024 22:55
@havogt
Copy link
Contributor

havogt commented Dec 4, 2024

please re-open if still relevant

@havogt havogt closed this Dec 4, 2024
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