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

Unroll negative loop bounds and retain pragmas inside unrolled loop body #443

Merged
merged 2 commits into from
Nov 22, 2024

Conversation

awnawab
Copy link
Contributor

@awnawab awnawab commented Nov 21, 2024

This PR provides the following two fixes to the loop unrolling functionality:

  • Unroll loops with negative bounds
  • Retain pragmas inside the unrolled loop body

Copy link

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

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.33%. Comparing base (72d35fb) to head (f723554).
Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #443   +/-   ##
=======================================
  Coverage   93.32%   93.33%           
=======================================
  Files         212      212           
  Lines       40769    40810   +41     
=======================================
+ Hits        38047    38089   +42     
+ Misses       2722     2721    -1     
Flag Coverage Δ
lint_rules 96.39% <ø> (ø)
loki 93.29% <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.


🚨 Try these New Features:

@awnawab
Copy link
Contributor Author

awnawab commented Nov 22, 2024

Can I please push an update here? I've thought of an edge case that would break the updates herein.

@awnawab awnawab force-pushed the naan-loop-unroll-fixes branch from bac536f to 6fae2b4 Compare November 22, 2024 10:33
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 good in principle but I think the pragma handling needs a little improvement

Comment on lines 682 to 683
_pragma = o.pragma if o.pragma and not 'unroll' in o.pragma[0].content.lower() else None
_pragma_post = o.pragma_post if o.pragma_post and not 'unroll' in o.pragma_post[0].content.lower() else None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we always have a tuple for o.pragma/o.pragma_post? (if not, we should for consistency). Are we otherwise certain it will always be the first entry in the pragma list? Also, the plain check for unroll in the text is guaranteed to cause aliasing issues - e.g. in an !$omp parallel do private (funroller)

I would suggest something like this:

Suggested change
_pragma = o.pragma if o.pragma and not 'unroll' in o.pragma[0].content.lower() else None
_pragma_post = o.pragma_post if o.pragma_post and not 'unroll' in o.pragma_post[0].content.lower() else None
_pragma = tuple(
p for p in as_tuple(o.pragma)
if not (p.keyword.lower() == 'loki' and p.content.lower().startswith('loop-urnoll')
) or None
_pragma_post = tuple(
p for p in as_tuple(o.pragma_post)
if not (p.keyword.lower() == 'loki' and p.content.lower().startswith('loop-urnoll')
) or None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, that is indeed much safer! And yup, pragma/pragma_post is always a tuple.

@awnawab awnawab force-pushed the naan-loop-unroll-fixes branch from 6fae2b4 to f723554 Compare November 22, 2024 13:30
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 for taking care of the comment - and I like that you have even further cleaned-up my proposal via the use of pragma utilities!

Also, I should have applauded earlier on how super-clean the implementation: The use of is_constant and get_pyrange is really neat!

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

Looks good to me. :shipit:

@reuterbal reuterbal merged commit de34756 into main Nov 22, 2024
13 checks passed
@reuterbal reuterbal deleted the naan-loop-unroll-fixes branch November 22, 2024 16:51
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