psyclone.psyir.nodes.omp_directives#

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

Classes#

class psyclone.psyir.nodes.omp_directives.OMPRegionDirective(ast=None, children=None, parent=None)[source]#

Base class for all OpenMP region-related directives.

Inheritance

Inheritance diagram of OMPRegionDirective
class psyclone.psyir.nodes.omp_directives.OMPParallelDirective(ast=None, children=None, parent=None)[source]#

Class representing an OpenMP Parallel directive.

Inheritance

Inheritance diagram of OMPParallelDirective
begin_string()[source]#

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

Returns:

the opening statement of this directive.

Return type:

str

classmethod create(children=None)[source]#

Create an OMPParallelDirective.

Parameters:

children (List of psyclone.psyir.nodes.Node) – The child nodes of the new directive.

Returns:

A new OMPParallelDirective.

Return type:

psyclone.psyir.nodes.OMPParallelDirective

property default_clause#
Returns:

The OMPDefaultClause associated with this Directive.

Return type:

psyclone.psyir.nodes.OMPDefaultClause

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end parallel”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

infer_sharing_attributes()[source]#

The PSyIR does not specify if each symbol inside an OpenMP region is private, firstprivate, shared or shared but needs synchronisation, the attributes are inferred looking at the usage of each symbol inside the parallel region.

This method analyses the directive body and automatically classifies each symbol using the following rules: - All arrays are shared unless listed in the explicitly private list. - Scalars that are accessed only once are shared. - Scalars that are read-only or written outside a loop are shared. - Scalars written in multiple iterations of a loop are private, unless:

  • there is a write-after-read dependency in a loop iteration, in this case they are shared but need synchronisation;

  • they are read before in the same parallel region (but not inside the same loop iteration), in this case they are firstprivate.

  • they are only conditionally written in some iterations; in this case they are firstprivate.

This method returns the sets of private, firstprivate, and shared but needing synchronisation symbols, all symbols not in these sets are assumed shared. How to synchronise the symbols in the third set is up to the caller of this method.

Returns:

three set of symbols that classify each of the symbols in the directive body as PRIVATE, FIRSTPRIVATE or SHARED NEEDING SYNCHRONISATION.

Return type:

Tuple[Set(psyclone.psyir.symbols.Symbol), Set(psyclone.psyir.symbols.Symbol), Set(psyclone.psyir.symbols.Symbol)]

Raises:

GenerationError – if the DefaultClauseType associated with this OMPParallelDirective is not shared.

lower_to_language_level()[source]#

In-place construction of clauses as PSyIR constructs. At the higher level these clauses rely on dynamic variable dependence logic to decide what is private and what is shared, so we use this lowering step to find out which References are private, and place them explicitly in the lower-level tree to be processed by the backend visitor.

Returns:

the lowered version of this node.

Return type:

psyclone.psyir.node.Node

Raises:

GenerationError – if the OpenMP directive needs some synchronisation mechanism to create valid code. These are not implemented yet.

property private_clause#
Returns:

The current OMPPrivateClause associated with this Directive.

Return type:

psyclone.psyir.nodes.OMPPrivateClause

validate_global_constraints()[source]#

Perform validation checks that can only be done at code-generation time.

Raises:

GenerationError – if this OMPDoDirective is not enclosed within some OpenMP parallel region.

class psyclone.psyir.nodes.omp_directives.OMPSingleDirective(nowait=False, **kwargs)[source]#

Class representing an OpenMP SINGLE directive in the PSyIR.

Parameters:
  • nowait (bool) – argument describing whether this single should have a nowait clause applied. Default value is False.

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Inheritance

Inheritance diagram of OMPSingleDirective
begin_string()[source]#

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

Returns:

the opening statement of this directive.

Return type:

str

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end single”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

property nowait#
Returns:

whether the nowait clause is specified for this directive.

Return type:

bool

class psyclone.psyir.nodes.omp_directives.OMPMasterDirective(ast=None, children=None, parent=None)[source]#

Class representing an OpenMP MASTER directive in the PSyclone AST.

Inheritance

Inheritance diagram of OMPMasterDirective
begin_string()[source]#

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

Returns:

the opening statement of this directive.

Return type:

str

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end master”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

class psyclone.psyir.nodes.omp_directives.OMPDoDirective(omp_schedule='none', collapse=None, reprod=None, nowait=False, **kwargs)[source]#

Class representing an OpenMP DO directive in the PSyIR.

Parameters:
  • omp_schedule (Optional[str]) – the OpenMP schedule to use. Defaults to “none” which means it is implementation dependent.

  • collapse (Optional[int]) – optional number of nested loops to collapse into a single iteration space to parallelise. Defaults to None.

  • reprod (Optional[bool]) – whether or not to generate code for run-reproducible OpenMP reductions (if not specified the value is provided by the PSyclone Config file).

  • nowait (bool) – whether or not to add a nowait clause onto this directive. Default is False.

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Inheritance

