gcc/libgomp/testsuite/libgomp.fortran/target-memcpy-async-2.f90

92 lines
2.1 KiB
Fortran
Raw Normal View History

libgomp: Add new runtime routines omp_target_memcpy_async and omp_target_memcpy_rect_async This patch adds two new OpenMP runtime routines: omp_target_memcpy_async and omp_target_memcpy_rect_async. Both functions are introduced in OpenMP 5.1 as asynchronous variants of omp_target_memcpy and omp_target_memcpy_rect. In contrast to the synchronous variants, the asynchronous functions have two additional function parameters to allow the specification of task dependences: int depobj_count omp_depend_t *depobj_list integer(c_int), value :: depobj_count integer(omp_depend_kind), optional :: depobj_list(*) The implementation splits the synchronous functions into two parts: (a) check and (b) copy. Then (a) is used in the asynchronous functions for the sequential part, and the actual copy process (b) is executed in a new created task. The sequential part (a) takes into account the requirements for the return values: "The routine returns zero if successful. Otherwise, it returns a non-zero value." (omp_target_memcpy_async, OpenMP 5.1 spec, section 3.8.7) "An application can determine the number of inclusive dimensions supported by an implementation by passing NULL pointers (or C_NULL_PTR, for Fortran) for both dst and src. The routine returns the number of dimensions supported by the implementation for the specified device numbers. No copy operation is performed." (omp_target_memcpy_rect_async, OpenMP 5.1 spec, section 3.8.8) Due to asynchronicity an error is thrown if the asynchronous memcpy is not successful (in contrast to the synchronous functions which use a return value unequal to zero). gcc/ChangeLog: * omp-low.cc (omp_runtime_api_call): Added target_memcpy_async and target_memcpy_rect_async to omp_runtime_apis array. libgomp/ChangeLog: * libgomp.map: Added omp_target_memcpy_async and omp_target_memcpy_rect_async. * libgomp.texi: Both functions are now supported. * omp.h.in: Added omp_target_memcpy_async and omp_target_memcpy_rect_async. * omp_lib.f90.in: Added interfaces for both new functions. * omp_lib.h.in: Likewise. * target.c (ialias_redirect): Added for GOMP_task. (omp_target_memcpy): Restructured into check and copy part. (omp_target_memcpy_check): New helper function for omp_target_memcpy and omp_target_memcpy_async that checks requirements. (omp_target_memcpy_copy): New helper function for omp_target_memcpy and omp_target_memcpy_async that performs the memcpy. (omp_target_memcpy_async_helper): New helper function that is used in omp_target_memcpy_async for the asynchronous task. (omp_target_memcpy_async): Added. (omp_target_memcpy_rect): Restructured into check and copy part. (omp_target_memcpy_rect_check): New helper function for omp_target_memcpy_rect and omp_target_memcpy_rect_async that checks requirements. (omp_target_memcpy_rect_copy): New helper function for omp_target_memcpy_rect and omp_target_memcpy_rect_async that performs the memcpy. (omp_target_memcpy_rect_async_helper): New helper function that is used in omp_target_memcpy_rect_async for the asynchronous task. (omp_target_memcpy_rect_async): Added. * task.c (ialias): Added for GOMP_task. * testsuite/libgomp.c-c++-common/target-memcpy-async-1.c: New test. * testsuite/libgomp.c-c++-common/target-memcpy-async-2.c: New test. * testsuite/libgomp.c-c++-common/target-memcpy-rect-async-1.c: New test. * testsuite/libgomp.c-c++-common/target-memcpy-rect-async-2.c: New test. * testsuite/libgomp.fortran/target-memcpy-async-1.f90: New test. * testsuite/libgomp.fortran/target-memcpy-async-2.f90: New test. * testsuite/libgomp.fortran/target-memcpy-rect-async-1.f90: New test. * testsuite/libgomp.fortran/target-memcpy-rect-async-2.f90: New test.
2022-05-20 17:08:36 +08:00
! Test for omp_target_memcpy_async considering dependence objects.
program main
use omp_lib
use iso_c_binding
implicit none (external, type)
integer :: d, id, i, j
integer, target :: a(0:127), b(0:63), c(0:31), e(0:15), q(0:127)
type(c_ptr) :: p
integer(omp_depend_kind) :: obj(0:1)
d = omp_get_default_device ()
id = omp_get_initial_device ()
if (d < 0 .or. d >= omp_get_num_devices ()) &
d = id
p = omp_target_alloc (130 * c_sizeof (q), d)
if (.not. c_associated (p)) &
stop 0 ! okay
a = [(i + 1, i = 0, 127)]
b = [(i + 2, i = 0, 63)]
c = [(0, i = 0, 31)]
e = [(i + 4, i = 0, 15)]
!$omp parallel num_threads(5)
!$omp single
!$omp task depend(out: p)
if (omp_target_memcpy (p, c_loc (a), 128 * sizeof (a(0)), 0_c_size_t, &
0_c_size_t, d, id) /= 0) &
stop 1
!$omp end task
!$omp task depend(inout: p)
if (omp_target_memcpy (p, c_loc (b), 64 * sizeof (b(0)), 0_c_size_t, &
0_c_size_t, d, id) /= 0) &
stop 2
!$omp end task
!$omp task depend(out: c)
do j = 0, 31
c(j) = j + 3
end do
!$omp end task
!$omp depobj(obj(0)) depend(inout: p)
!$omp depobj(obj(1)) depend(in: c)
if (omp_target_memcpy_async (p, c_loc (c), 32 * sizeof (c(0)), 0_c_size_t, &
0_c_size_t, d, id, 2, obj) /= 0) &
stop 3
!$omp task depend(in: p)
if (omp_target_memcpy (p, c_loc (e), 16 * sizeof (e(0)), 0_c_size_t, &
0_c_size_t, d, id) /= 0) &
stop 4
!$omp end task
!$omp end single
!$omp end parallel
!$omp taskwait
q = [(0, i = 0, 127)]
if (omp_target_memcpy (c_loc (q), p, 128 * sizeof (q(0)), 0_c_size_t, &
0_c_size_t, id, d) /= 0) &
stop 5
do j = 0, 15
if (q(j) /= j+4) &
stop 10
end do
do j = 16, 31
if (q(j) /= j+3) &
stop 11
end do
do j = 32, 63
if (q(j) /= j+2) &
stop 12
end do
do j = 64, 127
if (q(j) /= j+1) &
stop 13
end do
call omp_target_free (p, d)
end program main