Reference Guide  2.5.0
psyclone.domain.common.psylayer.psyloop.PSyLoop Class Reference
Inheritance diagram for psyclone.domain.common.psylayer.psyloop.PSyLoop:
Collaboration diagram for psyclone.domain.common.psylayer.psyloop.PSyLoop:

Public Member Functions

def __init__ (self, valid_loop_types=None, **kwargs)
 
def __eq__ (self, other)
 
def dag_name (self)
 
def valid_loop_types (self)
 
def loop_type (self)
 
def loop_type (self, value)
 
def node_str (self, colour=True)
 
def field_space (self)
 
def field_space (self, my_field_space)
 
def field_name (self)
 
def field (self)
 
def field_name (self, my_field_name)
 
def iteration_space (self)
 
def iteration_space (self, it_space)
 
def kernel (self)
 
def kernel (self, kern)
 
def __str__ (self)
 
def has_inc_arg (self)
 
def unique_modified_args (self, arg_type)
 
def unique_fields_with_halo_reads (self)
 
def args_filter (self, arg_types=None, arg_accesses=None, unique=False)
 
def gen_mark_halos_clean_dirty (self, parent)
 

Public Attributes

 loop_type
 
 field
 
 field_name
 
 field_space
 
 iteration_space
 
 kernel
 

Detailed Description

Node representing a psylayer loop within the PSyIR. It extends the PSyIR
loop construct with information about the domain-specific iteration space
that the loop is traversing and utility methods to interact with other
psylayer nodes.

:param List[str] valid_loop_types: a list of loop types that are specific \
    to a particular API.
:param kwargs: additional keyword arguments provided to the PSyIR node.
:type kwargs: unwrapped dict.

Definition at line 46 of file psyloop.py.

Member Function Documentation

◆ __eq__()

def psyclone.domain.common.psylayer.psyloop.PSyLoop.__eq__ (   self,
  other 
)
Checks whether two nodes are equal. Two PSyLoop nodes are equal
if they have equal loop_type, field, field_name, field_space
iteraction_space and kernel.

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

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

Definition at line 82 of file psyloop.py.

82  def __eq__(self, other):
83  '''
84  Checks whether two nodes are equal. Two PSyLoop nodes are equal
85  if they have equal loop_type, field, field_name, field_space
86  iteraction_space and kernel.
87 
88  :param object other: the object to check equality to.
89 
90  :returns: whether other is equal to self.
91  :rtype: bool
92  '''
93  is_eq = super().__eq__(other)
94  is_eq = is_eq and self.loop_type == other.loop_type
95  is_eq = is_eq and self.field == other.field
96  is_eq = is_eq and self.field_name == other.field_name
97  is_eq = is_eq and self.field_space == other.field_space
98  is_eq = is_eq and self.iteration_space == other.iteration_space
99  is_eq = is_eq and self.kernel == other.kernel
100  # pylint: disable=protected-access
101  is_eq = is_eq and self._iterates_over == other._iterates_over
102 
103  return is_eq
104 

References psyclone.domain.common.psylayer.psyloop.PSyLoop._iterates_over, psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata._iterates_over, psyclone.parse.kernel.KernelType._iterates_over, psyclone.psyGen.Kern._iterates_over, psyclone.domain.common.psylayer.psyloop.PSyLoop.field, psyclone.psyGen.HaloExchange.field(), psyclone.domain.lfric.arg_ordering.ArgOrdering.field(), psyclone.domain.lfric.kern_call_arg_list.KernCallArgList.field(), psyclone.domain.lfric.kern_call_invoke_arg_list.KernCallInvokeArgList.field(), psyclone.domain.lfric.kern_stub_arg_list.KernStubArgList.field(), psyclone.domain.lfric.kernel_interface.KernelInterface.field(), psyclone.domain.common.psylayer.psyloop.PSyLoop.field_name, psyclone.gocean1p0.GOLoop.field_name, psyclone.domain.common.psylayer.psyloop.PSyLoop.field_space, psyclone.gocean1p0.GOLoop.field_space, psyclone.domain.common.psylayer.psyloop.PSyLoop.iteration_space, psyclone.gocean1p0.GOLoop.iteration_space, psyclone.domain.common.psylayer.psyloop.PSyLoop.kernel, psyclone.domain.common.psylayer.psyloop.PSyLoop.loop_type, psyclone.domain.lfric.lfric_loop.LFRicLoop.loop_type, psyclone.gocean1p0.GOLoop.loop_type, and psyclone.psyir.nodes.loop.Loop.loop_type().

