psyclone.domain.common.transformations#
Submodules#
Classes#
AlgInvoke2PSyCallTrans: Base class to transform (lower) an AlgorithmInvokeCall into aAlgTrans: Transform a generic PSyIR representation of the Algorithm layer toKernelModuleInlineTrans: Brings the routine being called into the same Container as the callRaisePSyIR2AlgTrans: Transform a generic PSyIR representation of an Algorithm-layer
- class psyclone.domain.common.transformations.AlgInvoke2PSyCallTrans[source]#
Base class to transform (lower) an AlgorithmInvokeCall into a standard Call to a generated PSy-layer routine. Requires the abstract get_arguments method to be implemented as the logic to create arguments can differ between APIs.
This transformation would normally be written as a lowering method on an AlgorithmInvokeCall. However, we don’t always want to lower the code as we want the flexibility to also be able to output algorithm-layer code containing invoke’s. We therefore need to selectively apply the lowering, which is naturally written as a transformation.
Inheritance

- apply(node, options=None, **kwargs)[source]#
Apply the transformation to the supplied AlgorithmInvokeCall. The supplied node will be replaced with a Call node with appropriate arguments. If there are no more invoke calls in the scope of the symbol table containing the ‘invoke’ symbol then that symbol is removed.
- Parameters:
node (
psyclone.domain.common.psyir.AlgorithmInvokeCall) – a PSyIR algorithm invoke call node.options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
- abstractmethod get_arguments(node, options=None)[source]#
- Parameters:
node (
psyclone.domain.common.psyir.AlgorithmInvokeCall) – a PSyIR algorithm invoke call node.options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
- static remove_imported_symbols(node)[source]#
Removes any imported kernel functor symbols from the supplied AlgorithmInvokeCall if they are not used in another AlgorithmInvokeCall. Also removes the associated container symbol if there are now no symbols imported from it.
- Parameters:
node (
psyclone.domain.common.algorithm.AlgorithmInvokeCall) – an AlgorithmInvokeCall node.
- validate(node, options=None, **kwargs)[source]#
Validate the node argument.
- Parameters:
node (
psyclone.domain.common.algorithm.AlgorithmInvokeCall) – a PSyIR node capturing an invoke call.options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
- Raises:
TransformationError – if the supplied call argument is not a PSyIR AlgorithmInvokeCall node.
InternalError – if no corresponding ‘invoke’ symbol is present.
- class psyclone.domain.common.transformations.AlgTrans[source]#
Transform a generic PSyIR representation of the Algorithm layer to a PSyclone version with specialised domain-specific nodes.
Inheritance

- apply(node, options=None, **kwargs)[source]#
Apply transformation to the supplied PSyIR node.
- Parameters:
node (
psyclone.psyir.node.Routineorpsyclone.psyir.node.Container) – a PSyIR node that is the root of a PSyIR tree.options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
- validate(node, options=None, **kwargs)[source]#
Validate the supplied PSyIR tree.
- Parameters:
node (
psyclone.psyir.node.Routineorpsyclone.psyir.node.Container) – a PSyIR node that is the root of a PSyIR tree.options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
- Raises:
TransformationError – if the supplied node argument is not a Routine or a Container.
TransformationError – if the supplied node argument has a parent.
- class psyclone.domain.common.transformations.KernelModuleInlineTrans[source]#
Brings the routine being called into the same Container as the call site. For example:
from psyclone.domain.common.transformations import \ KernelModuleInlineTrans inline_trans = KernelModuleInlineTrans() inline_trans.apply(schedule.walk(CodedKern)[0]) print(schedule.parent.view())
Warning
Not all Routines can be moved. This transformation will reject attempts to move routines that access private data in the original Container.
Inheritance

- apply(node, options=None, **kwargs)[source]#
Bring the implementation of this kernel/call into this Container.
NOTE: when applying this transformation to a Kernel in a PSyKAl invoke, all Kernels of that name in that invoke are marked as inlined. Similarly, when applied to a Call to a Routine in a particular scope, all Calls to a routine of that name in that scope are updated.
- Parameters:
node (
psyclone.psyGen.CodedKern|psyclone.psyir.nodes.Call) – the Kernel or Call to module-inline.options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
- validate(node, options=None, **kwargs)[source]#
Checks that the supplied node is a Kernel or Call and that it is possible to inline its PSyIR into the parent Container.
- Parameters:
node (
psyclone.psyGen.CodedKern|psyclone.psyir.nodes.Call) – the kernel or call which is the target of the transformation.options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
- Raises:
TransformationError – if the target node is not a sub-class of psyGen.CodedKern or psyir.nodes.Call or is an IntrinsicCall.
TransformationError – if there is no explicit import of the called Routine and there is already a Routine of that name in the parent Container.
TransformationError – if the call is to a polymorphic routine and there’s no Container at the call site to which to add the interface definition.
TransformationError – if the kernel cannot be safely inlined.
TransformationError – if the target of the supplied call is already module inlined.
- class psyclone.domain.common.transformations.RaisePSyIR2AlgTrans[source]#
Transform a generic PSyIR representation of an Algorithm-layer invoke call to a PSyclone version with specialised domain-specific nodes.
Inheritance

- apply(node, index=None, options=None, **kwargs)[source]#
Apply the transformation to the supplied node.
- Parameters:
node (
Call) – a PSyIR call node capturing an invoke call in generic PSyIR.index (
int) – the position of this invoke call relative to other invokes in the algorithm layer.options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
- validate(node, options=None, **kwargs)[source]#
Validate the node argument.
- Parameters:
node (
Call) – a PSyIR call node capturing an invoke call in generic PSyIR.options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
index (int) – the position of this invoke call relative to other invokes in the algorithm layer.
- Raises:
TransformationError – if the supplied call argument is not a PSyIR Call node.
TransformationError – if the supplied call argument does not have the expected name which would identify it as an invoke call.
TransformationError – if there is more than one named argument.
TransformationError – if the named argument does not conform to the name=str format.
TransformationError – if the name of the invoke is invalid.
TransformationError – if the invoke arguments are not a PSyIR ArrayReference or CodeBlock.