diff mbox series

[OpenACC] Use 'tgt' returned from 'gomp_map_vars' (was: [PATCH 02/13] OpenACC reference count overhaul)

Message ID 87mu5isnrg.fsf@euler.schwinge.homeip.net
State New
Headers show
Series [OpenACC] Use 'tgt' returned from 'gomp_map_vars' (was: [PATCH 02/13] OpenACC reference count overhaul) | expand

Commit Message

Thomas Schwinge June 4, 2020, 6:13 p.m. UTC
Hi!

On 2020-05-19T17:42:22+0200, I wrote:
> On 2019-12-17T22:02:27-0800, Julian Brown <julian@codesourcery.com> wrote:
>> --- a/libgomp/oacc-mem.c
>> +++ b/libgomp/oacc-mem.c
>
>> @@ -571,14 +570,16 @@ present_create_copy (unsigned f, void *h, size_t s, int async)
>>
>>        goacc_aq aq = get_goacc_asyncqueue (async);
>>
>> -      tgt = gomp_map_vars_async (acc_dev, aq, mapnum, &hostaddrs, NULL, &s,
>> -                             &kinds, true, GOMP_MAP_VARS_OPENACC);
>> -      n = tgt->list[0].key;
>> -      assert (n->refcount == 1);
>> -      assert (n->dynamic_refcount == 0);
>> -      n->dynamic_refcount++;
>> +      gomp_map_vars_async (acc_dev, aq, mapnum, &hostaddrs, NULL, &s, &kinds,
>> +                       true, GOMP_MAP_VARS_OPENACC_ENTER_DATA);
>>
>> -      d = tgt->to_free;
>> +      gomp_mutex_lock (&acc_dev->lock);
>> +      n = lookup_host (acc_dev, h, s);
>> +      assert (n != NULL);
>> +      assert (n->tgt_offset == 0);
>> +      assert ((uintptr_t) h == n->host_start);
>> +      d = (void *) n->tgt->tgt_start;
>> +      gomp_mutex_unlock (&acc_dev->lock);
>>      }
>
> [...], is there a reason that you changed this code to look up
> 'n = lookup_host ([...])'?  This is the case that 'gomp_map_vars' enters
> a new mapping, so by construction, 'n = tgt->list[0].key' must hold?  I
> tested the following: [...], and don't see any regressions.

You've included something similar (even slightly better!) in a bigger
other patch that you've sent, so I've now combined/split that out, and
pushed "[OpenACC] Use 'tgt' returned from 'gomp_map_vars'" to master
branch in commit f233418ccf6a16eb3bf53018852c5f8926780143, and
releases/gcc-10 branch in commit
c44c9858962ab8045d57d531a83b430dd7be8d5a, see attached.


Grüße
 Thomas


-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter
diff mbox series

Patch

From c44c9858962ab8045d57d531a83b430dd7be8d5a Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Thu, 14 May 2020 15:49:52 +0200
Subject: [PATCH] [OpenACC] Use 'tgt' returned from 'gomp_map_vars'

	libgomp/
	* oacc-mem.c (goacc_enter_datum): Use 'tgt' returned from
	'gomp_map_vars'.
	 (acc_map_data): Clean up accordingly.

Co-Authored-By: Julian Brown <julian@codesourcery.com>
(cherry picked from commit f233418ccf6a16eb3bf53018852c5f8926780143)
---
 libgomp/oacc-mem.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index 6713846c9429..e2fb651a2334 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -355,7 +355,6 @@  acc_is_present (void *h, size_t s)
 void
 acc_map_data (void *h, void *d, size_t s)
 {
-  struct target_mem_desc *tgt = NULL;
   size_t mapnum = 1;
   void *hostaddrs = h;
   void *devaddrs = d;
@@ -402,10 +401,13 @@  acc_map_data (void *h, void *d, size_t s)
 
       gomp_mutex_unlock (&acc_dev->lock);
 
-      tgt = gomp_map_vars (acc_dev, mapnum, &hostaddrs, &devaddrs, &sizes,
-			   &kinds, true, GOMP_MAP_VARS_ENTER_DATA);
+      struct target_mem_desc *tgt
+	= gomp_map_vars (acc_dev, mapnum, &hostaddrs, &devaddrs, &sizes,
+			 &kinds, true, GOMP_MAP_VARS_ENTER_DATA);
       assert (tgt);
+      assert (tgt->list_count == 1);
       splay_tree_key n = tgt->list[0].key;
+      assert (n);
       assert (n->refcount == 1);
       assert (n->virtual_refcount == 0);
       /* Special reference counting behavior.  */
@@ -555,16 +557,17 @@  goacc_enter_datum (void **hostaddrs, size_t *sizes, void *kinds, int async)
 
       goacc_aq aq = get_goacc_asyncqueue (async);
 
-      gomp_map_vars_async (acc_dev, aq, mapnum, hostaddrs, NULL, sizes, kinds,
-			   true, GOMP_MAP_VARS_OPENACC_ENTER_DATA);
+      struct target_mem_desc *tgt
+	= gomp_map_vars_async (acc_dev, aq, mapnum, hostaddrs, NULL, sizes,
+			       kinds, true, GOMP_MAP_VARS_OPENACC_ENTER_DATA);
+      assert (tgt);
+      assert (tgt->list_count == 1);
+      n = tgt->list[0].key;
+      assert (n);
+      assert (n->refcount == 1);
+      assert (n->virtual_refcount == 0);
 
-      gomp_mutex_lock (&acc_dev->lock);
-      n = lookup_host (acc_dev, hostaddrs[0], sizes[0]);
-      assert (n != NULL);
-      assert (n->tgt_offset == 0);
-      assert ((uintptr_t) hostaddrs[0] == n->host_start);
-      d = (void *) n->tgt->tgt_start;
-      gomp_mutex_unlock (&acc_dev->lock);
+      d = (void *) tgt->tgt_start;
     }
 
   if (profiling_p)
-- 
2.26.2