Reference Guide  2.5.0
psyclone.psyir.nodes.acc_directives.ACCLoopDirective Class Reference
Inheritance diagram for psyclone.psyir.nodes.acc_directives.ACCLoopDirective:
Collaboration diagram for psyclone.psyir.nodes.acc_directives.ACCLoopDirective:

Public Member Functions

def __init__ (self, collapse=None, independent=True, sequential=False, gang=False, vector=False, **kwargs)
 
def __eq__ (self, other)
 
def collapse (self)
 
def collapse (self, value)
 
def independent (self)
 
def sequential (self)
 
def gang (self)
 
def vector (self)
 
def node_str (self, colour=True)
 
def validate_global_constraints (self)
 
def gen_code (self, parent)
 
def begin_string (self, leading_acc=True)
 
def end_string (self)
 
- Public Member Functions inherited from psyclone.psyir.nodes.acc_directives.ACCRegionDirective
def signatures (self)
 
- Public Member Functions inherited from psyclone.psyir.nodes.directive.RegionDirective
def __init__ (self, ast=None, children=None, parent=None)
 
def dir_body (self)
 
def clauses (self)
 
def gen_post_region_code (self, parent)
 
- Public Member Functions inherited from psyclone.psyir.nodes.directive.Directive
def create_data_movement_deep_copy_refs (self)
 
- Public Member Functions inherited from psyclone.psyir.nodes.node.Node
def __init__ (self, ast=None, children=None, parent=None, annotations=None)
 
def coloured_name (self, colour=True)
 
def __str__ (self)
 
def ast (self)
 
def ast_end (self)
 
def ast (self, ast)
 
def ast_end (self, ast_end)
 
def annotations (self)
 
def dag (self, file_name='dag', file_format='svg')
 
def dag_gen (self, graph)
 
def dag_name (self)
 
def args (self)
 
def backward_dependence (self)
 
def forward_dependence (self)
 
def is_valid_location (self, new_node, position="before")
 
def depth (self)
 
def view (self, depth=0, colour=True, indent=" ", _index=None)
 
def addchild (self, child, index=None)
 
def children (self)
 
def children (self, my_children)
 
def parent (self)
 
def siblings (self)
 
def has_constructor_parent (self)
 
def position (self)
 
def abs_position (self)
 
def root (self)
 
def sameParent (self, node_2)
 
def walk (self, my_type, stop_type=None, depth=None)
 
def get_sibling_lists (self, my_type, stop_type=None)
 
def ancestor (self, my_type, excluding=None, include_self=False, limit=None, shared_with=None)
 
def kernels (self)
 
def following (self, routine=True)
 
def preceding (self, reverse=False, routine=True)
 
def immediately_precedes (self, node_2)
 
def immediately_follows (self, node_1)
 
def coded_kernels (self)
 
def loops (self)
 
def reductions (self, reprod=None)
 
def is_openmp_parallel (self)
 
def lower_to_language_level (self)
 
def reference_accesses (self, var_accesses)
 
def scope (self)
 
def replace_with (self, node, keep_name_in_context=True)
 
def pop_all_children (self)
 
def detach (self)
 
def copy (self)
 
def debug_string (self)
 
def origin_string (self)
 
def update_signal (self)
 
def path_from (self, ancestor)
 
- Public Member Functions inherited from psyclone.psyir.nodes.commentable_mixin.CommentableMixin
def preceding_comment (self)
 
def preceding_comment (self, comment)
 
def inline_comment (self)
 
def inline_comment (self, comment)
 

Public Attributes

 collapse
 
 independent
 
 sequential
 
 gang
 
 vector
 
- Public Attributes inherited from psyclone.psyir.nodes.node.Node
 position
 

Additional Inherited Members

- Static Public Attributes inherited from psyclone.psyir.nodes.node.Node
int START_DEPTH = 0
 
int START_POSITION = 0
 
 valid_annotations = tuple()
 

Detailed Description

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

:param int collapse: Number of nested loops to collapse into a single
                     iteration space or None.
:param bool independent: Whether or not to add the `independent` clause
                         to the loop directive.
:param bool sequential: whether or not to add the `seq` clause to the
                        loop directive.
:param bool gang: whether or not to add the `gang` clause to the
                  loop directive.
