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

Transformations: Move common SCC utility routines to utilities #354

Merged
merged 9 commits into from
Aug 1, 2024

Conversation

mlange05
Copy link
Collaborator

@mlange05 mlange05 commented Jul 29, 2024

Another small housekeeping change. This one adds a new sub-package transformations.single_column.util sub-package for common utilities that may be used across the several SCC sub-stages.

A small housekeeping change that moves utility methods from SCCBaseTransformation to the the common transformations.utilities subpackage. This primarily removes the awkward dependency on the SCCBaseTransformation class in other SCC sub-components, which provided this previously.

This change is largely cosmetic (simply copying methods over), except for the get_local_arrays utility, which is now used by the demotion and the annotations sub-component. This is in preparation for a more complex refactoring of the annotation sub-component to support multiple vectorisation and annotation schemes in a future PR.

@mlange05 mlange05 requested a review from reuterbal July 29, 2024 11:47
Copy link

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

@mlange05 mlange05 marked this pull request as draft July 29, 2024 16:54
@mlange05 mlange05 changed the title Transformations: Add scc.util for common utility routines Transformations: Move common SCC utility routines to utilities Jul 30, 2024
Copy link

codecov bot commented Jul 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.36%. Comparing base (b7ba5fc) to head (3226c32).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #354   +/-   ##
=======================================
  Coverage   95.35%   95.36%           
=======================================
  Files         173      173           
  Lines       36835    36896   +61     
=======================================
+ Hits        35124    35185   +61     
  Misses       1711     1711           
Flag Coverage Δ
lint_rules 96.39% <ø> (ø)
loki 95.34% <100.00%> (+<0.01%) ⬆️

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.

@mlange05 mlange05 marked this pull request as ready for review July 30, 2024 06:43
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, this looks great and removes the indeed awkward cross-referencing to utilities in the Base class, even from outside the SCC transformations.

We should consider creating dedicated tests for these utilities at some point - not mandating this for the PR but maybe create an issue to track this?

Finally, I have paid a little more attention to the new get_local_arrays utility and noticed that we might have a case-sensitivity problem there. Would be good to resolve that (or prove me wrong) before merging.

Flag whether to return unique instances of each symbol;
default: ``False``
"""
arg_names = tuple(a.name for a in routine.arguments)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could use routine._dummies here as a cheaper alternative because routine.arguments

  1. builds routine.symbol_map
  2. runs through routine._dummies to pick out the entries from the symbol_map in the right order

...and then we extract only the names again here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes


# Filter all variables by argument name to get local arrays
arrays = [v for v in variables if isinstance(v, sym.Array)]
arrays = [v for v in arrays if v.name not in arg_names]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like a potential case-sensitivity issue: v.name is a str, therefore we don't have the benefit of the case-agnostic comparison anymore - and if argument declaration doesn't match the casing of an array use, we might run into issues here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well spotted! I pushed a fix and tests for this now.

@mlange05
Copy link
Collaborator Author

mlange05 commented Aug 1, 2024

@reuterbal You are, of course, right about the testing. I've added at least rudimentary test coverage for each utility routine. As part of that I spotted an annoying inconsistency, that I also fixed: get_loop_bounds would simply return strings and leave the symbol resolution to the upstream call. I've now moved this, which makes testing nicer and removes redundancy. So, please take another look.

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, the changes look fantastic and also very much agreed on the change to the return type of get_loop_bounds! Much appreciate the additional testing!

Unless CI throws up some issues this is good to go!

@reuterbal reuterbal merged commit 7d56565 into main Aug 1, 2024
13 checks passed
@reuterbal reuterbal deleted the naml-scc-reshuffle branch August 1, 2024 12:26
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