Here is the call graph for this function:

◆ args_filter()

def psyclone.domain.common.psylayer.psyloop.PSyLoop.args_filter (   self,
  arg_types = None,
  arg_accesses = None,
  unique = False 
)
:returns: all arguments of type arg_types and arg_accesses. If these \
    are not set then return all arguments. If unique is set to \
    True then only return uniquely named arguments.
:rtype: List[:py:class:`psyclone.psyGen.Argument`]

Definition at line 309 of file psyloop.py.

309  def args_filter(self, arg_types=None, arg_accesses=None, unique=False):
310  '''
311  :returns: all arguments of type arg_types and arg_accesses. If these \
312  are not set then return all arguments. If unique is set to \
313  True then only return uniquely named arguments.
314  :rtype: List[:py:class:`psyclone.psyGen.Argument`]
315  '''
316  # Avoid circular import
317  # pylint: disable=import-outside-toplevel
318  from psyclone.psyGen import args_filter
319  all_args = []
320  all_arg_names = []
321  for call in self.kernels():
322  call_args = args_filter(call.arguments.args, arg_types,
323  arg_accesses)
324  if unique:
325  for arg in call_args:
326  if arg.name not in all_arg_names:
327  all_args.append(arg)
328  all_arg_names.append(arg.name)
329  else:
330  all_args.extend(call_args)
331  return all_args
332 

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

Here is the call graph for this function:

◆ dag_name()

def psyclone.domain.common.psylayer.psyloop.PSyLoop.dag_name (   self)
:returns: the dag name to use for this loop.
:rtype: str

Definition at line 106 of file psyloop.py.

106  def dag_name(self):
107  '''
108  :returns: the dag name to use for this loop.
109  :rtype: str
110 
111  '''
112  if self.loop_type:
113  _, position = self._find_position(self.ancestor(Routine))
114  name = f"loop_[{self.loop_type}]_{position}"
115  else:
116  name = super().dag_name
117  return name
118 

References psyclone.psyir.nodes.node.Node._find_position(), psyclone.psyir.nodes.node.Node.ancestor(), psyclone.domain.common.psylayer.psyloop.PSyLoop.loop_type, psyclone.domain.lfric.lfric_loop.LFRicLoop.loop_type, psyclone.gocean1p0.GOLoop.loop_type, and psyclone.psyir.nodes.loop.Loop.loop_type().

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

◆ field()

def psyclone.domain.common.psylayer.psyloop.PSyLoop.field (   self)
:returns: the field associated to this loop.
:rtype: :py:class:`psyclone.psyGen.Argument`

Definition at line 196 of file psyloop.py.

196  def field(self):
197  '''
198  :returns: the field associated to this loop.
199  :rtype: :py:class:`psyclone.psyGen.Argument`
200  '''
201  return self._field
202 

References psyclone.domain.common.psylayer.psyloop.PSyLoop._field, psyclone.domain.lfric.arg_index_to_metadata_index.ArgIndexToMetadataIndex._field(), psyclone.domain.lfric.lfric_loop.LFRicLoop._field, psyclone.domain.lfric.metadata_to_arguments_rules.MetadataToArgumentsRules._field(), and psyclone.psyGen.HaloExchange._field.

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

◆ field_name() [1/2]

def psyclone.domain.common.psylayer.psyloop.PSyLoop.field_name (   self)
:returns: the field name associated to this loop.
:rtype: str

Definition at line 188 of file psyloop.py.

188  def field_name(self):
189  '''
190  :returns: the field name associated to this loop.
191  :rtype: str
192  '''
193  return self._field_name
194 

References psyclone.domain.common.psylayer.psyloop.PSyLoop._field_name, and psyclone.domain.lfric.lfric_loop.LFRicLoop._field_name.

