Reference Guide  2.5.0
psyclone.gocean1p0.GOStencil Class Reference

Public Member Functions

def __init__ (self)
 
def load (self, stencil_info, kernel_name)
 
def has_stencil (self)
 
def name (self)
 
def depth (self, index0, index1)
 

Detailed Description

GOcean 1.0 stencil information for a kernel argument as obtained by
parsing the kernel meta-data. The expected structure of the
metadata and its meaning is provided in the description of the
load method

Definition at line 1699 of file gocean1p0.py.

Constructor & Destructor Documentation

◆ __init__()

def psyclone.gocean1p0.GOStencil.__init__ (   self)
 Set up any internal variables. 

Definition at line 1706 of file gocean1p0.py.

1706  def __init__(self):
1707  ''' Set up any internal variables. '''
1708  self._has_stencil = None
1709  self._stencil = [[0 for _ in range(3)] for _ in range(3)]
1710  self._name = None
1711  self._initialised = False
1712 

References psyclone.gocean1p0.GOStencil._has_stencil, psyclone.gocean1p0.GOStencil._initialised, psyclone.domain.common.algorithm.psyir.AlgorithmInvokeCall._name, psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata._name, psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata.GridArg._name, psyclone.domain.lfric.kernel.lfric_kernel_metadata.LFRicKernelMetadata._name, psyclone.dynamo0p3.DynFuncDescriptor03._name, psyclone.expression.NamedArg._name, psyclone.gocean1p0.GOKernelGridArgument._name, psyclone.gocean1p0.GOStencil._name, psyclone.nemo.NemoInvoke._name, psyclone.nemo.NemoPSy._name, psyclone.parse.algorithm.FileInfo._name, psyclone.parse.algorithm.InvokeCall._name, psyclone.parse.kernel.KernelProcedure._name, psyclone.parse.kernel.KernelType._name, psyclone.parse.module_info.ModuleInfo._name, psyclone.psyGen.PSy._name, psyclone.psyGen.Invoke._name, psyclone.psyGen.Kern._name, psyclone.psyGen.Argument._name, psyclone.psyir.nodes.container.Container._name, psyclone.psyir.nodes.routine.Routine._name, psyclone.psyir.symbols.symbol.Symbol._name, psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata.FieldArg._stencil, psyclone.domain.lfric.arg_index_to_metadata_index.ArgIndexToMetadataIndex._stencil(), psyclone.domain.lfric.kernel.field_arg_metadata.FieldArgMetadata._stencil, psyclone.domain.lfric.lfric_arg_descriptor.LFRicArgDescriptor._stencil, psyclone.domain.lfric.metadata_to_arguments_rules.MetadataToArgumentsRules._stencil(), psyclone.dynamo0p3.DynKernelArgument._stencil, psyclone.gocean1p0.GOStencil._stencil, and psyclone.parse.kernel.Descriptor._stencil.

Here is the call graph for this function:

Member Function Documentation

◆ depth()

def psyclone.gocean1p0.GOStencil.depth (   self,
  index0,
  index1 
)
Provides the depth of the stencil in the 8 possible stencil
directions in a 2d regular grid (see the description in the
load class for more information). Values must be between -1
and 1 as they are considered to be relative to the centre of
the stencil For example:

stencil(234,
        915,
        876)

returns

depth(-1,0) = 9
depth(1,1) = 4

:param int index0: the relative stencil offset for the first \
                   index of the associated array. This value \
                   must be between -1 and 1.
:param int index1: the relative stencil offset for the second \
                   index of the associated array. This value \
                   must be between -1 and 1

:returns: the depth of the stencil in the specified direction.
:rtype: int

:raises GenerationError: if the indices are out-of-bounds.

Definition at line 1900 of file gocean1p0.py.

1900  def depth(self, index0, index1):
1901  '''Provides the depth of the stencil in the 8 possible stencil
1902  directions in a 2d regular grid (see the description in the
1903  load class for more information). Values must be between -1
1904  and 1 as they are considered to be relative to the centre of
1905  the stencil For example:
1906 
1907  stencil(234,
1908  915,
1909  876)
1910 
1911  returns
1912 
1913  depth(-1,0) = 9
1914  depth(1,1) = 4
1915 
1916  :param int index0: the relative stencil offset for the first \
1917  index of the associated array. This value \
1918  must be between -1 and 1.
1919  :param int index1: the relative stencil offset for the second \
1920  index of the associated array. This value \
1921  must be between -1 and 1
1922 
1923  :returns: the depth of the stencil in the specified direction.
1924  :rtype: int
1925 
1926  :raises GenerationError: if the indices are out-of-bounds.
1927 
1928  '''
1929  self._check_init()
1930  if index0 < -1 or index0 > 1 or index1 < -1 or index1 > 1:
1931  raise GenerationError(
1932  f"The indices arguments to the depth method in the GOStencil "
1933  f"object must be between -1 and 1 but found "
1934  f"({index0},{index1})")
1935  return self._stencil[index0+1][index1+1]
1936 
1937 

