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

Public Member Functions

def name (self)
 
def apply (self, node, options=None)
 
def validate (self, nodes, options)
 
- Public Member Functions inherited from psyclone.psyir.transformations.region_trans.RegionTrans
def get_node_list (self, nodes)
 

Static Public Attributes

tuple excluded_node_types
 
- Static Public Attributes inherited from psyclone.psyir.transformations.region_trans.RegionTrans
tuple excluded_node_types = ()
 

Detailed Description

Enclose a sub-set of nodes from a Schedule within an OpenACC kernels
region (i.e. within "!$acc kernels" ... "!$acc end kernels" directives).

For example:

>>> from psyclone.parse.algorithm import parse
>>> from psyclone.psyGen import PSyFactory
>>> api = "nemo"
>>> ast, invokeInfo = parse(NEMO_SOURCE_FILE, api=api)
>>> psy = PSyFactory(api).create(invokeInfo)
>>>
>>> from psyclone.transformations import ACCKernelsTrans
>>> ktrans = ACCKernelsTrans()
>>>
>>> schedule = psy.invokes.get('tra_adv').schedule
>>> # Uncomment the following line to see a text view of the schedule
>>> # print(schedule.view())
>>> kernels = schedule.children[9]
>>> # Transform the kernel
>>> ktrans.apply(kernels)

Definition at line 2596 of file transformations.py.

Member Function Documentation

◆ apply()

def psyclone.transformations.ACCKernelsTrans.apply (   self,
  node,
  options = None 
)
Enclose the supplied list of PSyIR nodes within an OpenACC
Kernels region.

:param node: a node or list of nodes in the PSyIR to enclose.
:type node: (a list of) :py:class:`psyclone.psyir.nodes.Node`
:param options: a dictionary with options for transformations.
:type options: Optional[Dict[str, Any]]
:param bool options["default_present"]: whether or not the kernels \
    region should have the 'default present' attribute (indicating \
    that data is already on the accelerator). When using managed \
    memory this option should be False.

Reimplemented from psyclone.psyGen.Transformation.

Definition at line 2631 of file transformations.py.

2631  def apply(self, node, options=None):
2632  '''
2633  Enclose the supplied list of PSyIR nodes within an OpenACC
2634  Kernels region.
2635 
2636  :param node: a node or list of nodes in the PSyIR to enclose.
2637  :type node: (a list of) :py:class:`psyclone.psyir.nodes.Node`
2638  :param options: a dictionary with options for transformations.
2639  :type options: Optional[Dict[str, Any]]
2640  :param bool options["default_present"]: whether or not the kernels \
2641  region should have the 'default present' attribute (indicating \
2642  that data is already on the accelerator). When using managed \
2643  memory this option should be False.
2644 
2645  '''
2646  # Ensure we are always working with a list of nodes, even if only
2647  # one was supplied via the `node` argument.
2648  node_list = self.get_node_list(node)
2649 
2650  self.validate(node_list, options)
2651 
2652  parent = node_list[0].parent
2653  start_index = node_list[0].position
2654 
2655  if not options:
2656  options = {}
2657  default_present = options.get("default_present", False)
2658 
2659  # Create a directive containing the nodes in node_list and insert it.
2660  directive = ACCKernelsDirective(
2661  parent=parent, children=[node.detach() for node in node_list],
2662  default_present=default_present)
2663 
2664  parent.children.insert(start_index, directive)
2665 

References psyclone.psyir.transformations.region_trans.RegionTrans.get_node_list(), 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.ACCKernelsTrans.name (   self)
:returns: the name of this transformation class.
:rtype: str

Reimplemented from psyclone.psyGen.Transformation.

Definition at line 2624 of file transformations.py.

2624  def name(self):
2625  '''
2626  :returns: the name of this transformation class.
2627  :rtype: str
2628  '''
2629  return "ACCKernelsTrans"
2630 
Here is the caller graph for this function:

◆ validate()

def psyclone.transformations.ACCKernelsTrans.validate (   self,
  nodes,
  options 
)
Check that we can safely enclose the supplied node or list of nodes
within OpenACC kernels ... end kernels directives.

:param nodes: the proposed PSyIR node or nodes to enclose in the \
              kernels region.
:type nodes: (list of) :py:class:`psyclone.psyir.nodes.Node`
:param options: a dictionary with options for transformations.
:type options: Optional[Dict[str, Any]]

:raises NotImplementedError: if the supplied Nodes belong to \
                             a GOInvokeSchedule.
:raises TransformationError: if there are no Loops within the \
                             proposed region.

Reimplemented from psyclone.psyir.transformations.region_trans.RegionTrans.

Definition at line 2666 of file transformations.py.

2666  def validate(self, nodes, options):
2667  # pylint: disable=signature-differs
2668  '''
2669  Check that we can safely enclose the supplied node or list of nodes
2670  within OpenACC kernels ... end kernels directives.
2671 
2672  :param nodes: the proposed PSyIR node or nodes to enclose in the \
2673  kernels region.
2674  :type nodes: (list of) :py:class:`psyclone.psyir.nodes.Node`
2675  :param options: a dictionary with options for transformations.
2676  :type options: Optional[Dict[str, Any]]
2677 
2678  :raises NotImplementedError: if the supplied Nodes belong to \
2679  a GOInvokeSchedule.
2680  :raises TransformationError: if there are no Loops within the \
2681  proposed region.
2682 
2683  '''
2684  # Ensure we are always working with a list of nodes, even if only
2685  # one was supplied via the `nodes` argument.
2686  node_list = self.get_node_list(nodes)
2687 
2688  # Check that the front-end is valid
2689  sched = node_list[0].ancestor((NemoInvokeSchedule,
2690  LFRicInvokeSchedule))
2691  if not sched:
2692  raise NotImplementedError(
2693  "OpenACC kernels regions are currently only supported for the "
2694  "nemo and dynamo0.3 front-ends")
2695  super().validate(node_list, options)
2696 
2697  # Check that we have at least one loop or array range within
2698  # the proposed region
2699  for node in node_list:
2700  if (any(assign for assign in node.walk(Assignment)
2701  if assign.is_array_assignment) or node.walk(Loop)):
2702  break
2703  else:
2704  # Branch executed if loop does not exit with a break
2705  raise TransformationError(
2706  "A kernels transformation must enclose at least one loop or "
2707  "array range but none were found.")
2708 
2709 

References psyclone.psyir.transformations.region_trans.RegionTrans.get_node_list().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ excluded_node_types

tuple psyclone.transformations.ACCKernelsTrans.excluded_node_types
static
Initial value:
= (CodeBlock, Return, PSyDataNode,
psyGen.HaloExchange)

Definition at line 2620 of file transformations.py.


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