Inheritance diagram of OMPDoDirective
begin_string()[source]#

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

Returns:

the beginning statement for this directive.

Return type:

str

property collapse#
Returns:

the value of the collapse clause.

Return type:

int or NoneType

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end do”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

lower_to_language_level()[source]#

In-place construction of clauses as PSyIR constructs. The clauses here may need to be updated if code has changed, or be added if not yet present.

Returns:

the lowered version of this node.

Return type:

psyclone.psyir.node.Node

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.

Returns:

description of this node, possibly coloured.

Return type:

str

property nowait: bool#
Returns:

whether this directive has a nowait clause.

property omp_schedule#
Returns:

the omp_schedule for this object.

Return type:

str

property reprod#
Returns:

whether reprod has been set for this object or not.

validate_global_constraints()[source]#

Perform validation checks that can only be done at code-generation time.

Raises:

GenerationError – if this OMPDoDirective is not enclosed within some OpenMP parallel region.

class psyclone.psyir.nodes.omp_directives.OMPParallelDoDirective(**kwargs)[source]#

Class for the !$OMP PARALLEL DO directive. This inherits from both OMPParallelDirective (because it creates a new OpenMP thread-parallel region) and OMPDoDirective (because it causes a loop to be parallelised).

Parameters:

kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Inheritance

Inheritance diagram of OMPParallelDoDirective
begin_string()[source]#

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

Returns:

the beginning statement for this directive.

Return type:

str

classmethod create(children=None, **kwargs)[source]#

Create an OMPParallelDoDirective.

Parameters:
  • children (List of psyclone.psyir.nodes.Node) – The child nodes of the new directive.

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Returns:

A new OMPParallelDoDirective.

Return type:

psyclone.psyir.nodes.OMPParallelDoDirective

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end parallel do”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

lower_to_language_level()[source]#

In-place construction of clauses as PSyIR constructs. The clauses here may need to be updated if code has changed, or be added if not yet present.

Returns:

the lowered version of this node.

Return type:

psyclone.psyir.node.Node

validate_global_constraints()[source]#

Perform validation checks that can only be done at code-generation time.

class psyclone.psyir.nodes.omp_directives.OMPSerialDirective(ast=None, children=None, parent=None)[source]#

Abstract class representing OpenMP serial regions, e.g. OpenMP SINGLE or OpenMP Master.

Inheritance

Inheritance diagram of OMPSerialDirective
lower_to_language_level()[source]#

Checks that any task dependencies inside this node are valid.

validate_global_constraints()[source]#

Perform validation checks that can only be done at code-generation time.

Raises:
  • GenerationError – if this OMPSerial is not enclosed within some OpenMP parallel region.

  • GenerationError – if this OMPSerial is enclosed within any OMPSerialDirective subclass region.

class psyclone.psyir.nodes.omp_directives.OMPTaskloopDirective(grainsize=None, num_tasks=None, nogroup=False, **kwargs)[source]#

Class representing an OpenMP TASKLOOP directive in the PSyIR.

Parameters:
  • grainsize (int or None.) – The grainsize value used to specify the grainsize clause on this OpenMP directive. If this is None the grainsize clause is not applied. Default value is None.

  • num_tasks (int or None.) – The num_tasks value used to specify the num_tasks clause on this OpenMP directive. If this is None the num_tasks clause is not applied. Default value is None.

  • nogroup (bool) – Whether the nogroup clause should be used for this node. Default value is False

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Raises:

GenerationError – if this OMPTaskloopDirective has both a grainsize and num_tasks value specified.

Inheritance

Inheritance diagram of OMPTaskloopDirective
begin_string()[source]#

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

Returns:

the beginning statement for this directive.

Return type:

str

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end taskloop”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

property nogroup#
Returns:

the nogroup clause status of this node.

Return type:

bool

validate_global_constraints()[source]#

Perform validation checks that can only be done at code-generation time.

Raises:
  • GenerationError – if this OMPTaskloopDirective is not enclosed within an OpenMP serial region.

  • GenerationError – if this OMPTaskloopDirective has two Nogroup clauses as children.

class psyclone.psyir.nodes.omp_directives.OMPTargetDirective(nowait=False, **kwargs)[source]#

Class for the !$OMP TARGET directive that offloads the code contained in its region into an accelerator device.

Parameters:

nowait (bool) – whether or not to add a nowait clause onto this directive. Default is False.

Inheritance

Inheritance diagram of OMPTargetDirective
begin_string()[source]#

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

Returns:

the opening statement of this directive.

Return type:

str

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end target”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

