Reference Guide  2.5.0
psyclone.transformations.ACCEnterDataTrans Class Reference
Inheritance diagram for psyclone.transformations.ACCEnterDataTrans:
Collaboration diagram for psyclone.transformations.ACCEnterDataTrans:

Public Member Functions

def __str__ (self)
 
def name (self)
 
def apply (self, sched, options=None)
 
def validate (self, sched, options=None)
 

Detailed Description

Adds an OpenACC "enter data" directive to a Schedule.
For example:

>>> from psyclone.parse.algorithm import parse
>>> from psyclone.psyGen import PSyFactory
>>> api = "gocean1.0"
>>> ast, invokeInfo = parse(GOCEAN_SOURCE_FILE, api=api)
>>> psy = PSyFactory(api).create(invokeInfo)
>>>
>>> from psyclone.transformations import \
    ACCEnterDataTrans, ACCLoopTrans, ACCParallelTrans
>>> dtrans = ACCEnterDataTrans()
>>> ltrans = ACCLoopTrans()
>>> ptrans = ACCParallelTrans()
>>>
>>> schedule = psy.invokes.get('invoke_0').schedule
>>> # Uncomment the following line to see a text view of the schedule
>>> # print(schedule.view())
>>>
>>> # Apply the OpenACC Loop transformation to *every* loop in the schedule
>>> for child in schedule.children[:]:
...     ltrans.apply(child)
>>>
>>> # Enclose all of these loops within a single OpenACC parallel region
>>> ptrans.apply(schedule)
>>>
>>> # Add an enter data directive
>>> dtrans.apply(schedule)
>>>
>>> # Uncomment the following line to see a text view of the schedule
>>> # print(schedule.view())

Definition at line 2389 of file transformations.py.

Member Function Documentation

◆ apply()

def psyclone.transformations.ACCEnterDataTrans.apply (   self,
  sched,
  options = None 
)
Adds an OpenACC "enter data" directive to the invoke associated
with the supplied Schedule. Any fields accessed by OpenACC kernels
within this schedule will be added to this data region in
order to ensure they remain on the target device.

:param sched: schedule to which to add an "enter data" directive.
:type sched: sub-class of :py:class:`psyclone.psyir.nodes.Schedule`
:param options: a dictionary with options for transformations.
:type options: Optional[Dict[str, Any]]

Reimplemented from psyclone.psyGen.Transformation.

Definition at line 2435 of file transformations.py.

2435  def apply(self, sched, options=None):
2436  # pylint: disable=arguments-renamed
2437  '''Adds an OpenACC "enter data" directive to the invoke associated
2438  with the supplied Schedule. Any fields accessed by OpenACC kernels
2439  within this schedule will be added to this data region in
2440  order to ensure they remain on the target device.
2441 
2442  :param sched: schedule to which to add an "enter data" directive.
2443  :type sched: sub-class of :py:class:`psyclone.psyir.nodes.Schedule`
2444  :param options: a dictionary with options for transformations.
2445  :type options: Optional[Dict[str, Any]]
2446 
2447  '''
2448  # Ensure that the proposed transformation is valid
2449  self.validate(sched, options)
2450 
2451  # pylint: disable=import-outside-toplevel
2452  if isinstance(sched, LFRicInvokeSchedule):
2453  from psyclone.dynamo0p3 import DynACCEnterDataDirective as \
2454  AccEnterDataDir
2455  elif isinstance(sched, GOInvokeSchedule):
2456  from psyclone.gocean1p0 import GOACCEnterDataDirective as \
2457  AccEnterDataDir
2458  else:
2459  from psyclone.psyir.nodes import ACCEnterDataDirective as \
2460  AccEnterDataDir
2461 
2462  # Find the position of the first child statement of the current
2463  # schedule which contains an OpenACC compute construct.
2464  posn = 0
2465  directive_cls = (ACCParallelDirective, ACCKernelsDirective)
2466  directive = sched.walk(directive_cls, stop_type=directive_cls)
2467  if directive:
2468  current = directive[0]
2469  while current not in sched.children:
2470  current = current.parent
2471  posn = sched.children.index(current)
2472 
2473  # Add the directive at the position determined above, i.e. just before
2474  # the first statement containing an OpenACC compute construct.
2475  data_dir = AccEnterDataDir(parent=sched, children=[])
2476  sched.addchild(data_dir, index=posn)
2477 

