Reference Guide  2.5.0
psyclone.domain.nemo.transformations.nemo_outerarrayrange2loop_trans.NemoOuterArrayRange2LoopTrans Class Reference
Inheritance diagram for psyclone.domain.nemo.transformations.nemo_outerarrayrange2loop_trans.NemoOuterArrayRange2LoopTrans:
Collaboration diagram for psyclone.domain.nemo.transformations.nemo_outerarrayrange2loop_trans.NemoOuterArrayRange2LoopTrans:

Public Member Functions

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

Detailed Description

Provides a transformation from the outermost PSyIR ArrayReference
Range to a PSyIR Loop. For example:

>>> from psyclone.parse.algorithm import parse
>>> from psyclone.psyGen import PSyFactory
>>> api = "nemo"
>>> filename = "tra_adv.F90" # examples/nemo/code
>>> ast, invoke_info = parse(filename, api=api)
>>> psy = PSyFactory(api).create(invoke_info)
>>> schedule = psy.invokes.invoke_list[0].schedule
>>>
>>> from psyclone.psyir.nodes import Assignment
>>> from psyclone.domain.nemo.transformations import \
        NemoOuterArrayRange2LoopTrans
>>> from psyclone.transformations import TransformationError
>>>
>>> print(schedule.view())
>>> trans = NemoOuterArrayRange2LoopTrans()
>>> for assignment in schedule.walk(Assignment):
>>>     while True:
>>>         try:
>>>             trans.apply(assignment)
>>>         except TransformationError:
>>>             break
>>> print(schedule.view())

Definition at line 56 of file nemo_outerarrayrange2loop_trans.py.

Member Function Documentation

◆ apply()

def psyclone.domain.nemo.transformations.nemo_outerarrayrange2loop_trans.NemoOuterArrayRange2LoopTrans.apply (   self,
  node,
  options = None 
)
Apply the NemoOuterArrayRange2Loop transformation to the specified
node if the node is an Assignment and the left-hand-side of
the assignment is an Array Reference containing at least one
Range node specifying an access to an array index. If this is
the case then the outermost Range nodes within array
references within the assignment are replaced with references
to a loop index. A loop (with the same loop index) is
also placed around the modified assignment statement.

The name of the loop index is taken from the PSyclone
configuration file if a name exists for the particular array
index, otherwise a new name is generated. The bounds of the
loop are taken from the Range node if they are provided. If
not, the loop bounds are taken from the PSyclone configuration
file if bounds values are supplied. If not, the LBOUND or
UBOUND intrinsics are used as appropriate.

:param node: an Assignment node.
:type node: :py:class:`psyclone.psyir.nodes.Assignment`
:param options: a dictionary with options for \
    transformations. No options are used in this \
    transformation. This is an optional argument that defaults \
    to None.
:type options: Optional[Dict[str, Any]]
:param bool options["allow_string"]: whether to allow the
    transformation on a character type array range. Defaults to False.

Definition at line 84 of file nemo_outerarrayrange2loop_trans.py.

84  def apply(self, node, options=None):
85  '''Apply the NemoOuterArrayRange2Loop transformation to the specified
86  node if the node is an Assignment and the left-hand-side of
87  the assignment is an Array Reference containing at least one
88  Range node specifying an access to an array index. If this is
89  the case then the outermost Range nodes within array
90  references within the assignment are replaced with references
91  to a loop index. A loop (with the same loop index) is
92  also placed around the modified assignment statement.
93 
94  The name of the loop index is taken from the PSyclone
95  configuration file if a name exists for the particular array
96  index, otherwise a new name is generated. The bounds of the
97  loop are taken from the Range node if they are provided. If
98  not, the loop bounds are taken from the PSyclone configuration
99  file if bounds values are supplied. If not, the LBOUND or
100  UBOUND intrinsics are used as appropriate.
101 
102  :param node: an Assignment node.
103  :type node: :py:class:`psyclone.psyir.nodes.Assignment`
104  :param options: a dictionary with options for \
105  transformations. No options are used in this \
106  transformation. This is an optional argument that defaults \
107  to None.
108  :type options: Optional[Dict[str, Any]]
109  :param bool options["allow_string"]: whether to allow the
110  transformation on a character type array range. Defaults to False.
111 
112  '''
113  self.validate(node, options)
114 
115  # Get deepest array in LHS (excluding inside Ranges)
116  deepest_range = node.lhs.walk(Range, stop_type=Range)[-1]
117  lhs_array_ref = deepest_range.parent
118  index = lhs_array_ref.get_outer_range_index()
119  nemo_arrayrange2loop = NemoArrayRange2LoopTrans()
120  nemo_arrayrange2loop.apply(lhs_array_ref.children[index], options)
121 

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.domain.nemo.transformations.nemo_outerarrayrange2loop_trans.NemoOuterArrayRange2LoopTrans.name (   self)
:returns: the name of the transformation.
:rtype: str

