loki.transform.dependency_transform

Classes

DependencyTransformation(suffix[, mode, ...])

Basic Transformation class that facilitates dependency injection for transformed Module and Subroutine into complex source trees.

class DependencyTransformation(suffix, mode='module', module_suffix=None, include_path=None, replace_ignore_items=True)

Bases: Transformation

Basic Transformation class that facilitates dependency injection for transformed Module and Subroutine into complex source trees. It does so by appending a provided suffix argument to transformed subroutine and module objects and changing the target names of Import and CallStatement nodes on the call-site accordingly.

The DependencyTransformation provides two mode options:

  • strict honors dependencies via C-style headers

  • module replaces C-style header dependencies with explicit module imports

When applying the transformation to a source object, one of two “roles” can be specified via the role keyword:

  • driver: Only renames imports and calls to kernel routines

  • kernel: Renames routine or enclosing modules, as well as renaming any further imports and calls.

Note that routine.apply(transformation, role='driver') entails that the routine still mimicks its original counterpart and can therefore be used as a drop-in replacement during compilation that then diverts the dependency tree to the modified sub-tree.

Parameters:
  • suffix (str) – The suffix to apply during renaming

  • mode (str) – The injection mode to use; either ‘strict’ or ‘module’

  • module_suffix (str) – Special suffix to signal module names like _MOD

  • path (include) – Directory for generating additional header files

  • replace_ignore_items (bool) – Debug flag to toggle the replacement of calls to subroutines in the ignore. Default is True.

traverse_file_graph = True
recurse_to_modules = True
recurse_to_procedures = True
recurse_to_internal_procedures = False
transform_subroutine(routine, **kwargs)

Rename driver subroutine and all calls to target routines. In ‘strict’ mode, also re-generate the kernel interface headers.

update_result_var(routine)

Update name of result variable for function calls.

transform_module(module, **kwargs)

Rename kernel modules and re-point module-level imports.

transform_file(sourcefile, **kwargs)

In ‘module’ mode perform module-wrapping for dependency injection.

rename_calls(routine, **kwargs)

Update calls to actively transformed subroutines.

Parameters:

targets – Optional list of subroutine names for which to modify the corresponding calls.

rename_imports(source, imports, **kwargs)

Update imports of actively transformed subroutines.

Parameters:

targets – Optional list of subroutine names for which to modify the corresponding calls.

rename_interfaces(source, intfs, **kwargs)

Update explicit interfaces to actively transformed subroutines.

derive_module_name(modname)

Utility to derive a new module name from suffix and module_suffix

generate_interfaces(source)

Generate external header file with interface block for this subroutine.

module_wrap(sourcefile, **kwargs)

Wrap target subroutines in modules and replace in source file.