loki.transformations.dependency module

class DuplicateKernel(duplicate_kernels=None, duplicate_suffix='duplicated', duplicate_module_suffix=None, duplicate_subgraph=False)

Bases: Transformation

Duplicate subroutines which includes the creation of new :any:`Item`s as well as the addition of the corresponding new dependencies.

Therefore, this transformation creates a new item and also implements the relevant routines for dry-run pipeline planning runs.

Parameters:
  • duplicate_kernels (str|tuple|list, optional) – Kernel name(s) to be duplicated.

  • duplicate_suffix (str, optional) – Suffix to be used to append the original kernel name(s).

  • duplicate_module_suffix (str, optional) – Suffix to be used to append the original module name(s), if defined, otherwise duplicate_suffix

  • duplicate_subgraph (bool, optional) – Whether or not duplicate the subgraph beneath the kernel(s) that are duplicated.

creates_items = True
reverse_traversal = True
transform_subroutine(routine, **kwargs)

Defines the transformation to apply to Subroutine items.

For transformations that modify Subroutine objects, this method should be implemented. It gets called via the dispatch method apply().

Parameters:
  • routine (Subroutine) – The subroutine to be transformed.

  • **kwargs (optional) – Keyword arguments for the transformation.

plan_subroutine(routine, **kwargs)

Define the planning steps to apply for Subroutine items.

For transformations that modify the dependencies of routine (e.g., adding new procedure calls, inlining calls, renaming the interface) this should be implemented. It gets called via the dispatch method apply() if the optional plan_mode argument is set to True.

Parameters:
  • routine (Subroutine) – The subroutine to be transformed.

  • **kwargs (optional) – Keyword arguments for the transformation.

class RemoveKernel(remove_kernels=None)

Bases: Transformation

Remove subroutines which includes the removal of the relevant :any:`Item`s as well as the removal of the corresponding dependencies.

Therefore, this transformation creates a new item and also implements the relevant routines for dry-run pipeline planning runs.

Parameters:

remove_kernels (str|tuple|list, optional) – Kernel name(s) to be removed.

creates_items = True
transform_subroutine(routine, **kwargs)

Defines the transformation to apply to Subroutine items.

For transformations that modify Subroutine objects, this method should be implemented. It gets called via the dispatch method apply().

Parameters:
  • routine (Subroutine) – The subroutine to be transformed.

  • **kwargs (optional) – Keyword arguments for the transformation.

plan_subroutine(routine, **kwargs)

Define the planning steps to apply for Subroutine items.

For transformations that modify the dependencies of routine (e.g., adding new procedure calls, inlining calls, renaming the interface) this should be implemented. It gets called via the dispatch method apply() if the optional plan_mode argument is set to True.

Parameters:
  • routine (Subroutine) – The subroutine to be transformed.

  • **kwargs (optional) – Keyword arguments for the transformation.

class SeparateModesKernel(rename_suffix='_loki_{mode}')

Bases: Transformation

Duplicate subroutines which includes the creation of new :any:`Item`s as well as the addition of the corresponding new dependencies.

Therefore, this transformation creates a new item and also implements the relevant routines for dry-run pipeline planning runs.

Parameters:

rename_suffixstr, optional

Suffix to be used to append the original kernel name(s) and module name(s). Must be a valid format string that accepts a mode keyword argument, which is used to generate the suffix for the new item names.

creates_items = True
renames_items = True
reverse_traversal = True
rename_interfaces(item, mapping)

Update Interface names to actively transformed procedures.

Parameters:
  • item (Item) – The item for which to rename interfaces.

  • mapping (dict) – A mapping from old dependency item names to new dependency items.

rename_imports(item, mapping)

Update Import statements to actively transformed procedures and modules.

Updates imports of C-style headers and Fortran modules to match the new mode-specific names.

Parameters:
  • item (Item) – The item for which to rename imports.

  • mapping (dict) – A mapping from old dependency item names to new dependency items.

rename_calls(item, mapping)

Update CallStatement and InlineCall to actively transformed procedures

Parameters:
  • item (Item) – The item for which to rename calls.

  • mapping (dict) – A mapping from old dependency item names to new dependency items.

transform_subroutine(routine, **kwargs)

Transform the given subroutine by creating new items for the different modes and updating the dependencies accordingly.

plan_subroutine(routine, **kwargs)

Transform the given subroutine by creating new items for the different modes and registering the new dependencies in the item’s plan_data accordingly.