Skip to content

Commit

Permalink
#1010 Clean up LFRicLoop code
Browse files Browse the repository at this point in the history
  • Loading branch information
sergisiso committed Jan 28, 2025
1 parent 92fed41 commit bb53018
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
31 changes: 13 additions & 18 deletions src/psyclone/domain/lfric/lfric_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@
from psyclone.domain.lfric import LFRicConstants, LFRicKern
from psyclone.domain.lfric.lfric_types import LFRicTypes
from psyclone.errors import GenerationError, InternalError
from psyclone.psyGen import InvokeSchedule, HaloExchange
from psyclone.psyGen import (
InvokeSchedule, HaloExchange, zero_reduction_variables)
from psyclone.psyir.nodes import (
Loop, Literal, Schedule, Reference, ArrayReference, StructureReference,
Call, BinaryOperation, ArrayOfStructuresReference, Directive, DataNode)
Call, BinaryOperation, ArrayOfStructuresReference, Directive, DataNode,
Node)
from psyclone.psyir.symbols import (
DataSymbol, INTEGER_TYPE, UnresolvedType, UnresolvedInterface)

Expand Down Expand Up @@ -149,7 +151,6 @@ def lower_to_language_level(self):
self.detach()
return None

from psyclone.psyGen import zero_reduction_variables
# Get the list of calls (to kernels) that need reduction variables
if not self.is_openmp_parallel():
calls = self.reductions()
Expand Down Expand Up @@ -405,10 +406,9 @@ def upper_bound_halo_depth(self):
'''
return self._upper_bound_halo_depth

def lower_bound_psyir(self):
def lower_bound_psyir(self) -> Node:
'''
:returns: the PSyIR for this loop lower bound.
:rtype: :py:class:`psyclone.psyir.node.Node`
:raises GenerationError: if self._lower_bound_name is not "start"
for sequential code.
Expand Down Expand Up @@ -483,17 +483,15 @@ def _mesh_name(self):
return self.ancestor(InvokeSchedule).symbol_table.\
lookup_with_tag(tag_name).name

def upper_bound_psyir(self):
def upper_bound_psyir(self) -> Node:
'''
:returns: the PSyIR for this loop upper bound.
:rtype: :py:class:`psyclone.psyir.node.Node`
'''
sym_tab = self.ancestor(InvokeSchedule).symbol_table

# precompute halo_index as a string as we use it in more than
# one of the if clauses
halo_index = ""
# Precompute halo_index as we use it in more than one of the if clauses
halo_index = None
if self._upper_bound_halo_depth:
halo_index = self._upper_bound_halo_depth

Expand Down Expand Up @@ -876,14 +874,11 @@ def gen_mark_halos_clean_dirty(self):
# First set all of the halo dirty unless we are
# subsequently going to set all of the halo clean
for field in fields:
try:
field_symbol = sym_table.lookup(field.proxy_name)
except KeyError:
field_symbol = sym_table.new_symbol(
field.proxy_name,
symbol_type=DataSymbol,
datatype=UnresolvedType(),
interface=UnresolvedInterface())
field_symbol = sym_table.find_or_create(
field.proxy_name,
symbol_type=DataSymbol,
datatype=UnresolvedType(),
interface=UnresolvedInterface())
# Avoid circular import
# pylint: disable=import-outside-toplevel
from psyclone.dynamo0p3 import HaloWriteAccess
Expand Down
3 changes: 2 additions & 1 deletion src/psyclone/domain/lfric/lfric_loop_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ def initialise(self, cursor: int) -> int:
first = True
for idx, loop in enumerate(loops):

# pylint: disable=unidiomatic-typecheck
if type(loop) is Loop or loop.loop_type == "null":
# Generic or 'null' loops don't need any bounds updates.
# Generic or 'null' loops don't need any variables to be set
continue

# Set the lower bound
Expand Down
15 changes: 15 additions & 0 deletions src/psyclone/tests/domain/lfric/lfric_loop_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,3 +856,18 @@ def test_dof_loop_independent_iterations(monkeypatch, dist_mem):
lambda _1: [Message("just a test",
DTCode.WARN_SCALAR_REDUCTION)])
assert loop.independent_iterations()


def test_upper_bound_psyir_inner(monkeypatch):
''' Check that we get the correct Fortran generated if a loop's upper
bound is 'inner'. There are no transformations that allow this
configuration, so we need to patch the value.
'''
_, invoke_info = parse(os.path.join(BASE_PATH, "1_single_invoke.f90"),
api=TEST_API)
psy = PSyFactory(TEST_API, distributed_memory=True).create(invoke_info)
my_loop = psy.invokes.invoke_list[0].schedule.children[4]
monkeypatch.setattr(my_loop, "_upper_bound_name", value="inner")
ubound = my_loop.upper_bound_psyir()
assert "mesh%get_last_inner_cell(1)" in ubound.debug_string()

0 comments on commit bb53018

Please sign in to comment.