Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
371 changes: 73 additions & 298 deletions src/psyclone/domain/common/transformations/kernel_module_inline_trans.py

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion src/psyclone/psyGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,16 @@ def get_callees(self):
raise NotImplementedError(
f"get_callees() must be overridden in class {self.__class__}")

@property
def name(self) -> str:
'''
Override Kern.name to use the RoutineSymbol name if one is available.

'''
if self.routine:
return self.routine.symbol.name
return super().name

@property
def opencl_options(self):
'''
Expand Down Expand Up @@ -1304,7 +1314,7 @@ def lower_to_language_level(self) -> Node:
'''
symtab = self.ancestor(InvokeSchedule).symbol_table

rsymbol = symtab.lookup(self._name)
rsymbol = symtab.lookup(self.name)

# Create Call to the rsymbol with the argument expressions as children
# of the new node
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def test_kernelimportstoargumentstrans_no_wildcard_import():
trans = KernelImportsToArguments()
with pytest.raises(TransformationError) as err:
trans.apply(kernel)
assert ("'kernel_with_use_code' contains accesses to 'rdt' which is "
"unresolved" in str(err.value))
assert ("'kernel_with_use_code_inlined_' contains accesses to 'rdt' which "
"is unresolved" in str(err.value))


def test_kernelimportstoargumentstrans(fortran_writer):
Expand Down Expand Up @@ -166,16 +166,16 @@ def test_kernelimportstoargumentstrans(fortran_writer):

# Check the kernel code is generated as expected
kernel_code = fortran_writer(kernel.get_callees()[0])
assert ("subroutine kernel_with_use_code(ji, jj, istep, ssha, tmask, "
"rdt, magic)" in kernel_code)
assert ("subroutine kernel_with_use_code_inlined_(ji, jj, istep, ssha, "
"tmask, rdt, magic)" in kernel_code)
assert "real(kind=go_wp), intent(in) :: rdt" in kernel_code
assert "real(kind=go_wp), intent(inout) :: magic" in kernel_code

