psyclone.psyGen
This module provides generic support for PSyclone’s PSy code optimisation and generation. The classes in this method need to be specialised for a particular API and implementation.
Classes
PSyFactory
: Creates a specific version of the PSy. If a particular api is notPSy
: Base class to help manage and generate PSy code for a singleInvokes
: Manage the invoke calls.Invoke
: Manage an individual invoke call.InvokeSchedule
: Stores schedule information for an invocation call. Schedules can beGlobalSum
: Generic Global Sum class which can be added to and manipulatedHaloExchange
: Generic Halo Exchange class which can be added to andKern
: Base class representing a call to a sub-program unit from within theCodedKern
: Class representing a call to a PSyclone Kernel with a user-providedInlinedKern
: A class representing a kernel that is inlined.BuiltIn
: Parent class for all built-ins (field operations for which the userArguments
: Arguments abstract base class.DataAccess
: A helper class to simplify the determination of dependencies due toArgument
: Argument base class. Captures information on an argument that is passedKernelArgument
: This class provides information about individual kernel-callTransInfo
: This class provides information about, and access, to the availableTransformation
: Abstract baseclass for a transformation. Uses the abc module so itDummyTransformation
: Dummy transformation use elsewhere to keep pyreverse happy.
- class psyclone.psyGen.PSyFactory(api='', distributed_memory=None)
Creates a specific version of the PSy. If a particular api is not provided then the default api, as specified in the psyclone.cfg file, is chosen.
- Parameters:
api (str) – name of the PSyclone API (domain) for which to create a factory.
distributed_memory (bool) – whether or not the PSy object created will include support for distributed-memory parallelism.
- Raises:
TypeError – if the distributed_memory argument is not a bool.
Inheritance
- create(invoke_info)
Create the API-specific PSy instance.
- Parameters:
invoke_info (
psyclone.parse.algorithm.FileInfo
orfparser.two.Fortran2003.Program
) – information on the invoke()s found by parsing the Algorithm layer or (for NEMO) the fparser2 parse tree of the source file.- Returns:
an instance of the API-specific sub-class of PSy.
- Return type:
subclass of
psyclone.psyGen.PSy
- Raises:
InternalError – if this factory is found to have an unsupported type (API).
- class psyclone.psyGen.PSy(invoke_info)
Base class to help manage and generate PSy code for a single algorithm file. Takes the invocation information output from the function
parse.algorithm.parse()
as its input and stores this in a way suitable for optimisation and code generation.- Parameters:
invoke_info (
psyclone.parse.algorithm.FileInfo
) – An object containing the required invocation information for code optimisation and generation. Produced by the functionparse.algorithm.parse()
.
For example:
>>> from psyclone.parse.algorithm import parse >>> ast, info = parse("argspec.F90") >>> from psyclone.psyGen import PSyFactory >>> api = "..." >>> psy = PSyFactory(api).create(info) >>> print(psy.gen)
Inheritance
- property container
- Returns:
the container associated with this PSy object
- Return type:
- abstract property gen
Abstract base class for code generation function.
- Returns:
root node of generated Fortran AST.
- Return type:
- property invokes
- Returns:
the list of invokes.
- Return type:
psyclone.psyGen.Invokes
or derived class
- property name
- Returns:
the name of the PSy object.
- Return type:
str
- class psyclone.psyGen.Invokes(alg_calls, invoke_cls, psy)
Manage the invoke calls.
- Parameters:
alg_calls (list of
psyclone.parse.algorithm.InvokeCall
) – a list of invoke metadata extracted by the parser.invoke_cls (subclass of
psyclone.psyGen.Invoke
) – an api-specific Invoke class.psy (subclass of :py:class`psyclone.psyGen.PSy`) – the PSy instance containing this Invokes instance.
Inheritance
- gen_code(parent)
Create the f2pygen AST for each Invoke in the PSy layer.
- Parameters:
parent (psyclone.f2pygen.ModuleGen) – the parent node in the AST to which to add content.
- Raises:
GenerationError – if an invoke_list schedule is not an InvokeSchedule.
- get(invoke_name)
Gets the Invoke with the supplied name. If the name does not already begin with
invoke_
then a new name with this prepended is included in the search if no exact match is found initially.- Parameters:
invoke_name (str) – the name of the Invoke to get (not case- sensitive).
- Returns:
the invoke with the specified name.
- Return type:
- Raises:
RuntimeError – if no Invoke with the supplied name (with or without
invoke_
prepended) exists.
- property psy
- Returns:
the PSy instance that contains this instance.
- Return type:
subclass of
psyclone.psyGen.PSy
- class psyclone.psyGen.Invoke(alg_invocation, idx, schedule_class, invokes, reserved_names=None)
Manage an individual invoke call.
- Parameters:
alg_invocation (
psyclone.parse.algorithm.InvokeCall
) – metadata from the parsed code capturing information for this Invoke instance.idx (int) – position/index of this invoke call in the subroutine. If not None, this number is added to the name (“invoke_”).
schedule_class (
psyclone.psyGen.InvokeSchedule
) – the schedule class to create for this invoke.invokes (
psyclone.psyGen.Invokes
) – the Invokes instance that contains this Invoke instance.reserved_names (list of str) – optional list of reserved names, i.e. names that should not be used e.g. as a PSyclone-created variable name.
Inheritance
- first_access(arg_name)
Returns the first argument with the specified name passed to a kernel in our schedule
- abstract gen_code(parent)
Generates invocation code (the subroutine called by the associated invoke call in the algorithm layer). This consists of the PSy invocation subroutine and the declaration of its arguments.
- Parameters:
parent (
psyclone.f2pygen.ModuleGen
) – the node in the generated AST to which to add content.
- property invokes
- Returns:
the Invokes instance that contains this instance.
- Return type:
:py:class`psyclone.psyGen.Invokes`
- unique_declarations(argument_types, access=None, intrinsic_type=None)
Returns a list of all required declarations for the specified API argument types. If access is supplied (e.g. “write”) then only declarations with that access are returned. If an intrinsic type is supplied then only declarations with that intrinsic type are returned.
- Parameters:
argument_types (list of str) – the types of the kernel argument for the particular API.
access (
psyclone.core.access_type.AccessType
) – optional AccessType that the declaration should have.intrinsic_type (str) – optional intrinsic type of argument data.
- Returns:
a list of all declared kernel arguments.
- Return type:
list of
psyclone.psyGen.KernelArgument
- Raises:
InternalError – if at least one kernel argument type is not valid for the particular API.
InternalError – if an invalid access is specified.
InternalError – if an invalid intrinsic type is specified.
- unique_declns_by_intent(argument_types, intrinsic_type=None)
Returns a dictionary listing all required declarations for each type of intent (‘inout’, ‘out’ and ‘in’).
- Parameters:
argument_types (list of str) – the types of the kernel argument for the particular API for which the intent is required.
intrinsic_type (str) – optional intrinsic type of argument data.
- Returns:
dictionary containing ‘intent’ keys holding the kernel arguments as values for each type of intent.
- Return type:
dict of
psyclone.psyGen.KernelArgument
- Raises:
InternalError – if at least one kernel argument type is not valid for the particular API.
InternalError – if an invalid intrinsic type is specified.
- class psyclone.psyGen.InvokeSchedule(name, KernFactory, BuiltInFactory, alg_calls=None, reserved_names=None, **kwargs)
Stores schedule information for an invocation call. Schedules can be optimised using transformations.
>>> from psyclone.parse.algorithm import parse >>> ast, info = parse("algorithm.f90") >>> from psyclone.psyGen import PSyFactory >>> api = "..." >>> psy = PSyFactory(api).create(info) >>> invokes = psy.invokes >>> invokes.names >>> invoke = invokes.get("name") >>> schedule = invoke.schedule >>> print(schedule.view())
- Parameters:
name (str) – name of the Invoke.
KernFactory (type) – class instance of the factory to use when creating Kernels. e.g.
psyclone.domain.lfric.LFRicKernCallFactory
.BuiltInFactory (type) – class instance of the factory to use when creating built-ins. e.g.
psyclone.domain.lfric.lfric_builtins.LFRicBuiltInCallFactory
.alg_calls (list of
psyclone.parse.algorithm.KernelCall
) – list of Kernel calls in the schedule.kwargs (unwrapped dict.) – additional keyword arguments provided to the super class.
Inheritance
- gen_code(parent)
Generate the Nodes in the f2pygen AST for this schedule.
- Parameters:
parent (
psyclone.f2pygen.SubroutineGen
) – the parent Node (i.e. the enclosing subroutine) to which to add content.
- node_str(colour=True)
Returns the name of this node with appropriate control codes to generate coloured output in a terminal that supports it.
- Parameters:
colour (bool) – whether or not to include colour control codes.
- Returns:
description of this node, possibly coloured.
- Return type:
str
- property symbol_table
- Returns:
Table containing symbol information for the schedule.
- Return type:
- class psyclone.psyGen.GlobalSum(scalar, parent=None)
Generic Global Sum class which can be added to and manipulated in, a schedule.
- Parameters:
scalar (
psyclone.dynamo0p3.DynKernelArgument
) – the scalar that the global sum is stored intoparent (
psyclone.psyir.nodes.Node
) – optional parent (default None) of this object
Inheritance
- property args
Return the list of arguments associated with this node. Override the base method and simply return our argument.
- property dag_name
- Returns:
the name to use in the DAG for this node.
- Return type:
str
- node_str(colour=True)
Returns a text description of this node with (optional) control codes to generate coloured output in a terminal that supports it.
- Parameters:
colour (bool) – whether or not to include colour control codes.
- Returns:
description of this node, possibly coloured.
- Return type:
str
- property scalar
Return the scalar field that this global sum acts on
- class psyclone.psyGen.HaloExchange(field, check_dirty=True, vector_index=None, parent=None)
Generic Halo Exchange class which can be added to and manipulated in, a schedule.
- Parameters:
field (
psyclone.dynamo0p3.DynKernelArgument
) – the field that this halo exchange will act oncheck_dirty (bool) – optional argument default True indicating whether this halo exchange should be subject to a run-time check for clean/dirty halos.
vector_index (int) – optional vector index (default None) to identify which index of a vector field this halo exchange is responsible for.
parent (
psyclone.psyir.nodes.Node
) – optional parent (default None) of this object
Inheritance
- property args
Return the list of arguments associated with this node. Overide the base method and simply return our argument.
- check_vector_halos_differ(node)
Helper method which checks that two halo exchange nodes (one being self and the other being passed by argument) operating on the same field, both have vector fields of the same size and use different vector indices. If this is the case then the halo exchange nodes do not depend on each other. If this is not the case then an internal error will have occured and we raise an appropriate exception.
- Parameters:
node (
psyclone.psyGen.HaloExchange
) – a halo exchange which should exchange the same field as self.- Raises:
GenerationError – if the argument passed is not a halo exchange.
GenerationError – if the field name in the halo exchange passed in has a different name to the field in this halo exchange.
GenerationError – if the field in this halo exchange is not a vector field
GenerationError – if the vector size of the field in this halo exchange is different to vector size of the field in the halo exchange passed by argument.
GenerationError – if the vector index of the field in this halo exchange is the same as the vector index of the field in the halo exchange passed by argument.
- property dag_name
- Returns:
the name to use in a dag for this node.
- Return type:
str
- property field
Return the field that the halo exchange acts on
- property halo_depth
Return the depth of the halo exchange
- node_str(colour=True)
Returns the name of this node with (optional) control codes to generate coloured output in a terminal that supports it.
- Parameters:
colour (bool) – whether or not to include colour control codes.
- Returns:
description of this node, possibly coloured.
- Return type:
str
- property vector_index
If the field is a vector then return the vector index associated with this halo exchange. Otherwise return None
- class psyclone.psyGen.Kern(parent, call, name, ArgumentsClass, check=True)
Base class representing a call to a sub-program unit from within the PSy layer. It is possible for this unit to be in-lined within the PSy layer.
- Parameters:
parent (sub-class of
psyclone.psyir.nodes.Node
) – parent of this node in the PSyIR.call (
psyclone.parse.algorithm.KernelCall
) – information on the call itself, as obtained by parsing the Algorithm layer code.name (str) – the name of the routine being called.
ArgumentsClass (type of
psyclone.psyGen.Arguments
) – class to create the object that holds all information on the kernel arguments, as extracted from kernel meta-data (and accessible here via call.ktype).check (bool) – whether to check for consistency between the kernel metadata and the algorithm layer. Defaults to True.
- Raises:
GenerationError – if any of the arguments to the call are duplicated.
Inheritance
- property args
Return the list of arguments associated with this node. Overide the base method and simply return our arguments.
- is_coloured()
- Returns:
True if this kernel is being called from within a coloured loop.
- Return type:
bool
- property is_reduction
- Returns:
whether this kernel/built-in contains a reduction variable.
- Return type:
bool
- property local_reduction_name
- Returns:
a local reduction variable name that is unique for the current reduction argument name. This is used for thread-local reductions with reproducible reductions.
- Return type:
str
- property name
- Returns:
the name of the kernel.
- Return type:
str
- node_str(colour=True)
Returns the name of this node with (optional) control codes to generate coloured output in a terminal that supports it.
- Parameters:
colour (bool) – whether or not to include colour control codes.
- Returns:
description of this node, possibly coloured.
- Return type:
str
- property reduction_arg
- Returns:
the reduction variable if this kernel/built-in contains one and None otherwise.
- Return type:
psyclone.psyGen.KernelArgument
or NoneType
- reduction_sum_loop(parent)
Generate the appropriate code to place after the end parallel region.
- Parameters:
parent (
psyclone.f2pygen.SubroutineGen
) – the Node in the f2pygen AST to which to add new code.- Raises:
GenerationError – for an unsupported reduction access in LFRicBuiltIn.
- reference_accesses(var_accesses)
Get all variable access information. The API specific classes add the accesses to the arguments. So the code here only calls the baseclass, and increases the location.
- Parameters:
var_accesses (
psyclone.core.VariablesAccessInfo
) – VariablesAccessInfo instance that stores the information about variable accesses.
- property reprod_reduction
- Returns:
whether this kernel/built-in is enclosed within an OpenMP do loop. If so report whether it has the reproducible flag set. Note, this also catches OMPParallelDo Directives but they have reprod set to False so it is OK.
- Return type:
bool
- zero_reduction_variable(parent, position=None)
Generate code to zero the reduction variable and to zero the local reduction variable if one exists. The latter is used for reproducible reductions, if specified.
- Parameters:
parent (
psyclone.psyir.nodes.Node
) – the Node in the AST to which to add new code.position (str) – where to position the new code in the AST.
- Raises:
GenerationError – if the variable to zero is not a scalar.
GenerationError – if the reprod_pad_size (read from the configuration file) is less than 1.
GenerationError – for a reduction into a scalar that is neither ‘real’ nor ‘integer’.
- class psyclone.psyGen.CodedKern(KernelArguments, call, parent=None, check=True)
Class representing a call to a PSyclone Kernel with a user-provided implementation. The kernel may or may not be in-lined.
- Parameters:
KernelArguments (type) – the API-specific sub-class of
psyclone.psyGen.Arguments
to create.call (
psyclone.parse.algorithm.KernelCall
.) – Details of the call to this kernel in the Algorithm layer.parent (sub-class of
psyclone.psyir.nodes.Node
.) – the parent of this Node (kernel call) in the Schedule.check (bool) – whether to check for consistency between the kernel metadata and the algorithm layer. Defaults to True.
Inheritance
- property ast
Generate and return the fparser2 AST of the kernel source.
- Returns:
fparser2 AST of the Fortran file containing this kernel.
- Return type:
fparser.two.Fortran2003.Program
- property dag_name
- Returns:
the name to use in the DAG for this node.
- Return type:
str
- gen_code(parent)
Generates the f2pygen AST of the Fortran for this kernel call and writes the kernel itself to file if it has been transformed.
- Parameters:
parent (
psyclone.f2pygen.LoopGen
) – The parent of this kernel call in the f2pygen AST.- Raises:
GenerationError – if the call is module-inlined but the subroutine in not declared in this module.
- get_kernel_schedule()
Returns a PSyIR Schedule representing the kernel code. The Schedule is just generated on first invocation, this allows us to retain transformations that may subsequently be applied to the Schedule.
- Returns:
Schedule representing the kernel code.
- Return type:
- incremented_arg()
Returns the argument that has INC access. Raises a FieldNotFoundError if none is found.
- Return type:
str
- Raises:
FieldNotFoundError – if none is found.
- Returns:
a Fortran argument name.
- lower_to_language_level()
In-place replacement of CodedKern concept into language level PSyIR constructs. The CodedKern is implemented as a Call to a routine with the appropriate arguments.
- Returns:
the lowered version of this node.
- Return type:
psyclone.psyir.node.Node
- property modified
- Returns:
Whether or not this kernel has been modified (transformed).
- Return type:
bool
- property module_inline
- Returns:
whether or not this kernel is being module-inlined.
- Return type:
bool
- property module_name
- Returns:
The name of the Fortran module that contains this kernel
- Return type:
string
- node_str(colour=True)
Returns the name of this node with (optional) control codes to generate coloured output in a terminal that supports it.
- Parameters:
colour (bool) – whether or not to include colour control codes.
- Returns:
description of this node, possibly coloured.
- Return type:
str
- property opencl_options
- Returns:
dictionary of OpenCL options regarding the kernel.
- Return type:
dictionary
- rename_and_write()
Writes the (transformed) AST of this kernel to file and resets the ‘modified’ flag to False. By default (config.kernel_naming == “multiple”), the kernel is re-named so as to be unique within the kernel output directory stored within the configuration object. Alternatively, if config.kernel_naming is “single” then no re-naming and output is performed if there is already a transformed copy of the kernel in the output dir. (In this case a check is performed that the transformed kernel already present is identical to the one that we would otherwise write to file. If this is not the case then we raise a GenerationError.)
- Raises:
GenerationError – if config.kernel_naming == “single” and a different, transformed version of this kernel is already in the output directory.
NotImplementedError – if the kernel has been transformed but is also flagged for module-inlining.
- set_opencl_options(options)
Validate and store a set of options associated with the Kernel to tune the OpenCL code generation.
- Parameters:
options (dictionary of <string>:<value>) – a set of options to tune the OpenCL code.
- class psyclone.psyGen.InlinedKern(psyir_nodes, parent=None)
A class representing a kernel that is inlined. It has one child which stores the Schedule for the child nodes.
- Parameters:
psyir_nodes (list of
psyclone.psyir.nodes.Node
) – the list of PSyIR nodes that represent the body of this kernel.parent (sub-class of
psyclone.psyir.nodes.Node
) – the parent of this node in the PSyIR.
Inheritance
- abstract local_vars()
- Returns:
list of the variable (names) that are local to this kernel (and must therefore be e.g. threadprivate if doing OpenMP)
- Return type:
list of str
- node_str(colour=True)
Returns the name of this node with (optional) control codes to generate coloured output in a terminal that supports it.
- Parameters:
colour (bool) – whether or not to include colour control codes.
- Returns:
description of this node, possibly coloured.
- Return type:
str
- class psyclone.psyGen.BuiltIn
Parent class for all built-ins (field operations for which the user does not have to provide an implementation).
Inheritance
- property dag_name
- Returns:
the name to use in the DAG for this node.
- Return type:
str
- load(call, arguments, parent=None)
Set-up the state of this BuiltIn call
- local_vars()
Variables that are local to this built-in and therefore need to be made private when parallelising using OpenMP or similar. By default builtin’s do not have any local variables so set to nothing
- class psyclone.psyGen.Arguments(parent_call)
Arguments abstract base class.
- Parameters:
parent_call (sub-class of
psyclone.psyGen.Kern
) – kernel call with which the arguments are associated.
Inheritance
- property acc_args
- Returns:
the list of quantities that must be available on an OpenACC device before the associated kernel can be launched
- Return type:
list of str
- append(name, argument_type)
Abstract method to append KernelArguments to the Argument list.
- Parameters:
name (str) – name of the appended argument.
argument_type (str) – type of the appended argument.
- iteration_space_arg()
Returns an argument that can be iterated over, i.e. modified (has WRITE, READWRITE or INC access), but not the result of a reduction operation.
- Returns:
a Fortran argument name
- Return type:
string
- Raises:
GenerationError – if none such argument is found.
- property names
- Returns:
the Algorithm-visible kernel arguments in a comma-delimited string.
- Return type:
str
- abstract psyir_expressions()
- Returns:
the PSyIR expressions representing this Argument list.
- Return type:
list of
psyclone.psyir.nodes.Node
- raw_arg_list()
Abstract method to construct the class-specific argument list for a kernel call. Must be overridden in API-specific sub-class.
- Raises:
NotImplementedError – abstract method.
- property scalars
- Returns:
the list of scalar quantities belonging to this object
- Return type:
list of str
- class psyclone.psyGen.DataAccess(arg)
A helper class to simplify the determination of dependencies due to overlapping accesses to data associated with instances of the Argument class.
Inheritance
- property covered
Returns True if all of the data associated with this argument has been covered by the arguments provided in update_coverage
- Return bool:
True if all of an argument is covered by previous accesses and False if not.
- overlaps(arg)
Determine whether the accesses to the provided argument overlap with the accesses of the source argument. Overlap means that the accesses share at least one memory location. For example, the arguments both access the 1st index of the same field.
We do not currently deal with accesses to a subset of an argument (unless it is a vector). This distinction will need to be added once loop splitting is supported.
- Parameters:
arg (
psyclone.psyGen.Argument
) – the argument to compare with our internal argument- Return bool:
True if there are overlapping accesses between arguments (i.e. accesses share at least one memory location) and False if not.
- reset_coverage()
Reset internal state to allow re-use of the object for a different situation.
- update_coverage(arg)
Record any overlap between accesses to the supplied argument and the internal argument. Overlap means that the accesses to the two arguments share at least one memory location. If the overlap results in all of the accesses to the internal argument being covered (either directly or as a combination with previous arguments) then ensure that the covered() method returns True. Covered means that all memory accesses by the internal argument have at least one corresponding access by the supplied arguments.
- Parameters:
arg (
psyclone.psyGen.Argument
) – the argument used to compare with our internal argument in order to update coverage information
- class psyclone.psyGen.Argument(call, arg_info, access)
Argument base class. Captures information on an argument that is passed to a Kernel from an Invoke.
- Parameters:
call (
psyclone.psyGen.Kern
) – the kernel call that this argument is associated with.arg_info (
psyclone.parse.algorithm.Arg
) – Information about this argument collected by the parser.access (str) – the way in which this argument is accessed in the ‘Kern’. Valid values are specified in the config object of the current API.
Inheritance
- property argument_type
Returns the type of the argument. APIs that do not have this concept can use this base class version which just returns “field” in all cases. APIs with this concept can override this method.
- Returns:
the API type of the kernel argument.
- Return type:
str
- backward_dependence()
Returns the preceding argument that this argument has a direct dependence with, or None if there is not one. The argument may exist in a call, a haloexchange, or a globalsum.
- Returns:
the first preceding argument that has a dependence on this argument.
- Return type:
- backward_write_dependencies(ignore_halos=False)
Returns a list of previous write arguments that this argument has dependencies with. The arguments may exist in a call, a haloexchange (unless ignore_halos is True), or a globalsum. If none are found then return an empty list. If self is not a reader then return an empty list.
- Parameters:
ignore_halos (bool) – if True then any write dependencies involving a halo exchange are ignored. Defaults to False.
- Returns:
a list of arguments that have a preceding write dependence on this argument.
- Return type:
list of
psyclone.psyGen.Argument
- property call
Return the call that this argument is associated with
- property data_type
- Returns:
the data type of this argument. Default value is None, explicit implementation is left to a specific API.
- Return type:
str or NoneType
- forward_dependence()
Returns the following argument that this argument has a direct dependence on, or None if there is not one. The argument may exist in a call, a haloexchange, or a globalsum.
- Returns:
the first following argument that has a dependence on this argument.
- Return type:
- forward_read_dependencies()
Returns a list of following read arguments that this argument has dependencies with. The arguments may exist in a call, a haloexchange, or a globalsum. If none are found then return an empty list. If self is not a writer then return an empty list.
- Returns:
a list of following arguments that have a read dependence on this argument.
- Return type:
list of
psyclone.psyGen.Argument
- forward_write_dependencies(ignore_halos=False)
Returns a list of following write arguments that this argument has dependencies with. The arguments may exist in a call, a haloexchange (unless ignore_halos is True), or a globalsum. If none are found then return an empty list. If self is not a reader then return an empty list.
- Parameters:
ignore_halos (bool) – if True then any write dependencies involving a halo exchange are ignored. Defaults to False.
- Returns:
a list of arguments that have a following write dependence on this argument.
- Return type:
list of
psyclone.psyGen.Argument
- infer_datatype()
Infer the datatype of this argument using the API rules. If no specialisation of this method has been provided make the type UnresolvedType for now (it may be provided later in the execution).
- Returns:
the datatype of this argument.
- Return type:
:py:class::psyclone.psyir.symbols.DataType
- abstract property intrinsic_type
Abstract property for the intrinsic type of the argument with specific implementations in different APIs.
- Returns:
the intrinsic type of this argument.
- Return type:
str
- property module_name
- Returns:
the name of the Fortran module that contains definitions for the argument data type. Default value is None, explicit implementation is left to a specific API.
- Return type:
str or NoneType
- property precision
- Returns:
the precision of this argument. Default value is None, explicit implementation is left to a specific API.
- Return type:
str or NoneType
- abstract psyir_expression()
- Returns:
the PSyIR expression represented by this Argument.
- Return type:
- class psyclone.psyGen.KernelArgument(arg, arg_info, call)
This class provides information about individual kernel-call arguments as specified by the kernel argument metadata and the kernel invocation in the Algorithm layer.
- Parameters:
arg (
psyclone.parse.kernel.Descriptor
) – information obtained from the metadata for this kernel argument.arg_info (
psyclone.parse.algorithm.Arg
) – information on how this argument is specified in the Algorithm layer.call (
psyclone.psyGen.Kern
) – the PSyIR kernel node to which this argument pertains.
Inheritance
- abstract property is_scalar
- Returns:
whether this variable is a scalar variable or not.
- Return type:
bool
- property metadata_index
- Returns:
the position of the corresponding argument descriptor in the kernel metadata.
- Return type:
int
- class psyclone.psyGen.TransInfo(module=None, base_class=None)
This class provides information about, and access, to the available transformations in this implementation of PSyclone. New transformations will be picked up automatically as long as they subclass the abstract Transformation class.
For example:
>>> from psyclone.psyGen import TransInfo >>> t = TransInfo() >>> print(t.list) There is 1 transformation available: 1: SwapTrans, A test transformation >>> # accessing a transformation by index >>> trans = t.get_trans_num(1) >>> # accessing a transformation by name >>> trans = t.get_trans_name("SwapTrans")
Inheritance
- get_trans_name(name)
return the transformation with this name (use list() first to see available transformations)
- get_trans_num(number)
return the transformation with this number (use list() first to see available transformations)
- property list
return a string with a human readable list of the available transformations
- property num_trans
return the number of transformations available
- class psyclone.psyGen.Transformation
Abstract baseclass for a transformation. Uses the abc module so it can not be instantiated.
Inheritance
- abstract apply(node, options=None)
Abstract method that applies the transformation. This function must be implemented by each transform. As a minimum each apply function must take a node to which the transform is applied, and a dictionary of additional options, which will also be passed on to the validate functions. This dictionary is used to provide optional parameters, and also to modify the behaviour of validation of transformations: for example, if the user knows that a transformation can correctly be applied in a specific case, but the more generic code validation would not allow this. Validation functions should check for a key in the options dictionary to disable certain tests. Those keys will be documented in each apply() and validate() function.
Note that some apply() functions might take a slightly different set of parameters.
- Parameters:
node (depends on actual transformation) – The node (or list of nodes) for the transformation - specific to the actual transform used.
options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
- property name
- Returns:
the transformation’s class name.
- Return type:
str
- validate(node, options=None)
Method that validates that the input data is correct. It will raise exceptions if the input data is incorrect. This function needs to be implemented by each transformation.
The validate function can be called by the user independent of the apply() function, but it will automatically be executed as part of an apply() call.
As minimum each validate function must take a node to which the transform is applied and a dictionary of additional options. This dictionary is used to provide optional parameters and also to modify the behaviour of validation: for example, if the user knows that a transformation can correctly be applied in a specific case but the more generic code validation would not allow this. Validation functions should check for particular keys in the options dict in order to disable certain tests. Those keys will be documented in each apply() and validate() function as ‘options[“option-name”]’.
Note that some validate functions might take a slightly different set of parameters.
- Parameters:
node (depends on actual transformation) – The node (or list of nodes) for the transformation - specific to the actual transform used.
options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
- class psyclone.psyGen.DummyTransformation
Dummy transformation use elsewhere to keep pyreverse happy.
Inheritance
- apply(node, options=None)
Abstract method that applies the transformation. This function must be implemented by each transform. As a minimum each apply function must take a node to which the transform is applied, and a dictionary of additional options, which will also be passed on to the validate functions. This dictionary is used to provide optional parameters, and also to modify the behaviour of validation of transformations: for example, if the user knows that a transformation can correctly be applied in a specific case, but the more generic code validation would not allow this. Validation functions should check for a key in the options dictionary to disable certain tests. Those keys will be documented in each apply() and validate() function.
Note that some apply() functions might take a slightly different set of parameters.
- Parameters:
node (depends on actual transformation) – The node (or list of nodes) for the transformation - specific to the actual transform used.
options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
- property name
- Returns:
the transformation’s class name.
- Return type:
str