-
Notifications
You must be signed in to change notification settings - Fork 13
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
Extract: Improved region-outlining for complex procedures #412
Conversation
Documentation for this branch can be viewed at https://sites.ecmwf.int/docs/loki/412/index.html |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #412 +/- ##
==========================================
+ Coverage 93.07% 93.09% +0.01%
==========================================
Files 198 198
Lines 39449 39547 +98
==========================================
+ Hits 36719 36817 +98
Misses 2730 2730
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
1987b85
to
657550c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great and is a valuable expansion of functionality over the original stubs!
I've left a few minor comments that would be good to address but no major showstoppers. However, I think we have a duplication between sanitise_imports
and the new utility to remove unused imports.
loki/transformations/remove_code.py
Outdated
@@ -332,3 +337,68 @@ def visit_Import(self, o, **kwargs): | |||
|
|||
rebuilt = tuple(self.visit(i, **kwargs) for i in o.children) | |||
return self._rebuild(o, rebuilt) | |||
|
|||
|
|||
def do_remove_unused_imports(routine): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not redundant to or at least overlapping in functionality with the sanitise_imports
utility? I would prefer if we combined the two somehow.
loki/loki/transformations/utilities.py
Lines 281 to 295 in 83c9ebe
def sanitise_imports(module_or_routine): | |
""" | |
Sanitise imports by removing unused symbols and eliminating imports | |
with empty symbol lists. | |
Note that this is currently limited to imports that are identified to be :class:`Scalar`, | |
:class:`Array`, or :class:`ProcedureSymbol`. | |
""" | |
if isinstance(module_or_routine, Subroutine): | |
find_and_eliminate_unused_imports(module_or_routine) | |
elif isinstance(module_or_routine, Module): | |
used_symbols = set() | |
for routine in module_or_routine.subroutines: | |
used_symbols |= find_and_eliminate_unused_imports(routine) | |
eliminate_unused_imports(module_or_routine, used_symbols) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot had forgotten about the overlap with this. However, the existing utility doesn't work for my use case (and I'd argue Transformer
-based is better), but this certainly looks like something that deserves its own PR. If you don't mind, I'll drop this in a local rebase?
This now allows us to call outlining extraction on a single pragma region, while the overarching utility uses this in its own pragma loop.
Need to explicit give an empty tuple for kwargument when creating the CallStatement, as dataflow analysis will iterate it.
…lining Co-authored-by: Balthasar Reuter <[email protected]>
7b53b7e
to
66995cf
Compare
@reuterbal Ok, I've rebased out the import sanitisation utility for now and addressed all other comments in the top two commits, as we as a fresh rebase over main. Please have another look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, looks good.
I agree on the better implementation of the import sanitisation and happy to sort out the overlap separately!
This change brings various improvements to enable the use of
outine_pragma_regions
for more complex code regions. This is intended to eventually allow us to combine pragma-based extraction with auto-parallelisation to re-rewrite complex control-flow sections.In particular, this PR refactors the utility structure to allow invocations per-region, deals with derived type symbols and arguments, and imposes an ordering on extracted argument signatures. There are also other small improvements added, as well as a utility to remove unused imports and import symbols.
In more detail:
Transformer
, instead of the more complexNestedMaskedTransformer
to replacePragmaRegion
nodes