:param bool vector: whether or not to add the `vector` clause to the
                    loop directive.
:param kwargs: additional keyword arguments provided to the super class.
:type kwargs: unwrapped dict.

Definition at line 381 of file acc_directives.py.

Member Function Documentation

◆ __eq__()

def psyclone.psyir.nodes.acc_directives.ACCLoopDirective.__eq__ (   self,
  other 
)
Checks whether two nodes are equal. Two ACCLoopDirective nodes are
equal if their collapse, independent, sequential, gang, and vector
members are equal.

:param object other: the object to check equality to.

:returns: whether other is equal to self.
:rtype: bool

Reimplemented from psyclone.psyir.nodes.node.Node.

Definition at line 407 of file acc_directives.py.

407  def __eq__(self, other):
408  '''
409  Checks whether two nodes are equal. Two ACCLoopDirective nodes are
410  equal if their collapse, independent, sequential, gang, and vector
411  members are equal.
412 
413  :param object other: the object to check equality to.
414 
415  :returns: whether other is equal to self.
416  :rtype: bool
417  '''
418  is_eq = super().__eq__(other)
419  is_eq = is_eq and self.collapse == other.collapse
420  is_eq = is_eq and self.independent == other.independent
421  is_eq = is_eq and self.sequential == other.sequential
422  is_eq = is_eq and self.gang == other.gang
423  is_eq = is_eq and self.vector == other.vector
424 
425  return is_eq
426 

References psyclone.psyir.nodes.acc_directives.ACCLoopDirective.collapse, psyclone.psyir.nodes.omp_directives.OMPDoDirective.collapse, psyclone.psyir.nodes.omp_directives.OMPLoopDirective.collapse, psyclone.psyir.nodes.acc_directives.ACCLoopDirective.gang, psyclone.psyir.nodes.acc_directives.ACCLoopDirective.independent, psyclone.psyir.nodes.acc_directives.ACCLoopDirective.sequential, psyclone.domain.lfric.kernel.common_meta_arg_metadata.CommonMetaArgMetadata.vector, psyclone.domain.lfric.kernel.field_vector_arg_metadata.FieldVectorArgMetadata.vector, psyclone.domain.lfric.kernel.inter_grid_vector_arg_metadata.InterGridVectorArgMetadata.vector, and psyclone.psyir.nodes.acc_directives.ACCLoopDirective.vector.

◆ begin_string()

