psyclone.psyir.nodes.extract_node#

This module provides support for extraction of code within a specified invoke. The extracted code may be a single kernel, multiple occurrences of a kernel in an invoke, nodes in an invoke or the entire invoke (extraction applied to all Nodes).

There is currently only one class in this module: ExtractNode (see below).

Another class which contains helper functions for code extraction, such as wrapping up settings for generating driver for the extracted code, will be added in Issue #298.

Classes#

  • ExtractNode: This class can be inserted into a Schedule to mark Nodes for

class psyclone.psyir.nodes.extract_node.ExtractNode(ast=None, children=None, parent=None, options=None)[source]#

This class can be inserted into a Schedule to mark Nodes for code extraction using the ExtractRegionTrans transformation. By applying the transformation the Nodes marked for extraction become children of (the Schedule of) an ExtractNode.

Parameters:
  • ast (sub-class of fparser.two.Fortran2003.Base) – reference into the fparser2 parse tree corresponding to this node.

  • children (list of psyclone.psyir.nodes.Node) – the PSyIR nodes that are children of this node.

  • parent (psyclone.psyir.nodes.Node) – the parent of this node in the PSyIR tree.

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

  • options["prefix"] (str) – a prefix to use for the PSyData module name (prefix_psy_data_mod) and the PSyDataType (prefix_PSyDataType) - a “_” will be added automatically. It defaults to “extract”, which means the module name used will be extract_psy_data_mode, and the data type extract_PSyDataType.

  • options["post_var_postfix"] (str) – a postfix to be used when creating names to store values of output variable. A variable ‘a’ would store its value as ‘a’, and its output values as ‘a_post’ with the default post_var_postfix of ‘_post’.

  • options["read_write_info"] (py:class:psyclone.psyir.tools.ReadWriteInfo) – information about variables that are read and/or written in the instrumented code.

Inheritance

Inheritance diagram of ExtractNode
static bring_external_symbols(read_write_info, symbol_table)[source]#

Use the ModuleManager to explore external dependencies and bring symbols used in other modules into scope (with ImportInterface). The symbols will be tagged with a ‘signature@module_name’ tag.

Parameters:
static determine_postfix(read_write_info, postfix='_post')[source]#

This function prevents any name clashes that can occur when adding the postfix to output variable names. For example, if there is an output variable ‘a’, the driver (and the output file) will contain two variables: ‘a’ and ‘a_post’. But if there is also another variable called ‘a_post’, a name clash would occur (two identical keys in the output file, and two identical local variables in the driver). In order to avoid this, the suffix ‘post’ is changed (to ‘post0’, ‘post1’, …) until any name clashes are avoided. This works for structured and non-structured types.

Parameters:
  • read_write_info (psyclone.psyir.tools.ReadWriteInfo) – information about all input and output parameters.

  • postfix (str) – the postfix to append to each output variable.

Return type:

str

Returns:

a postfix that can be added to each output variable without generating a name clash.

property extract_body#
Returns:

the Schedule associated with this ExtractNode.

Return type:

psyclone.psyir.nodes.Schedule

flatten_references()[source]#

Replace StructureReferencces with a simple Reference and a flattened name (replacing all % with _).

get_unique_region_name(nodes)[source]#

This function returns the region and module name. If they are specified in the user options, these names will just be returned (it is then up to the user to guarantee uniqueness). Otherwise a name based on the module and invoke will be created using indices to make sure the name is unique.

Parameters:

nodes (List[Node]) – a list of nodes.

lower_to_language_level()[source]#

Lowers this node (and all children) to language-level PSyIR. The PSyIR tree is modified in-place.

Returns:

the lowered version of this node.

Return type:

psyclone.psyir.node.Node

property post_name#
Returns:

the _post_name member of this ExtractNode.

Return type:

str