Here is the caller graph for this function:

◆ field_name() [2/2]

def psyclone.domain.common.psylayer.psyloop.PSyLoop.field_name (   self,
  my_field_name 
)
 Set a new field_name for the field associated to this loop.

:param str my_field_name: the new field name.

Definition at line 204 of file psyloop.py.

204  def field_name(self, my_field_name):
205  ''' Set a new field_name for the field associated to this loop.
206 
207  :param str my_field_name: the new field name.
208  '''
209  self._field_name = my_field_name
210 

References psyclone.domain.common.psylayer.psyloop.PSyLoop._field_name, and psyclone.domain.lfric.lfric_loop.LFRicLoop._field_name.

Here is the caller graph for this function:

◆ field_space() [1/2]

def psyclone.domain.common.psylayer.psyloop.PSyLoop.field_space (   self)
:returns: the field_space associated this loop.
:rtype: str

Reimplemented in psyclone.gocean1p0.GOLoop.

Definition at line 171 of file psyloop.py.

171  def field_space(self):
172  '''
173  :returns: the field_space associated this loop.
174  :rtype: str
175  '''
176  return self._field_space
177 

References psyclone.domain.common.psylayer.psyloop.PSyLoop._field_space, psyclone.domain.lfric.lfric_loop.LFRicLoop._field_space, and psyclone.gocean1p0.GOLoop._field_space.

Here is the caller graph for this function:

◆ field_space() [2/2]

def psyclone.domain.common.psylayer.psyloop.PSyLoop.field_space (   self,
  my_field_space 
)
 Set a new field_space for this loop.

:param my_field_space: the new field_space value.
:rtype my_field_space: str

Reimplemented in psyclone.gocean1p0.GOLoop.

Definition at line 179 of file psyloop.py.

179  def field_space(self, my_field_space):
180  ''' Set a new field_space for this loop.
181 
182  :param my_field_space: the new field_space value.
183  :rtype my_field_space: str
184  '''
185  self._field_space = my_field_space
186 

References psyclone.domain.common.psylayer.psyloop.PSyLoop._field_space, psyclone.domain.lfric.lfric_loop.LFRicLoop._field_space, and psyclone.gocean1p0.GOLoop._field_space.

Here is the caller graph for this function:

◆ gen_mark_halos_clean_dirty()

def psyclone.domain.common.psylayer.psyloop.PSyLoop.gen_mark_halos_clean_dirty (   self,
  parent 
)
Generates the necessary code to mark halo regions as clean or dirty
following execution of this loop. This default implementation does
nothing.

TODO #1648 - this method should be removed when the corresponding
one in LFRicLoop is removed.

:param parent: the node in the f2pygen AST to which to add content.
:type parent: :py:class:`psyclone.f2pygen.BaseGen`

Reimplemented in psyclone.domain.lfric.lfric_loop.LFRicLoop.

Definition at line 333 of file psyloop.py.

333  def gen_mark_halos_clean_dirty(self, parent):
334  '''
335  Generates the necessary code to mark halo regions as clean or dirty
336  following execution of this loop. This default implementation does
337  nothing.
338 
339  TODO #1648 - this method should be removed when the corresponding
340  one in LFRicLoop is removed.
341 
342  :param parent: the node in the f2pygen AST to which to add content.
343  :type parent: :py:class:`psyclone.f2pygen.BaseGen`
344 
345  '''
346 
Here is the caller graph for this function:

◆ has_inc_arg()

def psyclone.domain.common.psylayer.psyloop.PSyLoop.has_inc_arg (   self)
:returns: True if any of the Kernels called within this loop have an \
        argument with INC access, False otherwise.
:rtype: bool

Definition at line 258 of file psyloop.py.

258  def has_inc_arg(self):
259  '''
260  :returns: True if any of the Kernels called within this loop have an \
261  argument with INC access, False otherwise.
262  :rtype: bool
263  '''
264  for kern_call in self.coded_kernels():
265  for arg in kern_call.arguments.args:
266  if arg.access == AccessType.INC:
267  return True
268  return False
269 