References psyclone.gocean1p0.GOStencil._check_init(), psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata.FieldArg._stencil, psyclone.domain.lfric.arg_index_to_metadata_index.ArgIndexToMetadataIndex._stencil(), psyclone.domain.lfric.kernel.field_arg_metadata.FieldArgMetadata._stencil, psyclone.domain.lfric.lfric_arg_descriptor.LFRicArgDescriptor._stencil, psyclone.domain.lfric.metadata_to_arguments_rules.MetadataToArgumentsRules._stencil(), psyclone.dynamo0p3.DynKernelArgument._stencil, psyclone.gocean1p0.GOStencil._stencil, and psyclone.parse.kernel.Descriptor._stencil.

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

◆ has_stencil()

def psyclone.gocean1p0.GOStencil.has_stencil (   self)
Specifies whether this argument has stencil information or not. The
only case when this is False is when the stencil information
specifies 'pointwise' as this indicates that there is no
stencil access.

:returns: True if this argument has stencil information and False \
          if not.
:rtype: bool

Definition at line 1874 of file gocean1p0.py.

1874  def has_stencil(self):
1875  '''Specifies whether this argument has stencil information or not. The
1876  only case when this is False is when the stencil information
1877  specifies 'pointwise' as this indicates that there is no
1878  stencil access.
1879 
1880  :returns: True if this argument has stencil information and False \
1881  if not.
1882  :rtype: bool
1883 
1884  '''
1885  self._check_init()
1886  return self._has_stencil
1887 

References psyclone.gocean1p0.GOStencil._check_init(), and psyclone.gocean1p0.GOStencil._has_stencil.

Here is the call graph for this function:

◆ load()

def psyclone.gocean1p0.GOStencil.load (   self,
  stencil_info,
  kernel_name 
)
Take parsed stencil metadata information, check it is valid and
store it in a convenient form. The kernel_name argument is
only used to provide the location if there is an error.

The stencil information should either be a name which
indicates a particular type of stencil or in the form
stencil(xxx,yyy,zzz) which explicitly specifies a stencil
shape where xxx, yyy and zzz are triplets of integers
indicating whether there is a stencil access in a particular
direction and the depth of that access. For example:

go_stencil(010,  !   N
           212,  !  W E
           010)  !   S

indicates that there is a stencil access of depth 1 in the
"North" and "South" directions and stencil access of depth 2
in the "East" and "West" directions. The value at the centre
of the stencil will not be used by PSyclone but can be 0 or 1
and indicates whether the local field value is accessed.

The convention is for the associated arrays to be
2-dimensional. If we denote the first dimension as "i" and the
second dimension as "j" then the following directions are
assumed:


> j
> ^
> |
> |
> ---->i

For example a stencil access like:

a(i,j) + a(i+1,j) + a(i,j-1)

would be stored as:

go_stencil(000,
           011,
           010)

:param stencil_info: contains the appropriate part of the parser AST
:type stencil_info: :py:class:`psyclone.expression.FunctionVar`
:param string kernel_name: the name of the kernel from where this \
                           stencil information came from.

:raises ParseError: if the supplied stencil information is invalid.

Definition at line 1714 of file gocean1p0.py.

