Skip to content

Commit

Permalink
#1010 Remove cursor argument from invoke_declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
sergisiso committed Jan 30, 2025
1 parent 1a67f95 commit 5d66448
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 133 deletions.
6 changes: 3 additions & 3 deletions doc/developer_guide/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ sub-class of the ``LFRicCollection`` abstract class:
A single ``LFRicCollection`` class is used for both Invokes and Kernel stubs
since it allows the code dealing with variable declarations to be shared.
A concrete sub-class of ``LFRicCollection`` must provide an
implementation of the ``invoke_declarations`` method (if the
implementation of the ``invoke_declarations`` method. If the
quantities associated with the collection require initialisation
this method should also insert the initialisation statements).
If stub-generation is to be supported for kernels that
within the PSy layer then the ``initialise`` method must also be
implemented. If stub-generation is to be supported for kernels that
make use of the collection type then an implementation must also be
provided for ``stub_declarations``.

Expand Down
7 changes: 1 addition & 6 deletions src/psyclone/domain/lfric/lfric_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def initialise(self, cursor: int) -> int:
'''

def invoke_declarations(self, cursor: int) -> int:
def invoke_declarations(self):
'''
Add necessary Invoke declarations for this Collection. Some of the
new symbols are not arguments and need to be initialised and therefore
Expand All @@ -128,10 +128,6 @@ def invoke_declarations(self, cursor: int) -> int:
By default we just sanity check that the class is appropriately
initialised - it is up to the sub-class to add required declarations.
:param cursor: position where to add the next initialisation
statements.
:returns: Updated cursor value.
:raises InternalError: if the class has been instantiated for a
kernel and not an invoke.
Expand All @@ -141,7 +137,6 @@ def invoke_declarations(self, cursor: int) -> int:
f"invoke_declarations() can only be called with a "
f"{type(self).__name__} instantiated for an invoke (not a "
f"kernel).")
return cursor

def stub_declarations(self):
'''
Expand Down
10 changes: 2 additions & 8 deletions src/psyclone/domain/lfric/lfric_dofmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,13 @@ def initialise(self, cursor: int) -> int:
cursor += 1
return cursor

def invoke_declarations(self, cursor: int) -> int:
def invoke_declarations(self):
'''
Declare all unique function space dofmaps in the PSy layer as pointers
to integer arrays of rank 2.
:param cursor: position where to add the next initialisation
statements.
:returns: Updated cursor value.
'''
cursor = super().invoke_declarations(cursor)
super().invoke_declarations()
# Function space dofmaps
for dmap in sorted(self._unique_fs_maps):
if dmap not in self.symtab:
Expand Down Expand Up @@ -251,8 +247,6 @@ def invoke_declarations(self, cursor: int) -> int:
"=> null()"))
self.symtab.add(dmap_sym, tag=dmap)

return cursor

def stub_declarations(self):
'''
Add dofmap-related declarations to a Kernel stub.
Expand Down
10 changes: 2 additions & 8 deletions src/psyclone/domain/lfric/lfric_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,19 @@ class LFRicFields(LFRicCollection):
or Kernel stub.
'''
def invoke_declarations(self, cursor: int) -> int:
def invoke_declarations(self):
'''
Add field-related declarations to the PSy-layer routine.
Note: PSy layer in LFRic does not modify the field objects. Hence,
their Fortran intents are always in (the data updated in the kernels
is only pointed to from the field object and is thus not a part of
the object).
:param cursor: position where to add the next initialisation
statements.
:returns: Updated cursor value.
:raises InternalError: for unsupported intrinsic types of field
argument data.
'''
cursor = super().invoke_declarations(cursor)
super().invoke_declarations()
# Create dict of all field arguments for checks
const = LFRicConstants()
fld_args = self._invoke.unique_declarations(
Expand Down Expand Up @@ -123,8 +119,6 @@ def invoke_declarations(self, cursor: int) -> int:
arg_symbol = self.symtab.lookup(arg.name)
arg_symbol.interface.access = ArgumentInterface.Access.READ

return cursor

def stub_declarations(self):
'''
Add field-related declarations to a Kernel stub.
Expand Down
5 changes: 2 additions & 3 deletions src/psyclone/domain/lfric/lfric_halo_depths.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(self, node):
depth_names.add(name)
self._halo_depth_vars.add(kern.halo_depth.symbol)

