Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/psyclone/domain/lfric/arg_ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ def get_array_reference(self, array_name, indices, intrinsic_type=None,
intrinsic_type = LFRicTypes("LFRicIntegerScalarDataType")()

if not symbol:
symbol = self._symtab.find_or_create(
array_name, tag=tag, symbol_type=DataSymbol,
symbol = self._symtab.find_or_create_tag(
tag=tag, root_name=array_name, symbol_type=DataSymbol,
datatype=ArrayType(
intrinsic_type,
[ArrayType.Extent.DEFERRED for _ in indices]))
Expand Down
41 changes: 30 additions & 11 deletions src/psyclone/domain/lfric/function_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def mangled_name(self):
self._mangled_name = self._mangle_fs_name()
return self._mangled_name

def _mangle_fs_name(self):
def _mangle_fs_name(self) -> str:
'''
Constructs the mangled version of a function-space name given a list
of kernel arguments if the argument's function space is any_*_space
Expand All @@ -137,12 +137,11 @@ def _mangle_fs_name(self):
space combined with the argument's name.

:returns: mangled name of this function space.
:rtype: str

:raises InternalError: if a function space to create the mangled \
name for is not one of 'any_space' or \
:raises InternalError: if a function space to create the mangled
name for is not one of 'any_space' or
'any_discontinuous_space' spaces.
:raises FieldNotFoundError: if no kernel argument was found on \
:raises FieldNotFoundError: if no kernel argument was found on
the specified function space.

'''
Expand All @@ -159,17 +158,37 @@ def _mangle_fs_name(self):
# List kernel arguments
args = self._kernel_args.args
# Mangle the function space name for any_*_space
lorig_name = self._orig_name.lower()
for arg in args:
for fspace in arg.function_spaces:
if (fspace and fspace.orig_name.lower() ==
self._orig_name.lower()):
mngl_name = self._short_name + "_" + arg.name
return mngl_name
if (fspace and fspace.orig_name.lower() == lorig_name):
return (f"{self._short_name}_"
f"{self._shorten_arg_name(arg.name)}")
# Raise an error if there are no kernel arguments on this
# function space
raise FieldNotFoundError(f"No kernel argument found for function "
f"space '{self._orig_name}'")

@staticmethod
def _shorten_arg_name(name: str) -> str:
'''
Shortens the provided name by splitting on any underscore characters
and reconstructing the name using the beginning and
ending chars from each token.

:param name: the name to shorten.

:returns: a shortened form of the name.

'''
new_parts = []
for part in name.split("_"):
new_name = part[0]
if len(part) > 1:
new_name += part[-1]
new_parts.append(new_name)
return "_".join(new_parts)

def _shorten_fs_name(self):
'''
Creates short names for any_*_spaces to be used for mangled names
Expand Down Expand Up @@ -197,9 +216,9 @@ def _shorten_fs_name(self):
f"{const.VALID_ANY_DISCONTINUOUS_SPACE_NAMES} spaces.")

# Split name string to find any_*_space ID and create a short name as
# "<start>" + "spc" + "ID"
# "<start>" + "s" + "ID"
fslist = self._orig_name.split("_")
self._short_name = start + "spc" + fslist[-1]
self._short_name = start + "s" + fslist[-1]
return self._short_name

@property
Expand Down
25 changes: 10 additions & 15 deletions src/psyclone/domain/lfric/kern_call_arg_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,24 +983,19 @@ def cell_ref_name(
if loop_type == "cells_in_tile":
tile_sym = self._symtab.find_or_create_integer_symbol(
"tile", tag="tile_loop_idx")
array_ref = self.get_array_reference(
self._kern.tilecolourmap,
[Reference(colour_sym), Reference(tile_sym),
Reference(cell_sym)],
tag="tmap" if self._kern.is_intergrid else None)
if var_accesses is not None:
var_accesses.add_access(Signature(array_ref.name),
AccessType.READ,
self._kern)
map_sym = self._symtab.lookup(self._kern.tilecolourmap)
array_ref = ArrayReference.create(
map_sym, [Reference(colour_sym), Reference(tile_sym),
Reference(cell_sym)])
else:
symbol = self._kern.colourmap
array_ref = ArrayReference.create(
symbol,
[Reference(colour_sym), Reference(cell_sym)])
if var_accesses is not None:
var_accesses.add_access(Signature(array_ref.name),
AccessType.READ,
self._kern)
symbol, [Reference(colour_sym), Reference(cell_sym)])

if var_accesses is not None:
var_accesses.add_access(Signature(array_ref.name),
AccessType.READ,
self._kern)

return (array_ref.debug_string(), array_ref)

Expand Down
4 changes: 2 additions & 2 deletions src/psyclone/domain/lfric/lfric_dofmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class LFRicDofmaps(LFRicCollection):
indirection) required by an invoke.

:param node: Kernel or Invoke for which to manage dofmaps.
:type node: :py:class:`psyclone.domain.lfric.LFRicKern` or \
:type node: :py:class:`psyclone.domain.lfric.LFRicKern` or
:py:class:`psyclone.domain.lfric.LFRicInvoke`

'''
Expand Down Expand Up @@ -297,7 +297,7 @@ def stub_declarations(self):
self.symtab.append_argument(nlayers)

dmap_symbol = self.symtab.find_or_create(
dmap, symbol_type=DataSymbol,
dmap, tag=dmap, symbol_type=DataSymbol,
datatype=ArrayType(LFRicTypes("LFRicIntegerScalarDataType")(),
[Reference(symbol), Reference(nlayers)]))
dmap_symbol.interface = ArgumentInterface(
Expand Down
8 changes: 5 additions & 3 deletions src/psyclone/domain/lfric/lfric_kern.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,11 @@ def tilecolourmap(self) -> DataSymbol:
# Declare array holding map from a given tile-colour-cell to
# the index of the cell (this is not initialised until code
# lowering)
new_name = sched.symbol_table.next_available_name("tmap")
decl = f"integer(kind=i_def), pointer :: {new_name}(:,:,:)"
tmap = sched.symbol_table.find_or_create_tag(
"tilecolourmap", root_name="tmap", symbol_type=DataSymbol,
datatype=UnsupportedFortranType(
"integer(kind=i_def), pointer :: tmap(:,:,:)")).name
datatype=UnsupportedFortranType(decl)).name

return tmap

Expand Down Expand Up @@ -793,7 +794,8 @@ def gen_stub(self) -> Container:
create_arg_list.generate()
arg_list = []
for argument_name in create_arg_list.arglist:
arg_list.append(stub_routine.symbol_table.lookup(argument_name))
sym = stub_routine.symbol_table.lookup(argument_name)
arg_list.append(sym)
stub_routine.symbol_table.specify_argument_list(arg_list)

return stub_module
Expand Down
24 changes: 12 additions & 12 deletions src/psyclone/lfric.py
Original file line number Diff line number Diff line change
Expand Up @@ -2626,6 +2626,7 @@ def __init__(self, fine_arg, coarse_arg):
[ArrayType.Extent.DEFERRED]*2)
sym = symtab.find_or_create(
base_name,
tag=base_name,
symbol_type=DataSymbol,
datatype=UnsupportedFortranType(
f"integer(kind=i_def), pointer :: {base_name}"
Expand Down Expand Up @@ -3016,7 +3017,7 @@ def stub_declarations(self):
dims.append(Literal(value, INTEGER_TYPE))
except ValueError:
dims.append(Reference(self.symtab.find_or_create(value)))
arg = self.symtab.find_or_create(
arg = self.symtab.find_or_create_tag(
basis, symbol_type=DataSymbol,
datatype=ArrayType(LFRicTypes("LFRicRealScalarDataType")(),
dims))
Expand Down Expand Up @@ -3257,8 +3258,9 @@ def initialise(self, cursor: int) -> int:
# Allocate basis arrays
for basis in basis_arrays:
dims = "("+",".join([":"]*len(basis_arrays[basis]))+")"
symbol = self.symtab.find_or_create(
basis, symbol_type=DataSymbol, datatype=UnsupportedFortranType(
symbol = self.symtab.find_or_create_tag(
basis,
symbol_type=DataSymbol, datatype=UnsupportedFortranType(
f"real(kind=r_def), allocatable :: {basis}{dims}"
))
alloc = IntrinsicCall.create(
Expand Down Expand Up @@ -3436,7 +3438,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.find_or_create(
self.symtab.find_or_create_tag(
name+"_"+qr_arg_name, symbol_type=DataSymbol,
datatype=UnsupportedFortranType(
f"{dtype}(kind={kind}), pointer :: "
Expand Down Expand Up @@ -3644,7 +3646,7 @@ def _compute_basis_fns(self, cursor):
Reference(self.symtab.lookup(first_dim)),
Reference(self.symtab.lookup(
basis_fn["fspace"].ndf_name)),
Reference(self.symtab.lookup(op_name))]
Reference(self.symtab.lookup_with_tag(op_name))]

# insert the basis array call
call = Call.create(
Expand Down Expand Up @@ -3701,7 +3703,7 @@ def _compute_basis_fns(self, cursor):
Literal('1', INTEGER_TYPE), [])
loop.loop_body.addchild(inner_loop)

symbol = self.symtab.lookup(op_name)
symbol = self.symtab.lookup_with_tag(op_name)
rhs = basis_fn['arg'].generate_method_call(
"call_function", function_space=basis_fn['fspace'])
rhs.addchild(Reference(self.symtab.lookup(basis_type)))
Expand Down Expand Up @@ -3759,7 +3761,7 @@ def deallocate(self):
# add the required deallocate call
dealloc = IntrinsicCall.create(
IntrinsicCall.Intrinsic.DEALLOCATE,
[Reference(self.symtab.lookup(name)) for name in
[Reference(self.symtab.lookup_with_tag(name)) for name in
sorted(func_space_var_names)]
)
if first:
Expand Down Expand Up @@ -3820,7 +3822,7 @@ def __init__(self, node):
bc_fs = op_arg.function_space_to
self._boundary_dofs.append(self.BoundaryDofs(op_arg, bc_fs))

def invoke_declarations(self):
def invoke_declarations(self) -> None:
'''
Add declarations for any boundary-dofs arrays required by an Invoke.

Expand All @@ -3838,10 +3840,8 @@ def invoke_declarations(self):
LFRicTypes("LFRicIntegerScalarDataType")(),
[ArrayType.Extent.DEFERRED]*2)
)
self.symtab.new_symbol(
name,
symbol_type=DataSymbol,
datatype=dtype)
self.symtab.find_or_create_tag(
name, symbol_type=DataSymbol, datatype=dtype)

def stub_declarations(self):
'''
Expand Down
16 changes: 8 additions & 8 deletions src/psyclone/tests/dependency_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ def test_lfric_cma(fortran_writer):
assert "cma_op1_cma_matrix: WRITE," in var_info
assert "cma_op1_ncol: WRITE+READ," in var_info
assert "cma_op1_nrow: WRITE+READ," in var_info
assert "cbanded_map_adspc1_lma_op1: WRITE+READ," in var_info
assert "cbanded_map_adspc2_lma_op1: WRITE+READ," in var_info
assert "cbanded_map_ads1_la_o1: WRITE+READ," in var_info
assert "cbanded_map_ads2_la_o1: WRITE+READ," in var_info
assert "lma_op1_local_stencil: WRITE+READ," in var_info
assert "lma_op1_proxy%ncell_3d: READ," in var_info

Expand All @@ -385,8 +385,8 @@ def test_lfric_cma2():
'''
psy, invoke_info = get_invoke("20.1_cma_apply.f90", "lfric", idx=0)
var_info = str(invoke_info.schedule.reference_accesses())
assert "cma_indirection_map_aspc1_field_a: READ," in var_info
assert "cma_indirection_map_aspc2_field_b: READ," in var_info
assert "cma_indirection_map_as1_fd_a: READ," in var_info
assert "cma_indirection_map_as2_fd_b: READ," in var_info


def test_lfric_stencils():
Expand Down Expand Up @@ -617,8 +617,8 @@ def test_lfric_stub_banded_dofmap():
create_arg_list = KernStubArgList(kernel)
create_arg_list.generate(var_accesses=var_accesses)
var_info = str(var_accesses)
assert "cbanded_map_adspc1_op_1: READ," in var_info
assert "cbanded_map_adspc2_op_1: READ" in var_info
assert "cbanded_map_ads1_op_1: READ," in var_info
assert "cbanded_map_ads2_op_1: READ" in var_info


def test_lfric_stub_indirection_dofmap():
Expand All @@ -632,8 +632,8 @@ def test_lfric_stub_indirection_dofmap():
create_arg_list = KernStubArgList(kernel)
create_arg_list.generate(var_accesses=var_accesses)
var_info = str(var_accesses)
assert "cma_indirection_map_aspc1_field_1: READ," in var_info
assert "cma_indirection_map_aspc2_field_2: READ" in var_info
assert "cma_indirection_map_as1_fd_1: READ," in var_info
assert "cma_indirection_map_as2_fd_2: READ" in var_info


def test_lfric_stub_boundary_dofmap():
Expand Down
6 changes: 3 additions & 3 deletions src/psyclone/tests/domain/lfric/arg_ordering_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ def test_arg_ordering_generate_cma_kernel(dist_mem, fortran_writer):
'cell', 'nlayers_lma_op1', 'ncell_2d', 'lma_op1_proxy%ncell_3d',
'lma_op1_local_stencil', 'cma_op1_cma_matrix', 'cma_op1_nrow',
'cma_op1_ncol', 'cma_op1_bandwidth', 'cma_op1_alpha', 'cma_op1_beta',
'cma_op1_gamma_m', 'cma_op1_gamma_p', 'ndf_adspc1_lma_op1',
'cbanded_map_adspc1_lma_op1', 'ndf_adspc2_lma_op1',
'cbanded_map_adspc2_lma_op1']
'cma_op1_gamma_m', 'cma_op1_gamma_p', 'ndf_ads1_la_o1',
'cbanded_map_ads1_la_o1', 'ndf_ads2_la_o1',
'cbanded_map_ads2_la_o1']

check_psyir_results(create_arg_list, fortran_writer)
psyir_arglist = create_arg_list.psyir_arglist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_fs_intergrid():
arg_list = KernCallAccArgList(restrict_kern)
arg_list.fs_intergrid(fspace)
# For the coarse mesh we need undf and the dofmap for the column.
assert arg_list._arglist == ['undf_aspc1_fld_m', 'map_aspc1_fld_m']
assert arg_list._arglist == ['undf_as1_fd_m', 'map_as1_fd_m']
fspace = FunctionSpace("w1", prolong_kern.arguments)
arg_list = KernCallAccArgList(prolong_kern)
arg_list.fs_intergrid(fspace)
Expand Down
22 changes: 11 additions & 11 deletions src/psyclone/tests/domain/lfric/kern_call_arg_list_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ def test_kerncallarglist_face_xyoz(dist_mem, fortran_writer):
'f2_3_data', 'f3_data', 'istp', 'ndf_w2', 'undf_w2',
'map_w2(:,cell)', 'basis_w2_qr_xyoz', 'basis_w2_qr_face', 'ndf_wchi',
'undf_wchi', 'map_wchi(:,cell)', 'diff_basis_wchi_qr_xyoz',
'diff_basis_wchi_qr_face', 'ndf_adspc1_f3', 'undf_adspc1_f3',
'map_adspc1_f3(:,cell)', 'basis_adspc1_f3_qr_xyoz',
'basis_adspc1_f3_qr_face', 'diff_basis_adspc1_f3_qr_xyoz',
'diff_basis_adspc1_f3_qr_face', 'np_xy_qr_xyoz', 'np_z_qr_xyoz',
'diff_basis_wchi_qr_face', 'ndf_ads1_f3', 'undf_ads1_f3',
'map_ads1_f3(:,cell)', 'basis_ads1_f3_qr_xyoz',
'basis_ads1_f3_qr_face', 'diff_basis_ads1_f3_qr_xyoz',
'diff_basis_ads1_f3_qr_face', 'np_xy_qr_xyoz', 'np_z_qr_xyoz',
'weights_xy_qr_xyoz', 'weights_z_qr_xyoz', 'nfaces_qr_face',
'np_xyz_qr_face', 'weights_xyz_qr_face']

Expand Down Expand Up @@ -355,8 +355,8 @@ def test_kerncallarglist_bcs(fortran_writer, monkeypatch):
create_arg_list = KernCallArgList(schedule.kernels()[0])
create_arg_list.generate()
assert create_arg_list._arglist == [
'nlayers_a', 'a_data', 'ndf_aspc1_a', 'undf_aspc1_a',
'map_aspc1_a(:,cell)', 'boundary_dofs_a']
'nlayers_a', 'a_data', 'ndf_as1_a', 'undf_as1_a',
'map_as1_a(:,cell)', 'boundary_dofs_a']

check_psyir_results(create_arg_list, fortran_writer)

Expand Down Expand Up @@ -390,7 +390,7 @@ def test_kerncallarglist_bcs_operator(fortran_writer):
create_arg_list.generate(access_info)
assert create_arg_list._arglist == [
'cell', 'nlayers_op_a', 'op_a_proxy%ncell_3d', 'op_a_local_stencil',
'ndf_aspc1_op_a', 'ndf_aspc2_op_a', 'boundary_dofs_op_a']
'ndf_as1_op_a', 'ndf_as2_op_a', 'boundary_dofs_op_a']

check_psyir_results(create_arg_list, fortran_writer)
assert (create_arg_list.psyir_arglist[2].datatype ==
Expand Down Expand Up @@ -557,10 +557,10 @@ def test_indirect_dofmap(fortran_writer):
'cma_op1_cma_matrix', 'cma_op1_nrow', 'cma_op1_ncol',
'cma_op1_bandwidth', 'cma_op1_alpha', 'cma_op1_beta',
'cma_op1_gamma_m', 'cma_op1_gamma_p',
'ndf_adspc1_field_a', 'undf_adspc1_field_a',
'map_adspc1_field_a(:,cell)', 'cma_indirection_map_adspc1_field_a',
'ndf_aspc1_field_b', 'undf_aspc1_field_b', 'map_aspc1_field_b(:,cell)',
'cma_indirection_map_aspc1_field_b'])
'ndf_ads1_fd_a', 'undf_ads1_fd_a',
'map_ads1_fd_a(:,cell)', 'cma_indirection_map_ads1_fd_a',
'ndf_as1_fd_b', 'undf_as1_fd_b', 'map_as1_fd_b(:,cell)',
'cma_indirection_map_as1_fd_b'])

check_psyir_results(create_arg_list, fortran_writer)

Expand Down
10 changes: 5 additions & 5 deletions src/psyclone/tests/domain/lfric/lfric_dofmaps_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ def test_lfricdofmaps_stub_gen():

expected = (
" subroutine columnwise_op_app_kernel_code(cell, ncell_2d, "
"field_1_aspc1_field_1, field_2_aspc2_field_2, cma_op_3, "
"field_1_as1_fd_1, field_2_as2_fd_2, cma_op_3, "
"cma_op_3_nrow, cma_op_3_ncol, cma_op_3_bandwidth, cma_op_3_alpha, "
"cma_op_3_beta, cma_op_3_gamma_m, cma_op_3_gamma_p, "
"ndf_aspc1_field_1, undf_aspc1_field_1, map_aspc1_field_1, "
"cma_indirection_map_aspc1_field_1, ndf_aspc2_field_2, "
"undf_aspc2_field_2, map_aspc2_field_2, "
"cma_indirection_map_aspc2_field_2)\n"
"ndf_as1_fd_1, undf_as1_fd_1, map_as1_fd_1, "
"cma_indirection_map_as1_fd_1, ndf_as2_fd_2, "
"undf_as2_fd_2, map_as2_fd_2, "
"cma_indirection_map_as2_fd_2)\n"
)
assert expected in stub_text
Loading
Loading