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

SCC: Add vectorisation annotations in SCCRevector and translate in SCCAnnotate #359

Merged
merged 12 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
6 changes: 3 additions & 3 deletions loki/transformations/block_index_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from loki.transformations.sanitise import resolve_associates
from loki.transformations.utilities import (
recursive_expression_map_update, get_integer_variable,
get_loop_bounds, check_routine_pragmas
get_loop_bounds, check_routine_sequential
)
from loki.transformations.single_column.base import SCCBaseTransformation

Expand Down Expand Up @@ -246,8 +246,8 @@ def process_kernel(self, routine, item, successors, targets, exclude_arrays):
v_index = get_integer_variable(routine, name=self.horizontal.index)
SCCBaseTransformation.resolve_masked_stmts(routine, loop_variable=v_index)

# Bail if routine is marked as sequential or routine has already been processed
if check_routine_pragmas(routine, directive=None):
# Bail if routine is marked as sequential
if check_routine_sequential(routine):
return

bounds = get_loop_bounds(routine, self.horizontal)
Expand Down
285 changes: 104 additions & 181 deletions loki/transformations/single_column/annotate.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions loki/transformations/single_column/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from loki.transformations.sanitise import resolve_associates
from loki.transformations.utilities import (
get_integer_variable, get_loop_bounds, check_routine_pragmas
get_integer_variable, get_loop_bounds, check_routine_sequential
)


Expand Down Expand Up @@ -164,7 +164,7 @@ def process_kernel(self, routine):
"""

# Bail if routine is marked as sequential or routine has already been processed
if check_routine_pragmas(routine, self.directive):
if check_routine_sequential(routine):
return

# Bail if routine is elemental
Expand Down
55 changes: 45 additions & 10 deletions loki/transformations/single_column/tests/test_scc.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ def test_scc_annotate_openacc(frontend, horizontal, blocking):
scc_transform = (SCCDevectorTransformation(horizontal=horizontal),)
scc_transform += (SCCDemoteTransformation(horizontal=horizontal),)
scc_transform += (SCCRevectorTransformation(horizontal=horizontal),)
scc_transform += (SCCAnnotateTransformation(horizontal=horizontal,
directive='openacc', block_dim=blocking),)
scc_transform += (SCCAnnotateTransformation(directive='openacc', block_dim=blocking),)
for transform in scc_transform:
transform.apply(driver, role='driver', targets=['compute_column'])
transform.apply(kernel, role='kernel')
Expand Down Expand Up @@ -407,9 +406,7 @@ def test_scc_nested(frontend, horizontal, blocking):
scc_pipeline.apply(inner_kernel, role='kernel')

# Apply annotate twice to test bailing out mechanism
scc_annotate = SCCAnnotateTransformation(
horizontal=horizontal, directive='openacc', block_dim=blocking
)
scc_annotate = SCCAnnotateTransformation(directive='openacc', block_dim=blocking)
scc_annotate.apply(driver, role='driver', targets=['compute_column'])
scc_annotate.apply(outer_kernel, role='kernel', targets=['compute_q'])
scc_annotate.apply(inner_kernel, role='kernel')
Expand Down Expand Up @@ -753,9 +750,10 @@ def test_scc_multiple_acc_pragmas(frontend, horizontal, blocking):


@pytest.mark.parametrize('frontend', available_frontends())
def test_scc_base_routine_seq_pragma(frontend, horizontal):
def test_scc_annotate_routine_seq_pragma(frontend, horizontal, blocking):
"""
Test that `!$loki routine seq` pragmas are replaced correctly by `!$acc routine seq` pragmas.
Test that `!$loki routine seq` pragmas are replaced correctly by
`!$acc routine seq` pragmas.
"""

fcode = """
Expand All @@ -764,8 +762,8 @@ def test_scc_base_routine_seq_pragma(frontend, horizontal):

integer, intent(in) :: nang
real, dimension(nang), intent(inout) :: work
!$loki routine seq
integer :: k
!$loki routine seq

do k=1,nang
work(k) = 1.
Expand All @@ -776,20 +774,57 @@ def test_scc_base_routine_seq_pragma(frontend, horizontal):

routine = Subroutine.from_source(fcode, frontend=frontend)

pragmas = FindNodes(Pragma).visit(routine.spec)
pragmas = FindNodes(Pragma).visit(routine.ir)
assert len(pragmas) == 1
assert pragmas[0].keyword == 'loki'
assert pragmas[0].content == 'routine seq'

transformation = SCCBaseTransformation(horizontal=horizontal, directive='openacc')
transformation = SCCAnnotateTransformation(directive='openacc', block_dim=blocking)
transformation.transform_subroutine(routine, role='kernel', targets=['some_kernel',])

# Ensure the routine pragma is in the first pragma in the spec
pragmas = FindNodes(Pragma).visit(routine.spec)
assert len(pragmas) == 1
assert pragmas[0].keyword == 'acc'
assert pragmas[0].content == 'routine seq'


@pytest.mark.parametrize('frontend', available_frontends())
def test_scc_annotate_empty_data_clause(frontend, horizontal, blocking):
"""
Test that we do not generate empty `!$acc data` clauses.
"""

fcode = """
subroutine some_kernel(n)
implicit none
! Scalars should not show up in `!$acc data` clause
integer, intent(inout) :: n
!$loki routine seq
integer :: k

k = n
do k=1, 3
n = k + 1.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this not be an integer literal 1?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, it should. Fixed now

enddo
end subroutine some_kernel
"""
routine = Subroutine.from_source(fcode, frontend=frontend)

pragmas = FindNodes(Pragma).visit(routine.ir)
assert len(pragmas) == 1
assert pragmas[0].keyword == 'loki'
assert pragmas[0].content == 'routine seq'

transformation = SCCAnnotateTransformation(directive='openacc', block_dim=blocking)
transformation.transform_subroutine(routine, role='kernel', targets=['some_kernel',])

# Ensure the routine pragma is in the first pragma in the spec
pragmas = FindNodes(Pragma).visit(routine.ir)
assert len(pragmas) == 1
assert pragmas[0].keyword == 'acc'
assert pragmas[0].content == 'routine seq'


@pytest.mark.parametrize('frontend', available_frontends())
def test_scc_vector_reduction(frontend, horizontal, blocking):
Expand Down
4 changes: 1 addition & 3 deletions loki/transformations/single_column/tests/test_scc_hoist.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ def test_scc_hoist_multiple_kernels_loops(tmp_path, frontend, trim_vector_sectio
transformation += (SCCDevectorTransformation(horizontal=horizontal, trim_vector_sections=trim_vector_sections),)
transformation += (SCCDemoteTransformation(horizontal=horizontal),)
transformation += (SCCRevectorTransformation(horizontal=horizontal),)
transformation += (SCCAnnotateTransformation(
horizontal=horizontal, directive='openacc', block_dim=blocking,
),)
transformation += (SCCAnnotateTransformation(directive='openacc', block_dim=blocking),)
for transform in transformation:
scheduler.process(transformation=transform)

Expand Down
Loading
Loading