Reference Guide  2.5.0
psyclone.parse.kernel.KernelType Class Reference
Inheritance diagram for psyclone.parse.kernel.KernelType:

Public Member Functions

def __init__ (self, ast, name=None)
 
def name (self)
 
def iterates_over (self)
 
def procedure (self)
 
def nargs (self)
 
def arg_descriptors (self)
 
def __repr__ (self)
 
def get_integer_variable (self, name)
 
def get_integer_array (self, name)
 

Detailed Description

Base class for describing Kernel Metadata.

This contains the name of the elemental procedure and metadata associated
with how that procedure is mapped over mesh entities.

:param ast: fparser1 AST for the parsed kernel meta-data.
:type ast: :py:class:`fparser.one.block_statements.BeginSource`
:param str name: name of the Fortran derived type describing the kernel.

:raises ParseError: if the supplied AST does not contain a Fortran \
module.
:raises ParseError: if the module name is too short to contain \
'_mod' at the end.
:raises ParseError: if the module name does not end in '_mod'.

Definition at line 777 of file kernel.py.

Member Function Documentation

◆ arg_descriptors()

def psyclone.parse.kernel.KernelType.arg_descriptors (   self)
:returns: a list of API-specific argument descriptors.
:rtype: list of API-specific specialisation of \
:py:class:`psyclone.kernel.Descriptor`

Definition at line 894 of file kernel.py.

894  def arg_descriptors(self):
895  '''
896  :returns: a list of API-specific argument descriptors.
897  :rtype: list of API-specific specialisation of \
898  :py:class:`psyclone.kernel.Descriptor`
899 
900  '''
901  return self._arg_descriptors
902 

References psyclone.domain.lfric.lfric_kern_metadata.LFRicKernMetadata._arg_descriptors, psyclone.gocean1p0.GOKernelType1p0._arg_descriptors, psyclone.parse.kernel.KernelType._arg_descriptors, psyclone.psyGen.Kern._arg_descriptors, and psyclone.psyGen.BuiltIn._arg_descriptors.

Here is the caller graph for this function:

◆ get_integer_array()

def psyclone.parse.kernel.KernelType.get_integer_array (   self,
  name 
)
 Parse the kernel meta-data and find the values of the
integer array variable with the supplied name. Returns an empty list
if no matching variable is found. The search is not case sensitive.

:param str name: the name of the integer array to find.

:return: list of values (lower-case).
:rtype: list of str.

:raises InternalError: if we fail to parse the LHS of the array \
                       declaration or the array constructor.
:raises ParseError: if the array is not of rank 1.
:raises ParseError: if the array extent is not specified using an \
                    integer literal.
:raises ParseError: if the RHS of the declaration is not an array \
                    constructor.
:raises InternalError: if the parse tree for the array constructor \
                       does not have the expected structure.
:raises ParseError: if the number of items in the array constructor \
                    does not match the extent of the array.

Definition at line 939 of file kernel.py.

939  def get_integer_array(self, name):
940  ''' Parse the kernel meta-data and find the values of the
941  integer array variable with the supplied name. Returns an empty list
942  if no matching variable is found. The search is not case sensitive.
943 
944  :param str name: the name of the integer array to find.
945 
946  :return: list of values (lower-case).
947  :rtype: list of str.
948 
949  :raises InternalError: if we fail to parse the LHS of the array \
950  declaration or the array constructor.
951  :raises ParseError: if the array is not of rank 1.
952  :raises ParseError: if the array extent is not specified using an \
953  integer literal.
954  :raises ParseError: if the RHS of the declaration is not an array \
955  constructor.
956  :raises InternalError: if the parse tree for the array constructor \
957  does not have the expected structure.
958  :raises ParseError: if the number of items in the array constructor \
959  does not match the extent of the array.
960 
961  '''
962  # Ensure the classes are setup for the Fortran2008 parser
963  _ = ParserFactory().create(std="f2008")
964  # Fortran is not case sensitive so nor is our matching
965  lower_name = name.lower()
966 
967  for statement, _ in fpapi.walk(self._ktype):
968  if not isinstance(statement, fparser1.typedecl_statements.Integer):
969  # This isn't an integer declaration so skip it
970  continue
971  # fparser only goes down to the statement level. We use fparser2 to
972  # parse the statement itself.
973  assign = Fortran2003.Assignment_Stmt(statement.entity_decls[0])
974  names = walk(assign.children, Fortran2003.Name)
975  if not names:
976  raise InternalError(f"Unsupported assignment statement: "
977  f"'{assign}'")
978 
979  if str(names[0]).lower() != lower_name:
980  # This is not the variable declaration we're looking for
981  continue
982 
983  if not isinstance(assign.children[0], Fortran2003.Part_Ref):
984  # Not an array declaration
985  return []
986 
987  if not isinstance(assign.children[0].children[1],
988  Fortran2003.Section_Subscript_List):
989  raise InternalError(
990  f"get_integer_array: expected array declaration to have a "
991  f"Section_Subscript_List but found "
992  f"'{type(assign.children[0].children[1]).__name__}' "
993  f"for: '{assign}'")
994 
995  dim_stmt = assign.children[0].children[1]
996  if len(dim_stmt.children) != 1:
997  raise ParseError(
998  f"get_integer_array: array must be 1D but found an array "
999  f"with {len(dim_stmt.children)} dimensions for name '"
1000  f"{name}'")
1001  if not isinstance(dim_stmt.children[0],
1002  Fortran2003.Int_Literal_Constant):
1003  raise ParseError(
1004  f"get_integer_array: array extent must be specified using "
1005  f"an integer literal but found '{dim_stmt.children[0]}' "
1006  f"for array '{name}'")
1007  # Get the declared size of the array
1008  array_extent = int(str(dim_stmt.children[0]))
1009 
1010  if not isinstance(assign.children[2],
1011  Fortran2003.Array_Constructor):
1012  raise ParseError(
1013  f"get_integer_array: RHS of assignment is not "
1014  f"an array constructor: '{assign}'")
1015  # fparser2 AST for Array_Constructor is:
1016  # Array_Constructor('[', Ac_Value_List(',', (Name('w0'),
1017  # Name('w1'))), ']')
1018  # Construct a list of the names in the array constructor
1019  names = walk(assign.children[2].children, Fortran2003.Name)
1020  if not names:
1021  raise InternalError(f"Failed to parse array constructor: "
1022  f"'{assign.items[2]}'")
1023  if len(names) != array_extent:
1024  # Ideally fparser would catch this but it isn't yet mature
1025  # enough.
1026  raise ParseError(
1027  f"get_integer_array: declared length of array '{name}' is "
1028  f"{array_extent} but constructor only contains "
1029  f"{len(names)} names: '{assign}'")
1030  return [str(name).lower() for name in names]
1031  # No matching declaration for the provided name was found
1032  return []

