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>
87 lines
2.0 KiB
C
87 lines
2.0 KiB
C
/* { dg-skip-if "" { *-*-* } { "-DACC_MEM_SHARED=1" } } */
|
|
|
|
/* Variant of 'deep-copy-7.c'. */
|
|
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include <openacc.h>
|
|
|
|
struct dc
|
|
{
|
|
int a;
|
|
int *b;
|
|
};
|
|
|
|
int
|
|
main ()
|
|
{
|
|
int n = 100, i, j, k;
|
|
struct dc v = { .a = 3 };
|
|
|
|
v.b = (int *) malloc (sizeof (int) * n);
|
|
|
|
for (k = 0; k < 16; k++)
|
|
{
|
|
/* Here, we do not explicitly copy the enclosing structure, but work
|
|
with fields directly. Make sure attachment counters and reference
|
|
counters work properly in that case. */
|
|
#pragma acc enter data copyin(v.a, v.b[0:n]) // 1
|
|
assert (acc_is_present (&v.b, sizeof v.b));
|
|
assert (acc_is_present (v.b, sizeof (int) * n));
|
|
#pragma acc enter data pcopyin(v.b[0:n]) // 2
|
|
#pragma acc enter data pcopyin(v.b[0:n]) // 3
|
|
|
|
#pragma acc parallel loop present(v.a, v.b)
|
|
for (i = 0; i < n; i++)
|
|
v.b[i] = k + v.a + i;
|
|
|
|
switch (k % 5)
|
|
{ // All optional.
|
|
case 0:
|
|
break;
|
|
case 1:
|
|
; //TODO PR95901
|
|
#pragma acc exit data detach(v.b) finalize
|
|
break;
|
|
case 2:
|
|
; //TODO PR95901
|
|
#pragma acc exit data detach(v.b)
|
|
break;
|
|
case 3:
|
|
acc_detach_finalize ((void **) &v.b);
|
|
break;
|
|
case 4:
|
|
acc_detach ((void **) &v.b);
|
|
break;
|
|
}
|
|
assert (acc_is_present (&v.b, sizeof v.b));
|
|
assert (acc_is_present (v.b, sizeof (int) * n));
|
|
{ // 3
|
|
acc_delete (&v.b, sizeof v.b);
|
|
assert (acc_is_present (&v.b, sizeof v.b));
|
|
acc_copyout (v.b, sizeof (int) * n);
|
|
assert (acc_is_present (v.b, sizeof (int) * n));
|
|
}
|
|
{ // 2
|
|
acc_delete (&v.b, sizeof v.b);
|
|
assert (acc_is_present (&v.b, sizeof v.b));
|
|
acc_copyout (v.b, sizeof (int) * n);
|
|
assert (acc_is_present (v.b, sizeof (int) * n));
|
|
}
|
|
{ // 1
|
|
acc_delete (&v.b, sizeof v.b);
|
|
assert (!acc_is_present (&v.b, sizeof v.b));
|
|
acc_copyout (v.b, sizeof (int) * n);
|
|
assert (!acc_is_present (v.b, sizeof (int) * n));
|
|
}
|
|
#pragma acc exit data delete(v.a)
|
|
|
|
for (i = 0; i < n; i++)
|
|
assert (v.b[i] == k + v.a + i);
|
|
|
|
assert (!acc_is_present (&v, sizeof (v)));
|
|
}
|
|
|
|
return 0;
|
|
}
|