def invoke_declarations(self, cursor: int) -> int:
def invoke_declarations(self):
'''
Creates the declarations for the depths to which any 'halo'
kernels iterate into the halos.
Expand All @@ -94,7 +94,7 @@ def invoke_declarations(self, cursor: int) -> int:
:returns: Updated cursor value.
'''
cursor = super().invoke_declarations(cursor)
super().invoke_declarations()
# Add the Invoke subroutine argument declarations for the
# different halo depths. They are declared as intent "in".
# pylint: disable=import-outside-toplevel
Expand All @@ -109,7 +109,6 @@ def invoke_declarations(self, cursor: int) -> int:
sym.interface = ArgumentInterface(
ArgumentInterface.Access.READ)
self.symtab.append_argument(sym)
return cursor


# ---------- Documentation utils -------------------------------------------- #
Expand Down
2 changes: 1 addition & 1 deletion src/psyclone/domain/lfric/lfric_invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def declare(self):
self.reference_element_properties,
self.mesh_properties, self.loop_bounds,
self.run_time_checks]:
cursor = entities.invoke_declarations(cursor)
entities.invoke_declarations()

for entities in [self.proxies, self.run_time_checks,
self.cell_iterators, self.meshes,
Expand Down
16 changes: 5 additions & 11 deletions src/psyclone/domain/lfric/lfric_run_time_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,28 @@ class LFRicRunTimeChecks(LFRicCollection):
'''

def invoke_declarations(self, cursor: int) -> int:
def invoke_declarations(self):
'''Insert declarations of all data and functions required by the
run-time checks code into the PSy layer.
:param cursor: position where to add the next initialisation
statements.
:returns: Updated cursor value.
'''
cursor = super().invoke_declarations(cursor)
super().invoke_declarations()
if Config.get().api_conf("lfric").run_time_checks:
# Only add if run-time checks are requested
const = LFRicConstants()
symtab = self._invoke.schedule.symbol_table
csym = symtab.find_or_create(
csym = self.symtab.find_or_create(
const.UTILITIES_MOD_MAP["logging"]["module"],
symbol_type=ContainerSymbol
)
symtab.find_or_create(
self.symtab.find_or_create(
"log_event", symbol_type=RoutineSymbol,
interface=ImportInterface(csym)
)
symtab.find_or_create(
self.symtab.find_or_create(
"LOG_LEVEL_ERROR", symbol_type=DataSymbol,
datatype=UnresolvedType(),
interface=ImportInterface(csym)
)
return cursor

def _check_field_fs(self, cursor: int) -> int:
'''
Expand Down
8 changes: 2 additions & 6 deletions src/psyclone/domain/lfric/lfric_scalar_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,19 @@ def __init__(self, node):
self._integer_scalars[intent] = []
self._logical_scalars[intent] = []

def invoke_declarations(self, cursor: int) -> int:
def invoke_declarations(self):
'''
Create argument lists and declarations for all scalar arguments
in an Invoke.
:param cursor: position where to add the next initialisation
statements.
:returns: Updated cursor value.
:raises InternalError: for unsupported argument intrinsic types.
:raises GenerationError: if the same scalar argument has different \
data types in different Kernel calls \
within the same Invoke.
'''
cursor = super().invoke_declarations(cursor)
super().invoke_declarations()
# Create dictionary of all scalar arguments for checks
const = LFRicConstants()
self._scalar_args = self._invoke.unique_declns_by_intent(
Expand Down Expand Up @@ -145,7 +142,6 @@ def invoke_declarations(self, cursor: int) -> int:

# Create declarations
self._create_declarations()
return cursor

def stub_declarations(self):
'''
Expand Down
9 changes: 2 additions & 7 deletions src/psyclone/domain/lfric/lfric_stencils.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,21 +381,16 @@ def unique_alg_vars(self):
'''
return self._unique_extent_vars + self._unique_direction_vars

def invoke_declarations(self, cursor: int) -> int:
def invoke_declarations(self):
'''
Declares all stencil maps, extent and direction arguments passed into
the PSy layer.
:param cursor: position where to add the next initialisation
statements.
:returns: Updated cursor value.
'''
cursor = super().invoke_declarations(cursor)
super().invoke_declarations()
self._declare_unique_extent_vars()
self._declare_unique_direction_vars()
self._declare_maps_invoke()
return cursor

def stub_declarations(self):
'''
Expand Down
Loading

0 comments on commit 5d66448

Please sign in to comment.