psyclone.psyir.nodes.acc_directives

This module contains the implementation of the various OpenACC Directive nodes.

Classes

class psyclone.psyir.nodes.acc_directives.ACCRegionDirective(ast=None, children=None, parent=None)

Base class for all OpenACC region directive statements.

Inheritance

Inheritance diagram of ACCRegionDirective
property signatures

Returns a 1-tuple or a 2-tuple of sets depending on the working API. If a 1-tuple, the set includes both input and output signatures (whether to arrays or objects) required by the Kernel call(s) that are children of this directive. If a 2-tuple, the first entry is the set of input signatures and the second entry is the set of output signatures. The set(s) describe the quantities that must be available on the remote device (probably a GPU) before the parallel region can be begun.

Returns:

1-tuple or 2-tuple of input and output sets of variable names

Return type:

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

validate_global_constraints()

Perform validation checks for any global constraints. This can only be done at code-generation time.

Raises:

GenerationError – if this ACCRegionDirective encloses any form of PSyData node since calls to PSyData routines within OpenACC regions are not supported.

class psyclone.psyir.nodes.acc_directives.ACCEnterDataDirective(children=None, parent=None)

Class representing a “!$ACC enter data” OpenACC directive in an InvokeSchedule. Must be sub-classed for a particular API because the way in which fields are marked as being on the remote device is API-dependent.

Parameters:

Inheritance

Inheritance diagram of ACCEnterDataDirective
begin_string()

Returns the beginning statement of this directive. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the opening statement of this directive.

Return type:

str

Raises:

GenerationError – if there are no variables to copy to the device.

data_on_device(parent)

Adds nodes into an InvokeSchedule to flag that the data required by the kernels in the data region is now on the device. The generic implementation doesn’t add any node but this can be redefined in the APIs if any infrastructure call is needed.

Parameters:

parent (psyclone.psyir.nodes.Node) – the node in the InvokeSchedule to which to add nodes

gen_code(parent)

Generate the elements of the f2pygen AST for this Node in the Schedule.

Parameters:

parent (psyclone.f2pygen.BaseGen) – node in the f2pygen AST to which to add node(s).

Raises:

GenerationError – if no data is found to copy in.

lower_to_language_level()

In-place replacement of this directive concept into language level PSyIR constructs.

Returns:

the lowered version of this node.

Return type:

psyclone.psyir.node.Node

class psyclone.psyir.nodes.acc_directives.ACCParallelDirective(default_present=True, **kwargs)

Class representing the !$ACC PARALLEL directive of OpenACC in the PSyIR. By default it includes the ‘DEFAULT(PRESENT)’ clause which means this node must either come after an EnterDataDirective or within a DataDirective.

Parameters:

default_present (bool) – whether this directive includes the ‘DEFAULT(PRESENT)’ clause.

Inheritance

Inheritance diagram of ACCParallelDirective
begin_string()

Returns the beginning statement of this directive, i.e. “acc parallel” plus any qualifiers. The backend is responsible for adding the correct characters to mark this as a directive (e.g. “!$”).

Returns:

the opening statement of this directive.

Return type:

str

property default_present
Returns:

whether the directive includes the ‘default(present)’ clause.

Return type:

bool

end_string()
Returns:

the closing statement for this directive.

Return type:

str

property fields

Returns a list of the names of field objects required by the Kernel call(s) that are children of this directive.

Returns:

list of names of field arguments.

Return type:

List[str]

gen_code(parent)

Generate the elements of the f2pygen AST for this Node in the Schedule.

Parameters:

parent (psyclone.f2pygen.BaseGen) – node in the f2pygen AST to which to add node(s).

class psyclone.psyir.nodes.acc_directives.ACCLoopDirective(collapse=None, independent=True, sequential=False, gang=False, vector=False, **kwargs)

Class managing the creation of a ‘!$acc loop’ OpenACC directive.

Parameters:
  • collapse (int) – Number of nested loops to collapse into a single iteration space or None.

  • independent (bool) – Whether or not to add the independent clause to the loop directive.

  • sequential (bool) – whether or not to add the seq clause to the loop directive.

  • gang (bool) – whether or not to add the gang clause to the loop directive.

  • vector (bool) – whether or not to add the vector clause to the loop directive.

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the super class.

Inheritance

Inheritance diagram of ACCLoopDirective
begin_string(leading_acc=True)

Returns the opening statement of this directive, i.e. “acc loop” plus any qualifiers. If leading_acc is False then the leading “acc loop” text is not included.

Parameters:

leading_acc (bool) – whether or not to include the leading “acc loop” in the text that is returned.

Returns:

the opening statement of this directive.

Return type:

str

property collapse
Returns:

the number of nested loops to collapse into a single iteration space for this node.

Return type:

int or None

end_string()

Would return the end string for this directive but “acc loop” doesn’t have a closing directive.

Returns:

empty string.

Return type:

str

property gang
Returns:

whether or not the gang clause is added to this loop directive.

Return type:

bool

gen_code(parent)

Generate the f2pygen AST entries in the Schedule for this OpenACC loop directive.

Parameters:

parent (sub-class of psyclone.f2pygen.BaseGen) – the parent Node in the Schedule to which to add our content.

Raises:

GenerationError – if this “!$acc loop” is not enclosed within an ACC Parallel region.

property independent

Returns whether the independent clause will be added to this loop directive.

Returns:

whether the independent clause will be added to this loop directive.

Return type:

bool

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 sequential
Returns:

whether or not the seq clause is added to this loop directive.

Return type:

bool

validate_global_constraints()

Perform validation of those global constraints that can only be done at code-generation time.

Raises:

