From ecb7337e15d7cae9669ecf34d0cd5680b7c12ed9 Mon Sep 17 00:00:00 2001 From: Sergi Siso Date: Thu, 22 Sep 2022 15:34:34 +0100 Subject: [PATCH] #1823 Start module inline refactoring --- .../gocean1p0_transformations_test.py | 29 ----------- src/psyclone/transformations.py | 49 ++++++++++++++++--- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/psyclone/tests/domain/gocean/transformations/gocean1p0_transformations_test.py b/src/psyclone/tests/domain/gocean/transformations/gocean1p0_transformations_test.py index d1188acd59..58c5240904 100644 --- a/src/psyclone/tests/domain/gocean/transformations/gocean1p0_transformations_test.py +++ b/src/psyclone/tests/domain/gocean/transformations/gocean1p0_transformations_test.py @@ -1030,35 +1030,6 @@ def test_module_inline_with_transformation(tmpdir): assert GOceanBuild(tmpdir).code_compiles(psy) -def test_module_no_inline_with_transformation(tmpdir): - ''' Test that we can switch off the inlining of a kernel routine - into the PSy layer module using a transformation. Relies on the - test_module_inline() test being successful to be a valid test. ''' - psy, invoke = get_invoke("single_invoke_three_kernels.f90", API, idx=0, - dist_mem=False) - schedule = invoke.schedule - kern_call = schedule.children[0].loop_body[0].loop_body[0] - # directly switch on inlining - kern_call.module_inline = True - inline_trans = KernelModuleInlineTrans() - # use a transformation to switch inlining off again - inline_trans.apply(kern_call, {"inline": False}) - gen = str(psy.gen) - # check that the subroutine has not been inlined - assert 'SUBROUTINE compute_cu_code(i, j, cu, p, u)' not in gen - # check that the associated use exists (as this is removed when - # inlining) - assert 'USE compute_cu_mod, ONLY: compute_cu_code' in gen - assert GOceanBuild(tmpdir).code_compiles(psy) - - -# we can not test if someone accidentally sets module_inline to True -# to an object that is not a Kernel as Python allows one to -# dynamically add new variables to an object. Therefore an error is -# never thrown. This would be testable if "inline" were a function. -# def test_inline_error_if_not_kernel(): - - def test_transformation_inline_error_if_not_kernel(): ''' Test that the inline transformation fails if the object being passed is not a kernel''' diff --git a/src/psyclone/transformations.py b/src/psyclone/transformations.py index ed6dc25a7c..a03053e608 100644 --- a/src/psyclone/transformations.py +++ b/src/psyclone/transformations.py @@ -1232,16 +1232,49 @@ def apply(self, node, options=None): if not options: options = {} - inline = options.get("inline", True) - # set kernel's inline status - if node.module_inline == inline: - # issue a warning here when we implement logging - # print "Warning, Kernel inline is already set to "+str(inline) - pass - else: - node.module_inline = inline + name = node.name + try: + existing_symbol = node.scope.symbol_table.lookup(name) + except KeyError: + existing_symbol = None + + if not existing_symbol: + # If it doesn't exist already, module-inline the subroutine by: + # 1) Registering the subroutine symbol in the Container + from psyclone.psyir.symbols import RoutineSymbol + from psyclone.psyir.nodes import Literal + node.root.symbol_table.add(RoutineSymbol(name)) + # 2) Insert the relevant code into the tree. + inlined_code = node.get_kernel_schedule() + + import pdb; pdb.set_trace() + for container in inlined_code.ancestor(Container): + cont + + for reference in inlined_code.walk(Reference): + try: + reference.scope.symbol_table.lookup( + reference.symbol.name, + scope_limit=inlined_code + ) + except KeyError: + import pdb; pdb.set_trace() + for literal in inlined_code.walk(Literal): + if isinstance(lit.datatype.precision, DataSymbol): + name = lit.datatype.precision.name + + import pdb; pdb.set_trace() + + + node.root.addchild(inlined_code.detach()) + + + + else: + import pdb; pdb.set_trace() + class Dynamo0p3ColourTrans(ColourTrans):