# Check that the PSy-layer generated code now contains the use statement
# and argument call
generated_code = str(psy.gen)
assert "use model_mod, only : magic, rdt" in generated_code
assert ("call kernel_with_use_code(i, j, oldu_fld, cu_fld%data, "
assert ("call kernel_with_use_code_inlined_(i, j, oldu_fld, cu_fld%data, "
"cu_fld%grid%tmask, rdt, magic)" in generated_code)
assert invoke.schedule.symbol_table.lookup("model_mod")
assert invoke.schedule.symbol_table.lookup("rdt")
Expand Down Expand Up @@ -210,8 +210,8 @@ def create_data_symbol(arg):
kernels = kernel.get_callees()
kernel_code = fortran_writer(kernels[0])

assert ("subroutine kernel_with_use_code(ji, jj, istep, ssha, tmask, rdt, "
"magic)" in kernel_code)
assert ("subroutine kernel_with_use_code_inlined_(ji, jj, istep, ssha, "
"tmask, rdt, magic)" in kernel_code)
assert "integer, intent(in) :: rdt" in kernel_code


Expand Down Expand Up @@ -261,15 +261,15 @@ def test_kernelimportstoarguments_multiple_kernels(fortran_writer):
# The kernels are checked before the psy.gen, so they don't include the
# modified suffix.
expected = [
["subroutine kernel_with_use_code(ji, jj, istep, ssha, tmask, rdt, "
"magic)",
["subroutine kernel_with_use_code_inlined_(ji, jj, istep, ssha, "
"tmask, rdt, magic)",
"real(kind=go_wp), intent(in) :: rdt"],
["subroutine kernel_with_use2_code(ji, jj, istep, ssha, tmask, cbfr,"
" rdt)",
["subroutine kernel_with_use2_code_inlined_(ji, jj, istep, ssha, "
"tmask, cbfr, rdt)",
"real(kind=go_wp), intent(inout) :: cbfr\n real(kind=go_wp), "
"intent(in) :: rdt"],
["subroutine kernel_with_use_code(ji, jj, istep, ssha, tmask, rdt, "
"magic)",
["subroutine kernel_with_use_code_inlined_(ji, jj, istep, ssha, "
"tmask, rdt, magic)",
"real(kind=go_wp), intent(in) :: rdt\n real(kind=go_wp), "
"intent(inout) :: magic"]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1530,8 +1530,8 @@ def raise_gen_error():
monkeypatch.setattr(kern, "get_callees", raise_gen_error)
with pytest.raises(TransformationError) as err:
rtrans.apply(kern)
assert ("Failed to create PSyIR for kernel 'continuity_code'. Cannot "
"transform such a kernel." in str(err.value))
assert ("Failed to create PSyIR for kernel 'continuity_code_inlined_'. "
"Cannot transform such a kernel." in str(err.value))


def test_accroutinetrans_with_routine(fortran_writer):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ def test_go_move_iteration_boundaries_inside_kernel_two_kernels_apply_twice(
ystop = cu_fld%internal%ystop
do j = 1, SIZE(cu_fld%data, dim=2), 1
do i = 1, SIZE(cu_fld%data, dim=1), 1
call compute_cu_code(i, j, cu_fld%data, p_fld%data, u_fld%data, xstart, \
xstop, ystart, ystop)
call compute_cu_code_inlined_(i, j, cu_fld%data, p_fld%data, u_fld%data,\
xstart, xstop, ystart, ystop)
enddo
enddo
xstart_1 = 1
Expand All @@ -219,8 +219,8 @@ def test_go_move_iteration_boundaries_inside_kernel_two_kernels_apply_twice(
ystop_1 = SIZE(uold_fld%data, dim=2)
do j = 1, SIZE(uold_fld%data, dim=2), 1
do i = 1, SIZE(uold_fld%data, dim=1), 1
call time_smooth_code(i, j, cu_fld%data, unew_fld%data, uold_fld%data, \
xstart_1, xstop_1, ystart_1, ystop_1)
call time_smooth_code_inlined_(i, j, cu_fld%data, unew_fld%data, \
uold_fld%data, xstart_1, xstop_1, ystart_1, ystop_1)
enddo
enddo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ def test_invoke_opencl_initialisation(kernel_outputdir, fortran_writer):
if (first_time) then
call psy_init()
cmd_queues => get_cmd_queues()
kernel_compute_cu_code = get_kernel_by_name('compute_cu_code')
kernel_compute_cu_code_inlined_ = get_kernel_by_name(\
'compute_cu_code_inlined_')
call initialise_device_buffer(cu_fld)
call initialise_device_buffer(p_fld)
call initialise_device_buffer(u_fld)
Expand All @@ -273,8 +274,9 @@ def test_invoke_opencl_initialisation(kernel_outputdir, fortran_writer):
cu_fld_cl_mem = transfer(cu_fld%device_ptr, cu_fld_cl_mem)
p_fld_cl_mem = transfer(p_fld%device_ptr, p_fld_cl_mem)
u_fld_cl_mem = transfer(u_fld%device_ptr, u_fld_cl_mem)
call compute_cu_code_set_args(kernel_compute_cu_code, cu_fld_cl_mem, \
p_fld_cl_mem, u_fld_cl_mem, xstart - 1, xstop - 1, ystart - 1, ystop - 1)
call compute_cu_code_inlined__set_args(kernel_compute_cu_code_inlined_, \
cu_fld_cl_mem, p_fld_cl_mem, u_fld_cl_mem, xstart - 1, xstop - 1, ystart - 1, \
ystop - 1)

! write data to the device'''
assert expected in generated_code
Expand Down Expand Up @@ -389,7 +391,8 @@ def test_invoke_opencl_initialisation_grid(kernel_outputdir):
if (first_time) then
call psy_init()
cmd_queues => get_cmd_queues()
kernel_compute_kernel_code = get_kernel_by_name('compute_kernel_code')
kernel_compute_kernel_code_inlined_ = get_kernel_by_name(\
'compute_kernel_code_inlined_')
call initialise_device_buffer(out_fld)
call initialise_device_buffer(in_out_fld)
call initialise_device_buffer(in_fld)
Expand All @@ -404,7 +407,8 @@ def test_invoke_opencl_initialisation_grid(kernel_outputdir):
dx_cl_mem = transfer(dx%device_ptr, dx_cl_mem)
gphiu_cl_mem = transfer(in_fld%grid%gphiu_device, \
gphiu_cl_mem)
call compute_kernel_code_set_args(kernel_compute_kernel_code, \
call compute_kernel_code_inlined__set_args(\
kernel_compute_kernel_code_inlined_, \
out_fld_cl_mem, in_out_fld_cl_mem, in_fld_cl_mem, dx_cl_mem, \
in_fld%grid%dx, gphiu_cl_mem, xstart - 1, xstop - 1, ystart - 1, \
ystop - 1)
Expand Down Expand Up @@ -595,7 +599,7 @@ def test_psy_init_defaults(kernel_outputdir):
if (.not.initialised) then
initialised = .true.
call ocl_env_init(1, ocl_device_num, .false., .false.)
kernel_names(1) = 'compute_cu_code'
kernel_names(1) = 'compute_cu_code_inlined_'
call add_kernels(1, kernel_names)
end if

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ def test_apply_raw_subroutine(
if start:
modinline_trans = KernelModuleInlineTrans()
modinline_trans.apply(call)
assert "sub" in psyir.children[0].symbol_table
assert "sub_inlined_" in psyir.children[0].symbol_table
inline_trans = InlineTrans()
inline_trans.apply(call)
output = fortran_writer(psyir)
Expand Down
Loading