1 /* Verify device memory allocation/deallocation
2 { dg-additional-options "-DOPENACC_RUNTIME" } using OpenACC Runtime Library routines,
3 { dg-additional-options "-DPOINTERS" } using pointers. */
5 /* { dg-skip-if "" { *-*-* } { "-DACC_MEM_SHARED=1" } } */
8 #elif OPENACC_DIRECTIVES
29 static bool cb_ev_alloc_expected
;
30 static size_t cb_ev_alloc_bytes
;
31 static const void *cb_ev_alloc_device_ptr
;
33 cb_ev_alloc (acc_prof_info
*prof_info
, acc_event_info
*event_info
, acc_api_info
*api_info
)
35 assert (cb_ev_alloc_expected
);
36 cb_ev_alloc_expected
= false;
38 cb_ev_alloc_bytes
= event_info
->data_event
.bytes
;
39 cb_ev_alloc_device_ptr
= event_info
->data_event
.device_ptr
;
42 static bool cb_ev_free_expected
;
43 static const void *cb_ev_free_device_ptr
;
45 cb_ev_free (acc_prof_info
*prof_info
, acc_event_info
*event_info
, acc_api_info
*api_info
)
47 assert (cb_ev_free_expected
);
48 cb_ev_free_expected
= false;
50 cb_ev_free_device_ptr
= event_info
->data_event
.device_ptr
;
54 /* Match the alignment processing that
55 'libgomp/target.c:gomp_map_vars_internal' is doing; simplified, not
56 considering special alignment requirements of certain data types. */
59 aligned_size (size_t tgt_size
)
61 size_t tgt_align
= sizeof (void *);
62 return tgt_size
+ tgt_align
- 1;
66 aligned_address (const void *tgt_start
)
68 size_t tgt_align
= sizeof (void *);
69 return (void *) (((uintptr_t) tgt_start
+ tgt_align
- 1) & ~(tgt_align
- 1));
77 /* A "create", [...], "delete" sequence. */
82 cb_ev_alloc_expected
= false;
83 cb_ev_free_expected
= false;
84 acc_prof_register (acc_ev_alloc
, cb_ev_alloc
, acc_reg
);
85 acc_prof_register (acc_ev_free
, cb_ev_free
, acc_reg
);
88 char *h
= (char *) malloc (SIZE
);
94 cb_ev_alloc_expected
= true;
96 d
= acc_create (h
, SIZE
);
99 # pragma acc enter data create (h[0:SIZE])
101 # pragma acc enter data create (h)
103 d
= acc_deviceptr (h
);
106 assert (!cb_ev_alloc_expected
);
107 assert (cb_ev_alloc_bytes
== aligned_size (SIZE
));
108 assert (aligned_address (cb_ev_alloc_device_ptr
) == d
);
109 assert (acc_is_present (h
, SIZE
));
112 acc_create (h
, SIZE
);
115 # pragma acc enter data create (h[0:SIZE])
117 # pragma acc enter data create (h)
122 # pragma acc data create (h[0:SIZE])
125 # pragma acc data create (h)
128 assert (acc_is_present (h
, SIZE
));
131 acc_delete (h
, SIZE
);
134 # pragma acc exit data delete (h[0:SIZE])
136 # pragma acc exit data delete (h)
139 assert (acc_is_present (h
, SIZE
));
141 cb_ev_free_expected
= true;
143 acc_delete (h
, SIZE
);
146 # pragma acc exit data delete (h[0:SIZE])
148 # pragma acc exit data delete (h)
151 assert (!cb_ev_free_expected
);
152 assert (cb_ev_free_device_ptr
== cb_ev_alloc_device_ptr
);
153 assert (!acc_is_present (h
, SIZE
));
159 acc_prof_unregister (acc_ev_alloc
, cb_ev_alloc
, acc_reg
);
160 acc_prof_unregister (acc_ev_free
, cb_ev_free
, acc_reg
);
164 /* A "map", [...] "unmap" sequence. */
169 cb_ev_alloc_expected
= false;
170 cb_ev_free_expected
= false;
171 acc_prof_register (acc_ev_alloc
, cb_ev_alloc
, acc_reg
);
172 acc_prof_register (acc_ev_free
, cb_ev_free
, acc_reg
);
175 char *h
= (char *) malloc (SIZE
);
181 cb_ev_alloc_expected
= true;
182 d
= acc_malloc (SIZE
);
184 assert (!cb_ev_alloc_expected
);
185 assert (cb_ev_alloc_bytes
== SIZE
);
186 assert (cb_ev_alloc_device_ptr
== d
);
188 acc_map_data (h
, d
, SIZE
);
189 assert (acc_is_present (h
, SIZE
));
192 acc_create (h
, SIZE
);
195 # pragma acc enter data create (h[0:SIZE])
197 # pragma acc enter data create (h)
202 # pragma acc data create (h[0:SIZE])
205 # pragma acc data create (h)
208 assert (acc_is_present (h
, SIZE
));
211 acc_delete (h
, SIZE
);
214 # pragma acc exit data delete (h[0:SIZE])
216 # pragma acc exit data delete (h)
219 assert (acc_is_present (h
, SIZE
));
222 assert (!acc_is_present (h
, SIZE
));
224 cb_ev_free_expected
= true;
226 assert (!cb_ev_free_expected
);
227 assert (cb_ev_free_device_ptr
== cb_ev_alloc_device_ptr
);
233 acc_prof_unregister (acc_ev_alloc
, cb_ev_alloc
, acc_reg
);
234 acc_prof_unregister (acc_ev_free
, cb_ev_free
, acc_reg
);
238 /* A structured 'data' construct. */
243 cb_ev_alloc_expected
= false;
244 cb_ev_free_expected
= false;
245 acc_prof_register (acc_ev_alloc
, cb_ev_alloc
, acc_reg
);
246 acc_prof_register (acc_ev_free
, cb_ev_free
, acc_reg
);
249 char *h
= (char *) malloc (SIZE
);
254 cb_ev_alloc_expected
= true;
256 # pragma acc data create (h[0:SIZE])
258 # pragma acc data create (h)
261 void *d
= acc_deviceptr (h
);
263 assert (!cb_ev_alloc_expected
);
264 assert (cb_ev_alloc_bytes
== aligned_size (SIZE
));
265 assert (aligned_address (cb_ev_alloc_device_ptr
) == d
);
266 assert (acc_is_present (h
, SIZE
));
269 acc_create (h
, SIZE
);
272 # pragma acc enter data create (h[0:SIZE])
274 # pragma acc enter data create (h)
279 # pragma acc data create (h[0:SIZE])
282 # pragma acc data create (h)
285 assert (acc_is_present (h
, SIZE
));
288 acc_delete (h
, SIZE
);
291 # pragma acc exit data delete (h[0:SIZE])
293 # pragma acc exit data delete (h)
296 assert (acc_is_present (h
, SIZE
));
298 cb_ev_free_expected
= true;
300 assert (!cb_ev_free_expected
);
301 assert (cb_ev_free_device_ptr
== cb_ev_alloc_device_ptr
);
302 assert (!acc_is_present (h
, SIZE
));
308 acc_prof_unregister (acc_ev_alloc
, cb_ev_alloc
, acc_reg
);
309 acc_prof_unregister (acc_ev_free
, cb_ev_free
, acc_reg
);