def psyclone.psyir.nodes.acc_directives.ACCLoopDirective.begin_string (   self,
  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.

:param bool leading_acc: whether or not to include the leading \
                         "acc loop" in the text that is returned.

:returns: the opening statement of this directive.
:rtype: str

Definition at line 561 of file acc_directives.py.

561  def begin_string(self, leading_acc=True):
562  ''' Returns the opening statement of this directive, i.e.
563  "acc loop" plus any qualifiers. If `leading_acc` is False then
564  the leading "acc loop" text is not included.
565 
566  :param bool leading_acc: whether or not to include the leading \
567  "acc loop" in the text that is returned.
568 
569  :returns: the opening statement of this directive.
570  :rtype: str
571 
572  '''
573  clauses = []
574  if leading_acc:
575  clauses = ["acc", "loop"]
576 
577  if self._sequential:
578  clauses += ["seq"]
579  else:
580  if self._gang:
581  clauses += ["gang"]
582  if self._vector:
583  clauses += ["vector"]
584  if self._independent:
585  clauses += ["independent"]
586  if self._collapse:
587  clauses += [f"collapse({self._collapse})"]
588  return " ".join(clauses)
589 

References psyclone.psyir.nodes.acc_directives.ACCLoopDirective._collapse, psyclone.psyir.nodes.omp_directives.OMPDoDirective._collapse, psyclone.psyir.nodes.omp_directives.OMPLoopDirective._collapse, psyclone.psyir.nodes.acc_directives.ACCLoopDirective._gang, psyclone.transformations.ACCLoopTrans._gang, psyclone.psyir.nodes.acc_directives.ACCLoopDirective._independent, psyclone.transformations.ACCLoopTrans._independent, psyclone.psyir.nodes.acc_directives.ACCLoopDirective._sequential, psyclone.transformations.ACCLoopTrans._sequential, psyclone.psyir.nodes.acc_directives.ACCLoopDirective._vector, and psyclone.transformations.ACCLoopTrans._vector.

Here is the caller graph for this function:

◆ collapse() [1/2]

def psyclone.psyir.nodes.acc_directives.ACCLoopDirective.collapse (   self)
:returns: the number of nested loops to collapse into a single \
          iteration space for this node.
:rtype: int or None

Definition at line 428 of file acc_directives.py.

428  def collapse(self):
429  '''
430  :returns: the number of nested loops to collapse into a single \
431  iteration space for this node.
432  :rtype: int or None
433  '''
434  return self._collapse
435 

References psyclone.psyir.nodes.acc_directives.ACCLoopDirective._collapse, psyclone.psyir.nodes.omp_directives.OMPDoDirective._collapse, and psyclone.psyir.nodes.omp_directives.OMPLoopDirective._collapse.

Here is the caller graph for this function:

◆ collapse() [2/2]

def psyclone.psyir.nodes.acc_directives.ACCLoopDirective.collapse (   self,
  value 
)
:param value: optional number of nested loop to collapse into a \
    single iteration space to parallelise. Defaults to None.
:type value: Optional[int]

:raises TypeError: if the collapse value given is not an integer \
    or NoneType.
:raises ValueError: if the collapse integer given is not positive.

Definition at line 437 of file acc_directives.py.

437  def collapse(self, value):
438  '''
439  :param value: optional number of nested loop to collapse into a \
440  single iteration space to parallelise. Defaults to None.
441  :type value: Optional[int]
442 
443  :raises TypeError: if the collapse value given is not an integer \
444  or NoneType.
445  :raises ValueError: if the collapse integer given is not positive.
446 
447  '''
448  if value is not None and not isinstance(value, int):
449  raise TypeError(
450  f"The ACCLoopDirective collapse clause must be a positive "
451  f"integer or None, but value '{value}' has been given.")
452 
453  if value is not None and value <= 0:
454  raise ValueError(
455  f"The ACCLoopDirective collapse clause must be a positive "
456  f"integer or None, but value '{value}' has been given.")
457 
458  self._collapse = value
459 

References psyclone.psyir.nodes.acc_directives.ACCLoopDirective._collapse, psyclone.psyir.nodes.omp_directives.OMPDoDirective._collapse, and psyclone.psyir.nodes.omp_directives.OMPLoopDirective._collapse.

Here is the caller graph for this function:

◆ end_string()

def psyclone.psyir.nodes.acc_directives.ACCLoopDirective.end_string (   self)
Would return the end string for this directive but "acc loop"
doesn't have a closing directive.

:returns: empty string.
:rtype: str

Definition at line 590 of file acc_directives.py.

590  def end_string(self):
591  '''
592  Would return the end string for this directive but "acc loop"
593  doesn't have a closing directive.
594 
595  :returns: empty string.
596  :rtype: str
597 
598  '''
599  return ""
600 
601 
Here is the caller graph for this function:

◆ gang()

def psyclone.psyir.nodes.acc_directives.ACCLoopDirective.gang (   self)
:returns: whether or not the `gang` clause is added to this loop
          directive.
:rtype: bool

Definition at line 481 of file acc_directives.py.

481  def gang(self):
482  '''
483  :returns: whether or not the `gang` clause is added to this loop
484  directive.
485  :rtype: bool
486  '''
487  return self._gang
488 

References psyclone.psyir.nodes.acc_directives.ACCLoopDirective._gang, and psyclone.transformations.ACCLoopTrans._gang.

Here is the caller graph for this function:

◆ gen_code()

def psyclone.psyir.nodes.acc_directives.ACCLoopDirective.gen_code (   self,
  parent 
)
Generate the f2pygen AST entries in the Schedule for this OpenACC
loop directive.

:param parent: the parent Node in the Schedule to which to add our
               content.
:type parent: sub-class of :py:class:`psyclone.f2pygen.BaseGen`
:raises GenerationError: if this "!$acc loop" is not enclosed within \
                         an ACC Parallel region.

Definition at line 539 of file acc_directives.py.

539  def gen_code(self, parent):
540  '''
541  Generate the f2pygen AST entries in the Schedule for this OpenACC
542  loop directive.
543 
544  :param parent: the parent Node in the Schedule to which to add our
545  content.
546  :type parent: sub-class of :py:class:`psyclone.f2pygen.BaseGen`
547  :raises GenerationError: if this "!$acc loop" is not enclosed within \
548  an ACC Parallel region.
549  '''
550  self.validate_global_constraints()
551 
552  # Add any clauses to the directive. We use self.begin_string() to avoid
553  # code duplication.
554  options_str = self.begin_string(leading_acc=False)
555 
556  parent.add(DirectiveGen(parent, "acc", "begin", "loop", options_str))
557 
558  for child in self.children:
559  child.gen_code(parent)
560 

References psyclone.psyir.nodes.acc_directives.ACCRoutineDirective.begin_string(), psyclone.psyir.nodes.acc_directives.ACCEnterDataDirective.begin_string(), psyclone.psyir.nodes.acc_directives.ACCParallelDirective.begin_string(), psyclone.psyir.nodes.acc_directives.ACCKernelsDirective.begin_string(), psyclone.psyir.nodes.acc_directives.ACCDataDirective.begin_string(), psyclone.psyir.nodes.acc_directives.ACCUpdateDirective.begin_string(), psyclone.psyir.nodes.acc_directives.ACCAtomicDirective.begin_string(), psyclone.psyir.nodes.omp_directives.OMPDeclareTargetDirective.begin_string(), psyclone.psyir.nodes.omp_directives.OMPTaskwaitDirective.begin_string(), psyclone.psyir.nodes.omp_directives.OMPSingleDirective.begin_string(), psyclone.psyir.nodes.omp_directives.OMPMasterDirective.begin_string(), psyclone.psyir.nodes.omp_directives.OMPParallelDirective.begin_string(), psyclone.psyir.nodes.omp_directives.OMPTaskloopDirective.begin_string(), psyclone.psyir.nodes.omp_directives.OMPDoDirective.begin_string(), psyclone.psyir.nodes.omp_directives.OMPParallelDoDirective.begin_string(), psyclone.psyir.nodes.omp_directives.OMPTargetDirective.begin_string(), psyclone.psyir.nodes.omp_directives.OMPLoopDirective.begin_string(), psyclone.psyir.nodes.omp_directives.OMPAtomicDirective.begin_string(), psyclone.psyir.nodes.omp_directives.OMPSimdDirective.begin_string(), psyclone.psyir.nodes.omp_task_directive.OMPTaskDirective.begin_string(), psyclone.psyir.nodes.acc_directives.ACCLoopDirective.begin_string(), psyclone.f2pygen.BaseGen.children(), psyclone.psyGen.InlinedKern.children, psyclone.psyir.nodes.node.Node.children(), psyclone.domain.lfric.lfric_kern.LFRicKern.validate_global_constraints(), psyclone.psyir.nodes.acc_directives.ACCRegionDirective.validate_global_constraints(), psyclone.psyir.nodes.acc_directives.ACCLoopDirective.validate_global_constraints(), psyclone.psyir.nodes.acc_directives.ACCAtomicDirective.validate_global_constraints(), psyclone.psyir.nodes.node.Node.validate_global_constraints(), psyclone.psyir.nodes.omp_directives.OMPDeclareTargetDirective.validate_global_constraints(), psyclone.psyir.nodes.omp_directives.OMPTaskwaitDirective.validate_global_constraints(), psyclone.psyir.nodes.omp_directives.OMPSerialDirective.validate_global_constraints(), psyclone.psyir.nodes.omp_directives.OMPParallelDirective.validate_global_constraints(), psyclone.psyir.nodes.omp_directives.OMPTaskloopDirective.validate_global_constraints(), psyclone.psyir.nodes.omp_directives.OMPDoDirective.validate_global_constraints(), psyclone.psyir.nodes.omp_directives.OMPParallelDoDirective.validate_global_constraints(), psyclone.psyir.nodes.omp_directives.OMPLoopDirective.validate_global_constraints(), psyclone.psyir.nodes.omp_directives.OMPAtomicDirective.validate_global_constraints(), psyclone.psyir.nodes.omp_directives.OMPSimdDirective.validate_global_constraints(), and psyclone.psyir.nodes.omp_task_directive.OMPTaskDirective.validate_global_constraints().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ independent()

def psyclone.psyir.nodes.acc_directives.ACCLoopDirective.independent (   self)
 Returns whether the independent clause will be added to this
loop directive.

:returns: whether the independent clause will be added to this loop \
          directive.
:rtype: bool

Definition at line 461 of file acc_directives.py.

461  def independent(self):
462  ''' Returns whether the independent clause will be added to this
463  loop directive.
464 
465  :returns: whether the independent clause will be added to this loop \
466  directive.
467  :rtype: bool
468  '''
469  return self._independent
470 

References psyclone.psyir.nodes.acc_directives.ACCLoopDirective._independent, and psyclone.transformations.ACCLoopTrans._independent.

Here is the caller graph for this function:

◆ node_str()

def psyclone.psyir.nodes.acc_directives.ACCLoopDirective.node_str (   self,
  colour = True 
)
Returns the name of this node with (optional) control codes
to generate coloured output in a terminal that supports it.

:param bool colour: whether or not to include colour control codes.

:returns: description of this node, possibly coloured.
:rtype: str

Reimplemented from psyclone.psyir.nodes.node.Node.

Definition at line 498 of file acc_directives.py.

498  def node_str(self, colour=True):
499  '''
500  Returns the name of this node with (optional) control codes
501  to generate coloured output in a terminal that supports it.
502 
503  :param bool colour: whether or not to include colour control codes.
504 
505  :returns: description of this node, possibly coloured.
506  :rtype: str
507  '''
508  text = self.coloured_name(colour)
509  text += f"[sequential={self._sequential},"
510  text += f"gang={self._gang},"
511  text += f"vector={self._vector},"
512  text += f"collapse={self._collapse},"
513  text += f"independent={self._independent}]"
514  return text
515 

References psyclone.psyir.nodes.node.Node.coloured_name().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sequential()

def psyclone.psyir.nodes.acc_directives.ACCLoopDirective.sequential (   self)
:returns: whether or not the `seq` clause is added to this loop \
          directive.
:rtype: bool

Definition at line 472 of file acc_directives.py.

472  def sequential(self):
473  '''
474  :returns: whether or not the `seq` clause is added to this loop \
475  directive.
476  :rtype: bool
477  '''
478  return self._sequential
479 

References psyclone.psyir.nodes.acc_directives.ACCLoopDirective._sequential, and psyclone.transformations.ACCLoopTrans._sequential.

Here is the caller graph for this function:

◆ validate_global_constraints()

def psyclone.psyir.nodes.acc_directives.ACCLoopDirective.validate_global_constraints (   self)
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.

Reimplemented from psyclone.psyir.nodes.acc_directives.ACCRegionDirective.

Definition at line 516 of file acc_directives.py.

516  def validate_global_constraints(self):
517  '''
518  Perform validation of those global constraints that can only be done
519  at code-generation time.
520 
521  :raises GenerationError: if this ACCLoopDirective is not enclosed
522  within some OpenACC parallel or kernels region and is not in a
523  Routine that has been marked up with an 'ACC Routine' directive.
524  '''
525  parent_routine = self.ancestor(Routine)
526  if not (self.ancestor((ACCParallelDirective, ACCKernelsDirective),
527  limit=parent_routine) or
528  (parent_routine and parent_routine.walk(ACCRoutineDirective))):
529  location = (f"in routine '{parent_routine.name}' " if
530  parent_routine else "")
531  raise GenerationError(
532  f"ACCLoopDirective {location}must either have an "
533  f"ACCParallelDirective or ACCKernelsDirective as an ancestor "
534  f"in the Schedule or the routine must contain an "
535  f"ACCRoutineDirective.")
536 
537  super().validate_global_constraints()
538 

References psyclone.psyir.nodes.node.Node.ancestor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vector()

def psyclone.psyir.nodes.acc_directives.ACCLoopDirective.vector (   self)
:returns: whether or not the `vector` clause is added to this loop
          directive.
:rtype: bool

Definition at line 490 of file acc_directives.py.

490  def vector(self):
491  '''
492  :returns: whether or not the `vector` clause is added to this loop
493  directive.
494  :rtype: bool
495  '''
496  return self._vector
497 

References psyclone.psyir.nodes.acc_directives.ACCLoopDirective._vector, and psyclone.transformations.ACCLoopTrans._vector.

Here is the caller graph for this function:

The documentation for this class was generated from the following file: