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 vector section trimming in driver loop #169

Merged
merged 2 commits into from
Oct 12, 2023
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
23 changes: 20 additions & 3 deletions transformations/tests/test_single_column_coalesced.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ def test_scc_hoist_multiple_kernels(frontend, horizontal, vertical, blocking):


@pytest.mark.parametrize('frontend', available_frontends())
def test_scc_hoist_multiple_kernels_loops(frontend, horizontal, vertical, blocking):
@pytest.mark.parametrize('trim_vector_sections', [True, False])
def test_scc_hoist_multiple_kernels_loops(frontend, trim_vector_sections, horizontal, vertical, blocking):
"""
Test hoisting of column temporaries to "driver" level.
"""
Expand All @@ -429,7 +430,6 @@ def test_scc_hoist_multiple_kernels_loops(frontend, horizontal, vertical, blocki
!$loki driver-loop
do b=1, nb
end = nlon - nb
!$loki separator
do jk = 2, nz
do jl = start, end
q(jl, jk, b) = 2.0 * jk * jl
Expand Down Expand Up @@ -523,7 +523,7 @@ def test_scc_hoist_multiple_kernels_loops(frontend, horizontal, vertical, blocki
kernel = scheduler.item_map["kernel_mod#kernel"].routine

transformation = (SCCBaseTransformation(horizontal=horizontal, directive='openacc'),)
transformation += (SCCDevectorTransformation(horizontal=horizontal, trim_vector_sections=False),)
transformation += (SCCDevectorTransformation(horizontal=horizontal, trim_vector_sections=trim_vector_sections),)
transformation += (SCCDemoteTransformation(horizontal=horizontal),)
transformation += (SCCRevectorTransformation(horizontal=horizontal),)
transformation += (SCCAnnotateTransformation(
Expand Down Expand Up @@ -567,6 +567,16 @@ def test_scc_hoist_multiple_kernels_loops(frontend, horizontal, vertical, blocki
assert driver_loops[2].variable == 'jk'
assert driver_loops[2].bounds == '2:nz'

# check location of loop-bound assignment
assign = FindNodes(Assignment).visit(driver_loops[0])[0]
assert assign.lhs == 'end'
assert assign.rhs == 'nlon-nb'
assigns = FindNodes(Assignment).visit(driver_loops[1])
if trim_vector_sections:
assert not assign in assigns
else:
assert assign in assigns

assert driver_loops[4] in FindNodes(Loop).visit(driver_loops[3].body)
assert driver_loops[5] in FindNodes(Loop).visit(driver_loops[3].body)
assert driver_loops[6] in FindNodes(Loop).visit(driver_loops[3].body)
Expand Down Expand Up @@ -596,6 +606,13 @@ def test_scc_hoist_multiple_kernels_loops(frontend, horizontal, vertical, blocki
assert driver_loops[10].variable == 'jk'
assert driver_loops[10].bounds == '2:nz'

# check location of loop-bound assignment
assign = FindNodes(Assignment).visit(driver_loops[8])[0]
assert assign.lhs == 'end'
assert assign.rhs == 'nlon-nb'
assigns = FindNodes(Assignment).visit(driver_loops[9])
assert not assign in assigns

rmtree(basedir)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def process_driver(self, routine, targets=()):
new_driver_loop = loop.clone(body=new_driver_loop)
sections = self.extract_vector_sections(new_driver_loop.body, self.horizontal)
if self.trim_vector_sections:
sections = self.get_trimmed_sections(routine, self.horizontal, sections)
sections = self.get_trimmed_sections(new_driver_loop, self.horizontal, sections)
section_mapper = {s: ir.Section(body=s, label='vector_section') for s in sections}
new_driver_loop = NestedTransformer(section_mapper).visit(new_driver_loop)
driver_loop_map[loop] = new_driver_loop
Expand Down