Skip to content

Commit

Permalink
SCCFuseVerticalLoops: introduce new arg 'apply_to' to possibly restri…
Browse files Browse the repository at this point in the history
…ct routines this transformation is applied to
  • Loading branch information
MichaelSt98 committed Oct 8, 2024
1 parent a60a10e commit 829e214
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions loki/transformations/single_column/tests/test_scc_vertical.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ def test_simple_scc_fuse_verticals_transformation(frontend, horizontal, vertical
kernel_loops = FindNodes(Loop).visit(kernel.body)
assert len(kernel_loops) == 5

# no-op as 'compute_column' is not within apply_to
SCCFuseVerticalLoops(vertical=vertical, apply_to=('another_kernel',)).apply(kernel, role='kernel')
# Ensure we have three loops in the kernel prior to transformation
kernel_loops = FindNodes(Loop).visit(kernel.body)
assert len(kernel_loops) == 5

# actual loop fusion and demotion ... (as apply_to is not provided and therefore all routines are dispatched)
SCCFuseVerticalLoops(vertical=vertical).apply(kernel, role='kernel')

# Ensure the two vertical loops are fused
Expand Down
8 changes: 7 additions & 1 deletion loki/transformations/single_column/vertical.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ class SCCFuseVerticalLoops(Transformation):
vertical : :any:`Dimension`
:any:`Dimension` object describing the variable conventions used in code
to define the vertical data dimension and iteration space.
apply_to : list of str, optional
list of routines to apply this transformation to, if not provided or None
apply to all routines (default: None)
"""

def __init__(self, vertical=None):
def __init__(self, vertical=None, apply_to=None):
self.vertical = vertical
self.apply_to = apply_to or ()

def transform_subroutine(self, routine, **kwargs):
"""
Expand All @@ -63,6 +67,8 @@ def transform_subroutine(self, routine, **kwargs):
return
role = kwargs['role']
if role == 'kernel':
if self.apply_to and routine.name.lower() not in self.apply_to:
return
self.process_kernel(routine)

def process_kernel(self, routine):
Expand Down

0 comments on commit 829e214

Please sign in to comment.