Skip to content

Commit

Permalink
#1010 Rename gen_code variable to code in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sergisiso committed Feb 3, 2025
1 parent fe26a76 commit 7040b7c
Show file tree
Hide file tree
Showing 15 changed files with 484 additions and 485 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -442,17 +442,16 @@ def test_module_inline_apply_transformation(tmpdir, fortran_writer):
assert (kern_call.ancestor(Container).symbol_table.
lookup("compute_cv_code").is_modulevar)

# We should see it in the output of both:
# - the backend
code = fortran_writer(schedule.root)
# Generate the code
code = str(psy.gen)
assert 'subroutine compute_cv_code(i, j, cv, p, v)' in code

# And the import has been remove from both, so check that the associated
# use no longer exists
assert 'use compute_cv_mod' not in code.lower()

# Do the gen_code check again because repeating the call resets some
# aspects and we need to see if the second call still works as expected
# Do the check again because repeating the call resets some aspects and we
# need to see if the second call still works as expected
gen = str(psy.gen)
assert 'subroutine compute_cv_code(i, j, cv, p, v)' in gen
assert 'use compute_cv_mod' not in gen
Expand Down
66 changes: 33 additions & 33 deletions src/psyclone/tests/domain/lfric/lfric_cell_halo_kernels_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,39 +107,39 @@ def test_psy_gen_halo_kernel(dist_mem, tmpdir, fortran_writer):
single kernel with operates_on=halo_cell_column. '''
psy, _ = get_invoke("1.4_into_halos_invoke.f90", TEST_API,
dist_mem=dist_mem, idx=0)
gen_code = str(psy.gen).lower()
code = str(psy.gen).lower()

# A halo kernel needs to look up the last halo column in the mesh.
# Therefore we require a mesh object.
if dist_mem:
assert "integer(kind=i_def), intent(in) :: hdepth" in gen_code
assert "integer(kind=i_def), intent(in) :: hdepth" in code

assert "type(mesh_type), pointer :: mesh => null()" in gen_code
assert "mesh => f1_proxy%vspace%get_mesh()" in gen_code
assert "type(mesh_type), pointer :: mesh => null()" in code
assert "mesh => f1_proxy%vspace%get_mesh()" in code
# Loop must be over halo cells only
assert "loop0_start = mesh%get_last_edge_cell() + 1" in gen_code
assert "loop0_start = mesh%get_last_edge_cell() + 1" in code
assert ("loop0_stop = mesh%get_last_halo_cell(hdepth)"
in gen_code)
in code)

assert (" do cell = loop0_start, loop0_stop, 1\n"
" call testkern_halo_only_code(nlayers_f1, a, "
"f1_data, f2_data, m1_data, m2_data, ndf_w1, undf_w1, "
"map_w1(:,cell), ndf_w2, undf_w2, map_w2(:,cell), ndf_w3, "
"undf_w3, map_w3(:,cell))"
in gen_code)
in code)

# Check for appropriate set-dirty/clean calls. Outermost halo remains
# dirty because field being updated is on continuous function space.
assert (" call f1_proxy%set_dirty()\n"
" call f1_proxy%set_clean(hdepth - 1)" in gen_code)
" call f1_proxy%set_clean(hdepth - 1)" in code)
else:
# No distributed memory so no halo region => no halo depths passed
# from Alg layer.
assert (" subroutine invoke_0_testkern_halo_only_type"
"(a, f1, f2, m1, m2)" in gen_code)
assert "integer, intent(in) :: hdepth" not in gen_code
"(a, f1, f2, m1, m2)" in code)
assert "integer, intent(in) :: hdepth" not in code
# Kernel is not called.
assert "call testkern_halo_only_code( " not in gen_code
assert "call testkern_halo_only_code( " not in code

assert LFRicBuild(tmpdir).code_compiles(psy)

Expand Down Expand Up @@ -170,12 +170,12 @@ def test_psy_gen_domain_two_kernel(dist_mem, tmpdir):
'''
psy, _ = get_invoke("1.4.1_into_halos_plus_domain_invoke.f90",
TEST_API, dist_mem=dist_mem, idx=0)
gen_code = str(psy.gen).lower()
code = str(psy.gen).lower()

if dist_mem:
assert "mesh => f1_proxy%vspace%get_mesh()" in gen_code
assert "mesh => f1_proxy%vspace%get_mesh()" in code

