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

Add DEVICEPTR annotations to data region in driver loop #145

Merged
merged 3 commits into from
Sep 14, 2023

Conversation

awnawab
Copy link
Contributor

@awnawab awnawab commented Sep 7, 2023

A small update to the DataOffload transformation to mark kernel array arguments as true device-pointers and skip address translation via the OpenACC map. This is needed when using the CUDA backend in the new FIELD_API. The new functionality has been tested here: https://github.com/ecmwf-ifs/ecwam/tree/naan-deviceptr.

NB: This is stacked on top of #142.

@github-actions
Copy link

github-actions bot commented Sep 7, 2023

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

@codecov
Copy link

codecov bot commented Sep 7, 2023

Codecov Report

Merging #145 (3ac1f46) into main (ed7e624) will increase coverage by 0.00%.
Report is 24 commits behind head on main.
The diff coverage is 90.90%.

@@           Coverage Diff            @@
##             main     #145    +/-   ##
========================================
  Coverage   92.09%   92.09%            
========================================
  Files          89       90     +1     
  Lines       16537    16664   +127     
========================================
+ Hits        15229    15347   +118     
- Misses       1308     1317     +9     
Flag Coverage Δ
lint_rules 96.22% <ø> (ø)
loki 92.04% <ø> (+0.01%) ⬆️
transformations 91.47% <90.90%> (-0.03%) ⬇️

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

Files Changed Coverage Δ
transformations/transformations/data_offload.py 92.85% <90.90%> (-0.25%) ⬇️

... and 2 files with indirect coverage changes

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.

Very nicely done and useful addition, many thanks!

Only real remark is related to naming: I'd prefer a marginally more descriptive naming of that option all the way through from CMake to transformation constructor. Suggestion would be something like assume_deviceptr but better variants do probably exist.

@@ -27,13 +27,17 @@ class DataOffloadTransformation(Transformation):
----------
remove_openmp : bool
Remove any existing OpenMP pragmas inside the marked region.
deviceptr : bool
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a little hard to judge from the brief option name what that implies. I would propose to follow the typical "start with a verb" naming scheme, e.g., by calling this assume_deviceptr? That implies imho also the requirement this imposes on the calling code to handle the offload.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seconded, either assume_deviceptr or use_deviceptr or mark_as_deviceptr (or similar). And ideally propagate change up to cmake layer (explicit is better than implicit 😉 )

Comment on lines 141 to 145
if self.deviceptr:
deviceptr = ''
if inargs+outargs+inoutargs:
deviceptr = f'deviceptr({", ".join(inargs+outargs+inoutargs)})'
pragma = Pragma(keyword='acc', content=f'data {deviceptr}')
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
if self.deviceptr:
deviceptr = ''
if inargs+outargs+inoutargs:
deviceptr = f'deviceptr({", ".join(inargs+outargs+inoutargs)})'
pragma = Pragma(keyword='acc', content=f'data {deviceptr}')
if self.deviceptr:
offload_args = inargs + outargs + inoutargs
if offload_args:
deviceptr = f' deviceptr({", ".join(offload_args)})'
else:
deviceptr = ''
pragma = Pragma(keyword='acc', content=f'data{deviceptr}')

Purely a matter of taste, but I find this a little hard to read with the repeated contracted "sum".

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seconded (but yes, matter of taste), spaces around operators used to be a pylint rule (for a reason).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seconded (but yes, matter of taste), spaces around operators used to be a pylint rule (for a reason).

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.

I Agree with all of the previous suggestions, but otherwise GTG. I've not tested this explicitly with any regression tests, but might try CLOUDSC later myself. This should not stop this being merged tho, so GTG from me. :shipit:

Comment on lines 141 to 145
if self.deviceptr:
deviceptr = ''
if inargs+outargs+inoutargs:
deviceptr = f'deviceptr({", ".join(inargs+outargs+inoutargs)})'
pragma = Pragma(keyword='acc', content=f'data {deviceptr}')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seconded (but yes, matter of taste), spaces around operators used to be a pylint rule (for a reason).

Comment on lines 141 to 145
if self.deviceptr:
deviceptr = ''
if inargs+outargs+inoutargs:
deviceptr = f'deviceptr({", ".join(inargs+outargs+inoutargs)})'
pragma = Pragma(keyword='acc', content=f'data {deviceptr}')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seconded (but yes, matter of taste), spaces around operators used to be a pylint rule (for a reason).

@@ -27,13 +27,17 @@ class DataOffloadTransformation(Transformation):
----------
remove_openmp : bool
Remove any existing OpenMP pragmas inside the marked region.
deviceptr : bool
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seconded, either assume_deviceptr or use_deviceptr or mark_as_deviceptr (or similar). And ideally propagate change up to cmake layer (explicit is better than implicit 😉 )

@awnawab
Copy link
Contributor Author

awnawab commented Sep 13, 2023

Thanks for the feedback @mlange05 and @reuterbal! I'll implement your recommendations later today. @mlange05 re trying this on CLOUDSC, you can see an example of this in action here: https://github.com/ecmwf-ifs/ecwam/tree/naan-deviceptr.

@awnawab awnawab force-pushed the naan-deviceptr branch 2 times, most recently from c968f52 to b972d49 Compare September 13, 2023 13:31
@@ -27,13 +27,17 @@ class DataOffloadTransformation(Transformation):
----------
remove_openmp : bool
Remove any existing OpenMP pragmas inside the marked region.
assume_deviceptr : bool
Copy link
Collaborator

Choose a reason for hiding this comment

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

Docstring and actual argument are out of sync here now. Can we call the argument assume_deviceptr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another silly oversight. Thanks for spotting this!

@@ -92,6 +92,8 @@ def cli(debug):
help='Run transformation to insert custom data offload regions.')
@click.option('--remove-openmp', is_flag=True, default=False,
help='Removes existing OpenMP pragmas in "!$loki data" regions.')
@click.option('--assume_deviceptr', is_flag=True, default=False,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think so far we used hyphen instead of underscore for options on the CLI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch! Corrected 👍

@awnawab awnawab force-pushed the naan-deviceptr branch 2 times, most recently from 22d6e7a to a41f639 Compare September 13, 2023 15:19
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.

Waiting for CI to confirm but looks good to me now. Many thanks for applying the renaming and apologies that this has turned into such a rat's tail of driving the renaming through the layers...

@reuterbal reuterbal merged commit 2322c1b into main Sep 14, 2023
12 checks passed
@reuterbal reuterbal deleted the naan-deviceptr branch September 14, 2023 08:02
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.

3 participants