psyclone.domain.lfric.transformations.lfric_loop_fuse_trans#

This module provides the LFRic-specific loop fusion transformation.

Classes#

class psyclone.domain.lfric.transformations.lfric_loop_fuse_trans.LFRicLoopFuseTrans[source]#

LFRic API specialisation of the base class in order to fuse two LFRic loops after performing validity checks. For example:

>>> from psyclone.parse.algorithm import parse
>>> from psyclone.psyGen import PSyFactory
>>>
>>> API = "lfric"
>>> FILENAME = "alg.x90"
>>> ast, invokeInfo = parse(FILENAME, api=API)
>>> psy = PSyFactory(API, distributed_memory=False).create(invoke_info)
>>> schedule = psy.invokes.get('invoke_0').schedule
>>>
>>> from psyclone.domain.lfric.transformations import LFRicLoopFuseTrans
>>> ftrans =  LFRicLoopFuseTrans()
>>>
>>> ftrans.apply(schedule[0], schedule[1])
>>> print(schedule.view())

The optional argument same_space can be set as

>>> ftrans.apply(schedule[0], schedule[1], {"same_space": True})

when applying the transformation.

Inheritance

Inheritance diagram of LFRicLoopFuseTrans
apply(node1, node2, options=None, **kwargs)[source]#

Applies the LFricLoopFuseTrans to the provided nodes.

Parameters:
  • node1 (LFRicLoop) – the first Loop to fuse.

  • node2 (LFRicLoop) – the second Loop to fuse.

  • options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.

  • options["same_space"] (bool) – this optional flag, set to True, asserts that an unknown iteration space (i.e. ANY_SPACE) matches the other iteration space. This is set at the user’s own risk. If both iteration spaces are discontinuous the loops can be fused without having to use the same_space flag.

  • force (bool) – whether to force fusion of the target loop (i.e. ignore any dependence analysis). This only skips a limited number of the checks, and does not fully force merging.

  • node_type_check (bool) – If the type of nodes enclosed in the loop should be tested to avoid including unsupported nodes in the transformation.

  • verbose (bool) – whether to log the reason the validation failed, at the moment with a comment in the provided PSyIR node.

validate(node1, node2, options=None, **kwargs)[source]#

Performs various checks to ensure that it is valid to apply the LFRicLoopFuseTrans transformation to the supplied loops.

Parameters:
  • node1 (LFRicLoop) – the first Loop to fuse.

  • node2 (LFRicLoop) – the second Loop to fuse.

  • options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.

  • options["same_space"] (bool) – this optional flag, set to True, asserts that an unknown iteration space (i.e. ANY_SPACE) matches the other iteration space. This is set at the user’s own risk. If both iteration spaces are discontinuous the loops can be fused without having to use the same_space flag.

  • force (bool) – whether to force fusion of the target loop (i.e. ignore any dependence analysis). This only skips a limited number of the checks, and does not fully force merging.

  • node_type_check (bool) – If the type of nodes enclosed in the loop should be tested to avoid including unsupported nodes in the transformation.

  • verbose (bool) – whether to log the reason the validation failed, at the moment with a comment in the provided PSyIR node.

Raises:
  • TransformationError – if either of the supplied loops contains an inter-grid kernel.

  • TransformationError – if one or both function spaces have invalid names.

  • TransformationError – if the same_space flag was set, but does not apply because neither field is on ANY_SPACE or the spaces are not the same.

  • TransformationError – if one or more of the iteration spaces is unknown (ANY_SPACE) and the same_space flag is not set to True.

  • TransformationError – if the loops are over different spaces that are not both discontinuous and the loops both iterate over cells.

  • TransformationError – if the loops’ upper bound names are not the same.

  • TransformationError – if the halo-depth indices of two loops are not the same.

  • TransformationError – if each loop already contains a reduction.

  • TransformationError – if the first loop has a reduction and the second loop reads the result of the reduction.