Skip to content

Commit

Permalink
SCC-STACK for ecphys
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSt98 committed Aug 30, 2023
1 parent c75cbea commit 8641294
Show file tree
Hide file tree
Showing 6 changed files with 391 additions and 83 deletions.
7 changes: 7 additions & 0 deletions loki/bulk/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def __init__(self, default, routines, disable=None, dimensions=None, dic2p=None,
self.routines = CaseInsensitiveDict(routines)
else:
self.routines = CaseInsensitiveDict((r.name, r) for r in as_tuple(routines))
for routine in self.routines:
if 'trafo' in self.routines[routine]:
if isinstance(self.routines[routine]['trafo'], list):
self.routines[routine]['trafo'] = self.routines[routine]['trafo'][0]
for key in self.routines[routine]['trafo']:
if isinstance(self.routines[routine]['trafo'][key], list):
self.routines[routine]['trafo'][key] = self.routines[routine]['trafo'][key][0]
self.disable = as_tuple(disable)
self.dimensions = dimensions
self.enable_imports = enable_imports
Expand Down
1 change: 1 addition & 0 deletions loki/expression/mappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ def map_variable_symbol(self, expr, *args, **kwargs):
recurse_to_declaration_attributes = kwargs['recurse_to_declaration_attributes'] or expr.scope is None
kwargs['recurse_to_declaration_attributes'] = False

new_type = expr.type
if recurse_to_declaration_attributes:
old_type = expr.type
kind = self.rec(old_type.kind, *args, **kwargs)
Expand Down
28 changes: 25 additions & 3 deletions scripts/loki_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def transpile(out_path, header, source, driver, cpp, include, define, frontend,

@cli.command('plan')
@click.option('--mode', '-m', default='sca',
type=click.Choice(['idem', 'sca', 'claw', 'scc', 'scc-hoist']))
type=click.Choice(['idem', 'sca', 'claw', 'scc', 'scc-hoist', 'scc-stack']))
@click.option('--config', '-c', type=click.Path(),
help='Path to configuration file.')
@click.option('--header', '-I', type=click.Path(), multiple=True,
Expand Down Expand Up @@ -410,6 +410,7 @@ def plan(mode, config, header, source, build, root, cpp, directive, frontend, ca
paths += [Path(h).resolve().parent for h in header]
scheduler = Scheduler(paths=paths, config=config, frontend=frontend, full_parse=False, preprocess=cpp)

mode = mode.replace("-", "_")
# Construct the transformation plan as a set of CMake lists of source files
scheduler.write_cmake_plan(filepath=plan_file, mode=mode, buildpath=build, rootpath=root)

Expand All @@ -420,7 +421,7 @@ def plan(mode, config, header, source, build, root, cpp, directive, frontend, ca

@cli.command('ecphys')
@click.option('--mode', '-m', default='sca',
type=click.Choice(['idem', 'sca', 'claw', 'scc', 'scc-hoist']))
type=click.Choice(['idem', 'sca', 'claw', 'scc', 'scc-hoist', 'scc-stack']))
@click.option('--config', '-c', type=click.Path(),
help='Path to configuration file.')
@click.option('--header', '-I', type=click.Path(), multiple=True,
Expand All @@ -443,6 +444,7 @@ def ecphys(mode, config, header, source, build, cpp, directive, frontend):
of interdependent subroutines.
"""

# TODO: still problem with '-' within "scc-stack"??
info('[Loki] Bulk-processing physics using config: %s ', config)
config = SchedulerConfig.from_file(config)

Expand Down Expand Up @@ -490,7 +492,7 @@ def ecphys(mode, config, header, source, build, cpp, directive, frontend):
# Define the target dimension to strip from kernel and caller
transformation = ExtractSCATransformation(horizontal=horizontal)

if mode in ['scc', 'scc-hoist']:
if mode in ['scc', 'scc-hoist', 'scc-stack']:
# Compose the main SCC transformation from core components based on config
transformation = (
SCCBaseTransformation(horizontal=horizontal, directive=directive),
Expand Down Expand Up @@ -527,6 +529,26 @@ def ecphys(mode, config, header, source, build, cpp, directive, frontend):
else:
raise RuntimeError('[Loki] Convert could not find specified Transformation!')

if mode in ['scc-stack']:
if frontend == Frontend.OMNI:
# To make the pool allocator size derivation work correctly, we need
# to normalize the 1:end-style index ranges that OMNI introduces
class NormalizeRangeIndexingTransformation(Transformation):
def transform_subroutine(self, routine, **kwargs):
normalize_range_indexing(routine)

scheduler.process(transformation=NormalizeRangeIndexingTransformation())

horizontal = scheduler.config.dimensions['horizontal']
vertical = scheduler.config.dimensions['vertical']
block_dim = scheduler.config.dimensions['block_dim']
transformation = TemporariesPoolAllocatorTransformation(
block_dim=block_dim, directive='openacc', check_bounds=False
)
scheduler.process(transformation=transformation, reverse=True)

mode = mode.replace("-", "_")

# Apply the dependency-injection transformation
dependency = DependencyTransformation(
mode='module', module_suffix='_MOD', suffix=f'_{mode.upper()}'
Expand Down
Loading

0 comments on commit 8641294

Please sign in to comment.