assert "integer(kind=i_def) :: ncell_2d_no_halos" in gen_code
assert "integer(kind=i_def) :: ncell_2d_no_halos" in code

expected = ""
if dist_mem:
Expand All @@ -189,11 +189,11 @@ def test_psy_gen_domain_two_kernel(dist_mem, tmpdir):
expected += (
" call testkern_domain_code(nlayers_f1, ncell_2d_no_halos, a, "
"f1_data, ndf_w3, undf_w3, map_w3)\n")
assert expected in gen_code
assert expected in code
if dist_mem:
assert (" ! set halos dirty/clean for fields modified in the "
"above loop(s)\n"
" call f1_proxy%set_dirty()\n" in gen_code)
" call f1_proxy%set_dirty()\n" in code)

assert LFRicBuild(tmpdir).code_compiles(psy)

Expand All @@ -207,10 +207,10 @@ def test_psy_gen_halo_kernel_discontinuous_space(dist_mem, tmpdir):
'''
psy, _ = get_invoke("1.4.2_multi_into_halos_invoke.f90",
TEST_API, dist_mem=dist_mem, idx=0)
gen_code = str(psy.gen).lower()
code = str(psy.gen).lower()
if dist_mem:
assert "integer(kind=i_def), intent(in) :: hdepth" in gen_code
assert "integer(kind=i_def), intent(in) :: other_depth" in gen_code
assert "integer(kind=i_def), intent(in) :: hdepth" in code
assert "integer(kind=i_def), intent(in) :: other_depth" in code

# The halo-only kernel updates a field on a continuous function space
# and thus leaves the outermost halo cell dirty.
Expand All @@ -221,7 +221,7 @@ def test_psy_gen_halo_kernel_discontinuous_space(dist_mem, tmpdir):
! set halos dirty/clean for fields modified in the above loop(s)
call f1_proxy%set_dirty()
call f1_proxy%set_clean(hdepth - 1)''' in gen_code
call f1_proxy%set_clean(hdepth - 1)''' in code

# testkern_code is a 'normal' kernel and thus leaves all halo cells
# dirty.
Expand All @@ -231,7 +231,7 @@ def test_psy_gen_halo_kernel_discontinuous_space(dist_mem, tmpdir):
enddo
! set halos dirty/clean for fields modified in the above loop(s)
call f1_proxy%set_dirty()''' in gen_code
call f1_proxy%set_dirty()''' in code

# testkern_halo_and_owned_code operates in the halo for a field on a
# discontinuous function space and therefore the halo is left clean to
Expand All @@ -243,18 +243,18 @@ def test_psy_gen_halo_kernel_discontinuous_space(dist_mem, tmpdir):
! set halos dirty/clean for fields modified in the above loop(s)
call f1_proxy%set_dirty()
call f1_proxy%set_clean(other_depth)''' in gen_code
call f1_proxy%set_clean(other_depth)''' in code
else:
# No distributed memory.
# => no halo depths to pass from Algorithm layer.
assert "integer(kind=i_def), intent(in) :: hdepth" not in gen_code
assert "integer(kind=i_def), intent(in) :: other_depth" not in gen_code
assert "integer(kind=i_def), intent(in) :: hdepth" not in code
assert "integer(kind=i_def), intent(in) :: other_depth" not in code
# => no halos so no need to call a kernel which only operates on
# halo cells.
assert "call testkern_halo_only_code(" not in gen_code
assert "call testkern_halo_only_code(" not in code
# However, a kernel that operates on owned *and* halo cells must still
# be called.
assert "call testkern_halo_and_owned_code(nlayers_f1, a" in gen_code
assert "call testkern_halo_and_owned_code(nlayers_f1, a" in code

assert LFRicBuild(tmpdir).code_compiles(psy)

Expand All @@ -267,23 +267,23 @@ def test_psy_gen_halo_kernel_literal_depths(dist_mem, tmpdir):
'''
psy, _ = get_invoke("1.4.3_literal_depth_into_halos_invoke.f90",
TEST_API, dist_mem=dist_mem, idx=0)
gen_code = str(psy.gen).lower()
code = str(psy.gen).lower()
if dist_mem:
# Make sure we aren't attempting to specify literal values in the
# argument list to the PSy-layer routine.
assert "subroutine invoke_0(a, f1, f2, m1, m2, hdepth)" in gen_code
assert "subroutine invoke_0(a, f1, f2, m1, m2, hdepth)" in code
# First kernel operates into the halo to a depth of '2' but updates a
# field on a continuous function space so only the level-1 halo is
# left clean.
assert '''call f1_proxy%set_dirty()
call f1_proxy%set_clean(1)''' in gen_code
call f1_proxy%set_clean(1)''' in code
assert '''call f1_proxy%set_dirty()
call f1_proxy%set_clean(hdepth)''' in gen_code
call f1_proxy%set_clean(hdepth)''' in code
assert '''call f1_proxy%set_dirty()
call f1_proxy%set_clean(5)''' in gen_code
call f1_proxy%set_clean(5)''' in code
else:
assert "call testkern_halo_only_code(" not in gen_code
assert "call testkern_halo_and_owned_code(nlayers_f1, a" in gen_code
assert "call testkern_halo_only_code(" not in code
assert "call testkern_halo_and_owned_code(nlayers_f1, a" in code
assert LFRicBuild(tmpdir).code_compiles(psy)


Expand Down
58 changes: 29 additions & 29 deletions src/psyclone/tests/domain/lfric/lfric_domain_kernels_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,19 @@ def test_psy_gen_domain_kernel(dist_mem, tmpdir, fortran_writer):
_, info = parse(os.path.join(BASE_PATH, "25.0_domain.f90"),
api=TEST_API)
psy = PSyFactory(TEST_API, distributed_memory=dist_mem).create(info)
gen_code = str(psy.gen).lower()
code = str(psy.gen).lower()

# A domain kernel needs the number of columns in the mesh. Therefore
# we require a mesh object.
assert "type(mesh_type), pointer :: mesh => null()" in gen_code
assert "mesh => f1_proxy%vspace%get_mesh()" in gen_code
assert "integer(kind=i_def) :: ncell_2d_no_halos" in gen_code
assert "ncell_2d_no_halos = mesh%get_last_edge_cell()" in gen_code
assert "type(mesh_type), pointer :: mesh => null()" in code
assert "mesh => f1_proxy%vspace%get_mesh()" in code
assert "integer(kind=i_def) :: ncell_2d_no_halos" in code
assert "ncell_2d_no_halos = mesh%get_last_edge_cell()" in code

# Kernel call should include whole dofmap and not be within a loop
assert (" call testkern_domain_code(nlayers_f1, ncell_2d_no_halos, "
"b, f1_data, ndf_w3, undf_w3, map_w3)" in gen_code)
assert "do " not in gen_code
"b, f1_data, ndf_w3, undf_w3, map_w3)" in code)
assert "do " not in code

assert LFRicBuild(tmpdir).code_compiles(psy)

Expand All @@ -307,10 +307,10 @@ def test_psy_gen_domain_two_kernel(dist_mem, tmpdir):
_, info = parse(os.path.join(BASE_PATH, "25.1_2kern_domain.f90"),
api=TEST_API)
psy = PSyFactory(TEST_API, distributed_memory=dist_mem).create(info)
gen_code = str(psy.gen).lower()
code = str(psy.gen).lower()

assert "mesh => f2_proxy%vspace%get_mesh()" in gen_code
assert "integer(kind=i_def) :: ncell_2d_no_halos" in gen_code
assert "mesh => f2_proxy%vspace%get_mesh()" in code
assert "integer(kind=i_def) :: ncell_2d_no_halos" in code

expected = (
" enddo\n")
Expand All @@ -323,12 +323,12 @@ def test_psy_gen_domain_two_kernel(dist_mem, tmpdir):
expected += (
" call testkern_domain_code(nlayers_f1, ncell_2d_no_halos, b, "
"f1_data, ndf_w3, undf_w3, map_w3)\n")
assert expected in gen_code
assert expected in code
if dist_mem:
assert (
# " ! set halos dirty/clean for fields modified in the "
# "above kernel\n"
" call f1_proxy%set_dirty()\n" in gen_code)
" call f1_proxy%set_dirty()\n" in code)

assert LFRicBuild(tmpdir).code_compiles(psy)

Expand All @@ -341,16 +341,16 @@ def test_psy_gen_domain_multi_kernel(dist_mem, tmpdir):
_, info = parse(os.path.join(BASE_PATH, "25.2_multikern_domain.f90"),
api=TEST_API)
psy = PSyFactory(TEST_API, distributed_memory=dist_mem).create(info)
gen_code = str(psy.gen).lower()
code = str(psy.gen).lower()

# Check that we only have one last-edge-cell assignment
assert gen_code.count("ncell_2d_no_halos = mesh%get_last_edge_cell()") == 1
assert code.count("ncell_2d_no_halos = mesh%get_last_edge_cell()") == 1

expected = (
" call testkern_domain_code(nlayers_f1, ncell_2d_no_halos, "
"b, f1_data, ndf_w3, undf_w3, map_w3)\n")
if dist_mem:
assert "loop1_stop = mesh%get_last_halo_cell(1)\n" in gen_code
assert "loop1_stop = mesh%get_last_halo_cell(1)\n" in code
expected += (
"\n"
" ! set halos dirty/clean for fields modified in "
Expand All @@ -367,9 +367,9 @@ def test_psy_gen_domain_multi_kernel(dist_mem, tmpdir):
" end if\n"
" call f1_proxy%halo_exchange(depth=1)\n")
else:
assert "loop1_stop = f2_proxy%vspace%get_ncell()\n" in gen_code
assert "loop1_stop = f2_proxy%vspace%get_ncell()\n" in code
expected += " do cell = loop1_start, loop1_stop, 1\n"
assert expected in gen_code
assert expected in code

expected = (
" enddo\n")
Expand All @@ -382,14 +382,14 @@ def test_psy_gen_domain_multi_kernel(dist_mem, tmpdir):
expected += (
" call testkern_domain_code(nlayers_f1, ncell_2d_no_halos, c, "
"f1_data, ndf_w3, undf_w3, map_w3)\n")
assert expected in gen_code
assert expected in code
if dist_mem:
assert (
" ! set halos dirty/clean for fields modified in the "
"above loop(s)\n"
" call f5_proxy%set_dirty()\n"
"\n"
" end subroutine invoke_0" in gen_code)
" end subroutine invoke_0" in code)

assert LFRicBuild(tmpdir).code_compiles(psy)

Expand All @@ -402,17 +402,17 @@ def test_domain_plus_cma_kernels(dist_mem, tmpdir):
_, info = parse(os.path.join(BASE_PATH, "25.3_multikern_domain_cma.f90"),
api=TEST_API)
psy = PSyFactory(TEST_API, distributed_memory=dist_mem).create(info)
gen_code = str(psy.gen).lower()

assert "type(mesh_type), pointer :: mesh => null()" in gen_code
assert "integer(kind=i_def) :: ncell_2d" in gen_code
assert "integer(kind=i_def) :: ncell_2d_no_halos" in gen_code
assert "mesh => f1_proxy%vspace%get_mesh()" in gen_code
assert "ncell_2d = mesh%get_ncells_2d()" in gen_code
assert "ncell_2d_no_halos = mesh%get_last_edge_cell()" in gen_code
code = str(psy.gen).lower()

assert "type(mesh_type), pointer :: mesh => null()" in code
assert "integer(kind=i_def) :: ncell_2d" in code
assert "integer(kind=i_def) :: ncell_2d_no_halos" in code
assert "mesh => f1_proxy%vspace%get_mesh()" in code
assert "ncell_2d = mesh%get_ncells_2d()" in code
assert "ncell_2d_no_halos = mesh%get_last_edge_cell()" in code
assert ("call testkern_domain_code(nlayers_f1, ncell_2d_no_halos, b, "
"f1_data, ndf_w3, undf_w3, map_w3)" in gen_code)
"f1_data, ndf_w3, undf_w3, map_w3)" in code)
assert ("call columnwise_op_asm_kernel_code(cell, nlayers_lma_op1, "
"ncell_2d, lma_op1_proxy%ncell_3d," in gen_code)
"ncell_2d, lma_op1_proxy%ncell_3d," in code)

assert LFRicBuild(tmpdir).code_compiles(psy)
24 changes: 12 additions & 12 deletions src/psyclone/tests/domain/lfric/lfric_field_codegen_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,11 +962,11 @@ def test_int_field_2qr_shapes(dist_mem, tmpdir):
api=TEST_API)
psy = PSyFactory(TEST_API, distributed_memory=dist_mem).create(invoke_info)
assert LFRicBuild(tmpdir).code_compiles(psy)
gen_code = str(psy.gen)
code = str(psy.gen)
# Check that the qr-related variables are all declared
assert (" type(quadrature_xyoz_type), intent(in) :: qr_xyoz\n"
" type(quadrature_face_type), intent(in) :: qr_face\n"
in gen_code)
in code)
assert """
real(kind=r_def), allocatable :: basis_w2_qr_xyoz(:,:,:,:)
real(kind=r_def), allocatable :: basis_w2_qr_face(:,:,:,:)
Expand All @@ -976,21 +976,21 @@ def test_int_field_2qr_shapes(dist_mem, tmpdir):
real(kind=r_def), allocatable :: diff_basis_adspc1_f3_qr_xyoz(:,:,:,:)
real(kind=r_def), allocatable :: basis_adspc1_f3_qr_face(:,:,:,:)
real(kind=r_def), allocatable :: diff_basis_adspc1_f3_qr_face(:,:,:,:)
""" in gen_code
""" in code
assert (" real(kind=r_def), pointer, dimension(:,:) :: "
"weights_xyz_qr_face => null()\n" in gen_code)
assert " integer(kind=i_def) :: np_xyz_qr_face\n" in gen_code
assert " integer(kind=i_def) :: nfaces_qr_face\n" in gen_code
"weights_xyz_qr_face => null()\n" in code)
assert " integer(kind=i_def) :: np_xyz_qr_face\n" in code
assert " integer(kind=i_def) :: nfaces_qr_face\n" in code
assert (
" integer(kind=i_def) :: np_xy_qr_xyoz\n"
" integer(kind=i_def) :: np_z_qr_xyoz\n"
" real(kind=r_def), pointer :: weights_xy_qr_xyoz(:) => "
"null()\n"
" real(kind=r_def), pointer :: weights_z_qr_xyoz(:) => "
"null()\n"
in gen_code)
assert "type(quadrature_face_proxy_type) :: qr_face_proxy\n" in gen_code
assert "type(quadrature_xyoz_proxy_type) :: qr_xyoz_proxy\n" in gen_code
in code)
assert "type(quadrature_face_proxy_type) :: qr_face_proxy\n" in code
assert "type(quadrature_xyoz_proxy_type) :: qr_xyoz_proxy\n" in code
# Allocation and computation of (some of) the basis/differential
# basis functions
assert (" ALLOCATE(basis_adspc1_f3_qr_xyoz(dim_adspc1_f3,"
Expand All @@ -1001,7 +1001,7 @@ def test_int_field_2qr_shapes(dist_mem, tmpdir):
"ndf_adspc1_f3,np_xyz_qr_face,nfaces_qr_face))\n"
" ALLOCATE(diff_basis_adspc1_f3_qr_face(diff_dim_adspc1_f3,"
"ndf_adspc1_f3,np_xyz_qr_face,nfaces_qr_face))\n"
in gen_code)
in code)
assert (" call qr_xyoz%compute_function(BASIS, f3_proxy%vspace, "
"dim_adspc1_f3, ndf_adspc1_f3, basis_adspc1_f3_qr_xyoz)\n"
" call qr_xyoz%compute_function(DIFF_BASIS, "
Expand All @@ -1011,7 +1011,7 @@ def test_int_field_2qr_shapes(dist_mem, tmpdir):
"dim_adspc1_f3, ndf_adspc1_f3, basis_adspc1_f3_qr_face)\n"
" call qr_face%compute_function(DIFF_BASIS, "
"f3_proxy%vspace, diff_dim_adspc1_f3, ndf_adspc1_f3, "
"diff_basis_adspc1_f3_qr_face)\n" in gen_code)
"diff_basis_adspc1_f3_qr_face)\n" in code)
# Check that the kernel call itself is correct
assert (
"testkern_2qr_int_field_code(nlayers_f1, f1_data, "
Expand All @@ -1023,7 +1023,7 @@ def test_int_field_2qr_shapes(dist_mem, tmpdir):
"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, "
"weights_xy_qr_xyoz, weights_z_qr_xyoz, nfaces_qr_face, "
"np_xyz_qr_face, weights_xyz_qr_face)\n" in gen_code)
"np_xyz_qr_face, weights_xyz_qr_face)\n" in code)


# Tests for Invokes calling kernels that contain real- and
Expand Down
Loading

0 comments on commit 7040b7c

Please sign in to comment.