gcc/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-3.c
Julian Brown 5d5be7bfb5 OpenACC 2.6 deep copy: attach/detach API routines
libgomp/
	* libgomp.h (struct splay_tree_aux): Add attach_count field.
	(gomp_attach_pointer, gomp_detach_pointer): Add prototypes.
	* libgomp.map (OACC_2.6): New section. Add acc_attach,
	acc_attach_async, acc_detach, acc_detach_async, acc_detach_finalize,
	acc_detach_finalize_async.
	* oacc-mem.c (acc_attach_async, acc_attach, goacc_detach_internal,
	acc_detach, acc_detach_async, acc_detach_finalize,
	acc_detach_finalize_async): New functions.
	* openacc.h (acc_attach, acc_attach_async, acc_detach,
	(acc_detach_async, acc_detach_finalize, acc_detach_finalize_async): Add
	prototypes.
	* target.c (gomp_attach_pointer, gomp_detach_pointer): New functions.
	(gomp_remove_var_internal): Free attachment counts if present.
	* testsuite/libgomp.oacc-c-c++-common/deep-copy-3.c: New test.
	* testsuite/libgomp.oacc-c-c++-common/deep-copy-5.c: New test.

Co-Authored-By: Thomas Schwinge <thomas@codesourcery.com>

From-SVN: r279624
2019-12-20 01:20:27 +00:00

35 lines
517 B
C

#include <assert.h>
#include <stdlib.h>
#include <openacc.h>
int
main ()
{
int n = 100, i;
int *a = (int *) malloc (sizeof (int) * n);
int *b;
for (i = 0; i < n; i++)
a[i] = i+1;
#pragma acc enter data copyin(a[:n]) create(b)
b = a;
acc_attach ((void **)&b);
#pragma acc parallel loop present (b[:n])
for (i = 0; i < n; i++)
b[i] = i+1;
acc_detach ((void **)&b);
#pragma acc exit data copyout(a[:n], b)
for (i = 0; i < 10; i++)
assert (a[i] == b[i]);
free (a);
return 0;
}