loki.bulk.scheduler
Classes
|
Work queue manager to enqueue and process individual Item routines/modules with a given kernel. |
|
Configuration object for the transformation |
- class Scheduler(paths, config=None, seed_routines=None, preprocess=False, includes=None, defines=None, definitions=None, xmods=None, omni_includes=None, full_parse=True, frontend=Frontend.FP)
Bases:
object
Work queue manager to enqueue and process individual Item routines/modules with a given kernel.
Note: The processing module can create a callgraph and perform automated discovery, to enable easy bulk-processing of large numbers of source files.
- Parameters:
paths (str or list of str) – List of paths to search for automated source file detection.
config (dict or str, optional) – Configuration dict or path to scheduler configuration file
seed_routines (list of str, optional) – Names of routines from which to populate the callgraph initially. If not provided, these will be inferred from the given config.
preprocess (bool, optional) – Flag to trigger CPP preprocessing (by default False).
includes (list of str, optional) – Include paths to pass to the C-preprocessor.
defines (list of str, optional) – Symbol definitions to pass to the C-preprocessor.
definitions (list of
Module
, optional) –Module
object(s) that may supply external type or procedure definitions.xmods (str, optional) – Path to directory to find and store
.xmod
files when using the OMNI frontend.omni_includes (list of str, optional) – Additional include paths to pass to the preprocessor run as part of the OMNI frontend parse. If set, this replaces (!)
includes
, otherwiseomni_includes
defaults to the value ofincludes
.full_parse (bool, optional) – Flag indicating whether a full parse of all sourcefiles is required. By default a full parse is executed, use this flag to suppress.
frontend (
Frontend
, optional) – Frontend to use when parsing source files (defaultFP
).
- depths
depth of each item according to the topological generations (stratified item graph)
- Type:
- source_suffixes = ['.f90', '.F90', '.f', '.F']
- property routines
- property typedefs
- property dependencies
All individual pairs of
Item
that represent a dependency and form an edge in the :any`Scheduler` call graph.
- property definitions
The list of definitions that the source files in the callgraph provide
- property file_graph
Alternative dependency graph based on relations between source files
- Return type:
nx.DiGraph
- create_item(name)
Create an Item by looking up the path and setting all inferred properties.
If the item cannot be created due to unknown source files, and the default configuration does not force
strict
behaviour,None
is returned.Note that this takes a SchedulerConfig object for default options and an item-specific dict with override options, as well as given attributes that might be forced on this item from its parent.
- find_routine(routine)
Find the given routine name in the
obj_map
This looks for matching candidates, possibly ignoring module scopes. If this yields more than one match, it will print a warning and use the first match. If
strict
mode is active,RuntimeError
is raised.This is used when filling the scheduler graph with the initial starting points without the need to provide these with fully-qualified names.
- add_dependencies(dependencies)
Add new dependencies to the item graph
- Parameters:
dependencies (dict) – Mapping from items to new dependencies of that item
- item_successors(item)
Yields list of successor
Item
for the givenitem
Successors are all items onto which a dependency exists, such as call targets.
For intermediate items, such as
ProcedureBindingItem
, this yields also the successors of these items to provide direct access to the called routine.
- process(transformation)
Process all
items
in the scheduler’s graphBy default, the traversal is performed in topological order, which ensures that
CallStatement
objects are always processed before their targetSubroutine
. This order can be reversed by settingreverse
toTrue
.The scheduler applies the transformation to the IR node corresponding to each item in the scheduler’s graph. For example, for a
SubroutineItem
, the transformation is applied to the correspondingSubroutine
object.Optionally, the traversal can be performed on a source file level only, by setting
use_file_graph
toTrue
. This calls the transformation on allSourcefile
objects that contain at least one object corresponding to an item in the scheduler graph. If combined with aitem_filter
, only source files with at least one object corresponding to an item of that type are processed.
- callgraph(path, with_file_graph=False)
Generate a callgraph visualization and dump to file.
- Parameters:
path (str or pathlib.Path) – Path to write the callgraph figure to.
with_filegraph (bool or str or pathlib.Path) – Visualize file dependencies in an additional file. Can be set to True or a file path to write to.
- write_cmake_plan(filepath, mode, buildpath, rootpath)
Generate the “plan file”, a CMake file defining three lists that contain the respective files to append / remove / transform. These lists are used by the CMake wrappers to schedule the source updates and update the source lists of the CMake target object accordingly.
- class SchedulerConfig(default, routines, disable=None, dimensions=None, dic2p=None, derived_types=None, enable_imports=False)
Bases:
object
Configuration object for the transformation
Scheduler
that encapsulates default behaviour and item-specific behaviour. Can be create either from a raw dictionary or configration file.- Parameters:
default (dict) – Default options for each item
routines (dict of dicts or list of dicts) – Dicts with routine-specific options.
dimensions (dict of dicts or list of dicts) – Dicts with options to define :any`Dimension` objects.
disable (list of str) – Subroutine names that are entirely disabled and will not be added to either the callgraph that we traverse, nor the visualisation. These are intended for utility routines that pop up in many routines but can be ignored in terms of program control flow, like
flush
orabort
.enable_imports (bool) – Disable the inclusion of module imports as scheduler dependencies.
- classmethod from_dict(config)
- classmethod from_file(path)