References psyclone.parse.algorithm.ParsedCall._ktype, and psyclone.parse.kernel.KernelType._ktype.

◆ get_integer_variable()

def psyclone.parse.kernel.KernelType.get_integer_variable (   self,
  name 
)
 Parse the kernel meta-data and find the value of the
integer variable with the supplied name. Return None if no
matching variable is found. The search is not case sensitive.

:param str name: the name of the integer variable to find.

:return: value of the specified integer variable (lower case) or None.
:rtype: str

:raises ParseError: if the RHS of the assignment is not a Name.

Definition at line 906 of file kernel.py.

906  def get_integer_variable(self, name):
907  ''' Parse the kernel meta-data and find the value of the
908  integer variable with the supplied name. Return None if no
909  matching variable is found. The search is not case sensitive.
910 
911  :param str name: the name of the integer variable to find.
912 
913  :return: value of the specified integer variable (lower case) or None.
914  :rtype: str
915 
916  :raises ParseError: if the RHS of the assignment is not a Name.
917 
918  '''
919  # Ensure the Fortran2008 parser is initialised
920  _ = ParserFactory().create(std="f2008")
921  # Fortran is not case sensitive so nor is our matching
922  lower_name = name.lower()
923 
924  for statement, _ in fpapi.walk(self._ktype):
925  if isinstance(statement, fparser1.typedecl_statements.Integer):
926  # fparser only goes down to the statement level. We use
927  # fparser2 to parse the statement itself (eventually we'll
928  # use fparser2 to parse the whole thing).
929  assign = Fortran2003.Assignment_Stmt(
930  statement.entity_decls[0])
931  if str(assign.items[0]).lower() == lower_name:
932  if not isinstance(assign.items[2], Fortran2003.Name):
933  raise ParseError(
934  f"get_integer_variable: RHS of assignment is not "
935  f"a variable name: '{assign}'")
936  return str(assign.items[2]).lower()
937  return None
938 

References psyclone.parse.algorithm.ParsedCall._ktype, and psyclone.parse.kernel.KernelType._ktype.

◆ iterates_over()

def psyclone.parse.kernel.KernelType.iterates_over (   self)
:returns: the name of the iteration space supported by this kernel
:rtype: str

Definition at line 866 of file kernel.py.

866  def iterates_over(self):
867  '''
868  :returns: the name of the iteration space supported by this kernel
869  :rtype: str
870 
871  '''
872  return self._iterates_over
873 

References psyclone.domain.common.psylayer.psyloop.PSyLoop._iterates_over, psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata._iterates_over, psyclone.parse.kernel.KernelType._iterates_over, and psyclone.psyGen.Kern._iterates_over.

Here is the caller graph for this function:

◆ name()

◆ nargs()

def psyclone.parse.kernel.KernelType.nargs (   self)
:returns: the number of arguments specified in the metadata.
:rtype: int

Reimplemented in psyclone.gocean1p0.GOKernelType1p0.

Definition at line 885 of file kernel.py.

885  def nargs(self):
886  '''
887  :returns: the number of arguments specified in the metadata.
888  :rtype: int
889 
890  '''
891  return len(self._arg_descriptors)
892 

References psyclone.domain.lfric.lfric_kern_metadata.LFRicKernMetadata._arg_descriptors, psyclone.gocean1p0.GOKernelType1p0._arg_descriptors, psyclone.parse.kernel.KernelType._arg_descriptors, psyclone.psyGen.Kern._arg_descriptors, and psyclone.psyGen.BuiltIn._arg_descriptors.

Here is the caller graph for this function:

◆ procedure()

def psyclone.parse.kernel.KernelType.procedure (   self)
:returns: a kernelprocedure instance which contains a parse tree \
of the kernel subroutine and its name.
:rtype: :py:class:`psyclone.parse.kernel.KernelProcedure`

Definition at line 875 of file kernel.py.

875  def procedure(self):
876  '''
877  :returns: a kernelprocedure instance which contains a parse tree \
878  of the kernel subroutine and its name.
879  :rtype: :py:class:`psyclone.parse.kernel.KernelProcedure`
880 
881  '''
882  return self._procedure
883 

References psyclone.parse.kernel.KernelType._procedure.


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