from psyclone.parse.algorithm import parse
from psyclone.parse.utils import ParseError
from psyclone.psyGen import PSyFactory, GenerationError
api="gocean1.0"
filename = "alg.f90"
ast, invokeInfo = parse(filename, api=api, invoke_name="invoke")
psy = PSyFactory(api).create(invokeInfo)
print(psy.invokes.names)
dict_keys(['invoke_0'])
from psyclone.psyGen import TransInfo
t = TransInfo()
ltrans = t.get_trans_name('OMPLoopTrans')
rtrans = t.get_trans_name('OMPParallelTrans')
trans = t.get_trans_name('OMPParallelLoopTrans')
schedule = psy.invokes.get('invoke_0').schedule
schedule.view()
new_schedule = schedule
GOInvokeSchedule[invoke='invoke_0', Constant loop bounds=True] Loop[type='outer', field_space='go_cu', it_space='go_internal_pts'] Literal[value:'2'] Literal[value:'jstop'] Literal[value:'1'] Schedule[] Loop[type='inner', field_space='go_cu', it_space='go_internal_pts'] Literal[value:'2'] Literal[value:'istop+1'] Literal[value:'1'] Schedule[] CodedKern compute_cu_code(cu_fld,p_fld,u_fld) [module_inline=False] Loop[type='outer', field_space='go_cv', it_space='go_internal_pts'] Literal[value:'2'] Literal[value:'jstop+1'] Literal[value:'1'] Schedule[] Loop[type='inner', field_space='go_cv', it_space='go_internal_pts'] Literal[value:'2'] Literal[value:'istop'] Literal[value:'1'] Schedule[] CodedKern compute_cv_code(cv_fld,p_fld,v_fld) [module_inline=False] Loop[type='outer', field_space='go_cf', it_space='go_internal_pts'] Literal[value:'2'] Literal[value:'jstop+1'] Literal[value:'1'] Schedule[] Loop[type='inner', field_space='go_cf', it_space='go_internal_pts'] Literal[value:'2'] Literal[value:'istop+1'] Literal[value:'1'] Schedule[] CodedKern compute_z_code(z_fld,p_fld,u_fld,v_fld,dx,dy) [module_inline=False] Loop[type='outer', field_space='go_ct', it_space='go_internal_pts'] Literal[value:'2'] Literal[value:'jstop'] Literal[value:'1'] Schedule[] Loop[type='inner', field_space='go_ct', it_space='go_internal_pts'] Literal[value:'2'] Literal[value:'istop'] Literal[value:'1'] Schedule[] CodedKern compute_h_code(h_fld,p_fld,u_fld,v_fld) [module_inline=False]
Apply the OpenMP Loop transformation to every loop in the schedule
for child in schedule.children:
newschedule, memento = ltrans.apply(child, reprod=True)
schedule = newschedule
Enclose all of these loops within a single OpenMP PARALLEL region
newschedule, memento = rtrans.apply(schedule.children)
print(newschedule.dag_name)
print(memento)
schedule <psyclone.undoredo.Memento object at 0x7f338cf91ac8>
from psyclone.transformations import OMPParallelLoopTrans
ast, invokeInfo = parse("dynamo.F90")
psy = PSyFactory("dynamo0.1").create(invokeInfo)
schedule = psy.invokes.get('invoke_v3_kernel_type').schedule
schedule.view()
--------------------------------------------------------------------------- ParseError Traceback (most recent call last) <ipython-input-25-587445d66120> in <module> ----> 1 ast, invokeInfo = parse("dynamo.F90") 2 psy = PSyFactory("dynamo0.1").create(invokeInfo) 3 schedule = psy.invokes.get('invoke_v3_kernel_type').schedule 4 schedule.view() ~/Development/python/workspace/notebooks/venv/lib/python3.7/site-packages/psyclone/parse/algorithm.py in parse(alg_filename, api, invoke_name, kernel_path, line_length) 100 # function for compatibility. 101 my_parser = Parser(api, invoke_name, kernel_path, line_length) --> 102 return my_parser.parse(alg_filename) 103 104 ~/Development/python/workspace/notebooks/venv/lib/python3.7/site-packages/psyclone/parse/algorithm.py in parse(self, alg_filename) 218 if call_name.lower() == self._invoke_name.lower(): 219 # The call statement is an invoke --> 220 invoke_call = self.create_invoke_call(statement) 221 invoke_calls.append(invoke_call) 222 ~/Development/python/workspace/notebooks/venv/lib/python3.7/site-packages/psyclone/parse/algorithm.py in create_invoke_call(self, statement) 265 elif isinstance(argument, (Data_Ref, Part_Ref)): 266 # This should be a kernel call. --> 267 kernel_call = self.create_kernel_call(argument) 268 kernel_calls.append(kernel_call) 269 ~/Development/python/workspace/notebooks/venv/lib/python3.7/site-packages/psyclone/parse/algorithm.py in create_kernel_call(self, argument) 302 # This is a coded kernel 303 kernel_call = self.create_coded_kernel_call( --> 304 kernel_name, args) 305 return kernel_call 306 ~/Development/python/workspace/notebooks/venv/lib/python3.7/site-packages/psyclone/parse/algorithm.py in create_coded_kernel_call(self, kernel_name, args) 375 return KernelCall(module_name, 376 KernelTypeFactory(api=self._api).create( --> 377 modast, name=kernel_name), args) 378 379 def update_arg_to_module_map(self, statement): ~/Development/python/workspace/notebooks/venv/lib/python3.7/site-packages/psyclone/parse/kernel.py in create(self, parse_tree, name) 236 elif self._type == "dynamo0.3": 237 from psyclone.dynamo0p3 import DynKernMetadata --> 238 return DynKernMetadata(parse_tree, name=name) 239 elif self._type == "gocean0.1": 240 from psyclone.gocean0p1 import GOKernelType ~/Development/python/workspace/notebooks/venv/lib/python3.7/site-packages/psyclone/dynamo0p3.py in __init__(self, ast, name) 846 self._arg_descriptors = [] 847 for arg_type in self._inits: --> 848 self._arg_descriptors.append(DynArgDescriptor03(arg_type)) 849 # parse the func_type metadata if it exists 850 found = False ~/Development/python/workspace/notebooks/venv/lib/python3.7/site-packages/psyclone/dynamo0p3.py in __init__(self, arg_type) 555 "{0}), but found '{1}' in '{2}'". 556 format(GH_VALID_ARG_TYPE_NAMES, arg_type.args[0].name, --> 557 arg_type)) 558 self._type = arg_type.args[0].name 559 else: ParseError: "Parse Error: In the dynamo0.3 API the 1st argument of a meta_arg entry should be a valid argument type (one of ['gh_field', 'gh_operator', 'gh_columnwise_operator', 'gh_real', 'gh_integer']), but found 'gh_rw' in 'arg_type(gh_rw, v3, fe, .true., .false., .true.)'"
trans = OMPParallelLoopTrans()
new_schedule, memento = trans.apply(schedule.children[0])
--------------------------------------------------------------------------- TransformationError Traceback (most recent call last) <ipython-input-20-0d7c7ddfa6bb> in <module> 1 trans = OMPParallelLoopTrans() ----> 2 new_schedule, memento = trans.apply(schedule.children[0]) ~/Development/python/workspace/notebooks/venv/lib/python3.7/site-packages/psyclone/transformations.py in apply(self, node) 939 :py:class:`psyclone.undoredo.Memento`) 940 ''' --> 941 self._validate(node) 942 943 schedule = node.root ~/Development/python/workspace/notebooks/venv/lib/python3.7/site-packages/psyclone/transformations.py in _validate(self, node) 911 if not isinstance(node, Loop): 912 raise TransformationError("Error in {0} transformation. The " --> 913 "node is not a loop.".format(self.name)) 914 915 # Check we are not a sequential loop TransformationError: 'Transformation Error: Error in OMPParallelLoopTrans transformation. The node is not a loop.'