This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gomp4] Fix acc_shutdown issue.


Hi,

The attached patch fixes an issue that showed up
when running the C/C++ version of asyncwait-1
within the libgomp testsuite. The issue arose
because the entries added for the address
mapping tables were not complete. Now that they
are, a special function is no longer needed to
remove the entries and gomp_unmap_vars can be
used.

Committed to gomp-4_0-branch.

Jim
diff --git a/libgomp/oacc-init.c b/libgomp/oacc-init.c
index 3a1aa28..63ac710 100644
--- a/libgomp/oacc-init.c
+++ b/libgomp/oacc-init.c
@@ -293,9 +293,12 @@ acc_shutdown_1 (acc_device_t d)
 
       if (walk->dev)
 	{
-	  gomp_mutex_lock (&walk->dev->lock);
-	  gomp_free_memmap (&walk->dev->mem_map);
-	  gomp_mutex_unlock (&walk->dev->lock);
+	  while (walk->dev->mem_map.root)
+	    {
+	      struct target_mem_desc *tgt = walk->dev->mem_map.root->key.tgt;
+
+	      gomp_unmap_vars (tgt, false);
+	    }
 
 	  walk->dev = NULL;
 	  walk->base_dev = NULL;
diff --git a/libgomp/target.c b/libgomp/target.c
index 1062998..227fe26 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -680,14 +680,17 @@ gomp_load_image_to_device (struct gomp_device_descr *devicep,
     }
 
   /* Insert host-target address mapping into splay tree.  */
-  struct target_mem_desc *tgt = gomp_malloc (sizeof (*tgt));
+  struct target_mem_desc *tgt =
+	  gomp_malloc (sizeof (*tgt)
+		       + sizeof (tgt->list[0])
+		       * (num_funcs + num_vars) * sizeof (*tgt->array));
   tgt->array = gomp_malloc ((num_funcs + num_vars) * sizeof (*tgt->array));
   tgt->refcount = 1;
   tgt->tgt_start = 0;
   tgt->tgt_end = 0;
   tgt->to_free = NULL;
   tgt->prev = NULL;
-  tgt->list_count = 0;
+  tgt->list_count = num_funcs + num_vars;
   tgt->device_descr = devicep;
   splay_tree_node array = tgt->array;
 
@@ -702,6 +705,8 @@ gomp_load_image_to_device (struct gomp_device_descr *devicep,
       k->async_refcount = 0;
       k->copy_from = false;
       k->dealloc_host = false;
+      tgt->list[i] = k;
+      tgt->refcount++;
       array->left = NULL;
       array->right = NULL;
       splay_tree_insert (&devicep->mem_map, array);
@@ -729,6 +734,8 @@ gomp_load_image_to_device (struct gomp_device_descr *devicep,
       k->async_refcount = 0;
       k->copy_from = false;
       k->dealloc_host = false;
+      tgt->list[i] = k;
+      tgt->refcount++;
       array->left = NULL;
       array->right = NULL;
       splay_tree_insert (&devicep->mem_map, array);
@@ -898,22 +905,6 @@ gomp_unload_device (struct gomp_device_descr *devicep)
     }
 }
 
-/* Free address mapping tables.  MM must be locked on entry, and remains locked
-   on return.  */
-
-attribute_hidden void
-gomp_free_memmap (struct splay_tree_s *mem_map)
-{
-  while (mem_map->root)
-    {
-      struct target_mem_desc *tgt = mem_map->root->key.tgt;
-
-      splay_tree_remove (mem_map, &mem_map->root->key);
-      free (tgt->array);
-      free (tgt);
-    }
-}
-
 /* This function de-initializes the target device, specified by DEVICEP.
    DEVICEP must be locked on entry, and remains locked on return.  */
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]