References psyclone.nemo.NemoInvokeSchedule.coded_kernels(), and psyclone.psyir.nodes.node.Node.coded_kernels().

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

◆ iteration_space() [1/2]

def psyclone.domain.common.psylayer.psyloop.PSyLoop.iteration_space (   self)
:returns: the iteration_space of this loop.
:rtype: str

Reimplemented in psyclone.gocean1p0.GOLoop.

Definition at line 212 of file psyloop.py.

212  def iteration_space(self):
213  '''
214  :returns: the iteration_space of this loop.
215  :rtype: str
216  '''
217  return self._iteration_space
218 

References psyclone.domain.common.psylayer.psyloop.PSyLoop._iteration_space, psyclone.domain.lfric.lfric_loop.LFRicLoop._iteration_space, and psyclone.gocean1p0.GOLoop._iteration_space.

Here is the caller graph for this function:

◆ iteration_space() [2/2]

def psyclone.domain.common.psylayer.psyloop.PSyLoop.iteration_space (   self,
  it_space 
)
 Set a new iteration space for this loop.

:param str it_space: the new iteration_space fore this loop.

Reimplemented in psyclone.gocean1p0.GOLoop.

Definition at line 220 of file psyloop.py.

220  def iteration_space(self, it_space):
221  ''' Set a new iteration space for this loop.
222 
223  :param str it_space: the new iteration_space fore this loop.
224  '''
225  self._iteration_space = it_space
226 

References psyclone.domain.common.psylayer.psyloop.PSyLoop._iteration_space, psyclone.domain.lfric.lfric_loop.LFRicLoop._iteration_space, and psyclone.gocean1p0.GOLoop._iteration_space.

Here is the caller graph for this function:

◆ kernel() [1/2]

def psyclone.domain.common.psylayer.psyloop.PSyLoop.kernel (   self)
:returns: the kernel object associated with this PSyLoop (if any).
:rtype: Optional[:py:class:`psyclone.psyGen.Kern`]

Definition at line 228 of file psyloop.py.

228  def kernel(self):
229  '''
230  :returns: the kernel object associated with this PSyLoop (if any).
231  :rtype: Optional[:py:class:`psyclone.psyGen.Kern`]
232  '''
233  return self._kern
234 

References psyclone.domain.common.psylayer.psyloop.PSyLoop._kern, psyclone.domain.lfric.arg_ordering.ArgOrdering._kern, and psyclone.domain.lfric.lfric_loop.LFRicLoop._kern.

Here is the caller graph for this function:

◆ kernel() [2/2]

def psyclone.domain.common.psylayer.psyloop.PSyLoop.kernel (   self,
  kern 
)

◆ loop_type() [1/2]

def psyclone.domain.common.psylayer.psyloop.PSyLoop.loop_type (   self)
:returns: the (domain-specific) type of this loop.
:rtype: str

Definition at line 128 of file psyloop.py.

128  def loop_type(self):
129  '''
130  :returns: the (domain-specific) type of this loop.
131  :rtype: str
132  '''
133  return self._loop_type
134 

References psyclone.domain.common.psylayer.psyloop.PSyLoop._loop_type, psyclone.domain.lfric.lfric_loop.LFRicLoop._loop_type, and psyclone.gocean1p0.GOLoop._loop_type.

Here is the caller graph for this function:

◆ loop_type() [2/2]

def psyclone.domain.common.psylayer.psyloop.PSyLoop.loop_type (   self,
  value 
)
Set the type of this Loop.

:param str value: the type of this loop.

:raises TypeError: if the specified value is not a recognised \
    loop type.

Definition at line 136 of file psyloop.py.

136  def loop_type(self, value):
137  '''
138  Set the type of this Loop.
139 
140  :param str value: the type of this loop.
141 
142  :raises TypeError: if the specified value is not a recognised \
143  loop type.
144  '''
145  if value not in self._valid_loop_types:
146  raise TypeError(
147  f"Error, loop_type value ({value}) is invalid. Must be one of "
148  f"{self._valid_loop_types}.")
149  self._loop_type = value
150 

