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

Enable inlining of a subroutine with an array subrange in an argument #484

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

awnawab
Copy link
Contributor

@awnawab awnawab commented Feb 5, 2025

A small fix to the inlining trafo that enables inlining of calls where we pass a subrange of an array argument, i.e.:

real :: a(8)

!$loki inline
call kernel(a(5:8)

....

subroutine kernel
real, intent(in) :: a(4)

Copy link

github-actions bot commented Feb 5, 2025

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

@awnawab awnawab changed the title Enable passing a subrange of an array argument Enable inlining of a subroutine with an array subrange in an argument Feb 5, 2025
@awnawab awnawab force-pushed the naan-inline-array-arg branch from 0bbdfb3 to 2945b63 Compare February 5, 2025 20:52
@awnawab awnawab force-pushed the naan-inline-array-arg branch from 2945b63 to a341e11 Compare February 6, 2025 08:27
Copy link

codecov bot commented Feb 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.17%. Comparing base (48c5cbf) to head (fe9e1e7).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #484   +/-   ##
=======================================
  Coverage   96.17%   96.17%           
=======================================
  Files         224      224           
  Lines       40386    40371   -15     
=======================================
- Hits        38842    38828   -14     
+ Misses       1544     1543    -1     
Flag Coverage Δ
lint_rules 96.39% <ø> (ø)
loki 96.17% <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.

@awnawab awnawab marked this pull request as ready for review February 6, 2025 09:42
@awnawab awnawab requested review from mlange05 and reuterbal February 6, 2025 09:42
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 great and very useful. I've flagged a few corner cases, that I think we want to cover in the tests to avoid future debug pain. Otherwise great, many thanks! 🙏 (I might just steal that for the associate resolve some time. 😉 )

real(kind=8) :: tmp(m)
integer :: i

tmp(1:m) = x
do i=1, n
a(i) = b(i) + sum(tmp)
end do
do i=1,4
c(i) = 0.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we add an assignment d(i) = 1. here too, to check that this index is shifted too?

use BNDS_module, only: n, m
use another_module, only: x

real(kind=8), intent(inout) :: a(n), b(n)
real(kind=8), intent(out) :: c(4), d(4)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens to real, intent(inout) :: e(0:3) in the two cases below? Could we add a test for this too, just to cover our bases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was indeed a corner case I'd missed, thanks!

new_dimensions[indices[index]] = dim
# if the argument contains an array range, we must map the bounds accordingly
if isinstance(val.dimensions[index], sym.Range) and (lower := val.dimensions[index].lower):
if isinstance(dim, sym.Range):
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, there's a similar index-shifting problem in the associate resolver. We could possibly re-use a shared utility for this if we were to externalise this? This is beyond this PR tho.

@awnawab awnawab force-pushed the naan-inline-array-arg branch from c8f3482 to 8ab97d7 Compare February 6, 2025 15:02
@awnawab awnawab force-pushed the naan-inline-array-arg branch from 8ab97d7 to 98ca42b Compare February 6, 2025 15:07
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, this looks great!

@awnawab
Copy link
Contributor Author

awnawab commented Feb 18, 2025

Please wait to merge this, I think I've missed the edge case where we are passing a subrange of a dimension and there are different lbounds for the argument and dummy. I'll confirm today and push a fix + test if necessary.

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