References psyclone.domain.lfric.kernel.lfric_kernel_metadata.LFRicKernelMetadata.validate(), psyclone.transformations.MoveTrans.validate(), psyclone.transformations.Dynamo0p3AsyncHaloExchangeTrans.validate(), psyclone.domain.common.transformations.alg_invoke_2_psy_call_trans.AlgInvoke2PSyCallTrans.validate(), psyclone.domain.common.transformations.alg_trans.AlgTrans.validate(), psyclone.domain.common.transformations.kernel_module_inline_trans.KernelModuleInlineTrans.validate(), psyclone.domain.common.transformations.raise_psyir_2_alg_trans.RaisePSyIR2AlgTrans.validate(), psyclone.domain.gocean.transformations.gocean_const_loop_bounds_trans.GOConstLoopBoundsTrans.validate(), psyclone.domain.gocean.transformations.gocean_move_iteration_boundaries_inside_kernel_trans.GOMoveIterationBoundariesInsideKernelTrans.validate(), psyclone.domain.gocean.transformations.gocean_opencl_trans.GOOpenCLTrans.validate(), psyclone.domain.gocean.transformations.raise_psyir_2_gocean_kern_trans.RaisePSyIR2GOceanKernTrans.validate(), psyclone.domain.lfric.transformations.lfric_alg_invoke_2_psy_call_trans.LFRicAlgInvoke2PSyCallTrans.validate(), psyclone.domain.lfric.transformations.raise_psyir_2_lfric_kern_trans.RaisePSyIR2LFRicKernTrans.validate(), psyclone.domain.nemo.transformations.create_nemo_invoke_schedule_trans.CreateNemoInvokeScheduleTrans.validate(), psyclone.domain.nemo.transformations.create_nemo_psy_trans.CreateNemoPSyTrans.validate(), psyclone.domain.nemo.transformations.nemo_allarrayrange2loop_trans.NemoAllArrayRange2LoopTrans.validate(), psyclone.domain.nemo.transformations.nemo_arrayrange2loop_trans.NemoArrayRange2LoopTrans.validate(), psyclone.domain.nemo.transformations.nemo_outerarrayrange2loop_trans.NemoOuterArrayRange2LoopTrans.validate(), psyclone.psyad.transformations.assignment_trans.AssignmentTrans.validate(), psyclone.psyGen.Transformation.validate(), psyclone.psyir.transformations.acc_update_trans.ACCUpdateTrans.validate(), psyclone.psyir.transformations.allarrayaccess2loop_trans.AllArrayAccess2LoopTrans.validate(), psyclone.psyir.transformations.arrayaccess2loop_trans.ArrayAccess2LoopTrans.validate(), psyclone.psyir.transformations.arrayrange2loop_trans.ArrayRange2LoopTrans.validate(), psyclone.psyir.transformations.chunk_loop_trans.ChunkLoopTrans.validate(), psyclone.psyir.transformations.fold_conditional_return_expressions_trans.FoldConditionalReturnExpressionsTrans.validate(), psyclone.psyir.transformations.hoist_local_arrays_trans.HoistLocalArraysTrans.validate(), psyclone.psyir.transformations.hoist_loop_bound_expr_trans.HoistLoopBoundExprTrans.validate(), psyclone.psyir.transformations.hoist_trans.HoistTrans.validate(), psyclone.psyir.transformations.inline_trans.InlineTrans.validate(), psyclone.psyir.transformations.intrinsics.array_reduction_base_trans.ArrayReductionBaseTrans.validate(), psyclone.psyir.transformations.intrinsics.dotproduct2code_trans.DotProduct2CodeTrans.validate(), psyclone.psyir.transformations.intrinsics.intrinsic2code_trans.Intrinsic2CodeTrans.validate(), psyclone.psyir.transformations.intrinsics.matmul2code_trans.Matmul2CodeTrans.validate(), psyclone.psyir.transformations.loop_swap_trans.LoopSwapTrans.validate(), psyclone.psyir.transformations.loop_tiling_2d_trans.LoopTiling2DTrans.validate(), psyclone.psyir.transformations.loop_trans.LoopTrans.validate(), psyclone.psyir.transformations.omp_task_trans.OMPTaskTrans.validate(), psyclone.psyir.transformations.omp_taskwait_trans.OMPTaskwaitTrans.validate(), psyclone.psyir.transformations.parallel_loop_trans.ParallelLoopTrans.validate(), psyclone.psyir.transformations.reference2arrayrange_trans.Reference2ArrayRangeTrans.validate(), psyclone.psyir.transformations.replace_induction_variables_trans.ReplaceInductionVariablesTrans.validate(), psyclone.transformations.OMPDeclareTargetTrans.validate(), psyclone.transformations.DynamoOMPParallelLoopTrans.validate(), psyclone.transformations.Dynamo0p3OMPLoopTrans.validate(), psyclone.transformations.GOceanOMPLoopTrans.validate(), psyclone.transformations.Dynamo0p3RedundantComputationTrans.validate(), psyclone.transformations.Dynamo0p3KernelConstTrans.validate(), psyclone.transformations.ACCRoutineTrans.validate(), psyclone.transformations.KernelImportsToArguments.validate(), psyclone.domain.gocean.transformations.gocean_loop_fuse_trans.GOceanLoopFuseTrans.validate(), psyclone.domain.lfric.transformations.lfric_loop_fuse_trans.LFRicLoopFuseTrans.validate(), psyclone.psyir.transformations.loop_fuse_trans.LoopFuseTrans.validate(), psyclone.domain.gocean.transformations.gocean_extract_trans.GOceanExtractTrans.validate(), psyclone.domain.lfric.transformations.lfric_extract_trans.LFRicExtractTrans.validate(), psyclone.psyir.transformations.extract_trans.ExtractTrans.validate(), psyclone.psyir.transformations.nan_test_trans.NanTestTrans.validate(), psyclone.psyir.transformations.read_only_verify_trans.ReadOnlyVerifyTrans.validate(), psyclone.transformations.ParallelRegionTrans.validate(), psyclone.transformations.OMPParallelTrans.validate(), psyclone.transformations.ACCParallelTrans.validate(), psyclone.transformations.ACCKernelsTrans.validate(), psyclone.transformations.ACCDataTrans.validate(), psyclone.psyir.transformations.psy_data_trans.PSyDataTrans.validate(), psyclone.psyir.transformations.region_trans.RegionTrans.validate(), and psyclone.transformations.ACCEnterDataTrans.validate().

