From 77ce5555480140ec57c4d39169dfff19ad4a7d96 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Wed, 18 Dec 2019 18:02:37 +0100 Subject: [PATCH] [OpenACC] Refactor 'goacc_enter_data' so that it can be called from 'goacc_insert_pointer', "present" case, and simplify No functional changes. libgomp/ * oacc-mem.c (goacc_enter_data): Refactor, so that it can be called... (goacc_insert_pointer): ... from here, "present" case. (goacc_insert_pointer): Inline function into... (GOACC_enter_exit_data): ... here, and simplify. From-SVN: r279540 --- libgomp/ChangeLog | 6 +++ libgomp/oacc-mem.c | 92 ++++++++++++++++++++-------------------------- 2 files changed, 46 insertions(+), 52 deletions(-) diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index 7cf85682e7b..779f276ca99 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,5 +1,11 @@ 2019-12-18 Thomas Schwinge + * oacc-mem.c (goacc_enter_data): Refactor, so that it can be + called... + (goacc_insert_pointer): ... from here, "present" case. + (goacc_insert_pointer): Inline function into... + (GOACC_enter_exit_data): ... here, and simplify. + * oacc-mem.c (goacc_enter_data): Refactor, so that it can be called... (goacc_insert_pointer): ... from here, "not present" case. diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c index 3806e2d69a0..15eb17b846e 100644 --- a/libgomp/oacc-mem.c +++ b/libgomp/oacc-mem.c @@ -513,6 +513,9 @@ goacc_enter_data (size_t mapnum, void **hostaddrs, size_t *sizes, void *kinds, if (mapnum == 1 && (!hostaddrs[0] || !sizes[0])) gomp_fatal ("[%p,+%d] is a bad range", hostaddrs[0], (int) sizes[0]); + else if (mapnum > 1 + && !hostaddrs[0]) + return /* n/a */ (void *) -1; goacc_lazy_initialize (); @@ -539,9 +542,8 @@ goacc_enter_data (size_t mapnum, void **hostaddrs, size_t *sizes, void *kinds, gomp_mutex_lock (&acc_dev->lock); n = lookup_host (acc_dev, hostaddrs[0], sizes[0]); - if (n) + if (n && mapnum == 1) { - assert (mapnum == 1); void *h = hostaddrs[0]; size_t s = sizes[0]; @@ -561,6 +563,32 @@ goacc_enter_data (size_t mapnum, void **hostaddrs, size_t *sizes, void *kinds, gomp_mutex_unlock (&acc_dev->lock); } + else if (n && mapnum > 1) + { + d = /* n/a */ (void *) -1; + + assert (n->refcount != REFCOUNT_INFINITY + && n->refcount != REFCOUNT_LINK); + + bool processed = false; + + struct target_mem_desc *tgt = n->tgt; + for (size_t i = 0; i < tgt->list_count; i++) + if (tgt->list[i].key == n) + { + for (size_t j = 0; j < mapnum; j++) + if (i + j < tgt->list_count && tgt->list[i + j].key) + { + tgt->list[i + j].key->refcount++; + tgt->list[i + j].key->dynamic_refcount++; + } + processed = true; + } + + gomp_mutex_unlock (&acc_dev->lock); + if (!processed) + gomp_fatal ("dynamic refcount incrementing failed for pointer/pset"); + } else { gomp_mutex_unlock (&acc_dev->lock); @@ -894,45 +922,6 @@ acc_update_self_async (void *h, size_t s, int async) ones implicitly follow suit. Similarly, 'copyout' is done only for the first mapping. */ -static void -goacc_insert_pointer (size_t mapnum, void **hostaddrs, size_t *sizes, - void *kinds, int async) -{ - struct target_mem_desc *tgt; - struct goacc_thread *thr = goacc_thread (); - struct gomp_device_descr *acc_dev = thr->dev; - - if (*hostaddrs == NULL) - return; - - if (acc_is_present (*hostaddrs, *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; - for (size_t i = 0; i < tgt->list_count; i++) - if (tgt->list[i].key == n) - { - for (size_t j = 0; j < mapnum; j++) - if (i + j < tgt->list_count && tgt->list[i + j].key) - { - tgt->list[i + j].key->refcount++; - tgt->list[i + j].key->dynamic_refcount++; - } - return; - } - /* Should not reach here. */ - gomp_fatal ("Dynamic refcount incrementing failed for pointer/pset"); - } - - goacc_enter_data (mapnum, hostaddrs, sizes, kinds, async); -} - static void goacc_remove_pointer (void *h, size_t s, unsigned short kind, int async) { @@ -1190,18 +1179,17 @@ GOACC_enter_exit_data (int flags_m, size_t mapnum, void **hostaddrs, break; } - goacc_enter_data (1, &hostaddrs[i], &sizes[i], &kinds[i], async); - } - else - { - goacc_insert_pointer (pointer, &hostaddrs[i], &sizes[i], &kinds[i], - async); - /* Increment 'i' by two because OpenACC requires fortran - arrays to be contiguous, so each PSET is associated with - one of MAP_FORCE_ALLOC/MAP_FORCE_PRESET/MAP_FORCE_TO, and - one MAP_POINTER. */ - i += pointer - 1; + /* We actually have one mapping. */ + pointer = 1; } + + goacc_enter_data (pointer, &hostaddrs[i], &sizes[i], &kinds[i], + async); + /* If applicable, increment 'i' further; OpenACC requires fortran + arrays to be contiguous, so each PSET is associated with + one of MAP_FORCE_ALLOC/MAP_FORCE_PRESET/MAP_FORCE_TO, and + one MAP_POINTER. */ + i += pointer - 1; } } else -- 2.30.2