| 1 |
! Test for omp_target_memcpy_rect_async considering dependence objects. |
| 2 |
|
| 3 |
program main |
| 4 |
use omp_lib |
| 5 |
use iso_c_binding |
| 6 |
implicit none (external, type) |
| 7 |
integer :: d, id, i, j |
| 8 |
integer, target :: a(0:127), b(0:63), c(0:127), e(0:15), q(0:127) |
| 9 |
type(c_ptr) :: p |
| 10 |
integer(omp_depend_kind) :: obj(0:2) |
| 11 |
|
| 12 |
integer(kind=c_size_t) :: volume(0:2) |
| 13 |
integer(kind=c_size_t) :: dst_offsets(0:2) |
| 14 |
integer(kind=c_size_t) :: src_offsets(0:2) |
| 15 |
integer(kind=c_size_t) :: dst_dimensions(0:2) |
| 16 |
integer(kind=c_size_t) :: src_dimensions(0:2) |
| 17 |
|
| 18 |
d = omp_get_default_device () |
| 19 |
id = omp_get_initial_device () |
| 20 |
|
| 21 |
if (d < 0 .or. d >= omp_get_num_devices ()) & |
| 22 |
d = id |
| 23 |
|
| 24 |
p = omp_target_alloc (130 * c_sizeof (q), d) |
| 25 |
if (.not. c_associated (p)) & |
| 26 |
stop 0 ! okay |
| 27 |
|
| 28 |
a = [(42, i = 0, 127)] |
| 29 |
b = [(24, i = 0, 63)] |
| 30 |
c = [(0, i = 0, 127)] |
| 31 |
e = [(77, i = 0, 15)] |
| 32 |
|
| 33 |
volume(2) = 3 |
| 34 |
volume(1) = 2 |
| 35 |
volume(0) = 2 |
| 36 |
dst_offsets(2) = 0 |
| 37 |
dst_offsets(1) = 0 |
| 38 |
dst_offsets(0) = 0 |
| 39 |
src_offsets(2) = 0 |
| 40 |
src_offsets(1) = 0 |
| 41 |
src_offsets(0) = 0 |
| 42 |
dst_dimensions(2) = 5 |
| 43 |
dst_dimensions(1) = 4 |
| 44 |
dst_dimensions(0) = 3 |
| 45 |
src_dimensions(2) = 4 |
| 46 |
src_dimensions(1) = 3 |
| 47 |
src_dimensions(0) = 2 |
| 48 |
|
| 49 |
!$omp parallel num_threads(5) |
| 50 |
!$omp single |
| 51 |
|
| 52 |
!$omp task depend(out: p) |
| 53 |
if (omp_target_memcpy (p, c_loc (a), 128 * sizeof (a(0)), 0_c_size_t, & |
| 54 |
0_c_size_t, d, id) /= 0) & |
| 55 |
stop 1 |
| 56 |
!$omp end task |
| 57 |
|
| 58 |
!$omp task depend(inout: p) |
| 59 |
if (omp_target_memcpy (p, c_loc (b), 64 * sizeof (b(0)), 0_c_size_t, & |
| 60 |
0_c_size_t, d, id) /= 0) & |
| 61 |
stop 2 |
| 62 |
!$omp end task |
| 63 |
|
| 64 |
!$omp task depend(out: c) |
| 65 |
do j = 0, 127 |
| 66 |
c(j) = j + 1 |
| 67 |
end do |
| 68 |
!$omp end task |
| 69 |
|
| 70 |
!$omp depobj(obj(0)) depend(inout: p) |
| 71 |
!$omp depobj(obj(1)) depend(in: c) |
| 72 |
|
| 73 |
! This produces: 1 2 3 - - 5 6 7 - - at positions 0..9 and |
| 74 |
! 13 14 15 - - 17 18 19 - - at positions 20..29. |
| 75 |
if (omp_target_memcpy_rect_async (p, c_loc (c), sizeof (c(0)), 3, volume, & |
| 76 |
dst_offsets, src_offsets, & |
| 77 |
dst_dimensions, src_dimensions, d, id, & |
| 78 |
2, obj) /= 0) & |
| 79 |
stop 3 |
| 80 |
|
| 81 |
!$omp task depend(in: p) |
| 82 |
if (omp_target_memcpy (p, c_loc (e), 16 * sizeof (e(0)), 0_c_size_t, & |
| 83 |
0_c_size_t, d, id) /= 0) & |
| 84 |
stop 4 |
| 85 |
!$omp end task |
| 86 |
|
| 87 |
!$omp end single |
| 88 |
!$omp end parallel |
| 89 |
|
| 90 |
!$omp taskwait |
| 91 |
|
| 92 |
q = [(0, i = 0, 127)] |
| 93 |
if (omp_target_memcpy (c_loc (q), p, 128 * sizeof (q(0)), 0_c_size_t, & |
| 94 |
0_c_size_t, id, d) /= 0) & |
| 95 |
stop 5 |
| 96 |
|
| 97 |
do j = 0, 15 |
| 98 |
if (q(j) /= 77) & |
| 99 |
stop 6 |
| 100 |
end do |
| 101 |
|
| 102 |
if (q(20) /= 13 .or. q(21) /= 14 .or. q(22) /= 15 .or. q(25) /= 17 & |
| 103 |
.or. q(26) /= 18 .or. q(27) /= 19) & |
| 104 |
stop 7 |
| 105 |
|
| 106 |
do j = 28, 63 |
| 107 |
if (q(j) /= 24) & |
| 108 |
stop 8 |
| 109 |
end do |
| 110 |
|
| 111 |
do j = 64, 127 |
| 112 |
if (q(j) /= 42) & |
| 113 |
stop 9 |
| 114 |
end do |
| 115 |
|
| 116 |
call omp_target_free (p, d) |
| 117 |
end program main |