bc4ed079dc
Attach and detach operations are not supposed to affect structural or dynamic reference counts for OpenACC. Previously they did so, which led to subtle problems in some circumstances. We can avoid reference-counting attach/detach operations by extending and slightly repurposing the do_detach field in target_var_desc. It is now called is_attach to better reflect its new role. 2020-07-27 Julian Brown <julian@codesourcery.com> Thomas Schwinge <thomas@codesourcery.com> libgomp/ * libgomp.h (struct target_var_desc): Rename do_detach field to is_attach. * oacc-mem.c (goacc_exit_datum_1): Add assert. Don't set finalize for GOMP_MAP_FORCE_DETACH. Update checking to use is_attach field. (goacc_enter_data_internal): Don't affect reference counts for attach mappings. (goacc_exit_data_internal): Don't affect reference counts for detach mappings. * target.c (gomp_map_vars_existing): Don't affect reference counts for attach mappings. (gomp_map_vars_internal): Set renamed is_attach flag unconditionally to mark attach mappings. (gomp_unmap_vars_internal): Use is_attach flag to prevent affecting reference count for attach mappings. * testsuite/libgomp.oacc-c-c++-common/mdc-refcount-1.c: New test. * testsuite/libgomp.oacc-c-c++-common/mdc-refcount-2.c: New test. * testsuite/libgomp.oacc-c-c++-common/mdc-refcount-2.c: New test. * testsuite/libgomp.oacc-fortran/deep-copy-6-no_finalize.F90: Mark test as shouldfail. * testsuite/libgomp.oacc-fortran/deep-copy-6.f90: Adjust to fail gracefully in no-finalize mode. Co-Authored-By: Thomas Schwinge <thomas@codesourcery.com>
61 lines
1008 B
C
61 lines
1008 B
C
/* { dg-skip-if "" { *-*-* } { "-DACC_MEM_SHARED=1" } } */
|
|
|
|
#include <openacc.h>
|
|
#include <assert.h>
|
|
|
|
#define N 1024
|
|
|
|
struct mystr {
|
|
int *data;
|
|
};
|
|
|
|
static void
|
|
test (unsigned variant)
|
|
{
|
|
int arr[N];
|
|
struct mystr s;
|
|
|
|
s.data = arr;
|
|
|
|
acc_copyin (&s, sizeof (s));
|
|
acc_create (s.data, N * sizeof (int));
|
|
|
|
for (int i = 0; i < 20; i++)
|
|
{
|
|
if ((variant + i) % 1)
|
|
{
|
|
#pragma acc enter data attach(s.data)
|
|
}
|
|
else
|
|
acc_attach ((void **) &s.data);
|
|
|
|
if ((variant + i) % 2)
|
|
{
|
|
#pragma acc exit data detach(s.data)
|
|
}
|
|
else
|
|
acc_detach ((void **) &s.data);
|
|
}
|
|
|
|
assert (acc_is_present (arr, N * sizeof (int)));
|
|
assert (acc_is_present (&s, sizeof (s)));
|
|
|
|
acc_delete (arr, N * sizeof (int));
|
|
|
|
assert (!acc_is_present (arr, N * sizeof (int)));
|
|
|
|
acc_copyout (&s, sizeof (s));
|
|
|
|
assert (!acc_is_present (&s, sizeof (s)));
|
|
assert (s.data == arr);
|
|
}
|
|
|
|
int
|
|
main (int argc, char *argv[])
|
|
{
|
|
for (unsigned variant = 0; variant < 4; ++variant)
|
|
test (variant);
|
|
|
|
return 0;
|
|
}
|