Skip to content

Commit

Permalink
#1823 Start module inline refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sergisiso committed Sep 22, 2022
1 parent 07ae8ec commit ecb7337
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'''
Expand Down
49 changes: 41 additions & 8 deletions src/psyclone/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit ecb7337

Please sign in to comment.