psyclone.psyir.tools

Tool module, containing all generic (API independent) tools.

Submodules

Classes

  • DTCode: A simple enum to store the various info, warning and error

  • DependencyTools: This class provides some useful dependency tools, allowing a user to

  • ReadWriteInfo: This class stores signature and container name of variables read or

class psyclone.psyir.tools.DTCode(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)

A simple enum to store the various info, warning and error codes used in the dependency analysis. It is based in IntEnum so the codes can be compared with the …_MIN and …_MAX values.

Inheritance

Inheritance diagram of DTCode
class psyclone.psyir.tools.DependencyTools(loop_types_to_parallelise=None)

This class provides some useful dependency tools, allowing a user to overwrite/modify functions depending on the application. It includes a messaging system where functions can store messages that might be useful for the user to see.

Parameters:

loop_types_to_parallelise (Optional[List[str]]) – A list of loop types that will be considered for parallelisation. An example loop type might be ‘lat’, indicating that only loops over latitudes should be parallelised. The actually supported list of loop types is specified in the PSyclone config file. This can be used to exclude for example 1-dimensional loops.

Raises:

TypeError – if an invalid loop type is specified.

Inheritance

Inheritance diagram of DependencyTools
can_loop_be_parallelised(loop, test_all_variables=False, signatures_to_ignore=None)

This function analyses a loop in the PsyIR to see if it can be safely parallelised.

Parameters:
  • loop (psyclone.psyir.nodes.Loop) – the loop node to be analysed.

  • test_all_variables (bool) – if True, it will test if all variable accesses can be parallelised, otherwise it will stop after the first variable is found that can not be parallelised.

  • signatures_to_ignore (Optional[ List[psyclone.core.Signature]]) – list of signatures for which to skip the access checks.

Returns:

True if the loop can be parallelised.

Return type:

bool

Raises:

TypeError – if the supplied node is not a Loop.

get_all_messages()

Returns all messages that have been stored by the last function the user has called.

Returns:

a list of all messages.

Return type:

List[str]

get_in_out_parameters(node_list, options=None)

Returns a ReadWriteInfo object that contains all variables that are input and output parameters to the specified node list. This function calls get_input_parameter and get_output_parameter, but avoids the repeated computation of the variable usage.

Parameters:
  • node_list (List[psyclone.psyir.nodes.Node]) – list of PSyIR nodes to be analysed.

  • options (Optional[Dict[str, Any]]) – a dictionary with options for the dependency tools which will also be used when creating the VariablesAccessInfo instance if required.

  • options["COLLECT-ARRAY-SHAPE-READS"] (Any) – if this option is set to a True value, arrays used as first parameter to the PSyIR operators lbound, ubound, or size will be reported as ‘read’. Otherwise, these accesses will be ignored.

Returns:

a ReadWriteInfo object with the information about input- and output parameters.

Return type:

psyclone.psyir.tools.ReadWriteInfo

get_input_parameters(read_write_info, node_list, variables_info=None, options=None)

Adds all variables that are input parameters (i.e. are read before potentially being written) to the read_write_info object.

Parameters:
  • read_write_info (psyclone.psyir.tools.ReadWriteInfo) – this object stores the information about all input parameters.

  • node_list (List[psyclone.psyir.nodes.Node]) – list of PSyIR nodes to be analysed.

  • variables_info (psyclone.core.variables_info.VariablesAccessInfo) – optional variable usage information, can be used to avoid repeatedly collecting this information.

  • options – a dictionary with options for the dependency tools which will also be used when creating the VariablesAccessInfo instance if required.

  • options["COLLECT-ARRAY-SHAPE-READS"] (Any) – if this option is set to a True value, arrays used as first parameter to the PSyIR operators lbound, ubound, or size will be reported as ‘read’. Otherwise, these accesses will be ignored.

get_output_parameters(read_write_info, node_list, variables_info=None, options=None)

Adds all variables that are output parameters (i.e. are written) to the read_write_info object.

Parameters:
  • read_write_info (psyclone.psyir.tools.ReadWriteInfo) – this object stores the information about output parameters.

  • node_list (List[psyclone.psyir.nodes.Node]) – list of PSyIR nodes to be analysed.

  • variables_info (Optional[psyclone.core.variables_info.VariablesAccessInfo]) – optional variable usage information, can be used to avoid repeatedly collecting this information.

  • options – a dictionary with options for the dependency tools which will also be used when creating the VariablesAccessInfo instance if required.

  • options["COLLECT-ARRAY-SHAPE-READS"] (Any) – if this option is set to a True value, arrays used as first parameter to the PSyIR operators lbound, ubound, or size will be reported as ‘read’. Otherwise, these accesses will be ignored.

class psyclone.psyir.tools.ReadWriteInfo

This class stores signature and container name of variables read or written. The container name is optional, it will default to “” if the signature belongs to a symbol declared in the local scope, otherwise it is the name of the container from which it must be imported.

The information is stored in lists of tuples, the first element being the container name, the second the signature. When accessing any of these two lists, the getter will make sure that the lists are sorted. This will guarantee that, for example, the kernel extraction and driver creation read the variables in the same order.

Inheritance

Inheritance diagram of ReadWriteInfo
add_read(signature, container_name=None)

This function adds a read access to the specified signature and container name. The container_name is optional and defaults to “”, indicating that this signature is not based on importing a symbol from an external container (i.e. a module in Fortran).

Parameters:
  • signature (psyclone.core.Signature) – the signature of the access.

  • container_name (Optional[str]) – the container name (optional)

add_write(signature, container_name=None)

This function adds a write access to the specified signature and container name. The container_name is optional and defaults to “”, indicating that this signature is not based on importing a symbol from an external container (i.e. a module in Fortran).

Parameters:
  • signature (psyclone.core.Signature) – the signature of the access.

  • container_name (Optional[str]) – the container name (optional)

is_read(signature)
Returns:

whether the signature is in the read list (independent of the container name).

Return type:

bool

property read_list

:returns the sorted list of container_name,signature pairs that are read. :rtype: List[Tuple[str,:py:class:psyclone.core.Signature]]

property set_of_all_used_vars

This property returns a set with all (container_name, Signature) tuples. Since it is a set this guarantees that each tuple is only listed once.

Returns:

set with all (container_name, Signature) pairs.

Return type:

Set[Tuple[str, psyclone.core.Signature]]

property signatures_read

Convenience function to return only the signatures read.

:returns the list of all signatures read. :rtype: List[psyclone.core.Signature]

property signatures_written

Convenience function to return only the signatures written.

:returns the list of all signatures written. :rtype: List[psyclone.core.Signature]

property write_list

:returns the sorted list of container_name,signature pairs that are written. :rtype: List[Tuple[str,:py:class:psyclone.core.Signature]]