GenerationError – if this ACCLoopDirective is not enclosed within some OpenACC parallel or kernels region and is not in a Routine that has been marked up with an ‘ACC Routine’ directive.

property vector
Returns:

whether or not the vector clause is added to this loop directive.

Return type:

bool

class psyclone.psyir.nodes.acc_directives.ACCKernelsDirective(children=None, parent=None, default_present=True)

Class representing the !$ACC KERNELS directive in the PSyIR.

Parameters:
  • children (List[psyclone.psyir.nodes.Node]) – the PSyIR nodes to be enclosed in the Kernels region and which are therefore children of this node.

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

  • default_present (bool) – whether or not to add the “default(present)” clause to the kernels directive.

Inheritance

Inheritance diagram of ACCKernelsDirective
begin_string()

Returns the beginning statement of this directive, i.e. “acc kernels …”. The backend is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the beginning statement for this directive.

Return type:

str

property default_present
Returns:

whether the “default(present)” clause is added to the kernels directive.

Return type:

bool

end_string()

Returns the ending statement for this directive. The backend is responsible for adding the language-specific syntax that marks this as a directive.

Returns:

the closing statement for this directive.

Return type:

str

gen_code(parent)

Generate the f2pygen AST entries in the Schedule for this OpenACC Kernels directive.

Parameters:

parent (sub-class of psyclone.f2pygen.BaseGen) – the parent Node in the Schedule to which to add this content.

class psyclone.psyir.nodes.acc_directives.ACCDataDirective(ast=None, children=None, parent=None)

Class representing the !$ACC DATA … !$ACC END DATA directive in the PSyIR.

Inheritance

Inheritance diagram of ACCDataDirective
begin_string()
Returns:

the beginning of the opening statement of this directive.

Return type:

str

end_string()
Returns:

the text for the end of this directive region.

Return type:

str

gen_code(_)
Raises:

InternalError – the ACC data directive is currently only supported for the NEMO API and that uses the PSyIR backend to generate code. fparser2 parse tree.

class psyclone.psyir.nodes.acc_directives.ACCUpdateDirective(signatures, direction, children=None, parent=None, if_present=True)

Class representing the OpenACC update directive in the PSyIR. It has a direction attribute that can be set to ‘self’, ‘host’ or ‘device’, the set of symbols being updated and an optional if_present clause.

Parameters:
  • signatures (Set[psyclone.core.Signature]) – the access signature(s) that need to be synchronised with the device.

  • direction (str) – the direction of the synchronisation.

  • children (List[psyclone.psyir.nodes.Node]) – list of nodes which the directive should have as children.

  • parent (psyclone.psyir.nodes.Node) – the node in the InvokeSchedule to which to add this directive as a child.

  • if_present (Optional[bool]) – whether or not to include the ‘if_present’ clause on the update directive (this instructs the directive to silently ignore any variables that are not on the device).

Inheritance

Inheritance diagram of ACCUpdateDirective
begin_string()

Returns the beginning statement of this directive, i.e. “acc update host(symbol)”. The backend is responsible for adding the correct characters to mark this as a directive (e.g. “!$”).

Returns:

the opening statement of this directive.

Return type:

str

property direction
Returns:

the direction of the synchronisation.

Return type:

str

property if_present
Returns:

whether or not to add the ‘if_present’ clause.

Return type:

bool

property sig_set
Returns:

the set of signatures to synchronise with the device.

Return type:

Set[psyclone.core.Signature]

class psyclone.psyir.nodes.acc_directives.ACCStandaloneDirective(ast=None, children=None, parent=None, annotations=None)

Base class for all standalone OpenACC directive statements.

Inheritance

Inheritance diagram of ACCStandaloneDirective
class psyclone.psyir.nodes.acc_directives.ACCDirective

Base mixin class for all OpenACC directive statements.

This class is useful to provide a unique common ancestor to all the OpenACC directives, for instance when traversing the tree with node.walk(ACCDirective)

Note that classes inheriting from it must place the ACCDirective in front of the other Directive node sub-class, so that the Python MRO gives preference to this class’s attributes.

Inheritance

Inheritance diagram of ACCDirective
class psyclone.psyir.nodes.acc_directives.ACCRoutineDirective(ast=None, children=None, parent=None, annotations=None)

Class representing a “!$ACC routine” OpenACC directive in PSyIR.

Inheritance

Inheritance diagram of ACCRoutineDirective
begin_string()

Returns the beginning statement of this directive, i.e. “acc routine”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the opening statement of this directive.

Return type:

str

gen_code(parent)

Generate the fortran ACC Routine Directive and any associated code.

Parameters:

parent (sub-class of psyclone.f2pygen.BaseGen) – the parent Node in the Schedule to which to add our content.

class psyclone.psyir.nodes.acc_directives.ACCAtomicDirective(ast=None, children=None, parent=None)

OpenACC directive to represent that the memory accesses in the associated assignment must be performed atomically. Note that the standard supports blocks with 2 assignments but this is currently unsupported in the PSyIR.

Inheritance

Inheritance diagram of ACCAtomicDirective
begin_string()
Returns:

the opening string statement of this directive.

Return type:

str

end_string()
Returns:

the ending string statement of this directive.

Return type:

str

static is_valid_atomic_statement(stmt)

Check if a given statement is a valid OpenACC atomic expression.

Parameters:

stmt (psyclone.psyir.nodes.Node) – a node to be validated.

Returns:

whether a given statement is compliant with the OpenACC atomic expression.

Return type:

bool

validate_global_constraints()

Perform validation of those global constraints that can only be done at code-generation time.

Raises:

GenerationError – if the ACCAtomicDirective associated statement does not conform to a valid OpenACC atomic operation.