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

Fix SccAnnotate when existing acc pragmas declare a copy category more than once #409

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions loki/transformations/single_column/annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ def find_acc_vars(self, routine, targets):
if not driver_loops:
continue

# When a key is given multiple times, get_pragma_parameters returns a list
# We merge them here into single entries to make our life easier below
parameters = {key: ', '.join(as_tuple(value)) for key, value in parameters.items()}

if (default := parameters.get('default', None)):
if not 'none' in [p.strip().lower() for p in default.split(',')]:
for loop in driver_loops:
Expand Down
17 changes: 10 additions & 7 deletions loki/transformations/single_column/tests/test_scc.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,29 +247,29 @@ def test_scc_annotate_openacc(frontend, horizontal, blocking, acc_data):
INTEGER, INTENT(IN) :: nlon, nz, nb ! Size of the horizontal and vertical
INTEGER, INTENT(IN) :: nproma, nlev ! Aliases of horizontal and vertical sizes
REAL, INTENT(INOUT) :: q(nlon,nz,nb)
REAL :: other_var(nlon)
REAL :: other_var(nlon), more_var(nlon)
INTEGER :: b, start, end

start = 1
end = nlon
{'!$acc data default(present)' if acc_data == 'default' else ''}
{'!$acc data copyin(other_var)' if acc_data == 'copyin' else ''}
{'!$acc data copyin(more_var) copyin(other_var)' if acc_data == 'copyin' else ''}
!
do b=1, nb
call compute_column(start, end, nlon, nproma, nz, q(:,:,b), other_var)
call compute_column(start, end, nlon, nproma, nz, q(:,:,b), other_var, more_var)
end do
!
{'!$acc end data' if acc_data else ''}
END SUBROUTINE column_driver
"""

fcode_kernel = """
SUBROUTINE compute_column(start, end, nlon, nproma, nlev, nz, q, other_var)
SUBROUTINE compute_column(start, end, nlon, nproma, nlev, nz, q, other_var, more_var)
INTEGER, INTENT(IN) :: start, end ! Iteration indices
INTEGER, INTENT(IN) :: nlon, nz ! Size of the horizontal and vertical
INTEGER, INTENT(IN) :: nproma, nlev ! Aliases of horizontal and vertical sizes
REAL, INTENT(INOUT) :: q(nlon,nz)
REAL, INTENT(IN) :: other_var
REAL, INTENT(IN) :: other_var(nlon), more_var(nlon)
REAL :: t(nlon,nz)
REAL :: a(nlon)
REAL :: d(nproma)
Expand Down Expand Up @@ -317,7 +317,7 @@ def test_scc_annotate_openacc(frontend, horizontal, blocking, acc_data):
assert pragmas[0].keyword == 'acc'
assert pragmas[0].content == 'routine vector'
assert pragmas[1].keyword == 'acc'
assert pragmas[1].content == 'data present(q)'
assert pragmas[1].content == 'data present(q, other_var, more_var)'
assert pragmas[-1].keyword == 'acc'
assert pragmas[-1].content == 'end data'

Expand All @@ -338,7 +338,10 @@ def test_scc_annotate_openacc(frontend, horizontal, blocking, acc_data):
if acc_data:
assert driver_loops[0].pragma[0].content == 'parallel loop gang vector_length(nlon)'
else:
assert driver_loops[0].pragma[0].content == 'parallel loop gang private(other_var) vector_length(nlon)'
assert driver_loops[0].pragma[0].content in (
'parallel loop gang private(other_var, more_var) vector_length(nlon)',
'parallel loop gang private(more_var, other_var) vector_length(nlon)'
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] Curious, why would the ordering go off here? Should this not be deterministic?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well spotted! 🦅 - 👁️
I was wondering the same and I suspect it is here:

private_arrays = ', '.join(set(v.name for v in arrays if not v.name_parts[0].lower() in acc_vars))

We could replace this by

 private_arrays = ', '.join(dict.from_keys(v.name for v in arrays if not v.name_parts[0].lower() in acc_vars))

to have a stable sort but unique list. But didn't want to piggy-back this in this hotfix PR

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ahhh yes. I think I've fixed this in one of my dev branches. Not urgent now, this will happen one way or another, I think.

)


@pytest.mark.parametrize('frontend', available_frontends())
Expand Down
Loading