Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2245 Splitting LFRicLoopBounds from dynamo0p3.py #2260

Merged
merged 12 commits into from
Aug 30, 2023
Merged
6 changes: 4 additions & 2 deletions src/psyclone/domain/lfric/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
# Author J. Henrichs, Bureau of Meteorology
# Modified: I. Kavcic and L. Turner, Met Office
# Modified: I. Kavcic, L. Turner and O. Brunt, Met Office
# R. W. Ford and A. R. Porter, STFC Daresbury Lab

'''Module for the LFRic domain.
Expand Down Expand Up @@ -63,6 +63,7 @@
from psyclone.domain.lfric.arg_index_to_metadata_index import \
ArgIndexToMetadataIndex
from psyclone.domain.lfric.lfric_collection import LFRicCollection
from psyclone.domain.lfric.lfric_loop_bounds import LFRicLoopBounds


__all__ = [
Expand All @@ -77,4 +78,5 @@
'LFRicConstants',
'LFRicExtractDriverCreator',
'LFRicInvoke',
'LFRicSymbolTable']
'LFRicLoopBounds',
'LFRicSymbolTable']
6 changes: 3 additions & 3 deletions src/psyclone/domain/lfric/lfric_invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
# Authors R. W. Ford, A. R. Porter and S. Siso, STFC Daresbury Lab
# Modified I. Kavcic, A. Coughtrie and L. Turner, Met Office
# Modified I. Kavcic, A. Coughtrie, L. Turner and O. Brunt, Met Office
# Modified J. Henrichs, Bureau of Meteorology
# Modified A. B. G. Chalk and N. Nobre, STFC Daresbury Lab

Expand Down Expand Up @@ -100,8 +100,8 @@ def __init__(self, alg_invocation, idx, invokes):
DynMeshes, DynBoundaryConditions,
DynProxies, LFRicRunTimeChecks,
DynCellIterators, DynReferenceElement,
LFRicMeshProperties, LFRicLoopBounds,
DynGlobalSum)
LFRicMeshProperties, DynGlobalSum)
from psyclone.domain.lfric import LFRicLoopBounds
self.scalar_args = LFRicScalarArgs(self)

# Initialise our Invoke stencil information
Expand Down
115 changes: 115 additions & 0 deletions src/psyclone/domain/lfric/lfric_loop_bounds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# -----------------------------------------------------------------------------
# BSD 3-Clause License
#
# Copyright (c) 2017-2023, Science and Technology Facilities Council.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
# Authors R. W. Ford, A. R. Porter and S. Siso, STFC Daresbury Lab
# Modified I. Kavcic, A. Coughtrie, L. Turner and O. Brunt, Met Office
# Modified J. Henrichs, Bureau of Meteorology
# Modified A. B. G. Chalk and N. Nobre, STFC Daresbury Lab

''' This module provides the LFRicLoopBounds Class that handles all variables
required for specifying loop limits within an LFRic PSy-layer routine.'''

# Imports
from psyclone.configuration import Config
from psyclone.domain.lfric import LFRicCollection
from psyclone.f2pygen import AssignGen, CommentGen, DeclGen


class LFRicLoopBounds(LFRicCollection):
arporter marked this conversation as resolved.
Show resolved Hide resolved

'''
Handles all variables required for specifying loop limits within
an LFRic PSy-layer routine.
'''

def _invoke_declarations(self, parent):
'''
Only needed because method is virtual in parent class.

:param parent: the f2pygen node representing the PSy-layer routine.
:type parent: :py:class:`psyclone.f2pygen.SubroutineGen`

'''

def initialise(self, parent):
'''
Updates the f2pygen AST so that all of the variables holding the lower
and upper bounds of all loops in an Invoke are initialised.

:param parent: the f2pygen node representing the PSy-layer routine.
:type parent: :py:class:`psyclone.f2pygen.SubroutineGen`

