Reference Guide  2.5.0
psyclone.domain.nemo.transformations.nemo_allarrayrange2loop_trans.NemoAllArrayRange2LoopTrans Class Reference
Inheritance diagram for psyclone.domain.nemo.transformations.nemo_allarrayrange2loop_trans.NemoAllArrayRange2LoopTrans:
Collaboration diagram for psyclone.domain.nemo.transformations.nemo_allarrayrange2loop_trans.NemoAllArrayRange2LoopTrans:

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 for all PSyIR Array Ranges in an
assignment to PSyIR Loops. 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 \
        NemoAllArrayRange2LoopTrans
>>>
>>> print(schedule.view())
>>> trans = NemoAllArrayRange2LoopTrans()
>>> for assignment in schedule.walk(Assignment):
>>>     trans.apply(assignment)
>>> print(schedule.view())

Definition at line 55 of file nemo_allarrayrange2loop_trans.py.

Member Function Documentation

◆ apply()

def psyclone.domain.nemo.transformations.nemo_allarrayrange2loop_trans.NemoAllArrayRange2LoopTrans.apply (   self,
  node,
  options = None 
)
Apply the NemoAllArrayRange2Loop 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 all Range nodes within array references within
the assignment are replaced with references to the appropriate
loop indices. The appropriate number of Loops are also placed around
the modified assignment statement.

The name of each 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 each
loop are taken from the Range node if they are provided. If
not, the loop bounds are taken from the PSyclone configuration
file if a bounds value is supplied. If not, the LBOUND or
UBOUND intrinsics are used as appropriate. The type of the
Loop is also taken from the configuration file if it is
supplied for that index, otherwise it is specified as being
"unknown".

: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.
:param bool options["verbose"]: whether to print out the reason
    why the inner transformation was not applied. This is useful
    because this transfomation succeeds even if one of the inner
    transformations fails, and therefor the reason why the inner
    transformation failed is not propagated.
: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.

Reimplemented from psyclone.psyGen.Transformation.

Definition at line 78 of file nemo_allarrayrange2loop_trans.py.

78  def apply(self, node, options=None):
79  '''Apply the NemoAllArrayRange2Loop transformation to the specified
80  node if the node is an Assignment and the left-hand-side of
81  the assignment is an Array Reference containing at least one
82  Range node specifying an access to an array index. If this is
83  the case then all Range nodes within array references within
84  the assignment are replaced with references to the appropriate
85  loop indices. The appropriate number of Loops are also placed around
86  the modified assignment statement.
87 
88  The name of each loop index is taken from the PSyclone
89  configuration file if a name exists for the particular array
90  index, otherwise a new name is generated. The bounds of each
91  loop are taken from the Range node if they are provided. If
92  not, the loop bounds are taken from the PSyclone configuration
93  file if a bounds value is supplied. If not, the LBOUND or
94  UBOUND intrinsics are used as appropriate. The type of the
95  Loop is also taken from the configuration file if it is
96  supplied for that index, otherwise it is specified as being
97  "unknown".
98 
99  :param node: an Assignment node.
100  :type node: :py:class:`psyclone.psyir.nodes.Assignment`
101  :param options: a dictionary with options for transformations. No
102  options are used in this transformation. This is an optional
103  argument that defaults to None.
104  :param bool options["verbose"]: whether to print out the reason
105  why the inner transformation was not applied. This is useful
106  because this transfomation succeeds even if one of the inner
107  transformations fails, and therefor the reason why the inner
108  transformation failed is not propagated.
109  :type options: Optional[Dict[str, Any]]
110  :param bool options["allow_string"]: whether to allow the
111  transformation on a character type array range. Defaults to False.
112 
113  '''
114  self.validate(node, options)
115 
116  trans = NemoOuterArrayRange2LoopTrans()
117  try:
118  while True:
119  trans.apply(node, options)
120  except TransformationError as err:
121  # TODO #11: Instead we could use proper logging
122  if options and options.get("verbose", False):
123  errmsg = str(err)
124  # Skip the errors that are obious and are generated for any
125  # statement that is not an array expression
126  if "assignment node should be an expression with an array " \
127  "that has a Range node" not in errmsg and \
128  "be a Reference that contains an array access somewhere" \
129  not in errmsg:
130  print(errmsg)
131 

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_allarrayrange2loop_trans.NemoAllArrayRange2LoopTrans.name (   self)
:returns: the name of the transformation.
:rtype: str

Reimplemented from psyclone.psyGen.Transformation.

Definition at line 137 of file nemo_allarrayrange2loop_trans.py.

137  def name(self):
138  '''
139  :returns: the name of the transformation.
140  :rtype: str
141 
142  '''
143  return type(self).__name__
144 
Here is the caller graph for this function:

◆ validate()

def psyclone.domain.nemo.transformations.nemo_allarrayrange2loop_trans.NemoAllArrayRange2LoopTrans.validate (   self,
  node,
  options = None 
)
Perform various checks to ensure that it is valid to apply the
NemoArrayRange2LoopTrans 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.

Reimplemented from psyclone.psyGen.Transformation.

Definition at line 145 of file nemo_allarrayrange2loop_trans.py.

145  def validate(self, node, options=None):
146  '''Perform various checks to ensure that it is valid to apply the
147  NemoArrayRange2LoopTrans transformation to the supplied PSyIR Node.
148 
149  :param node: the node that is being checked.
150  :type node: :py:class:`psyclone.psyir.nodes.Assignment`
151  :param options: a dictionary with options for \
152  transformations. No options are used in this \
153  transformation. This is an optional argument that defaults \
154  to None.
155  :type options: Optional[Dict[str, Any]]
156 
157  :raises TransformationError: if the supplied node is not an \
158  Assignment.
159 
160  '''
161  # Am I an assignment node?
162  if not isinstance(node, Assignment):
163  raise TransformationError(
164  f"Error in NemoAllArrayRange2LoopTrans transformation. The "
165  f"supplied node argument should be a PSyIR Assignment, but "
166  f"found '{type(node).__name__}'.")
167 
168 
169 # For automatic document generation
Here is the caller graph for this function:

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