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

Public Member Functions

def __str__ (self)
 
def apply (self, node, options=None)
 
- Public Member Functions inherited from psyclone.psyir.transformations.loop_trans.LoopTrans
def validate (self, node, options=None)
 
def name (self)
 

Additional Inherited Members

- Static Public Attributes inherited from psyclone.psyir.transformations.loop_trans.LoopTrans
tuple excluded_node_types = ()
 

Detailed Description

Split a Dynamo 0.3 loop over cells into colours so that it can be
parallelised. For example:

>>> from psyclone.parse.algorithm import parse
>>> from psyclone.psyGen import PSyFactory
>>> import transformations
>>> import os
>>> import pytest
>>>
>>> TEST_API = "dynamo0.3"
>>> _,info=parse(os.path.join(os.path.dirname(os.path.abspath(__file__)),
>>>              "tests", "test_files", "dynamo0p3",
>>>              "4.6_multikernel_invokes.f90"),
>>>              api=TEST_API)
>>> psy = PSyFactory(TEST_API).create(info)
>>> invoke = psy.invokes.get('invoke_0')
>>> schedule = invoke.schedule
>>>
>>> ctrans = Dynamo0p3ColourTrans()
>>> otrans = DynamoOMPParallelLoopTrans()
>>>
>>> # Colour all of the loops
>>> for child in schedule.children:
>>>     ctrans.apply(child)
>>>
>>> # Then apply OpenMP to each of the colour loops
>>> for child in schedule.children:
>>>     otrans.apply(child.children[0])
>>>
>>> # Uncomment the following line to see a text view of the schedule
>>> # print(schedule.view())

Colouring in the LFRic (Dynamo 0.3) API is subject to the following rules:

* Only kernels which operate on 'CELL_COLUMN's and which increment a
  field on a continuous function space require colouring. Kernels that
  update a field on a discontinuous function space will cause this
  transformation to raise an exception. Kernels that only write to a field
  on a continuous function space also do not require colouring but are
  permitted.
* A kernel may have at most one field with 'GH_INC' access.
* A separate colour map will be required for each field that is coloured
  (if an invoke contains >1 kernel call).

Definition at line 1040 of file transformations.py.

Member Function Documentation

◆ apply()

def psyclone.transformations.Dynamo0p3ColourTrans.apply (   self,
  node,
  options = None 
)
Performs Dynamo0.3-specific error checking and then uses the parent
class to convert the Loop represented by :py:obj:`node` into a
nested loop where the outer loop is over colours and the inner
loop is over cells of that colour.

:param node: the loop to transform.
:type node: :py:class:`psyclone.domain.lfric.LFRicLoop`
:param options: a dictionary with options for transformations.\
:type options: Optional[Dict[str, Any]]

Reimplemented from psyclone.transformations.ColourTrans.

Definition at line 1090 of file transformations.py.

1090  def apply(self, node, options=None):
1091  '''Performs Dynamo0.3-specific error checking and then uses the parent
1092  class to convert the Loop represented by :py:obj:`node` into a
1093  nested loop where the outer loop is over colours and the inner
1094  loop is over cells of that colour.
1095 
1096  :param node: the loop to transform.
1097  :type node: :py:class:`psyclone.domain.lfric.LFRicLoop`
1098  :param options: a dictionary with options for transformations.\
1099  :type options: Optional[Dict[str, Any]]
1100 
1101  '''
1102  # check node is a loop
1103  super().validate(node, options=options)
1104 
1105  # Check we need colouring
1106  const = LFRicConstants()
1107  if node.field_space.orig_name in \
1108  const.VALID_DISCONTINUOUS_NAMES:
1109  raise TransformationError(
1110  "Error in DynamoColour transformation. Loops iterating over "
1111  "a discontinuous function space are not currently supported.")
1112 
1113  # Colouring is only necessary (and permitted) if the loop is
1114  # over cells. Since this is the default it is represented by
1115  # an empty string.
1116  if node.loop_type != "":
1117  raise TransformationError(
1118  f"Error in DynamoColour transformation. Only loops over cells "
1119  f"may be coloured but this loop is over {node.loop_type}")
1120 
1121  # Check whether we have a field that has INC access
1122  if not node.has_inc_arg():
1123  # TODO generate a warning here as we don't need to colour
1124  # a loop that does not update a field with INC access
1125  pass
1126 
1127  # Check that we're not attempting to colour a loop that is
1128  # already within an OpenMP region (because the loop over
1129  # colours *must* be sequential)
1130  if node.ancestor(OMPDirective):
1131  raise TransformationError("Cannot have a loop over colours "
1132  "within an OpenMP parallel region.")
1133 
1134  super().apply(node, options=options)
1135 

References psyclone.psyir.transformations.loop_trans.LoopTrans.validate().

Here is the call graph for this function:

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