Skip to content

Commit

Permalink
Merge pull request #125 from ecmwf-ifs/naml-scc-more-trafo-logging
Browse files Browse the repository at this point in the history
SCC: Better logging and warning for "bad" code constructs
  • Loading branch information
reuterbal authored Aug 31, 2023
2 parents cf5c2c6 + 6098cdb commit 3846c67
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion loki/transform/transform_array_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,4 @@ def demote_variables(routine, variable_names, dimensions):
)
routine.spec = Transformer(decl_map).visit(routine.spec)

info(f'[Loki] {routine.name}:: demoted variable(s): {", ".join(variable_names)}')
info(f'[Loki::Transform] Demoted variables in {routine.name}: {", ".join(variable_names)}')
23 changes: 18 additions & 5 deletions transformations/transformations/single_column_coalesced.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ def kernel_annotate_vector_loops_openacc(cls, routine, horizontal, vertical):
private_arrays = [v for v in private_arrays if not any(vertical.size in d for d in v.shape)]
private_arrays = [v for v in private_arrays if not any(horizontal.size in d for d in v.shape)]

if private_arrays:
# Log private arrays in vector regions, as these can impact performance
info(
f'[Loki-SCC::Annotate] Marking private arrays in {routine.name}: '
f'{[a.name for a in private_arrays]}'
)

mapper = {}
with pragma_regions_attached(routine):
for region in FindNodes(PragmaRegion).visit(routine.body):
Expand Down Expand Up @@ -359,6 +366,12 @@ def kernel_annotate_sequential_loops_openacc(cls, routine, horizontal):
# Perform pragma addition in place to avoid nested loop replacements
loop._update(pragma=(ir.Pragma(keyword='acc', content='loop seq'),))

# Warn if we detect vector insisde sequential loop nesting
nested_loops = FindNodes(ir.Loop).visit(loop.body)
loop_pragmas = flatten(as_tuple(l.pragma) for l in as_tuple(nested_loops))
if any('loop vector' in pragma.content for pragma in loop_pragmas):
info(f'[Loki-SCC::Annotate] Detected vector loop in sequential loop in {routine.name}')

@classmethod
def kernel_annotate_subroutine_present_openacc(cls, routine):
"""
Expand All @@ -382,12 +395,12 @@ def kernel_annotate_subroutine_present_openacc(cls, routine):
@classmethod
def insert_annotations(cls, routine, horizontal, vertical, hoist_column_arrays):

# Mark all non-parallel loops as `!$acc loop seq`
cls.kernel_annotate_sequential_loops_openacc(routine, horizontal)

# Mark all parallel vector loops as `!$acc loop vector`
cls.kernel_annotate_vector_loops_openacc(routine, horizontal, vertical)

# Mark all non-parallel loops as `!$acc loop seq`
cls.kernel_annotate_sequential_loops_openacc(routine, horizontal)

# Wrap the routine body in `!$acc data present` markers
# to ensure device-resident data is used for array and struct arguments.
cls.kernel_annotate_subroutine_present_openacc(routine)
Expand Down Expand Up @@ -712,8 +725,8 @@ def hoist_temporary_column_arrays(cls, routine, call, horizontal, vertical, bloc
) for v in column_locals]
new_call = call.clone(arguments=call.arguments + as_tuple(new_args))

info(f'[Loki-SCC] Hoisted variables in call {routine.name} => {call.name}:'
f'{[v.name for v in column_locals]}')
info(f'[Loki-SCC::Hoist] Hoisted variables in call {routine.name} => {call.name}:'
f'{", ".join(v.name for v in column_locals)}')

# Find the iteration index variable for the specified horizontal
v_index = SCCBaseTransformation.get_integer_variable(routine, name=horizontal.index)
Expand Down

0 comments on commit 3846c67

Please sign in to comment.