loki.transformations.replace_kernel
Classes
|
Replace configured kernel calls with alternative routines. |
- class ReplaceKernels(replace_kernels_map=None)
Bases:
TransformationReplace configured kernel calls with alternative routines.
This transformation supports:
replacing selected call targets by routine name;
remapping arguments by direct rename;
remapping arguments by extracting a member from a derived-type actual;
remapping arguments by formatting a custom expression template;
overriding an argument with a positional value;
overriding an argument with a literal or expression string;
rewriting
USEimports and.intfb.hinclude-style imports;optionally keeping the replacement routine out of scheduler traversal and CMake planning via
block=True.
Conceptually, the transformation walks each call site in the processed routine, looks for names listed in
replace_kernels_map, resolves the replacement routine, and reconstructs the actual argument list against the replacement signature. When the original call target is unresolved in the IR, the transformation also tries to resolve the original routine from source so that remapping can still be done against the original dummy argument names instead of the raw actual expressions. Once the replacement call has been rebuilt, the transformation updates imports/includes to match the new callee and optionally marks the replacement routine as blocked for further scheduler traversal.The replacement map accepts entries of the form:
{ 'old_kernel': { 'routine': 'new_kernel', 'args': { 'old_dummy': 'new_dummy', 'struct_arg': {'map_to': 'new_dummy', 'member': 'MEMBER'}, 'old_end': { 'map_to': 'new_end', 'expr': 'MOD({geom}%TOTAL%NGPTOT, {geom}%DIM%NPROMA)', 'placeholders': {'geom': 'geom'}, }, 'old_start': {'position': 1}, 'new_flag': '.true.', }, 'block': True, } }
- Parameters:
replace_kernels_map (dict, optional) –
Case-insensitive mapping from original routine name to replacement configuration. Each configuration entry supports the following keys:
routineName of the replacement routine.
argsOptional mapping that controls how actual arguments are rebuilt for the replacement call. Supported forms are:
'old_dummy': 'new_dummy'Map the actual argument of
old_dummyonto the replacement dummynew_dummy.'old_dummy': {'position': 1}Pass a positional literal or expression to the replacement dummy named
old_dummy.'old_dummy': {'map_to': 'new_dummy', 'member': 'MEMBER'}Pass
actual%MEMBERfrom the original argumentold_dummyto the replacement dummynew_dummy.
'old_dummy': {'map_to': 'new_dummy', 'expr': '...', 'placeholders': {'name': 'old_dummy_name'}}Build an expression by formatting the template string with the resolved original actual arguments and pass the result to the replacement dummy
new_dummy.'new_dummy': '.true.'Pass a literal or expression string directly to the replacement dummy
new_dummy.
blockIf true, mark the replacement routine/module as blocked in the current scheduler item so that it is not traversed or added to the generated plan.
- creates_items = True
- transform_subroutine(routine, **kwargs)
Defines the transformation to apply to
Subroutineitems.For transformations that modify
Subroutineobjects, this method should be implemented. It gets called via the dispatch methodapply().- 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
Subroutineitems.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 methodapply()if the optionalplan_modeargument is set to True.- Parameters:
routine (
Subroutine) – The subroutine to be transformed.**kwargs (optional) – Keyword arguments for the transformation.