openacc: Deep copy attach/detach should not affect reference counts
authorJulian Brown <julian@codesourcery.com>
Thu, 18 Jun 2020 12:11:08 +0000 (05:11 -0700)
committerJulian Brown <julian@codesourcery.com>
Mon, 27 Jul 2020 16:16:57 +0000 (09:16 -0700)
commitbc4ed079dc09a62168699227a794ac52a5b6f6a4
tree48c5dac67ba13e457724af37f8cec35501cf3d2e
parent2251b4a5423efa8ee0d7e67537b63e404a1f6afa
openacc: Deep copy attach/detach should not affect reference counts

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>
libgomp/libgomp.h
libgomp/oacc-mem.c
libgomp/target.c
libgomp/testsuite/libgomp.oacc-c-c++-common/mdc-refcount-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.oacc-c-c++-common/mdc-refcount-2.c [new file with mode: 0644]
libgomp/testsuite/libgomp.oacc-c-c++-common/mdc-refcount-3.c [new file with mode: 0644]
libgomp/testsuite/libgomp.oacc-fortran/deep-copy-6-no_finalize.F90
libgomp/testsuite/libgomp.oacc-fortran/deep-copy-6.f90