Skip to content

Commit

Permalink
inline and sequence association tests in single column transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfhm committed Nov 10, 2023
1 parent 8f069d5 commit 95e9cbf
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions transformations/tests/test_single_column_coalesced.py
Original file line number Diff line number Diff line change
Expand Up @@ -1721,3 +1721,85 @@ def test_single_column_coalesced_vector_section_trim_complex(frontend, horizonta
else:
assert assign in loop.body
assert(len(FindNodes(Assignment).visit(loop.body)) == 4)


@pytest.mark.parametrize('frontend', available_frontends())
@pytest.mark.parametrize('inline_members', [False, True])
@pytest.mark.parametrize('resolve_sequence_association', [False, True])
def test_single_column_coalesced_inline_and_sequence_association(frontend, horizontal,
inline_members, resolve_sequence_association,
capsys):
"""
Test the combinations of routine inlining and sequence association
"""

fcode_kernel = """
subroutine some_kernel(nlon, start, end)
implicit none
integer, intent(in) :: nlon, start, end
real, dimension(nlon) :: work
call contained_kernel(work(1))
contains
subroutine contained_kernel(work)
implicit none
real, dimension(nlon) :: work
integer :: jl
do jl = start, end
work(jl) = 1.
enddo
end subroutine contained_kernel
end subroutine some_kernel
"""

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

scc_transform = SCCBaseTransformation(horizontal=horizontal,
inline_members=inline_members,
resolve_sequence_association=resolve_sequence_association)

#Not really doing anything for contained routines
if (not inline_members and not resolve_sequence_association):
scc_transform.apply(routine, role='kernel')

assert len(routine.members) == 1
assert not FindNodes(Loop).visit(routine.body)

#Should fail because it can't resolve sequence association
elif (inline_members and not resolve_sequence_association):
with pytest.raises(RuntimeError) as e_info:
scc_transform.apply(routine, role='kernel')
assert(e_info.exconly() ==
'RuntimeError: [Loki::TransformInline] Unable to resolve member subroutine call')

#Check that the call is properly modified
elif (not inline_members and resolve_sequence_association):
scc_transform.apply(routine, role='kernel')

assert len(routine.members) == 1
call = FindNodes(CallStatement).visit(routine.body)[0]
assert fgen(call).lower() == 'call contained_kernel(work(1:nlon))'

#Check that the contained subroutine has been inlined
else:
scc_transform.apply(routine, role='kernel')

assert len(routine.members) == 0

loop = FindNodes(Loop).visit(routine.body)[0]
assert loop.variable == 'jl'
assert loop.bounds == 'start:end'

assign = FindNodes(Assignment).visit(loop.body)[0]
assert fgen(assign).lower() == 'work(jl) = 1.'





0 comments on commit 95e9cbf

Please sign in to comment.