Debian Codegraph @

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

raw
1 ! Test for omp_target_memcpy_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:31), e(0:15), q(0:127)
9 type(c_ptr) :: p
10 integer(omp_depend_kind) :: obj(0:1)
11
12 d = omp_get_default_device ()
13 id = omp_get_initial_device ()
14
15 if (d < 0 .or. d >= omp_get_num_devices ()) &
16 d = id
17
18 p = omp_target_alloc (130 * c_sizeof (q), d)
19 if (.not. c_associated (p)) &
20 stop 0 ! okay
21
22 a = [(i + 1, i = 0, 127)]
23 b = [(i + 2, i = 0, 63)]
24 c = [(0, i = 0, 31)]
25 e = [(i + 4, i = 0, 15)]
26
27 !$omp parallel num_threads(5)
28 !$omp single
29
30 !$omp task depend(out: p)
31 if (omp_target_memcpy (p, c_loc (a), 128 * sizeof (a(0)), 0_c_size_t, &
32 0_c_size_t, d, id) /= 0) &
33 stop 1
34 !$omp end task
35
36 !$omp task depend(inout: p)
37 if (omp_target_memcpy (p, c_loc (b), 64 * sizeof (b(0)), 0_c_size_t, &
38 0_c_size_t, d, id) /= 0) &
39 stop 2
40 !$omp end task
41
42 !$omp task depend(out: c)
43 do j = 0, 31
44 c(j) = j + 3
45 end do
46 !$omp end task
47
48 !$omp depobj(obj(0)) depend(inout: p)
49 !$omp depobj(obj(1)) depend(in: c)
50 if (omp_target_memcpy_async (p, c_loc (c), 32 * sizeof (c(0)), 0_c_size_t, &
51 0_c_size_t, d, id, 2, obj) /= 0) &
52 stop 3
53
54 !$omp task depend(in: p)
55 if (omp_target_memcpy (p, c_loc (e), 16 * sizeof (e(0)), 0_c_size_t, &
56 0_c_size_t, d, id) /= 0) &
57 stop 4
58 !$omp end task
59
60 !$omp end single
61 !$omp end parallel
62
63 !$omp taskwait
64
65 q = [(0, i = 0, 127)]
66 if (omp_target_memcpy (c_loc (q), p, 128 * sizeof (q(0)), 0_c_size_t, &
67 0_c_size_t, id, d) /= 0) &
68 stop 5
69
70 do j = 0, 15
71 if (q(j) /= j+4) &
72 stop 10
73 end do
74
75 do j = 16, 31
76 if (q(j) /= j+3) &
77 stop 11
78 end do
79
80 do j = 32, 63
81 if (q(j) /= j+2) &
82 stop 12
83 end do
84
85 do j = 64, 127
86 if (q(j) /= j+1) &
87 stop 13
88 end do
89
90 call omp_target_free (p, d)
91 end program main