[OpenACC] Don't open-code 'gomp_remove_var' in 'acc_unmap_data' (was: [PATCH 2/7] [OpenACC] Adjust dynamic reference count semantics)

Message ID 87eequsn4x.fsf@euler.schwinge.homeip.net
State New
Headers show
Series
  • [OpenACC] Don't open-code 'gomp_remove_var' in 'acc_unmap_data' (was: [PATCH 2/7] [OpenACC] Adjust dynamic reference count semantics)
Related show

Commit Message

Thomas Schwinge June 4, 2020, 6:26 p.m.
Hi Julian!

On 2020-05-22T15:16:05-0700, Julian Brown <julian@codesourcery.com> wrote:
> --- a/libgomp/oacc-mem.c

> +++ b/libgomp/oacc-mem.c


> @@ -475,14 +475,19 @@ acc_unmap_data (void *h)

>        gomp_mutex_unlock (&acc_dev->lock);

>        gomp_fatal ("cannot unmap target block");

>      }

> -  else if (tgt->refcount > 1)

> -    tgt->refcount--;

> -  else

> +

> +  if (tgt->refcount == 1)

>      {

> -      free (tgt->array);

> -      free (tgt);

> +      /* This is the last reference.  Nullifying these fields prevents

> +      'gomp_unmap_tgt' via 'gomp_remove_var' from freeing the target

> +      memory.  */

> +      tgt->tgt_end = 0;

> +      tgt->to_free = NULL;

>      }

>

> +  bool is_tgt_unmapped = gomp_remove_var (acc_dev, n);

> +  assert (is_tgt_unmapped);


Also should again remove the 'splay_tree_remove' that you'd added further
up.  I've pushed "[OpenACC] Don't open-code 'gomp_remove_var' in
'acc_unmap_data'" to master branch in commit
2112d3242f413979931e371423dcead9d19440e7, and releases/gcc-10 branch in
commit 1bca30efec5d684f03dfb88ed93cbe26e68d35b0, 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

Patch

From 1bca30efec5d684f03dfb88ed93cbe26e68d35b0 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Fri, 29 May 2020 14:21:03 +0200
Subject: [PATCH] [OpenACC] Don't open-code 'gomp_remove_var' in
 'acc_unmap_data'

	libgomp/
	* oacc-mem.c (acc_unmap_data): Don't open-code 'gomp_remove_var'.

Co-Authored-By: Julian Brown <julian@codesourcery.com>
(cherry picked from commit 2112d3242f413979931e371423dcead9d19440e7)
---
 libgomp/oacc-mem.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index 6314f5d8b686..8e8c7c3093d5 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -468,8 +468,6 @@  acc_unmap_data (void *h)
 		  (void *) h, (int) host_size);
     }
 
-  splay_tree_remove (&acc_dev->mem_map, n);
-
   struct target_mem_desc *tgt = n->tgt;
 
   if (tgt->refcount == REFCOUNT_INFINITY)
@@ -482,8 +480,12 @@  acc_unmap_data (void *h)
      'acc_map_data'.  */
   assert (tgt->refcount == 1);
 
-  free (tgt->array);
-  free (tgt);
+  /* Nullifying these fields prevents 'gomp_unmap_tgt' via 'gomp_remove_var'
+     from freeing the target memory.  */
+  tgt->tgt_end = 0;
+  tgt->to_free = NULL;
+
+  gomp_remove_var (acc_dev, n);
 
   gomp_mutex_unlock (&acc_dev->lock);
 
-- 
2.26.2