1 /* Test if, if_present clauses on host_data construct. */
2
3 /* { dg-additional-options "-fopt-info-all-omp" }
4 { dg-additional-options "--param=openacc-privatization=noisy" }
5 { dg-additional-options "-foffload=-fopt-info-all-omp" }
6 { dg-additional-options "-foffload=--param=openacc-privatization=noisy" }
7 Prune a few: uninteresting, and potentially varying depending on GCC configuration (data types) or 'assert' implementation:
8 { dg-prune-output {note: variable 'D\.[0-9]+' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} }
9 { dg-prune-output {note: variable 'iftmp\.[0-9]+' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} } */
10
11 /* C/C++ variant of 'libgomp.oacc-fortran/host_data-5.F90' */
12
13 #include <assert.h>
14 #include <stdint.h>
15
16 void
17 foo (float *p, intptr_t host_p, int cond)
18 {
19 assert (p == (float *) host_p);
20
21 #pragma acc data copyin(host_p)
22 {
23 #pragma acc host_data use_device(p) if_present
24 /* { dg-note {variable 'host_p\.[0-9]+' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} "" { target *-*-* } .-1 } */
25 /* p not mapped yet, so it will be equal to the host pointer. */
26 assert (p == (float *) host_p);
27
28 #pragma acc data copy(p[0:100])
29 /* { dg-note {variable 'host_p\.[0-9]+' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} "" { target *-*-* } .-1 } */
30 {
31 /* Not inside a host_data construct, so p is still the host pointer. */
32 assert (p == (float *) host_p);
33
34 #pragma acc host_data use_device(p)
35 /* { dg-note {variable 'host_p\.[0-9]+' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} "" { target *-*-* } .-1 } */
36 {
37 #if ACC_MEM_SHARED
38 assert (p == (float *) host_p);
39 #else
40 /* The device address is different from host address. */
41 assert (p != (float *) host_p);
42 #endif
43 }
44
45 #pragma acc host_data use_device(p) if_present
46 /* { dg-note {variable 'host_p\.[0-9]+' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} "" { target *-*-* } .-1 } */
47 {
48 #if ACC_MEM_SHARED
49 assert (p == (float *) host_p);
50 #else
51 /* p is present now, so this is the same as above. */
52 assert (p != (float *) host_p);
53 #endif
54 }
55
56 #pragma acc host_data use_device(p) if(cond)
57 /* { dg-note {variable 'host_p\.[0-9]+' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} "" { target *-*-* } .-1 } */
58 {
59 #if ACC_MEM_SHARED
60 assert (p == (float *) host_p);
61 #else
62 /* p is the device pointer iff cond is true. */
63 assert ((p != (float *) host_p) == cond);
64 #endif
65 }
66 }
67 }
68 }
69
70 int
71 main (void)
72 {
73 float arr[100];
74 foo (arr, (intptr_t) arr, 0);
75 foo (arr, (intptr_t) arr, 1);
76
77 return 0;
78 }