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

Fixes to minor issues related to SCC HOIST #211

Merged
merged 7 commits into from
Jan 24, 2024

Conversation

skarppinen
Copy link
Contributor

Hello.

This PR contains two very small changes. I discuss them below.

… move sccannotate one step further, to also add acc present statements for scc hoisted arrays
@@ -150,6 +151,8 @@ def transform_subroutine(self, routine, **kwargs):
call_map = CaseInsensitiveDict((str(call.name), call) for call in calls)

for child in successors:
if not isinstance(child, SubroutineItem):
continue
arg_map = dict(call_map[child.local_name].arg_iter())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If SCC HOIST is used together with GlobalVarOffloadTransformation, some of successors may be Items (corresponding to the imported global variables). Therefore, adding this if statement to skip processing for Items other than SubroutineItems. To me, everything here seems to indicate this loop only processes subroutines.

scheduler.process( SCCAnnotateTransformation(
horizontal=horizontal, vertical=vertical, directive=directive, block_dim=block_dim
))

if mode in ['cuf-parametrise', 'cuf-hoist', 'cuf-dynamic']:
Copy link
Contributor Author

@skarppinen skarppinen Jan 17, 2024

Choose a reason for hiding this comment

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

Notice that this change moves the location of SCCAnnotate "one step" further in the SCC pipeline. The reasoning for this is that SCCHoistTemporaryArraysTransformation does the SCC hoisting, introducing new arguments to subroutines, that have to be marked as "present", This change ensures that SCCAnnotate adds these pragmas for the new arguments as well.

I am not sure whether SCCAnnotate should actually be moved after the next if statement even.

Copy link

codecov bot commented Jan 17, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (c86b83a) 92.26% compared to head (a78a296) 92.26%.

Files Patch % Lines
loki/transform/transform_hoist_variables.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #211   +/-   ##
=======================================
  Coverage   92.26%   92.26%           
=======================================
  Files          96       96           
  Lines       17124    17131    +7     
=======================================
+ Hits        15799    15806    +7     
  Misses       1325     1325           
Flag Coverage Δ
lint_rules 96.22% <ø> (+<0.01%) ⬆️
loki 92.24% <66.66%> (-0.01%) ⬇️
transformations 91.51% <ø> (+0.06%) ⬆️

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, this looks great to me.

I let @mlange05 assess whether moving the Annotate transformation is safe to do but in principle I think it would be great to have this later in the pipeline and develop it into a more generic offload annotation mechanism that will eventually be able to take on that duty for other transformations and programming models as well.

Otherwise, I have left two remarks. One of them relates to a suggestion to capture the original issue in the test base to ensure we don't re-introduce that bug in the future.

Comment on lines 236 to 238
scheduler.process( SCCAnnotateTransformation(
horizontal=horizontal, vertical=vertical, directive=directive, block_dim=block_dim
))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we should guard this as before:

Suggested change
scheduler.process( SCCAnnotateTransformation(
horizontal=horizontal, vertical=vertical, directive=directive, block_dim=block_dim
))
if mode in ['scc', 'scc-hoist', 'scc-stack']:
scheduler.process( SCCAnnotateTransformation(
horizontal=horizontal, vertical=vertical, directive=directive, block_dim=block_dim
))

Copy link
Contributor Author

@skarppinen skarppinen Jan 19, 2024

Choose a reason for hiding this comment

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

I agree, this is a good idea. I changed this.

@@ -150,6 +151,8 @@ def transform_subroutine(self, routine, **kwargs):
call_map = CaseInsensitiveDict((str(call.name), call) for call in calls)

for child in successors:
if not isinstance(child, SubroutineItem):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is currently not covered in the test base, which is why this bug existed in the first place.
I would suggest to amend the existing test test_single_column_coalesced_hoist_openacc by moving the integer c to a new module and importing it in the kernel.

Here's an untested implementation suggestion:

fcode_module = """
module my_scaling_value_mod
    implicit none
    REAL :: c = 5.345
end module my_scaling_value_mod
""".strip()

[...]

module_source = Sourcefile.from_source(fcode_module, frontend=frontend)
module = module_source['my_scaling_value_mod']

[...]

kernel.enrich(module) # do this before enriching the driver

[...]

module_item = GlobalVarImportItem(name='my_scaling_value_mod#c', source=module_source)

[...]

    # This replaces the current implementation
    for transform in scc_transform:
        transform.apply(driver, role='driver', item=driver_item, targets=['compute_column'], successors=[kernel_item])
        transform.apply(kernel, role='kernel', item=kernel_item), successors=[module_item])

Copy link
Contributor Author

@skarppinen skarppinen Jan 19, 2024

Choose a reason for hiding this comment

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

Thanks, this was a good idea.

I changed the test to the best of my ability, please check to see it is OK. I had to add the successors argument to the analysis part (a bit later than you suggested). I ran the modified test in the main branch to make sure that it fails there.

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 for the changes and the additional testing. All looks good from my side but I let @mlange05 confirm.

@skarppinen
Copy link
Contributor Author

Thanks for reviewing @reuterbal.

@reuterbal reuterbal added the ready to merge This PR has been approved and is ready to be merged label Jan 23, 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.

Hi, I can confirm this works as expected and is GTG from me. :shipit:

@reuterbal reuterbal merged commit 8fb60c5 into ecmwf-ifs:main Jan 24, 2024
8 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to 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.

3 participants