Skip to content

Commit

Permalink
#1010 Clean up f2pygen mentions and fix some tests/coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sergisiso committed Feb 3, 2025
1 parent 5996da2 commit 8db5dfa
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 44 deletions.
4 changes: 0 additions & 4 deletions src/psyclone/alg_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,6 @@ def _adduse(location, name, only=None, funcnames=None):
tree. This will be added at the first valid location before the
current location.
This function should be part of the fparser2 replacement for
f2pygen (which uses fparser1) but is kept here until this is
developed, see issue #240.
:param location: the current location (node) in the parse tree to which \
to add a USE.
:type location: :py:class:`fparser.two.utils.Base`
Expand Down
9 changes: 2 additions & 7 deletions src/psyclone/domain/lfric/lfric_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ def initialise(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
we provide a cursor to control the location of the initialisation
statements.
Add necessary Invoke declarations for this Collection.
By default we just sanity check that the class is appropriately
initialised - it is up to the sub-class to add required declarations.
Expand All @@ -140,9 +137,7 @@ def invoke_declarations(self):

def stub_declarations(self):
'''
Add necessary Kernel Stub declarations for this collection.
We do nothing by default - it is up to the sub-class to override
this method if declarations are required.
Add necessary Kernel Stub declarations for this Collection.
By default we just sanity check that the class is appropriately
initialised - it is up to the sub-class to add required declarations.
Expand Down
4 changes: 0 additions & 4 deletions src/psyclone/domain/lfric/lfric_halo_depths.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ def invoke_declarations(self):
Creates the declarations for the depths to which any 'halo'
kernels iterate into the halos.
:param cursor: position where to add the next initialisation
statements.
:returns: Updated cursor value.
'''
super().invoke_declarations()
# Add the Invoke subroutine argument declarations for the
Expand Down
2 changes: 1 addition & 1 deletion src/psyclone/domain/lfric/lfric_kern.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def is_intergrid(self):
@property
def colourmap(self: DataSymbol):
'''
:returns: the symbol representing the colourmap for this kernekl call.
:returns: the symbol representing the colourmap for this kernel call.
:raises InternalError: if this kernel is not coloured.
Expand Down
2 changes: 1 addition & 1 deletion src/psyclone/dynamo0p3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3182,7 +3182,7 @@ def _initialise_xyoz_qr(self, cursor):
const.QUADRATURE_TYPE_MAP["gh_quadrature_xyoz"]["intrinsic"]
kind = const.QUADRATURE_TYPE_MAP["gh_quadrature_xyoz"]["kind"]
for name in self.qr_weight_vars["xyoz"]:
self.symtab.new_symbol(
self.symtab.find_or_create(
name+"_"+qr_arg_name, symbol_type=DataSymbol,
datatype=UnsupportedFortranType(
f"{dtype}(kind={kind}), pointer :: "
Expand Down
6 changes: 3 additions & 3 deletions src/psyclone/psyir/transformations/omp_taskwait_trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ def get_forward_dependence(taskloop, root):
The forward dependency is never a child of taskloop, and must have
abs_position > taskloop.abs_position
:param taskloop: the taskloop node for which to find the \
forward_dependence.
:param taskloop: the taskloop node for which to find the
forward_dependence.
:type taskloop: :py:class:`psyclone.psyir.nodes.OMPTaskloopDirective`
:param root: the tree in which to search for the forward_dependence.
:type root: :py:class:`psyclone.psyir.nodes.OMPParallelDirective`
:returns: the forward_dependence of taskloop.
:rtype: :py:class:`psyclone.f2pygen.Node`
:rtype: :py:class:`psyclone.psyir.nodes.Node`
'''
# Check supplied the correct type for root
Expand Down
7 changes: 7 additions & 0 deletions src/psyclone/tests/domain/gocean/goloop_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ def test_goloop_create(monkeypatch):
''' Test that the GOLoop create method populates the relevant attributes
and creates the loop children. '''

# The parent must be a GOInvokeSchedule
with pytest.raises(GenerationError) as err:
goloop = GOLoop(loop_type="inner", parent=Schedule())
assert ("GOLoops must always be constructed with a parent which is inside"
" (directly or indirectly) of a GOInvokeSchedule"
in str(err.value))

# Monkeypatch the called GOLoops methods as this will be tested separately
monkeypatch.setattr(GOLoop, "lower_bound",
lambda x: Literal("10", INTEGER_TYPE))
Expand Down
16 changes: 11 additions & 5 deletions src/psyclone/tests/domain/lfric/lfric_kern_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,17 @@ def test_kern_last_cell_all_colours():
# Apply a colouring transformation to the loop.
trans = Dynamo0p3ColourTrans()
trans.apply(loop)
# We have to perform code generation as that sets-up the symbol table.
# pylint:disable=pointless-statement
psy.gen
assert (loop.kernel.last_cell_all_colours_symbol.name
== "last_halo_cell_all_colours")

symbol = loop.kernel.last_cell_all_colours_symbol
assert symbol.name == "last_halo_cell_all_colours"
assert len(symbol.datatype.shape) == 2 # It's a 2-dimensional array

# Delete the symbols and try again inside a loop wihtout a halo
sched.symbol_table._symbols.pop("last_halo_cell_all_colours")
loop.kernel.parent.parent._upper_bound_name = "not-a-halo"
symbol = loop.kernel.last_cell_all_colours_symbol
assert symbol.name == "last_edge_cell_all_colours"
assert len(symbol.datatype.shape) == 1 # It's a 1-dimensional array


def test_kern_last_cell_all_colours_intergrid():
Expand Down
2 changes: 1 addition & 1 deletion src/psyclone/tests/domain/lfric/lfric_loop_bounds_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_lbounds_initialise(monkeypatch, fortran_writer):
monkeypatch.setattr(invoke.schedule, "loops", lambda: [])
lbounds = LFRicLoopBounds(invoke)
# The initialise() should not raise an error but nothing should be
# added to the f2pygen tree.
# added to the PSyIR tree.
lbounds.initialise(0)
# Symbols representing loop bounds should be unaffected.
assert table.lookup("loop0_start") is start_sym
Expand Down
15 changes: 8 additions & 7 deletions src/psyclone/tests/gocean_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,20 @@ class GOceanOpenCLBuild(GOceanBuild):
'''

def code_compiles(self, psy_ast, dependencies=None):
'''Attempts to build the OpenCL Fortran code supplied as an AST of
f2pygen objects. Returns True for success, False otherwise.
'''
Use the given GOcean PSy class to generate the necessary PSyKAl
components to compile the OpenCL version of the psy-layer. Returns True
for success, False otherwise.
If no Fortran compiler is available then returns True. All files
produced are deleted.
:param psy_ast: the AST of the generated PSy layer.
:type psy_ast: instance of :py:class:`psyclone.psyGen.PSy`
:param dependencies: optional module- or file-names on which \
one or more of the kernels/PSy-layer depend (and \
that are not part of the GOcean infrastructure, \
dl_esm_inf). These dependencies will be built in \
the order they occur in this list.
:param dependencies: optional module- or file-names on which one or
more of the kernels/PSy-layer depend (and that are not part of the
GOcean infrastructure, dl_esm_inf). These dependencies will be
built in the order they occur in this list.
:type dependencies: list of str or NoneType
:return: True if generated code compiles, False otherwise.
Expand Down
16 changes: 8 additions & 8 deletions src/psyclone/tests/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,19 @@ def compile_file(self, filename, link=False):
raise CompileError(output)

def _code_compiles(self, psy_ast, dependencies=None):
'''Attempts to build the Fortran code supplied as an AST of
f2pygen objects. Returns True for success, False otherwise.
'''
Use the given PSy class to generate the necessary PSyKAl components
to compile the psy-layer. Returns True for success, False otherwise.
It is meant for internal test uses only, and must only be
called when compilation is actually enabled (use code_compiles
otherwse). All files produced are deleted.
:param psy_ast: The AST of the generated PSy layer.
:param psy_ast: The PSy object to build.
:type psy_ast: :py:class:`psyclone.psyGen.PSy`
:param dependencies: optional module- or file-names on which \
one or more of the kernels/PSy-layer depend (and \
that are not part of e.g. the GOcean or LFRic \
infrastructure). These dependencies will be built \
in the order they occur in this list.
:param dependencies: optional module- or file-names on which one or
more of the kernels/PSy-layer depend (and that are not part of
e.g. the GOcean or LFRic infrastructure). These dependencies will
be built in the order they occur in this list.
:type dependencies: List[str]
:return: True if generated code compiles, False otherwise.
Expand Down
6 changes: 3 additions & 3 deletions src/psyclone/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,9 +744,9 @@ def apply(self, node, options=None):
!$OMP END PARALLEL DO
:param node: the node (loop) to which to apply the transformation.
:type node: :py:class:`psyclone.f2pygen.DoGen`
:param options: a dictionary with options for transformations\
and validation.
:type node: :py:class:`psyclone.psyir.nodes.Loop`
:param options: a dictionary with options for transformations
and validation.
:type options: Optional[Dict[str, Any]]
'''
self.validate(node, options=options)
Expand Down

0 comments on commit 8db5dfa

Please sign in to comment.