'''
loops = self._invoke.schedule.loops()

if not loops:
return

parent.add(CommentGen(parent, ""))
parent.add(CommentGen(parent, " Set-up all of the loop bounds"))
parent.add(CommentGen(parent, ""))

sym_table = self._invoke.schedule.symbol_table
config = Config.get()
api_config = config.api_conf("dynamo0.3")

for idx, loop in enumerate(loops):

if loop.loop_type == "null":
# 'null' loops don't need any bounds.
continue

root_name = f"loop{idx}_start"
lbound = sym_table.find_or_create_integer_symbol(root_name,
tag=root_name)
parent.add(AssignGen(parent, lhs=lbound.name,
rhs=loop._lower_bound_fortran()))
entities = [lbound.name]

if loop.loop_type != "colour":
root_name = f"loop{idx}_stop"
ubound = sym_table.find_or_create_integer_symbol(root_name,
tag=root_name)
entities.append(ubound.name)
parent.add(AssignGen(parent, lhs=ubound.name,
rhs=loop._upper_bound_fortran()))

parent.add(DeclGen(parent, datatype="integer",
kind=api_config.default_kind["integer"],
entity_decls=entities))


# ---------- Documentation utils -------------------------------------------- #
# The list of module members that we wish AutoAPI to generate
# documentation for. (See https://psyclone-ref.readthedocs.io)
__all__ = ['LFRicLoopBounds']
65 changes: 1 addition & 64 deletions src/psyclone/dynamo0p3.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
# Authors R. W. Ford, A. R. Porter and S. Siso, STFC Daresbury Lab
# Modified I. Kavcic, A. Coughtrie and L. Turner, Met Office
# Modified I. Kavcic, A. Coughtrie, L. Turner and O. Brunt, Met Office
# Modified J. Henrichs, Bureau of Meteorology
# Modified A. B. G. Chalk and N. Nobre, STFC Daresbury Lab

Expand Down Expand Up @@ -3286,69 +3286,6 @@ def initialise(self, parent):
self._first_var.ref_name() + "%get_nlayers()"))


class LFRicLoopBounds(LFRicCollection):
'''
Handles all variables required for specifying loop limits within a
PSy-layer routine.

'''
def _invoke_declarations(self, parent):
'''
Only needed because method is virtual in parent class.

:param parent: the f2pygen node representing the PSy-layer routine.
:type parent: :py:class:`psyclone.f2pygen.SubroutineGen`

'''

def initialise(self, parent):
'''
Updates the f2pygen AST so that all of the variables holding the lower
and upper bounds of all loops in an Invoke are initialised.

:param parent: the f2pygen node representing the PSy-layer routine.
:type parent: :py:class:`psyclone.f2pygen.SubroutineGen`

'''
loops = self._invoke.schedule.loops()

if not loops:
return

parent.add(CommentGen(parent, ""))
parent.add(CommentGen(parent, " Set-up all of the loop bounds"))
parent.add(CommentGen(parent, ""))

sym_table = self._invoke.schedule.symbol_table
config = Config.get()
api_config = config.api_conf("dynamo0.3")

for idx, loop in enumerate(loops):

if loop.loop_type == "null":
# 'null' loops don't need any bounds.
continue

root_name = f"loop{idx}_start"
lbound = sym_table.find_or_create_integer_symbol(root_name,
tag=root_name)
parent.add(AssignGen(parent, lhs=lbound.name,
rhs=loop._lower_bound_fortran()))
entities = [lbound.name]

if loop.loop_type != "colour":
root_name = f"loop{idx}_stop"
ubound = sym_table.find_or_create_integer_symbol(root_name,
tag=root_name)
entities.append(ubound.name)
parent.add(AssignGen(parent, lhs=ubound.name,
rhs=loop._upper_bound_fortran()))

parent.add(DeclGen(parent, datatype="integer",
kind=api_config.default_kind["integer"],
entity_decls=entities))


class LFRicScalarArgs(LFRicCollection):
'''
Handles the declarations of scalar kernel arguments appearing in either
Expand Down
5 changes: 2 additions & 3 deletions src/psyclone/tests/domain/lfric/lfric_loop_bounds_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
# Author: A. R. Porter, STFC Daresbury Lab
# Modified: L. Turner, Met Office
# Modified: L. Turner and O. Brunt, Met Office

''' This module contains pytest tests for the LFRicLoopBounds collection
class. '''

from __future__ import absolute_import
import os

from psyclone.dynamo0p3 import LFRicLoopBounds
from psyclone.domain.lfric import LFRicLoopBounds
from psyclone.f2pygen import SubroutineGen, ModuleGen
from psyclone.parse.algorithm import parse
from psyclone.psyGen import PSyFactory
Expand Down
Loading