Here is the call graph for this function:

◆ name()

def psyclone.transformations.ACCEnterDataTrans.name (   self)
:returns: the name of this transformation.
:rtype: str

Reimplemented from psyclone.psyGen.Transformation.

Definition at line 2428 of file transformations.py.

2428  def name(self):
2429  '''
2430  :returns: the name of this transformation.
2431  :rtype: str
2432  '''
2433  return "ACCEnterDataTrans"
2434 
Here is the caller graph for this function:

◆ validate()

def psyclone.transformations.ACCEnterDataTrans.validate (   self,
  sched,
  options = None 
)
Check that we can safely apply the OpenACC enter-data transformation
to the supplied Schedule.

:param sched: Schedule to which to add an "enter data" directive.
:type sched: sub-class of :py:class:`psyclone.psyir.nodes.Schedule`
:param options: a dictionary with options for transformations.
:type options: Optional[Dict[str, Any]]

:raises TransformationError: if passed something that is not a \
    (subclass of) :py:class:`psyclone.psyir.nodes.Schedule`.

Reimplemented from psyclone.psyGen.Transformation.

Definition at line 2478 of file transformations.py.

2478  def validate(self, sched, options=None):
2479  # pylint: disable=arguments-differ, arguments-renamed
2480  '''
2481  Check that we can safely apply the OpenACC enter-data transformation
2482  to the supplied Schedule.
2483 
2484  :param sched: Schedule to which to add an "enter data" directive.
2485  :type sched: sub-class of :py:class:`psyclone.psyir.nodes.Schedule`
2486  :param options: a dictionary with options for transformations.
2487  :type options: Optional[Dict[str, Any]]
2488 
2489  :raises TransformationError: if passed something that is not a \
2490  (subclass of) :py:class:`psyclone.psyir.nodes.Schedule`.
2491 
2492  '''
2493  super().validate(sched, options)
2494 
2495  if not isinstance(sched, Schedule):
2496  raise TransformationError("Cannot apply an OpenACC enter data "
2497  "directive to something that is not a "
2498  "Schedule")
2499 
2500  # Check that we don't already have a data region of any sort
2501  directive_cls = (ACCDataDirective, ACCEnterDataDirective)
2502  if sched.walk(directive_cls, stop_type=directive_cls):
2503  raise TransformationError("Schedule already has an OpenACC data "
2504  "region - cannot add an enter data.")
2505 
2506 
Here is the caller graph for this function:

The documentation for this class was generated from the following file: