Reference Guide  2.5.0
psyclone.psyir.transformations.loop_trans.LoopTrans Class Reference
Inheritance diagram for psyclone.psyir.transformations.loop_trans.LoopTrans:
Collaboration diagram for psyclone.psyir.transformations.loop_trans.LoopTrans:

Public Member Functions

def validate (self, node, options=None)
 
def name (self)
 
- Public Member Functions inherited from psyclone.psyGen.Transformation
def apply (self, node, options=None)
 

Static Public Attributes

tuple excluded_node_types = ()
 

Detailed Description

This abstract class is a base class for all transformations that act
on a Loop node. It gives access to a validate function that
makes sure that the supplied node is a Loop.
We also check that all nodes to be enclosed are valid for this
transformation - this requires that the sub-class populate the
`excluded_node_types` tuple.

Definition at line 48 of file loop_trans.py.

Member Function Documentation

◆ name()

def psyclone.psyir.transformations.loop_trans.LoopTrans.name (   self)
:returns: the name of this class.
:rtype: str

Reimplemented from psyclone.psyGen.Transformation.

Reimplemented in psyclone.psyir.transformations.omp_task_trans.OMPTaskTrans.

Definition at line 133 of file loop_trans.py.

133  def name(self):
134  '''
135  :returns: the name of this class.
136  :rtype: str
137  '''
138  return self.__class__.__name__
139 
140 
141 # For Sphinx AutoAPI documentation generation

References psyclone.psyir.symbols.symbol.Symbol.__class__.

Here is the caller graph for this function:

◆ validate()

def psyclone.psyir.transformations.loop_trans.LoopTrans.validate (   self,
  node,
  options = None 
)
Checks that the supplied node is a valid target for a loop
transformation.

:param node: target PSyIR node.
:type node: subclass of :py:class:`psyclone.psyir.nodes.Node`
:param options: a dictionary with options for transformations.
:type options: Optional[Dict[str, Any]]
:param bool options["node-type-check"]: this flag controls if the \
    type of the nodes enclosed in the loop should be tested to \
    avoid including unsupported nodes in a transformation.

:raises TransformationError: if the supplied node is not a (fully- \
        formed) Loop.
:raises TransformationError: if any of the nodes within the loop are \
        of an unsupported type.
:raises TransformationError: if the loop is of 'null' type.
:raises TransformationError: if the supplied options are not a \
        dictionary.

Reimplemented from psyclone.psyGen.Transformation.

Reimplemented in psyclone.transformations.Dynamo0p3RedundantComputationTrans, psyclone.transformations.GOceanOMPLoopTrans, psyclone.transformations.Dynamo0p3OMPLoopTrans, psyclone.transformations.DynamoOMPParallelLoopTrans, psyclone.psyir.transformations.parallel_loop_trans.ParallelLoopTrans, psyclone.psyir.transformations.omp_task_trans.OMPTaskTrans, psyclone.psyir.transformations.loop_tiling_2d_trans.LoopTiling2DTrans, psyclone.psyir.transformations.loop_swap_trans.LoopSwapTrans, psyclone.psyir.transformations.hoist_loop_bound_expr_trans.HoistLoopBoundExprTrans, and psyclone.psyir.transformations.chunk_loop_trans.ChunkLoopTrans.

Definition at line 64 of file loop_trans.py.

64  def validate(self, node, options=None):
65  '''Checks that the supplied node is a valid target for a loop
66  transformation.
67 
68  :param node: target PSyIR node.
69  :type node: subclass of :py:class:`psyclone.psyir.nodes.Node`
70  :param options: a dictionary with options for transformations.
71  :type options: Optional[Dict[str, Any]]
72  :param bool options["node-type-check"]: this flag controls if the \
73  type of the nodes enclosed in the loop should be tested to \
74  avoid including unsupported nodes in a transformation.
75 
76  :raises TransformationError: if the supplied node is not a (fully- \
77  formed) Loop.
78  :raises TransformationError: if any of the nodes within the loop are \
79  of an unsupported type.
80  :raises TransformationError: if the loop is of 'null' type.
81  :raises TransformationError: if the supplied options are not a \
82  dictionary.
83 
84  '''
85  # pylint: disable=too-many-branches
86  if not isinstance(node, Loop):
87  raise TransformationError(
88  f"Target of {self.name} transformation must be a sub-class of "
89  f"Loop but got '{type(node).__name__}'")
90 
91  # The loop must be fully-formed.
92  if len(node.children) != 4:
93  raise TransformationError(
94  f"Error in {self.name} transformation. The target loop "
95  f"must have four children but found: "
96  f"{[type(child).__name__ for child in node.children]}.")
97 
98  if not options:
99  options = {}
100  if not isinstance(options, dict):
101  raise TransformationError(
102  f"Transformation validate method 'options' argument must be a "
103  f"dictionary but found '{type(options).__name__}'.")
104 
105  # Check that the proposed region contains only supported node types
106  if options.get("node-type-check", True):
107  # Stop at any instance of Kern to avoid going into the
108  # actual kernels, e.g. in Nemo inlined kernels
109  flat_list = [item for item in node.walk(object, stop_type=Kern)
110  if not isinstance(item, Schedule)]
111  for item in flat_list:
112  if isinstance(item, self.excluded_node_types):
113  raise TransformationError(
114  f"Nodes of type '{type(item).__name__}' cannot be "
115  f"enclosed by a {self.name} transformation")
116 
117  # Disable warning to avoid circular dependency
118  # pylint: disable=import-outside-toplevel
119  from psyclone.domain.common.psylayer import PSyLoop
120 
121  # A 'null' loop is one which exists in the PSyIR hierarchy (mainly for
122  # halo-exchange logic) but does *not* correspond to an actual loop
123  # in the code that is generated for the PSy layer.
124 
125  # TODO 1756: PSyLoop is a PSy-layer concept and 'null' is only defined
126  # in LFRic. Maybe a generic transformation validation is not the best
127  # place for this check.
128  if isinstance(node, PSyLoop) and node.loop_type == 'null':
129  raise TransformationError(
130  f"Cannot apply a {self.name} transformation to a 'null' loop.")
131 

References psyclone.psyir.transformations.extract_trans.ExtractTrans.excluded_node_types, psyclone.psyir.transformations.loop_swap_trans.LoopSwapTrans.excluded_node_types, psyclone.psyir.transformations.loop_trans.LoopTrans.excluded_node_types, psyclone.psyir.transformations.omp_target_trans.OMPTargetTrans.excluded_node_types, psyclone.psyir.transformations.parallel_loop_trans.ParallelLoopTrans.excluded_node_types, psyclone.psyir.transformations.profile_trans.ProfileTrans.excluded_node_types, psyclone.psyir.transformations.psy_data_trans.PSyDataTrans.excluded_node_types, psyclone.psyir.transformations.region_trans.RegionTrans.excluded_node_types, psyclone.transformations.ACCLoopTrans.excluded_node_types, psyclone.transformations.ParallelRegionTrans.excluded_node_types, psyclone.transformations.OMPSingleTrans.excluded_node_types, psyclone.transformations.OMPMasterTrans.excluded_node_types, psyclone.transformations.OMPParallelTrans.excluded_node_types, psyclone.transformations.ACCParallelTrans.excluded_node_types, psyclone.transformations.ACCKernelsTrans.excluded_node_types, and psyclone.transformations.ACCDataTrans.excluded_node_types.

Here is the caller graph for this function:

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