Debian Codegraph @

libgomp/testsuite/libgomp.fortran/dispatch-2.f90

raw
1 module m
2 use iso_c_binding
3 implicit none (type, external)
4 type(c_ptr) :: ref1, ref2, ref3, ref4
5 contains
6 subroutine foo(v, w, x, y)
7 type(C_ptr) :: v, w, x, y
8 value :: w, y
9 optional :: x, y
10 !$omp declare variant(bar) match ( construct = { dispatch } ) &
11 !$omp& adjust_args(need_device_ptr : v, w, x, y )
12 stop 1 ! should not get called
13 end
14 subroutine bar(a, b, c, d)
15 type(C_ptr) :: a, b, c, d
16 value :: b, d
17 optional :: c, d
18 if (.not. c_associated (a, ref1)) stop 2
19 if (.not. c_associated (b, ref2)) stop 3
20 if (.not. c_associated (c, ref3)) stop 3
21 if (.not. c_associated (d, ref4)) stop 3
22 end
23 end
24
25 program main
26 use omp_lib
27 use m
28 implicit none (type, external)
29 integer, target :: a, b, c, d
30 type(c_ptr) :: v, w, y, z
31 integer :: dev
32
33 do dev = -1, omp_get_num_devices ()
34 print *, 'dev ', dev
35
36 ! Cross check (1)
37 ref1 = omp_target_alloc (32_c_size_t, dev)
38 ref2 = omp_target_alloc (32_c_size_t, dev)
39 ref3 = omp_target_alloc (32_c_size_t, dev)
40 ref4 = omp_target_alloc (32_c_size_t, dev)
41 call bar (ref1, ref2, ref3, ref4)
42 call omp_target_free (ref1, dev)
43 call omp_target_free (ref2, dev)
44 call omp_target_free (ref3, dev)
45 call omp_target_free (ref4, dev)
46
47 v = c_loc(a)
48 w = c_loc(b)
49 y = c_loc(b)
50 z = c_loc(b)
51
52 !$omp target enter data device(dev) map(a, b, c, d)
53
54 ! Cross check (2)
55 ! This should be effectively identical to 'dispatch'
56 !$omp target data device(dev) use_device_ptr(v, w, y, z)
57 ref1 = v
58 ref2 = w
59 ref3 = y
60 ref4 = z
61 call bar (v, w, y, z)
62 !$omp end target data
63
64 !$omp dispatch device(dev)
65 call foo (v, w, y, z)
66
67 !$omp target exit data device(dev) map(a, b, c, d)
68 end do
69 end