property nowait: bool#
Returns:

whether this directive has a nowait clause.

class psyclone.psyir.nodes.omp_directives.OMPTaskwaitDirective(ast=None, children=None, parent=None, annotations=None)[source]#

Class representing an OpenMP TASKWAIT directive in the PSyIR.

Inheritance

Inheritance diagram of OMPTaskwaitDirective
begin_string()[source]#

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

Returns:

the opening statement of this directive.

class psyclone.psyir.nodes.omp_directives.OMPDirective[source]#

Base mixin class for all OpenMP-related directives.

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

Note that classes inheriting from it must place the OMPDirective 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 OMPDirective
class psyclone.psyir.nodes.omp_directives.OMPStandaloneDirective(ast=None, children=None, parent=None, annotations=None)[source]#

Base class for all OpenMP-related standalone directives.

Inheritance

Inheritance diagram of OMPStandaloneDirective
class psyclone.psyir.nodes.omp_directives.OMPLoopDirective(collapse=None, nowait=False, **kwargs)[source]#

Class for the !$OMP LOOP directive that specifies that the iterations of the associated loops may execute concurrently.

Parameters:
  • collapse (Optional[int]) – optional number of nested loops to collapse into a single iteration space to parallelise. Defaults to None.

  • nowait (bool) – whether or not to add a nowait clause onto this directive. Default is False.

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Inheritance

Inheritance diagram of OMPLoopDirective
begin_string()[source]#

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

Returns:

the opening statement of this directive.

Return type:

str

property collapse#
Returns:

the value of the collapse clause.

Return type:

int or NoneType

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end loop”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

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.

Returns:

description of this node, possibly coloured.

Return type:

str

property nowait: bool#
Returns:

whether this directive has a nowait clause.

validate_global_constraints()[source]#

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

Raises:
  • GenerationError – if this OMPLoopDirective has more than one child in its associated schedule.

  • GenerationError – if the schedule associated with this OMPLoopDirective does not contain a Loop.

  • GenerationError – this directive must be inside a omp target or parallel region.

  • GenerationError – if this OMPLoopDirective has a collapse clause but it doesn’t have the expected number of nested Loops.

class psyclone.psyir.nodes.omp_directives.OMPDeclareTargetDirective(ast=None, children=None, parent=None, annotations=None)[source]#

Class representing an OpenMP Declare Target directive in the PSyIR.

Inheritance

Inheritance diagram of OMPDeclareTargetDirective
begin_string()[source]#

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

Returns:

the opening statement of this directive.

Return type:

str

validate_global_constraints()[source]#

Perform validation checks that can only be done at code-generation time.

Raises:

GenerationError – if this directive is not the first statement in a routine.

class psyclone.psyir.nodes.omp_directives.OMPAtomicDirective(ast=None, children=None, parent=None, directive_type=None)[source]#

OpenMP 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.

Parameters:
  • ast (Optional[fparser.two.Fortran2003.Base]) – the entry in the fparser2 parse tree representing the code contained within this directive or None.

  • children (List[Node]) – the nodes that will be children of this Directive node or None.

  • parent (Node) – PSyIR node that is the parent of this Directive or None.

  • directive_type (psyclone.psyir.nodes.OMPAtomicDirective.                          AtomicDirectiveType) – the directive type of the atomic operation.

Inheritance

Inheritance diagram of OMPAtomicDirective
begin_string()[source]#
Returns:

the opening string statement of this directive.

Return type:

str

end_string()[source]#
Returns:

the ending string statement of this directive.

Return type:

str

validate_global_constraints()[source]#

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

Raises:

GenerationError – if the OMPAtomicDirective associated statement does not conform to a valid OpenMP atomic operation.

class psyclone.psyir.nodes.omp_directives.OMPSimdDirective(ast=None, children=None, parent=None)[source]#

OpenMP directive to inform that the associated loop can be vectorised.

Inheritance

Inheritance diagram of OMPSimdDirective
begin_string()[source]#
Returns:

the opening string statement of this directive.

Return type:

str

end_string()[source]#
Returns:

the ending string statement of this directive.

Return type:

str

validate_global_constraints()[source]#

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

Raises:

GenerationError – if the OMPSimdDirective does not contain precisely one loop.

class psyclone.psyir.nodes.omp_directives.OMPBarrierDirective(ast=None, children=None, parent=None, annotations=None)[source]#

Class representing an OpenMP BARRIER directive in the PSyIR.

Inheritance

Inheritance diagram of OMPBarrierDirective
begin_string()[source]#

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

Return type:

str

Returns:

the opening statement of this directive.

validate_global_constraints()[source]#

Perform validation checks that can only be done at code-generation time.

Raises:

GenerationError – if this OMPBarrier is not enclosed within some OpenMP parallel region.