1714  def load(self, stencil_info, kernel_name):
1715  '''Take parsed stencil metadata information, check it is valid and
1716  store it in a convenient form. The kernel_name argument is
1717  only used to provide the location if there is an error.
1718 
1719  The stencil information should either be a name which
1720  indicates a particular type of stencil or in the form
1721  stencil(xxx,yyy,zzz) which explicitly specifies a stencil
1722  shape where xxx, yyy and zzz are triplets of integers
1723  indicating whether there is a stencil access in a particular
1724  direction and the depth of that access. For example:
1725 
1726  go_stencil(010, ! N
1727  212, ! W E
1728  010) ! S
1729 
1730  indicates that there is a stencil access of depth 1 in the
1731  "North" and "South" directions and stencil access of depth 2
1732  in the "East" and "West" directions. The value at the centre
1733  of the stencil will not be used by PSyclone but can be 0 or 1
1734  and indicates whether the local field value is accessed.
1735 
1736  The convention is for the associated arrays to be
1737  2-dimensional. If we denote the first dimension as "i" and the
1738  second dimension as "j" then the following directions are
1739  assumed:
1740 
1741 
1742  > j
1743  > ^
1744  > |
1745  > |
1746  > ---->i
1747 
1748  For example a stencil access like:
1749 
1750  a(i,j) + a(i+1,j) + a(i,j-1)
1751 
1752  would be stored as:
1753 
1754  go_stencil(000,
1755  011,
1756  010)
1757 
1758  :param stencil_info: contains the appropriate part of the parser AST
1759  :type stencil_info: :py:class:`psyclone.expression.FunctionVar`
1760  :param string kernel_name: the name of the kernel from where this \
1761  stencil information came from.
1762 
1763  :raises ParseError: if the supplied stencil information is invalid.
1764 
1765  '''
1766  self._initialised = True
1767 
1768  if not isinstance(stencil_info, expr.FunctionVar):
1769  # the stencil information is not in the expected format
1770  raise ParseError(
1771  f"Meta-data error in kernel '{kernel_name}': 3rd descriptor "
1772  f"(stencil) of field argument is '{stencil_info}' but "
1773  f"expected either a name or the format 'go_stencil(...)'")
1774 
1775  # Get the name
1776  name = stencil_info.name.lower()
1777  const = GOceanConstants()
1778 
1779  if stencil_info.args:
1780  # The stencil info is of the form 'name(a,b,...), so the
1781  # name should be 'stencil' and there should be 3
1782  # arguments'
1783  self._has_stencil = True
1784  args = stencil_info.args
1785  if name != "go_stencil":
1786  raise ParseError(
1787  f"Meta-data error in kernel '{kernel_name}': 3rd "
1788  f"descriptor (stencil) of field argument is '{name}' but "
1789  f"must be 'go_stencil(...)")
1790  if len(args) != 3:
1791  raise ParseError(
1792  f"Meta-data error in kernel '{kernel_name}': 3rd "
1793  f"descriptor (stencil) of field argument with format "
1794  f"'go_stencil(...)', has {len(args)} arguments but should "
1795  f"have 3")
1796  # Each of the 3 args should be of length 3 and each
1797  # character should be a digit from 0-9. Whilst we are
1798  # expecting numbers, the parser represents these numbers
1799  # as strings so we have to perform string manipulation to
1800  # check and that extract them
1801  for arg_idx in range(3):
1802  arg = args[arg_idx]
1803  if not isinstance(arg, str):
1804  raise ParseError(
1805  f"Meta-data error in kernel '{kernel_name}': 3rd "
1806  f"descriptor (stencil) of field argument with format "
1807  f"'go_stencil(...)'. Argument index {arg_idx} should "
1808  f"be a number but found '{arg}'.")
1809  if len(arg) != 3:
1810  raise ParseError(
1811  f"Meta-data error in kernel '{kernel_name}': 3rd "
1812  f"descriptor (stencil) of field argument with format "
1813  f"'go_stencil(...)'. Argument index {arg_idx} should "
1814  f"consist of 3 digits but found {len(arg)}.")
1815  # The central value is constrained to be 0 or 1
1816  if args[1][1] not in ["0", "1"]:
1817  raise ParseError(
1818  f"Meta-data error in kernel '{kernel_name}': 3rd "
1819  f"descriptor (stencil) of field argument with format "
1820  f"'go_stencil(...)'. Argument index 1 position 1 "
1821  f"should be a number from 0-1 but found {args[1][1]}.")
1822  # It is not valid to specify a zero stencil. This is
1823  # indicated by the 'pointwise' name
1824  if args[0] == "000" and \
1825  (args[1] == "000" or args[1] == "010") and \
1826  args[2] == "000":
1827  raise ParseError(
1828  f"Meta-data error in kernel '{kernel_name}': 3rd "
1829  f"descriptor (stencil) of field argument with format "
1830  f"'go_stencil(...)'. A zero sized stencil has been "
1831  f"specified. This should be specified with the "
1832  f"'go_pointwise' keyword.")
1833  # store the values in an internal array as integers in i,j
1834  # order
1835  for idx0 in range(3):
1836  for idx1 in range(3):
1837  # The j coordinate needs to be 'reversed': the first
1838  # row (index 0 in args) is 'top', which should be
1839  # accessed using '+1', and the last row (index 2 in args)
1840  # needs to be accessed using '-1' (see depth()). Using
1841  # 2-idx1 mirrors the rows appropriately.
1842  self._stencil[idx0][2-idx1] = int(args[idx1][idx0])
1843  else:
1844  # stencil info is of the form 'name' so should be one of
1845  # our valid names
1846  if name not in const.VALID_STENCIL_NAMES:
1847  raise ParseError(
1848  f"Meta-data error in kernel '{kernel_name}': 3rd "
1849  f"descriptor (stencil) of field argument is '{name}' "
1850  f"but must be one of {const.VALID_STENCIL_NAMES} or "
1851  f"go_stencil(...)")
1852  self._name = name
1853  # We currently only support one valid name ('pointwise')
1854  # which indicates that there is no stencil
1855  self._has_stencil = False
1856  # Define a 'stencil' for pointwise so that depth() can be used for
1857  # pointwise kernels without handling pointwise as special case
1858  self._stencil = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]
1859 

