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

SCCHoist: hoist inline call temporaries and don't hoist statically declared arrays #268

Merged
merged 4 commits into from
Apr 12, 2024

Conversation

awnawab
Copy link
Contributor

@awnawab awnawab commented Apr 2, 2024

This PR adds the capability to hoist temporaries declared in inline function calls. It also changes the default behaviour so that statically declared arrays are no longer hoisted.

Copy link

github-actions bot commented Apr 2, 2024

Documentation for this branch can be viewed at https://sites.ecmwf.int/docs/loki/268/index.html

Copy link
Collaborator

@MichaelSt98 MichaelSt98 left a comment

Choose a reason for hiding this comment

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

Thanks, the "inline call part" seems to have been missing indeed.
Further, the solution/new default via is_dimension_constant seems reasonable.

else:
new_args = tuple(v.clone(dimensions=None) for v in variables)
vmap = {call: call.clone(parameters=call.parameters + new_args)}
routine.body = SubstituteExpressions(vmap).visit(routine.body)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could move routine.body = SubstituteExpressions(vmap).visit(routine.body) outside the if/else statement ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, good spot, thanks!

Copy link

codecov bot commented Apr 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.88%. Comparing base (9aa9a37) to head (a72eb67).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #268   +/-   ##
=======================================
  Coverage   92.88%   92.88%           
=======================================
  Files         102      102           
  Lines       18253    18270   +17     
=======================================
+ Hits        16954    16971   +17     
  Misses       1299     1299           
Flag Coverage Δ
lint_rules 96.39% <ø> (ø)
loki 92.86% <100.00%> (+<0.01%) ⬆️
transformations 92.22% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@reuterbal reuterbal left a comment

Choose a reason for hiding this comment

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

Thanks, nice find and great fix. There seems to be a typo in the implementation, though, which suggests a shortfall in testing. I think it would be good to expand testing to cover that.

Comment on lines 367 to 369
new_args = dict((a.name, v.clone(dimensions=None)) for (a, v) in variables)
_call_clone = call.clone(kwparameters=call.kw_parameters)
_call_clone.kw_parameters.update(new_args)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find this pattern of in-place updating the call attribute a little weird, particularly since we expect to only add new kwargs to the end. Wouldn't something more similar to the other argument_remapping method be a little more intuitive?

Also, the clone call has a typo (kwparameters vs. kw_parameters), which suggests we don't have a test with existing kw_parameters :) Could you add one for that?

Suggested change
new_args = dict((a.name, v.clone(dimensions=None)) for (a, v) in variables)
_call_clone = call.clone(kwparameters=call.kw_parameters)
_call_clone.kw_parameters.update(new_args)
kw_params = call.kw_parameters
kw_params += tuple((a.name, v.clone(dimensions=None)) for (a, v) in variables)
_call_clone = call.clone(kwparameters=dict(kw_params))

Copy link
Collaborator

@reuterbal reuterbal left a comment

Choose a reason for hiding this comment

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

Many thanks, this looks great now!

@reuterbal reuterbal added the ready for merge This PR has been approved and is ready to be merged label Apr 11, 2024
Copy link
Collaborator

@mlange05 mlange05 left a comment

Choose a reason for hiding this comment

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

Only had a brief looks, but LGTM. :shipit:

@@ -240,7 +243,7 @@ def transform_subroutine(self, routine, **kwargs):
routine.arguments += hoisted_temporaries

call_map = {}
for call in FindNodes(CallStatement).visit(routine.body):
for call in FindNodes(CallStatement).visit(routine.body) + list(FindInlineCalls().visit(routine.body)):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Both of these should return tuples, I think. Better to fix the return of the visitor than to cast here, no? Or am I missing something?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We have a bit of a mismatch there, something we should clean up separately:

  • FindNodes has indeed always returned lists. Since these are built incrementally and can be quite long, there could indeed a performance impact from using tuples
  • Expression visitors return by default sets, unless unique=False is used.

@reuterbal reuterbal merged commit 1cc3701 into main Apr 12, 2024
12 checks passed
@reuterbal reuterbal deleted the naan-scc-hoist branch April 12, 2024 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for merge This PR has been approved and is ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants