Debian Codegraph @

libgomp/testsuite/libgomp.fortran/target-memcpy-rect-async-1.f90

raw
1 ! Test for omp_target_memcpy_rect_async without 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 :: q(0:127), q2(0:127)
9 type(c_ptr) :: p
10 integer(omp_depend_kind) :: obj(1:0)
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 integer(kind=c_size_t) :: empty(1:0)
18
19 d = omp_get_default_device ()
20 id = omp_get_initial_device ()
21
22 if (d < 0 .or. d >= omp_get_num_devices ()) &
23 d = id
24
25 p = omp_target_alloc (130 * c_sizeof (q), d)
26 if (.not. c_associated (p)) &
27 stop 0 ! okay
28
29 if (omp_target_memcpy_rect_async (C_NULL_PTR, C_NULL_PTR, 0_c_size_t, 0, &
30 empty, empty, empty, empty, empty, d, id, &
31 0, obj) < 3 &
32 .or. omp_target_memcpy_rect_async (C_NULL_PTR, C_NULL_PTR, 0_c_size_t, 0, &
33 empty, empty, empty, empty, empty, &
34 id, d, 0, obj) < 3 &
35 .or. omp_target_memcpy_rect_async (C_NULL_PTR, C_NULL_PTR, 0_c_size_t, 0, &
36 empty, empty, empty, empty, empty, &
37 id, id, 0, obj) < 3) &
38 stop 1
39
40 q = [(0, i = 0, 127)]
41 if (omp_target_memcpy (p, c_loc (q), 128 * sizeof (q(0)), 0_c_size_t, &
42 0_c_size_t, d, id) /= 0) &
43 stop 2
44
45 q = [(i+1, i = 0, 127)]
46
47 volume(2) = 3
48 volume(1) = 2
49 volume(0) = 1
50 dst_offsets(2) = 0
51 dst_offsets(1) = 0
52 dst_offsets(0) = 0
53 src_offsets(2) = 0
54 src_offsets(1) = 0
55 src_offsets(0) = 0
56 dst_dimensions(2) = 5
57 dst_dimensions(1) = 4
58 dst_dimensions(0) = 3
59 src_dimensions(2) = 4
60 src_dimensions(1) = 3
61 src_dimensions(0) = 2
62
63 if (omp_target_memcpy_rect_async (p, c_loc (q), sizeof (q(0)), 3, volume, &
64 dst_offsets, src_offsets, dst_dimensions, src_dimensions, d, id, 0, &
65 obj) /= 0) &
66 stop 3
67
68 !$omp taskwait
69
70 q2 = [(0, i = 0, 127)]
71 if (omp_target_memcpy (c_loc (q2), p, 128 * sizeof (q2(0)), 0_c_size_t, &
72 0_c_size_t, id, d) /= 0) &
73 stop 4
74
75 ! q2 is expected to contain: 1 2 3 0 0 5 6 7 0 0 .. 0
76 if (q2(0) /= 1 .or. q2(1) /= 2 .or. q2(2) /= 3 .or. q2(3) /= 0 &
77 .or. q2(4) /= 0 .or. q2(5) /= 5 .or. q2(6) /= 6 .or. q2(7) /= 7) &
78 stop 5
79
80 do j = 8, 127
81 if (q2(j) /= 0) &
82 stop 6
83 end do
84
85 call omp_target_free (p, d)
86 end program main