Definition at line 127 of file nemo_outerarrayrange2loop_trans.py.

127  def name(self):
128  '''
129  :returns: the name of the transformation.
130  :rtype: str
131 
132  '''
133  return type(self).__name__
134 
Here is the caller graph for this function:

◆ validate()

def psyclone.domain.nemo.transformations.nemo_outerarrayrange2loop_trans.NemoOuterArrayRange2LoopTrans.validate (   self,
  node,
  options = None 
)
Perform various checks to ensure that it is valid to apply the
NemoOuterArrayRange2LoopTrans transformation to the supplied
PSyIR Node.

:param node: the node that is being checked.
:type node: :py:class:`psyclone.psyir.nodes.Assignment`
:param options: a dictionary with options for \
    transformations. No options are used in this \
    transformation. This is an optional argument that defaults \
    to None.
:type options: Optional[Dict[str, Any]]

:raises TransformationError: if the supplied node is not an \
    Assignment node, if the Assignment node does not have an \
    Array-type Reference node on its left hand side or if the \
    Array-type node does not contain at least one Range \
    node.

Definition at line 135 of file nemo_outerarrayrange2loop_trans.py.

135  def validate(self, node, options=None):
136  '''Perform various checks to ensure that it is valid to apply the
137  NemoOuterArrayRange2LoopTrans transformation to the supplied
138  PSyIR Node.
139 
140  :param node: the node that is being checked.
141  :type node: :py:class:`psyclone.psyir.nodes.Assignment`
142  :param options: a dictionary with options for \
143  transformations. No options are used in this \
144  transformation. This is an optional argument that defaults \
145  to None.
146  :type options: Optional[Dict[str, Any]]
147 
148  :raises TransformationError: if the supplied node is not an \
149  Assignment node, if the Assignment node does not have an \
150  Array-type Reference node on its left hand side or if the \
151  Array-type node does not contain at least one Range \
152  node.
153 
154  '''
155  # Am I an assignment node?
156  if not isinstance(node, Assignment):
157  raise TransformationError(
158  f"Error in NemoOuterArrayRange2LoopTrans transformation. The "
159  f"supplied node argument should be a PSyIR Assignment, but "
160  f"found '{type(node).__name__}'.")
161 
162  # Is the LHS an array reference?
163  if not (isinstance(node.lhs, Reference) and node.lhs.walk(ArrayMixin)):
164  raise TransformationError(
165  f"Error in NemoOuterArrayRange2LoopTrans transformation. The "
166  f"LHS of the supplied assignment node should be a Reference "
167  f"that contains an array access somewhere in the expression, "
168  f"but found '{node.lhs}'.")
169  # Has the array reference got a range?
170  if not node.lhs.walk(Range):
171  raise TransformationError(
172  f"Error in NemoOuterArrayRange2LoopTrans transformation. The "
173  f"LHS of the supplied assignment node should be an expression "
174  f"with an array that has a Range node, but found "
175  f"'{node.lhs}'.")
176 
177 
178 # For automatic document generation
Here is the caller graph for this function:

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