References psyclone.domain.common.psylayer.psyloop.PSyLoop._loop_type, psyclone.domain.lfric.lfric_loop.LFRicLoop._loop_type, psyclone.gocean1p0.GOLoop._loop_type, and psyclone.domain.common.psylayer.psyloop.PSyLoop._valid_loop_types.

Here is the caller graph for this function:

◆ node_str()

def psyclone.domain.common.psylayer.psyloop.PSyLoop.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 in psyclone.domain.lfric.lfric_loop.LFRicLoop.

Definition at line 151 of file psyloop.py.

151  def node_str(self, colour=True):
152  '''
153  Returns the name of this node with (optional) control codes
154  to generate coloured output in a terminal that supports it.
155 
156  :param bool colour: whether or not to include colour control codes.
157 
158  :returns: description of this node, possibly coloured.
159  :rtype: str
160 
161  '''
162  return (f"{self.coloured_name(colour)}[type='{self._loop_type}', "
163  f"field_space='{self._field_space}', "
164  f"it_space='{self.iteration_space}']")
165 
Here is the caller graph for this function:

◆ unique_fields_with_halo_reads()

def psyclone.domain.common.psylayer.psyloop.PSyLoop.unique_fields_with_halo_reads (   self)
:returns: fields in this loop that require at least some of their \
    halo to be clean to work correctly.
:rtype: List[:py:class:`psyclone.psyGen.Argument`]

Definition at line 291 of file psyloop.py.

291  def unique_fields_with_halo_reads(self):
292  '''
293  :returns: fields in this loop that require at least some of their \
294  halo to be clean to work correctly.
295  :rtype: List[:py:class:`psyclone.psyGen.Argument`]
296  '''
297 
298  unique_fields = []
299  unique_field_names = []
300 
301  for call in self.kernels():
302  for arg in call.arguments.args:
303  if self._halo_read_access(arg):
304  if arg.name not in unique_field_names:
305  unique_field_names.append(arg.name)
306  unique_fields.append(arg)
307  return unique_fields
308 

References psyclone.domain.common.psylayer.psyloop.PSyLoop._halo_read_access(), psyclone.domain.lfric.lfric_loop.LFRicLoop._halo_read_access(), psyclone.gocean1p0.GOLoop._halo_read_access(), and psyclone.psyir.nodes.node.Node.kernels().

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

◆ unique_modified_args()

def psyclone.domain.common.psylayer.psyloop.PSyLoop.unique_modified_args (   self,
  arg_type 
)
Return all unique arguments of the given type from kernels inside
this loop that are modified.

:param str arg_type: the type of kernel argument (e.g. field, \
                     operator) to search for.
:returns: all unique arguments of the given type from kernels inside \
    this loop that are modified.
:rtype: List[:py:class:`psyclone.psyGen.DynKernelArgument`]

Definition at line 270 of file psyloop.py.

270  def unique_modified_args(self, arg_type):
271  '''Return all unique arguments of the given type from kernels inside
272  this loop that are modified.
273 
274  :param str arg_type: the type of kernel argument (e.g. field, \
275  operator) to search for.
276  :returns: all unique arguments of the given type from kernels inside \
277  this loop that are modified.
278  :rtype: List[:py:class:`psyclone.psyGen.DynKernelArgument`]
279  '''
280  arg_names = []
281  args = []
282  for call in self.kernels():
283  for arg in call.arguments.args:
284  if arg.argument_type.lower() == arg_type:
285  if arg.access != AccessType.READ:
286  if arg.name not in arg_names:
287  arg_names.append(arg.name)
288  args.append(arg)
289  return args
290 

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

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

◆ valid_loop_types()

def psyclone.domain.common.psylayer.psyloop.PSyLoop.valid_loop_types (   self)
:returns: the (domain-specific) loop types allowed by this instance.
:rtype: list of str

Definition at line 120 of file psyloop.py.

120  def valid_loop_types(self):
121  '''
122  :returns: the (domain-specific) loop types allowed by this instance.
123  :rtype: list of str
124  '''
125  return self._valid_loop_types
126 

References psyclone.domain.common.psylayer.psyloop.PSyLoop._valid_loop_types.


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