References psyclone.gocean1p0.GOStencil._has_stencil, psyclone.gocean1p0.GOStencil._initialised, psyclone.domain.common.algorithm.psyir.AlgorithmInvokeCall._name, psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata._name, psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata.GridArg._name, psyclone.domain.lfric.kernel.lfric_kernel_metadata.LFRicKernelMetadata._name, psyclone.dynamo0p3.DynFuncDescriptor03._name, psyclone.expression.NamedArg._name, psyclone.gocean1p0.GOKernelGridArgument._name, psyclone.gocean1p0.GOStencil._name, psyclone.nemo.NemoInvoke._name, psyclone.nemo.NemoPSy._name, psyclone.parse.algorithm.FileInfo._name, psyclone.parse.algorithm.InvokeCall._name, psyclone.parse.kernel.KernelProcedure._name, psyclone.parse.kernel.KernelType._name, psyclone.parse.module_info.ModuleInfo._name, psyclone.psyGen.PSy._name, psyclone.psyGen.Invoke._name, psyclone.psyGen.Kern._name, psyclone.psyGen.Argument._name, psyclone.psyir.nodes.container.Container._name, psyclone.psyir.nodes.routine.Routine._name, psyclone.psyir.symbols.symbol.Symbol._name, psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata.FieldArg._stencil, psyclone.domain.lfric.arg_index_to_metadata_index.ArgIndexToMetadataIndex._stencil(), psyclone.domain.lfric.kernel.field_arg_metadata.FieldArgMetadata._stencil, psyclone.domain.lfric.lfric_arg_descriptor.LFRicArgDescriptor._stencil, psyclone.domain.lfric.metadata_to_arguments_rules.MetadataToArgumentsRules._stencil(), psyclone.dynamo0p3.DynKernelArgument._stencil, psyclone.gocean1p0.GOStencil._stencil, and psyclone.parse.kernel.Descriptor._stencil.

Here is the call graph for this function:

◆ name()

def psyclone.gocean1p0.GOStencil.name (   self)
Provides the stencil name if one is provided

:returns: the name of the type of stencil if this is provided \
          and 'None' if not.
:rtype: str

Definition at line 1889 of file gocean1p0.py.

1889  def name(self):
1890  '''Provides the stencil name if one is provided
1891 
1892  :returns: the name of the type of stencil if this is provided \
1893  and 'None' if not.
1894  :rtype: str
1895 
1896  '''
1897  self._check_init()
1898  return self._name
1899 

References psyclone.gocean1p0.GOStencil._check_init(), psyclone.domain.common.algorithm.psyir.AlgorithmInvokeCall._name, psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata._name, psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata.GridArg._name, psyclone.domain.lfric.kernel.lfric_kernel_metadata.LFRicKernelMetadata._name, psyclone.dynamo0p3.DynFuncDescriptor03._name, psyclone.expression.NamedArg._name, psyclone.gocean1p0.GOKernelGridArgument._name, psyclone.gocean1p0.GOStencil._name, psyclone.nemo.NemoInvoke._name, psyclone.nemo.NemoPSy._name, psyclone.parse.algorithm.FileInfo._name, psyclone.parse.algorithm.InvokeCall._name, psyclone.parse.kernel.KernelProcedure._name, psyclone.parse.kernel.KernelType._name, psyclone.parse.module_info.ModuleInfo._name, psyclone.psyGen.PSy._name, psyclone.psyGen.Invoke._name, psyclone.psyGen.Kern._name, psyclone.psyGen.Argument._name, psyclone.psyir.nodes.container.Container._name, psyclone.psyir.nodes.routine.Routine._name, and psyclone.psyir.symbols.symbol.Symbol._name.

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

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