diff options
author | Thomas Schwinge <thomas@codesourcery.com> | 2019-12-09 23:52:56 +0100 |
---|---|---|
committer | Thomas Schwinge <tschwinge@gcc.gnu.org> | 2019-12-09 23:52:56 +0100 |
commit | 47afc7b4ddd124bf8bb0747920c5e5906e4704c3 (patch) | |
tree | ab50a6d8c9d2d8c3ce075a07fc9d2d8c32a5a207 /libgomp/oacc-mem.c | |
parent | cec41816c18f2857f8362825222ef4de0a6e596e (diff) | |
download | gcc-47afc7b4ddd124bf8bb0747920c5e5906e4704c3.zip gcc-47afc7b4ddd124bf8bb0747920c5e5906e4704c3.tar.gz gcc-47afc7b4ddd124bf8bb0747920c5e5906e4704c3.tar.bz2 |
[PR92116, PR92877] [OpenACC] Replace 'openacc.data_environ' by standard libgomp mechanics
libgomp/
PR libgomp/92116
PR libgomp/92877
* oacc-mem.c (lookup_dev): Reimplement. Adjust all users.
* libgomp.h (struct acc_dispatch_t): Remove 'data_environ' member.
Adjust all users.
* testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-4-2.c:
Remove XFAIL.
* testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-4.c:
Likewise.
* testsuite/libgomp.oacc-c-c++-common/pr92877-1.c: New file.
Co-Authored-By: Julian Brown <julian@codesourcery.com>
From-SVN: r279147
Diffstat (limited to 'libgomp/oacc-mem.c')
-rw-r--r-- | libgomp/oacc-mem.c | 121 |
1 files changed, 27 insertions, 94 deletions
diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c index 81ebddf..369a116 100644 --- a/libgomp/oacc-mem.c +++ b/libgomp/oacc-mem.c @@ -50,44 +50,42 @@ lookup_host (struct gomp_device_descr *dev, void *h, size_t s) return key; } -/* Return block containing [D->S), or NULL if not contained. - The list isn't ordered by device address, so we have to iterate - over the whole array. This is not expected to be a common - operation. The device lock associated with TGT must be locked on entry, and - remains locked on exit. */ +/* Helper for lookup_dev. Iterate over splay tree. */ static splay_tree_key -lookup_dev (struct target_mem_desc *tgt, void *d, size_t s) +lookup_dev_1 (splay_tree_node node, uintptr_t d, size_t s) { - int i; - struct target_mem_desc *t; + splay_tree_key key = &node->key; + if (d >= key->tgt->tgt_start && d + s <= key->tgt->tgt_end) + return key; - if (!tgt) - return NULL; + key = NULL; + if (node->left) + key = lookup_dev_1 (node->left, d, s); + if (!key && node->right) + key = lookup_dev_1 (node->right, d, s); - for (t = tgt; t != NULL; t = t->prev) - { - if (t->tgt_start <= (uintptr_t) d && t->tgt_end >= (uintptr_t) d + s) - break; - } + return key; +} - if (!t) - return NULL; +/* Return block containing [D->S), or NULL if not contained. - for (i = 0; i < t->list_count; i++) - { - void * offset; + This iterates over the splay tree. This is not expected to be a common + operation. - splay_tree_key k = &t->array[i].key; - offset = d - t->tgt_start + k->tgt_offset; + The device lock associated with MEM_MAP must be locked on entry, and remains + locked on exit. */ - if (k->host_start + offset <= (void *) k->host_end) - return k; - } +static splay_tree_key +lookup_dev (splay_tree mem_map, void *d, size_t s) +{ + if (!mem_map || !mem_map->root) + return NULL; - return NULL; + return lookup_dev_1 (mem_map->root, (uintptr_t) d, s); } + /* OpenACC is silent on how memory exhaustion is indicated. We return NULL. */ @@ -147,7 +145,7 @@ acc_free (void *d) /* We don't have to call lazy open here, as the ptr value must have been returned by acc_malloc. It's not permitted to pass NULL in (unless you got that null from acc_malloc). */ - if ((k = lookup_dev (acc_dev->openacc.data_environ, d, 1))) + if ((k = lookup_dev (&acc_dev->mem_map, d, 1))) { void *offset = d - k->tgt->tgt_start + k->tgt_offset; void *h = k->host_start + offset; @@ -300,7 +298,7 @@ acc_hostptr (void *d) gomp_mutex_lock (&acc_dev->lock); - n = lookup_dev (acc_dev->openacc.data_environ, d, 1); + n = lookup_dev (&acc_dev->mem_map, d, 1); if (!n) { @@ -395,7 +393,7 @@ acc_map_data (void *h, void *d, size_t s) (int)s); } - if (lookup_dev (thr->dev->openacc.data_environ, d, s)) + if (lookup_dev (&thr->dev->mem_map, d, s)) { gomp_mutex_unlock (&acc_dev->lock); gomp_fatal ("device address [%p, +%d] is already mapped", (void *)d, @@ -418,11 +416,6 @@ acc_map_data (void *h, void *d, size_t s) thr->api_info = NULL; } } - - gomp_mutex_lock (&acc_dev->lock); - tgt->prev = acc_dev->openacc.data_environ; - acc_dev->openacc.data_environ = tgt; - gomp_mutex_unlock (&acc_dev->lock); } void @@ -482,25 +475,11 @@ acc_unmap_data (void *h) if (t->refcount == 2) { - struct target_mem_desc *tp; - /* This is the last reference, so pull the descriptor off the chain. This avoids gomp_unmap_vars via gomp_unmap_tgt from freeing the device memory. */ t->tgt_end = 0; t->to_free = 0; - - for (tp = NULL, t = acc_dev->openacc.data_environ; t != NULL; - tp = t, t = t->prev) - if (n->tgt == t) - { - if (tp) - tp->prev = t->prev; - else - acc_dev->openacc.data_environ = t->prev; - - break; - } } gomp_mutex_unlock (&acc_dev->lock); @@ -597,13 +576,7 @@ present_create_copy (unsigned f, void *h, size_t s, int async) /* Initialize dynamic refcount. */ tgt->list[0].key->dynamic_refcount = 1; - gomp_mutex_lock (&acc_dev->lock); - d = tgt->to_free; - tgt->prev = acc_dev->openacc.data_environ; - acc_dev->openacc.data_environ = tgt; - - gomp_mutex_unlock (&acc_dev->lock); } if (profiling_p) @@ -749,21 +722,6 @@ delete_copyout (unsigned f, void *h, size_t s, int async, const char *libfnname) if (n->refcount == 0) { - if (n->tgt->refcount == 2) - { - struct target_mem_desc *tp, *t; - for (tp = NULL, t = acc_dev->openacc.data_environ; t != NULL; - tp = t, t = t->prev) - if (n->tgt == t) - { - if (tp) - tp->prev = t->prev; - else - acc_dev->openacc.data_environ = t->prev; - break; - } - } - if (f & FLAG_COPYOUT) { goacc_aq aq = get_goacc_asyncqueue (async); @@ -954,11 +912,6 @@ gomp_acc_insert_pointer (size_t mapnum, void **hostaddrs, size_t *sizes, /* Initialize dynamic refcount. */ tgt->list[0].key->dynamic_refcount = 1; - - gomp_mutex_lock (&acc_dev->lock); - tgt->prev = acc_dev->openacc.data_environ; - acc_dev->openacc.data_environ = tgt; - gomp_mutex_unlock (&acc_dev->lock); } void @@ -1009,26 +962,6 @@ gomp_acc_remove_pointer (void *h, size_t s, bool force_copyfrom, int async, if (n->refcount == 0) { - if (t->refcount == minrefs) - { - /* This is the last reference, so pull the descriptor off the - chain. This prevents gomp_unmap_vars via gomp_unmap_tgt from - freeing the device memory. */ - struct target_mem_desc *tp; - for (tp = NULL, t = acc_dev->openacc.data_environ; t != NULL; - tp = t, t = t->prev) - { - if (n->tgt == t) - { - if (tp) - tp->prev = t->prev; - else - acc_dev->openacc.data_environ = t->prev; - break; - } - } - } - /* Set refcount to 1 to allow gomp_unmap_vars to unmap it. */ n->refcount = 1; t->refcount = minrefs; |