diff options
author | Thomas Schwinge <thomas@codesourcery.com> | 2019-12-11 17:49:27 +0100 |
---|---|---|
committer | Thomas Schwinge <tschwinge@gcc.gnu.org> | 2019-12-11 17:49:27 +0100 |
commit | d6e8c01cff1bee743a9d00e9a43303ec29fde233 (patch) | |
tree | a256dc21f4379bbf80ccbefa183250b98d71d98a /libgomp/oacc-mem.c | |
parent | 57963e3934de387ade6b314a5d72330c28f30806 (diff) |
[PR92843] [OpenACC] Fix dynamic reference counting for structured 'REFCOUNT_INFINITY'
libgomp/
PR libgomp/92843
* oacc-mem.c (present_create_copy, delete_copyout): Fix dynamic
reference counting for structured 'REFCOUNT_INFINITY'. Add some
assertions.
(goacc_insert_pointer, goacc_remove_pointer): Adjust accordingly.
* testsuite/libgomp.oacc-c-c++-common/pr92843-1.c: New file.
* testsuite/libgomp.oacc-c-c++-common/clauses-1.c: Fix OpenACC.
* testsuite/libgomp.oacc-c-c++-common/lib-82.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/nested-1.c: Likewise.
From-SVN: r279234
Diffstat (limited to 'libgomp/oacc-mem.c')
-rw-r--r-- | libgomp/oacc-mem.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c index 571e0606ac8..a809d0495a6 100644 --- a/libgomp/oacc-mem.c +++ b/libgomp/oacc-mem.c @@ -543,11 +543,11 @@ present_create_copy (unsigned f, void *h, size_t s, int async) gomp_fatal ("[%p,+%d] not mapped", (void *)h, (int)s); } + assert (n->refcount != REFCOUNT_LINK); if (n->refcount != REFCOUNT_INFINITY) - { - n->refcount++; - n->dynamic_refcount++; - } + n->refcount++; + n->dynamic_refcount++; + gomp_mutex_unlock (&acc_dev->lock); } else if (!(f & FLAG_CREATE)) @@ -573,8 +573,10 @@ present_create_copy (unsigned f, void *h, size_t s, int async) tgt = gomp_map_vars_async (acc_dev, aq, mapnum, &hostaddrs, NULL, &s, &kinds, true, GOMP_MAP_VARS_OPENACC); - /* Initialize dynamic refcount. */ - tgt->list[0].key->dynamic_refcount = 1; + n = tgt->list[0].key; + assert (n->refcount == 1); + assert (n->dynamic_refcount == 0); + n->dynamic_refcount++; d = tgt->to_free; } @@ -698,12 +700,9 @@ delete_copyout (unsigned f, void *h, size_t s, int async, const char *libfnname) (void *) h, (int) s, (void *) n->host_start, (int) host_size); } - if (n->refcount == REFCOUNT_INFINITY) - { - n->refcount = 0; - n->dynamic_refcount = 0; - } - if (n->refcount < n->dynamic_refcount) + assert (n->refcount != REFCOUNT_LINK); + if (n->refcount != REFCOUNT_INFINITY + && n->refcount < n->dynamic_refcount) { gomp_mutex_unlock (&acc_dev->lock); gomp_fatal ("Dynamic reference counting assert fail\n"); @@ -711,13 +710,15 @@ delete_copyout (unsigned f, void *h, size_t s, int async, const char *libfnname) if (f & FLAG_FINALIZE) { - n->refcount -= n->dynamic_refcount; + if (n->refcount != REFCOUNT_INFINITY) + n->refcount -= n->dynamic_refcount; n->dynamic_refcount = 0; } else if (n->dynamic_refcount) { + if (n->refcount != REFCOUNT_INFINITY) + n->refcount--; n->dynamic_refcount--; - n->refcount--; } if (n->refcount == 0) @@ -895,6 +896,8 @@ goacc_insert_pointer (size_t mapnum, void **hostaddrs, size_t *sizes, splay_tree_key n; gomp_mutex_lock (&acc_dev->lock); n = lookup_host (acc_dev, *hostaddrs, *sizes); + assert (n->refcount != REFCOUNT_INFINITY + && n->refcount != REFCOUNT_LINK); gomp_mutex_unlock (&acc_dev->lock); tgt = n->tgt; @@ -917,10 +920,11 @@ goacc_insert_pointer (size_t mapnum, void **hostaddrs, size_t *sizes, goacc_aq aq = get_goacc_asyncqueue (async); tgt = gomp_map_vars_async (acc_dev, aq, mapnum, hostaddrs, NULL, sizes, kinds, true, GOMP_MAP_VARS_OPENACC); + splay_tree_key n = tgt->list[0].key; + assert (n->refcount == 1); + assert (n->dynamic_refcount == 0); + n->dynamic_refcount++; gomp_debug (0, " %s: mappings prepared\n", __FUNCTION__); - - /* Initialize dynamic refcount. */ - tgt->list[0].key->dynamic_refcount = 1; } static void @@ -950,6 +954,8 @@ goacc_remove_pointer (void *h, size_t s, bool force_copyfrom, int async, t = n->tgt; + assert (n->refcount != REFCOUNT_INFINITY + && n->refcount != REFCOUNT_LINK); if (n->refcount < n->dynamic_refcount) { gomp_mutex_unlock (&acc_dev->lock); @@ -963,8 +969,8 @@ goacc_remove_pointer (void *h, size_t s, bool force_copyfrom, int async, } else if (n->dynamic_refcount) { - n->dynamic_refcount--; n->refcount--; + n->dynamic_refcount--; } gomp_mutex_unlock (&acc_dev->lock); |