psyclone.domain.nemo.transformations.create_nemo_loop_trans

Module providing a transformation from a generic PSyIR Loop into a NEMO Loop.

Classes

class psyclone.domain.nemo.transformations.create_nemo_loop_trans.CreateNemoLoopTrans

Transform a generic PSyIR Loop into a NemoLoop. For example:

>>> from psyclone.psyir.frontend.fortran import FortranReader
>>> from psyclone.psyir.nodes import Loop
>>> from psyclone.domain.nemo.transformations import CreateNemoLoopTrans
>>> code = '''
... subroutine sub()
...   integer :: ji, tmp(10)
...   do ji=1, 10
...     tmp(ji) = 2*ji
...   end do
... end subroutine sub'''
>>> psyir = FortranReader().psyir_from_source(code)
>>> loops = psyir.walk(Loop)
>>> trans = CreateNemoLoopTrans()
>>> trans.apply(loops[0])
>>> print(psyir.view(colour=False))
FileContainer[]
    Routine[name:'sub']
        0: Loop[type='lon', field_space='None', it_space='None']
            Literal[value:'1', Scalar<INTEGER, UNDEFINED>]
            Literal[value:'10', Scalar<INTEGER, UNDEFINED>]
            Literal[value:'1', Scalar<INTEGER, UNDEFINED>]
            Schedule[]
                0: Assignment[]
                    ArrayReference[name:'tmp']
                        Reference[name:'ji']
                    BinaryOperation[operator:'MUL']
                        Literal[value:'2', Scalar<INTEGER, UNDEFINED>]
                        Reference[name:'ji']

As shown above, the resulting Schedule now contains a NemoLoop, indicated by the “type=’lon’” (for ‘longitude’) annotation for the Loop node.

Inheritance

Inheritance diagram of CreateNemoLoopTrans
apply(loop, options=None)

Takes a generic PSyIR Loop node and replaces it with a NemoLoop.

Parameters:
  • loop (psyclone.psyir.nodes.Loop) – the Loop node to be transformed.

  • options (Optional[Dict[str, Any]]) – a dictionary with options for transformations. No options are used in this transformation. This is an optional argument that defaults to None.

property name
Returns:

the name of the transformation.

Return type:

str

TODO #1214 remove this method.

validate(node, options=None)

Check that the supplied node is a valid target for this transformation.

Parameters:
  • node (psyclone.psyir.nodes.Node) – the target of the transformation.

  • options (Optional[Dict[str, Any]]) – a dictionary with options for transformations. No options are used in this transformation. This is an optional argument that defaults to None.

Raises:

TransformationError – if the supplied node is not a Routine.