psyclone.domain.nemo.transformations.create_nemo_psy_trans
Module providing a transformation from a generic PSyIR representation of a PSy layer into a NEMO-specific one.
Classes
CreateNemoPSyTrans
: Transform generic (language-level) PSyIR representation into a PSyclone
- class psyclone.domain.nemo.transformations.create_nemo_psy_trans.CreateNemoPSyTrans
Transform generic (language-level) PSyIR representation into a PSyclone version with specialised, NEMO-specific nodes. For example:
>>> from psyclone.psyir.frontend.fortran import FortranReader >>> from psyclone.psyir.nodes import Loop >>> from psyclone.domain.nemo.transformations import CreateNemoPSyTrans >>> 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) >>> loop = psyir.walk(Loop)[0] >>> trans = CreateNemoPSyTrans() >>> trans.apply(psyir) >>> print(psyir.view(colour=False, indent=" ")) FileContainer[] NemoInvokeSchedule[invoke='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']
The result of this transformation is that the root Routine has been converted into a NemoInvokeSchedule, the Loop is now a NemoLoop (with type ‘lon’ [for longitude]) and the body of the loop is now an InlinedKern.
Inheritance
- apply(psyir, options=None)
Takes generic PSyIR and replaces recognised structures with NEMO-specific PSyIR (in-place). Note that this may mean replacing the top-level node itself and therefore this routine returns the root of the modified tree.
- Parameters:
psyir (
psyclone.psyir.nodes.Node
) – the root node of the PSyIR tree to process.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 root of the PSyIR tree 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.
- Raises:
TransformationError – if the supplied node is not a PSyIR node.