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

Block-index injection transformations #303

Merged
merged 37 commits into from
May 28, 2024
Merged

Conversation

awnawab
Copy link
Contributor

@awnawab awnawab commented Apr 29, 2024

In order to mitigate the cost of creating thread-local copies of data structures, per-block views of fields can be replaced with full field views and the block-index can be inserted into the field pointer.

This is achieved via two transformations:

  • BlockViewToFieldViewTransformation: A very IFS specific transformation that simply replaces per-block view pointers with full field pointers. It also injects the missing type definitions for FIELD_RANKSUFF_ARRAY types.
  • BlockIndexInjectTransformation: A general transformation that injects the block-index to all arrays that have a local rank one less than their declared rank

Copy link

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

Copy link

codecov bot commented Apr 29, 2024

Codecov Report

Attention: Patch coverage is 99.03537% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 95.14%. Comparing base (f3e7d90) to head (6707094).

Files Patch % Lines
...oki/transformations/block_index_transformations.py 98.70% 2 Missing ⚠️
...i/transformations/tests/test_block_index_inject.py 98.97% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #303      +/-   ##
==========================================
+ Coverage   95.12%   95.14%   +0.02%     
==========================================
  Files         165      167       +2     
  Lines       35143    35374     +231     
==========================================
+ Hits        33429    33656     +227     
- Misses       1714     1718       +4     
Flag Coverage Δ
lint_rules 96.38% <ø> (-0.02%) ⬇️
loki 95.12% <99.03%> (+0.02%) ⬆️

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

@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.

Really nice! And I just started to implement some transformation/utilities on top of/utilising the BlockIndexInjectTransformation without encountering any problem.

Nevertheless, some comments regarding some typos and questions/suggestions (probably because I have not fully understood the BlockViewToFieldViewTransformation)

cmake/loki_transform.cmake Outdated Show resolved Hide resolved
transformations/tests/test_block_index_inject.py Outdated Show resolved Hide resolved
paths=(blockview_to_fieldview_code[0],), config=config, seed_routines='driver', frontend=frontend
)
scheduler.process(BlockViewToFieldViewTransformation(horizontal, global_gfl_ptr=True))
scheduler.process(BlockIndexInjectTransformation(blocking))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could/should we add some tests/assertions to test the result/output of BlockViewToFieldViewTransformation before applying BlockIndexInjectTransformation? Like this only the combination of both transformation is tested?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, and I'll also use those tests to mop-up the missing lines highlighted by the coverage report. Thanks!

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.

First of all, apologies for the delay in reviewing this.

Many thanks, this looks great and I like the structure with the split into two transformation steps to separate generic and specific functionality.

I've left quite a few comments, some are already a couple of days old and therefore might be outdated by now, but they are mostly about details or documentation.

scripts/loki_transform.py Outdated Show resolved Hide resolved

# First get rank mismatched call statement args
vmap = {}
for call in [call for call in FindNodes(ir.CallStatement).visit(body) if call.name in targets]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
for call in [call for call in FindNodes(ir.CallStatement).visit(body) if call.name in targets]:
for call in FindNodes(ir.CallStatement).visit(body):
if call.name in targets:

loki/transformations/block_index_transformations.py Outdated Show resolved Hide resolved
@awnawab awnawab force-pushed the naan-block-index-inject branch 3 times, most recently from f7153f9 to cd8eed3 Compare May 11, 2024 16:50
@awnawab
Copy link
Contributor Author

awnawab commented May 13, 2024

Thanks again @reuterbal for the derived-type enrichment fix 🙏

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! Sorry for the kerfuffle around enrichment but I'm glad this solution works as I had a suspicion this was a symptom of an underlying bug.

@awnawab awnawab requested a review from mlange05 May 25, 2024 20:37
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.

Very happy with this overall, so GTG from me.

I left a few comments about overall structure of the transformations sub-package, but these are merely meant as commentary, as this change highlights the need for further restructuring.


# Sanitize the subroutine
resolve_associates(routine)
v_index = SCCBaseTransformation.get_integer_variable(routine, name=self.horizontal.index)
Copy link
Collaborator

Choose a reason for hiding this comment

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

[no action] Note to self, these should be separated out into general utilities. The fact that this field trafo is calling into the SCC stack signals the problem.

parent = self.build_ydvars_global_gfl_ptr(parent)

_type = var.type
if 'gfl_ptr' in var.basename.lower():
Copy link
Collaborator

Choose a reason for hiding this comment

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

[no action] This is extremely bespoke to (potentially changing) IFS conventions, which is absolutely fine for now. In the future we will likely need to factor out bespoke "IFS Fields" transformations into a separate sub-package, as we add more to these.

@reuterbal reuterbal merged commit 77114a9 into main May 28, 2024
12 checks passed
@reuterbal reuterbal deleted the naan-block-index-inject branch May 28, 2024 12:47
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