Skip to content

Commit

Permalink
#2711 Better testing
Browse files Browse the repository at this point in the history
  • Loading branch information
oakleybrunt committed Sep 20, 2024
1 parent 56be42e commit ef8225b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 46 deletions.
3 changes: 1 addition & 2 deletions src/psyclone/domain/lfric/lfric_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ def load(self, kern):
self.set_lower_bound("start")
const = LFRicConstants()
if kern.iterates_over == "dof":
# If the kernel is a built-in/pointwise operation
# then this loop must be over DoFs
# This loop must be over DoFs
if Config.get().api_conf("lfric").compute_annexed_dofs \
and Config.get().distributed_memory \
and not kern.is_reduction:
Expand Down
5 changes: 4 additions & 1 deletion src/psyclone/dynamo0p3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,10 @@ def initialise(self, parent):
# from the field proxy and undf is not required.
if not (self._dofs_only and Config.get().distributed_memory):
if self._invoke.field_on_space(function_space):
undf_name = function_space.undf_name
if self._invoke.operates_on_dofs_only:
undf_name = function_space.bare_undf_name
else:
undf_name = function_space.undf_name
parent.add(AssignGen(parent, lhs=undf_name,
rhs=name + "%" +
arg.ref_name(function_space) +
Expand Down
86 changes: 46 additions & 40 deletions src/psyclone/tests/domain/lfric/dofkern_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,36 +178,7 @@ def test_is_dofkern():
kern = LFRicKern()
kern.load_meta(ktype=md)
# Assert that the identifier is set
assert kern.is_dofkern


def test_multiple_write_args():
'''
Check that LFRicKernMetadata raises no errors when user-defined dof kernel
defines more than one metadata arg of type 'gh_field' with an access type
of 'gh_write'.
'''
# Substitute field for multiple writes
code = CODE.replace(
"""
type(arg_type), dimension(2) :: meta_args = &
(/ arg_type(gh_field, gh_real, gh_write, w1), &
arg_type(gh_field, gh_real, gh_read, w2) &
""",
"""
type(arg_type), dimension(3) :: meta_args = &
(/ arg_type(gh_field, gh_real, gh_write, w1), &
arg_type(gh_field, gh_real, gh_write, w1), &
arg_type(gh_field, gh_real, gh_read, w1) &
""",
1)
ast = fpapi.parse(code, ignore_comments=False)
name = "testkern_dofs_type"
# Load the metadata into an empty kernel
md = LFRicKernMetadata(ast, name=name)
# Proxy assertion that validating dof kern passes
assert md.is_dofkern
assert kern.iterates_over == "dof"


def test_upper_bound_undf():
Expand All @@ -230,22 +201,40 @@ def test_upper_bound_undf():
assert expected in code


def test_upper_bound_dofowned():
def test_upper_bounds(monkeypatch, annexed, dist_mem):
'''
Checks that the correct upper bound is generated for a dof-kernel when
distributed memory is set to 'True'. This should be set to the last dof
owned by the vector space and be accessed by the 'get_last_dof_owned'
subroutine.
Checks that the correct upper bound is generated for a dof-kernel for all
permutations of the `DISTRIBUTED_MEMORY` and `COMPUTE_ANNEXED_DOFS`
configuration settings.
'''
# Set up annexed dofs
config = Config.get()
lfric_config = config.api_conf("lfric")
monkeypatch.setattr(lfric_config, "_compute_annexed_dofs", annexed)

_, invoke_info = parse(os.path.join(BASE_PATH,
"1.14_single_invoke_dofs.f90"),
api=TEST_API)
psy = PSyFactory(TEST_API, distributed_memory=True).create(invoke_info)
psy = PSyFactory(TEST_API, distributed_memory=dist_mem).create(invoke_info)
code = str(psy.gen)

expected = (" loop0_start = 1\n"
" loop0_stop = f1_proxy%vspace%get_last_dof_owned()")
# Distributed memory
if annexed and dist_mem:
expected = (" loop0_start = 1\n"
" loop0_stop = f1_proxy%vspace%get_last_dof_annexed()"
)
elif not annexed and dist_mem:
expected = (" loop0_start = 1\n"
" loop0_stop = f1_proxy%vspace%get_last_dof_owned()"
)

# Shared memory
elif not annexed and not dist_mem or \
annexed and not dist_mem:
expected = (" loop0_start = 1\n"
" loop0_stop = undf"
)

assert expected in code

Expand All @@ -263,7 +252,24 @@ def test_indexed_field_args():
psy = PSyFactory(TEST_API, distributed_memory=False).create(invoke_info)
code = str(psy.gen)

expected = ("CALL testkern_dofs_code("
"f1_data(df), f2_data(df), f3_data(df), f4_data(df)")
expected = ("CALL testkern_dofs_code(f1_data(df), f2_data(df), "
"f3_data(df), f4_data(df), scalar_arg, undf)")

assert expected in code


def test_undf_initialisation():
'''
Test that the 'bare' undf name is used when intialising the undf
variable for dof kernels.
'''
_, invoke_info = parse(os.path.join(BASE_PATH,
"1.14_single_invoke_dofs.f90"),
api=TEST_API)
psy = PSyFactory(TEST_API, distributed_memory=False).create(invoke_info)
code = str(psy.gen)

expected = "undf = f1_proxy%vspace%get_undf()"

assert expected in code
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ program single_invoke_dofs
implicit none

type(field_type) :: f1, f2, f3, f4
real(kind=r_def) :: scalar_arg

call invoke( &
testkern_dofs_type(f1, f2, f3, f4) &
testkern_dofs_type(f1, f2, f3, f4, scalar_arg) &
)

end program single_invoke_dofs
5 changes: 3 additions & 2 deletions src/psyclone/tests/test_files/dynamo0p3/testkern_dofs_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ module testkern_dofs_mod

! User-defined single kernel that operates on DoFs (currently not supported)
type, extends(kernel_type) :: testkern_dofs_type
type(arg_type), dimension(4) :: meta_args = &
type(arg_type), dimension(5) :: meta_args = &
(/ arg_type(gh_field, gh_real, gh_write, w1), &
arg_type(gh_field, gh_real, gh_read, w1), &
arg_type(gh_field, gh_real, gh_read, w1), &
arg_type(gh_field, gh_real, gh_read, w1) &
arg_type(gh_field, gh_real, gh_read, w1), &
arg_type(gh_scalar, gh_real, gh_read) &
/)
integer :: operates_on = DOF
contains
Expand Down

0 comments on commit ef8225b

Please sign in to comment.