psyclone.psyir.nodes.acc_directives#
This module contains the implementation of the various OpenACC Directive nodes.
Classes#
ACCRegionDirective: Base class for all OpenACC region directive statements.ACCEnterDataDirective: Class representing a “!$ACC enter data” OpenACC directive inACCParallelDirective: Class representing the !$ACC PARALLEL directive of OpenACCACCLoopDirective: Class managing the creation of a ‘!$acc loop’ OpenACC directive.ACCKernelsDirective: Class representing the !$ACC KERNELS directive in the PSyIR.ACCDataDirective: Class representing the !$ACC DATA … !$ACC END DATA directiveACCUpdateDirective: Class representing the OpenACC update directive in the PSyIR. It hasACCStandaloneDirective: Base class for all standalone OpenACC directive statements.ACCDirective: Base mixin class for all OpenACC directive statements.ACCRoutineDirective: Class representing an “ACC routine” OpenACC directive in PSyIR.ACCAtomicDirective: OpenACC directive to represent that the memory accesses in the associatedACCWaitDirective: Class representing the !$ACC WAIT directive in the PSyIR.
- class psyclone.psyir.nodes.acc_directives.ACCRegionDirective(ast=None, children=None, parent=None)[source]#
Base class for all OpenACC region directive statements.
Inheritance

- property signatures: Tuple[Set[Signature]] | Tuple[Set[Signature], Set[Signature]]#
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
- validate_global_constraints()[source]#
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, async_queue=False)[source]#
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:
children (
List[Node]) – list of nodes which the directive should have as children.parent (
Node) – the node in the InvokeSchedule to which to add this directive as a child.async_queue (
Union[bool,int,DataNode]) – Enable async support and attach it to the given queue. Can use False to disable, True to enable on default stream. Int to attach to the given stream ID or use a PSyIR expression to say at runtime what stream to be used.
- Raises:
TypeError – if async_queue is of the wrong type.
Inheritance

- begin_string()[source]#
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)[source]#
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 (
Node) – the node in the InvokeSchedule to which to add nodes
- class psyclone.psyir.nodes.acc_directives.ACCParallelDirective(async_queue=False, default_present=True, **kwargs)[source]#
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 or not.async_queue (
Union[bool,int,DataNode]) – Enable async support and attach it to the given queue. Can use False to disable, True to enable on default stream. Int to attach to the given stream ID or use a PSyIR expression to say at runtime what stream to be used.
Inheritance

- begin_string()[source]#
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. “!$”).
- Return type:
str- Returns:
the opening statement of this directive.
- property default_present: bool#
- Returns:
whether the directive includes the ‘default(present)’ clause.
- property fields: List[str]#
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.
- class psyclone.psyir.nodes.acc_directives.ACCLoopDirective(collapse=None, independent=True, sequential=False, gang=False, vector=False, **kwargs)[source]#
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 (
Dict) – additional keyword arguments provided to the super class.
Inheritance

- begin_string(leading_acc=True)[source]#
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.- Return type:
str- Returns:
the opening statement of this directive.
- property collapse: int | None#
- Returns:
the number of nested loops to collapse into a single iteration space for this node.
- end_string()[source]#
Would return the end string for this directive but “acc loop” doesn’t have a closing directive.
- Return type:
str- Returns:
empty string.
- property gang: bool#
- Returns:
whether or not the gang clause is added to this loop directive.
- property independent: bool#
Returns whether the independent clause will be added to this loop directive.
- Returns:
whether the independent clause will be added to this loop directive.
- node_str(colour=True)[source]#
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.- Return type:
str- Returns:
description of this node, possibly coloured.
- property sequential: bool#
- Returns:
whether or not the seq clause is added to this loop directive.
- validate_global_constraints()[source]#
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: bool#
- Returns:
whether or not the vector clause is added to this loop directive.
- class psyclone.psyir.nodes.acc_directives.ACCKernelsDirective(children=None, parent=None, default_present=True, async_queue=False)[source]#
Class representing the !$ACC KERNELS directive in the PSyIR.
- Parameters:
children (
List[Node]) – the PSyIR nodes to be enclosed in the Kernels region and which are therefore children of this node.parent (
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.
async_queue (
Union[bool,int,DataNode]) – Enable async support and attach it to the given queue. Can use False to disable, True to enable on default stream. Int to attach to the given stream ID or use a PSyIR expression to say at runtime what stream to be used.
Inheritance

- begin_string()[source]#
Returns the beginning statement of this directive, i.e. “acc kernels …”. The backend is responsible for adding the correct directive beginning (e.g. “!$”).
- Return type:
str- Returns:
the beginning statement for this directive.
- property default_present: bool#
- Returns:
whether the “default(present)” clause is added to the kernels directive.
- class psyclone.psyir.nodes.acc_directives.ACCDataDirective(ast=None, children=None, parent=None)[source]#
Class representing the !$ACC DATA … !$ACC END DATA directive in the PSyIR.
Inheritance

- class psyclone.psyir.nodes.acc_directives.ACCUpdateDirective(signatures, direction, children=None, parent=None, if_present=True, async_queue=False)[source]#
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 (
Signature) – the access signature(s) that need to be synchronised with the device.direction (
str) – the direction of the synchronisation.children (
List[Node]) – list of nodes which the directive should have as children.parent (
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).async_queue (
Union[bool,int,DataNode]) – Enable async support and attach it to the given queue. Can use False to disable, True to enable on default stream. Int to attach to the given stream ID or use a PSyIR expression to say at runtime what stream to be used.
Inheritance

- begin_string()[source]#
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. “!$”).
- Return type:
str- Returns:
the opening statement of this directive.
- property direction: str#
- Returns:
the direction of the synchronisation.
- property if_present: bool#
- Returns:
whether or not to add the ‘if_present’ clause.
- class psyclone.psyir.nodes.acc_directives.ACCStandaloneDirective(ast=None, children=None, parent=None, annotations=None)[source]#
Base class for all standalone OpenACC directive statements.
Inheritance

- class psyclone.psyir.nodes.acc_directives.ACCDirective[source]#
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

- class psyclone.psyir.nodes.acc_directives.ACCRoutineDirective(parallelism='seq', **kwargs)[source]#
Class representing an “ACC routine” OpenACC directive in PSyIR.
- Parameters:
parallelism (
str) – the level of parallelism in the routine, one of “gang”, “seq”, “vector”, “worker”.
Inheritance

- begin_string()[source]#
Returns the beginning statement of this directive, i.e. “acc routine”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).
- Return type:
str- Returns:
the opening statement of this directive.
- property parallelism#
- Returns:
the clause describing the level of parallelism within this routine (or a called one).
- Return type:
str
- class psyclone.psyir.nodes.acc_directives.ACCAtomicDirective(ast=None, children=None, parent=None)[source]#
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

- validate_global_constraints()[source]#
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.
- class psyclone.psyir.nodes.acc_directives.ACCWaitDirective(wait_queue=None)[source]#
Class representing the !$ACC WAIT directive in the PSyIR.
- Parameters:
wait_queue (
Union[Reference,int,None]) – Which ACC async stream to wait. None to wait all.
Inheritance
