]> gcc.gnu.org Git - gcc.git/commitdiff
[PR92503] [OpenACC] Don't silently 'acc_unmap_data' in 'acc_free'
authorThomas Schwinge <thomas@codesourcery.com>
Mon, 9 Dec 2019 22:52:47 +0000 (23:52 +0100)
committerThomas Schwinge <tschwinge@gcc.gnu.org>
Mon, 9 Dec 2019 22:52:47 +0000 (23:52 +0100)
libgomp/
PR libgomp/92503
* oacc-mem.c (acc_free): Error out instead of 'acc_unmap_data'.
* testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-1.c: New
file.
* testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-2.c:
Likewise.
* testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-3-2.c:
Likewise.
* testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-3.c:
Likewise.
* testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-4-2.c:
Likewise.
* testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-4.c:
Likewise.
* testsuite/libgomp.oacc-c-c++-common/clauses-1.c: Adjust.
* testsuite/libgomp.oacc-c-c++-common/context-1.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/context-2.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/context-3.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/context-4.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-13.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-14.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-18.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-91.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/nested-1.c: Likewise.

From-SVN: r279146

18 files changed:
libgomp/ChangeLog
libgomp/oacc-mem.c
libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-2.c [new file with mode: 0644]
libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-3-2.c [new file with mode: 0644]
libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-3.c [new file with mode: 0644]
libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-4-2.c [new file with mode: 0644]
libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-4.c [new file with mode: 0644]
libgomp/testsuite/libgomp.oacc-c-c++-common/clauses-1.c
libgomp/testsuite/libgomp.oacc-c-c++-common/context-1.c
libgomp/testsuite/libgomp.oacc-c-c++-common/context-2.c
libgomp/testsuite/libgomp.oacc-c-c++-common/context-3.c
libgomp/testsuite/libgomp.oacc-c-c++-common/context-4.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-13.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-14.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-18.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-91.c
libgomp/testsuite/libgomp.oacc-c-c++-common/nested-1.c

index 7606f17825dfb5a743e4ca1da9a3afa0ee113796..62092a2d765a15c81f7506fa0623c5dcde1ee74c 100644 (file)
@@ -1,5 +1,30 @@
 2019-12-09  Thomas Schwinge  <thomas@codesourcery.com>
 
+       PR libgomp/92503
+       * oacc-mem.c (acc_free): Error out instead of 'acc_unmap_data'.
+       * testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-1.c: New
+       file.
+       * testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-2.c:
+       Likewise.
+       * testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-3-2.c:
+       Likewise.
+       * testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-3.c:
+       Likewise.
+       * testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-4-2.c:
+       Likewise.
+       * testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-4.c:
+       Likewise.
+       * testsuite/libgomp.oacc-c-c++-common/clauses-1.c: Adjust.
+       * testsuite/libgomp.oacc-c-c++-common/context-1.c: Likewise.
+       * testsuite/libgomp.oacc-c-c++-common/context-2.c: Likewise.
+       * testsuite/libgomp.oacc-c-c++-common/context-3.c: Likewise.
+       * testsuite/libgomp.oacc-c-c++-common/context-4.c: Likewise.
+       * testsuite/libgomp.oacc-c-c++-common/lib-13.c: Likewise.
+       * testsuite/libgomp.oacc-c-c++-common/lib-14.c: Likewise.
+       * testsuite/libgomp.oacc-c-c++-common/lib-18.c: Likewise.
+       * testsuite/libgomp.oacc-c-c++-common/lib-91.c: Likewise.
+       * testsuite/libgomp.oacc-c-c++-common/nested-1.c: Likewise.
+
        PR libgomp/92840
        * oacc-mem.c (acc_map_data): Clarify reference counting behavior.
        (acc_unmap_data): Add error case for 'REFCOUNT_INFINITY'.
index 480b9fbb71bf2c4d9724480629d06de134def53b..81ebddf7580203ee2986ef2e3dd06b88a5f17e27 100644 (file)
@@ -121,9 +121,6 @@ acc_malloc (size_t s)
   return res;
 }
 
-/* OpenACC 2.0a (3.2.16) doesn't specify what to do in the event
-   the device address is mapped. We choose to check if it mapped,
-   and if it is, to unmap it. */
 void
 acc_free (void *d)
 {
@@ -152,13 +149,15 @@ acc_free (void *d)
      (unless you got that null from acc_malloc).  */
   if ((k = lookup_dev (acc_dev->openacc.data_environ, d, 1)))
     {
-      void *offset;
-
-      offset = d - k->tgt->tgt_start + k->tgt_offset;
-
+      void *offset = d - k->tgt->tgt_start + k->tgt_offset;
+      void *h = k->host_start + offset;
+      size_t h_size = k->host_end - k->host_start;
       gomp_mutex_unlock (&acc_dev->lock);
-
-      acc_unmap_data ((void *)(k->host_start + offset));
+      /* PR92503 "[OpenACC] Behavior of 'acc_free' if the memory space is still
+        used in a mapping".  */
+      gomp_fatal ("refusing to free device memory space at %p that is still"
+                 " mapped at [%p,+%d]",
+                 d, h, (int) h_size);
     }
   else
     gomp_mutex_unlock (&acc_dev->lock);
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-1.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-1.c
new file mode 100644 (file)
index 0000000..4fc6068
--- /dev/null
@@ -0,0 +1,28 @@
+/* Verify that we refuse 'acc_free', after 'acc_map_data'.  */
+
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <openacc.h>
+
+int
+main ()
+{
+  const int N = 108;
+
+  char *h = (char *) malloc (N);
+  void *d = acc_malloc (N - 10);
+  if (!d)
+    abort ();
+  acc_map_data (h, d, N - 19);
+
+  fprintf (stderr, "CheCKpOInT\n");
+  acc_free (d);
+
+  return 0;
+}
+
+/* { dg-output "CheCKpOInT(\n|\r\n|\r).*" }
+   { dg-output "refusing to free device memory space at \[0-9a-fA-FxX\]+ that is still mapped at \\\[\[0-9a-fA-FxX\]+,\\\+89\\\]" }
+   { dg-shouldfail "" } */
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-2.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-2.c
new file mode 100644 (file)
index 0000000..3f6a8e5
--- /dev/null
@@ -0,0 +1,27 @@
+/* Verify that we refuse 'acc_free', after 'acc_create'.  */
+
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <openacc.h>
+
+int
+main ()
+{
+  const int N = 108;
+
+  char *h = (char *) malloc (N);
+  void *d = acc_create (h, N - 1);
+  if (!d)
+    abort ();
+
+  fprintf (stderr, "CheCKpOInT\n");
+  acc_free (d);
+
+  return 0;
+}
+
+/* { dg-output "CheCKpOInT(\n|\r\n|\r).*" }
+   { dg-output "refusing to free device memory space at \[0-9a-fA-FxX\]+ that is still mapped at \\\[\[0-9a-fA-FxX\]+,\\\+107\\\]" }
+   { dg-shouldfail "" } */
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-3-2.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-3-2.c
new file mode 100644 (file)
index 0000000..9f45048
--- /dev/null
@@ -0,0 +1,28 @@
+/* Verify that we refuse 'acc_free', inside 'host_data', after '#pragma acc enter data create'.  */
+
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <openacc.h>
+
+int
+main ()
+{
+  const int N = 108;
+
+  char *h = (char *) malloc (N);
+#pragma acc enter data create (h[0:N - 2])
+
+#pragma acc host_data use_device (h)
+  {
+    fprintf (stderr, "CheCKpOInT\n");
+    acc_free (h);
+  }
+
+  return 0;
+}
+
+/* { dg-output "CheCKpOInT(\n|\r\n|\r).*" }
+   { dg-output "refusing to free device memory space at \[0-9a-fA-FxX\]+ that is still mapped at \\\[\[0-9a-fA-FxX\]+,\\\+106\\\]" }
+   { dg-shouldfail "" } */
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-3.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-3.c
new file mode 100644 (file)
index 0000000..1620830
--- /dev/null
@@ -0,0 +1,28 @@
+/* Verify that we refuse 'acc_free', after '#pragma acc enter data create'.  */
+
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <openacc.h>
+
+int
+main ()
+{
+  const int N = 108;
+
+  char *h = (char *) malloc (N);
+#pragma acc enter data create (h[0:N - 3])
+  void *d = acc_deviceptr (h);
+  if (!d)
+    abort ();
+
+  fprintf (stderr, "CheCKpOInT\n");
+  acc_free (d);
+
+  return 0;
+}
+
+/* { dg-output "CheCKpOInT(\n|\r\n|\r).*" }
+   { dg-output "refusing to free device memory space at \[0-9a-fA-FxX\]+ that is still mapped at \\\[\[0-9a-fA-FxX\]+,\\\+105\\\]" }
+   { dg-shouldfail "" } */
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-4-2.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-4-2.c
new file mode 100644 (file)
index 0000000..bbf4431
--- /dev/null
@@ -0,0 +1,31 @@
+/* Verify that we refuse 'acc_free', inside 'host_data', inside 'data'.  */
+
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <openacc.h>
+
+int
+main ()
+{
+  const int N = 108;
+
+  char *h = (char *) malloc (N);
+#pragma acc data create (h[0:N - 44])
+  {
+#pragma acc host_data use_device (h)
+    {
+      fprintf (stderr, "CheCKpOInT\n");
+      acc_free (h);
+    }
+  }
+
+  return 0;
+}
+
+/* { dg-output "CheCKpOInT(\n|\r\n|\r).*" }
+   TODO PR92877
+   { dg-output "libgomp: cuMemGetAddressRange_v2 error: named symbol not found" { target openacc_nvidia_accel_selected } }
+   { dg-output "refusing to free device memory space at \[0-9a-fA-FxX\]+ that is still mapped at \\\[\[0-9a-fA-FxX\]+,\\\+64\\\]" { xfail *-*-* } }
+   { dg-shouldfail "" } */
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-4.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_free-pr92503-4.c
new file mode 100644 (file)
index 0000000..6212f9e
--- /dev/null
@@ -0,0 +1,32 @@
+/* Verify that we refuse 'acc_free', inside 'data'.  */
+
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <openacc.h>
+
+int
+main ()
+{
+  const int N = 108;
+
+  char *h = (char *) malloc (N);
+#pragma acc data create (h[0:N - 21])
+  {
+    void *d = acc_deviceptr (h);
+    if (!d)
+      abort ();
+
+    fprintf (stderr, "CheCKpOInT\n");
+    acc_free (d);
+  }
+
+  return 0;
+}
+
+/* { dg-output "CheCKpOInT(\n|\r\n|\r).*" }
+   TODO PR92877
+   { dg-output "libgomp: cuMemGetAddressRange_v2 error: named symbol not found" { target openacc_nvidia_accel_selected } }
+   { dg-output "refusing to free device memory space at \[0-9a-fA-FxX\]+ that is still mapped at \\\[\[0-9a-fA-FxX\]+,\\\+87\\\]" { xfail *-*-* } }
+   { dg-shouldfail "" } */
index d36a2f1c3041690dfa7946083d643e8244ccf447..b0a96348c3a2085e18030071160482e246764ee2 100644 (file)
@@ -103,7 +103,10 @@ main (int argc, char **argv)
     if (acc_is_present (&b[0], (N * sizeof (float))))
       abort ();
 
-    acc_free (d);
+    acc_delete (&a[0], N * sizeof (float));
+
+    if (acc_is_present (&a[0], N * sizeof (float)))
+      abort ();
 
     for (i = 0; i < N; i++)
     {
@@ -162,7 +165,7 @@ main (int argc, char **argv)
     if (!acc_is_present (&b[0], (N * sizeof (float))))
       abort ();
 
-    acc_free (d);
+    acc_delete (&b[0], N * sizeof (float));
 
     if (acc_is_present (&b[0], (N * sizeof (float))))
       abort ();
@@ -557,7 +560,10 @@ main (int argc, char **argv)
     if (acc_is_present (&b[0], (N * sizeof (float))))
       abort ();
 
-    acc_free (d);
+    acc_delete (&a[0], N * sizeof (float));
+
+    if (acc_is_present (&a[0], N * sizeof (float)))
+      abort ();
 
     for (i = 0; i < N; i++)
     {
index dabc7063c68b9fc5da33dc70cb311f342cca7443..2e3b62ebbd26934b18a7f6ff942a99e2765344ba 100644 (file)
@@ -172,13 +172,13 @@ main (int argc, char **argv)
         exit (EXIT_FAILURE);
     }
 
+    acc_delete (&h_X[0], N * sizeof (float));
+    acc_delete (&h_Y1[0], N * sizeof (float));
+
     free (h_X);
     free (h_Y1);
     free (h_Y2);
 
-    acc_free (d_X);
-    acc_free (d_Y);
-
     context_check (pctx);
 
     s = cublasDestroy (h);
index 6a52f746dcb977a7165176b943ba600156a8d5ad..6bdcfe7d42924e7c66ae7ef5cddb77700cada34b 100644 (file)
@@ -182,13 +182,13 @@ main (int argc, char **argv)
         exit (EXIT_FAILURE);
     }
 
+    acc_delete (&h_X[0], N * sizeof (float));
+    acc_delete (&h_Y1[0], N * sizeof (float));
+
     free (h_X);
     free (h_Y1);
     free (h_Y2);
 
-    acc_free (d_X);
-    acc_free (d_Y);
-
     context_check (pctx);
 
     s = cublasDestroy (h);
index ccd276cd98f89554cf6761e9b55c20976d3ef500..8f14560ea8bcec77d03eada2f9b018828675ee95 100644 (file)
@@ -163,13 +163,13 @@ main (int argc, char **argv)
         exit (EXIT_FAILURE);
     }
 
+    acc_delete (&h_X[0], N * sizeof (float));
+    acc_delete (&h_Y1[0], N * sizeof (float));
+
     free (h_X);
     free (h_Y1);
     free (h_Y2);
 
-    acc_free (d_X);
-    acc_free (d_Y);
-
     context_check (pctx);
 
     s = cublasDestroy (h);
index 71365e8ed32e84f7b3887de9d63fe8faa378db0b..b403a5cf5cb48d9096fe5fba249a6d0f0ce12f49 100644 (file)
@@ -176,13 +176,13 @@ main (int argc, char **argv)
         exit (EXIT_FAILURE);
     }
 
+    acc_delete (&h_X[0], N * sizeof (float));
+    acc_delete (&h_Y1[0], N * sizeof (float));
+
     free (h_X);
     free (h_Y1);
     free (h_Y2);
 
-    acc_free (d_X);
-    acc_free (d_Y);
-
     context_check (pctx);
 
     s = cublasDestroy (h);
index d6655335e21571234cceee5761bcd312f81678cc..aca4c252091c7dc3c4714959a9cb2fced056c517 100644 (file)
@@ -51,7 +51,7 @@ main (int argc, char **argv)
   if (acc_is_present (h, 0) != 0)
     abort ();
 
-  acc_free (d);
+  acc_delete (h, N);
 
   if (acc_is_present (h, 1) != 0)
     abort ();
index ee21257c9a5d0da5542298360b82b68246202778..de6d38b060ce4f10be0e645ea1401ec49e047e76 100644 (file)
@@ -48,7 +48,7 @@ main (int argc, char **argv)
        abort ();
     }
 
-  acc_free (d);
+  acc_delete (h, N);
 
   for (i = 0; i < N; i++)
     {
index b686cc9481551d3ee449ca6a7df2c661904f9e9f..93bfb99f4153647f43a78a9c0750e73dc340b7e1 100644 (file)
@@ -23,7 +23,7 @@ main (int argc, char **argv)
 
   d = acc_copyin (h, N);
 
-  acc_free (d);
+  acc_delete (h, N);
 
   fprintf (stderr, "CheCKpOInT\n");
   acc_copyout (h, N);
index e00ef4f72062b877f728338170e5cf1ea0fafe1d..36fff089b83d856febf3f7f0cc638877d18f2e6a 100644 (file)
@@ -72,6 +72,8 @@ main (int argc, char **argv)
   if (async > (sync * 1.5))
     abort ();
 
+  acc_unmap_data (h);
+
   acc_free (d);
 
   free (h);
index 7ebfb8a562b791df4fd3140b50f16d5dae814927..4c599cda4b38fb81b2d3f18c66a076c9bb1357a1 100644 (file)
@@ -112,7 +112,10 @@ main (int argc, char **argv)
     if (acc_is_present (&b[0], (N * sizeof (float))))
       abort ();
 
-    acc_free (d);
+    acc_delete (&a[0], N * sizeof (float));
+
+    if (acc_is_present (&a[0], N * sizeof (float)))
+      abort ();
 
     for (i = 0; i < N; i++)
     {
@@ -177,7 +180,7 @@ main (int argc, char **argv)
     if (!acc_is_present (&b[0], (N * sizeof (float))))
       abort ();
 
-    acc_free (d);
+    acc_delete (&b[0], N * sizeof (float));
 
     if (acc_is_present (&b[0], (N * sizeof (float))))
       abort ();
@@ -609,7 +612,10 @@ main (int argc, char **argv)
     if (acc_is_present (&b[0], (N * sizeof (float))))
       abort ();
 
-    acc_free (d);
+    acc_delete (&a[0], N * sizeof (float));
+
+    if (acc_is_present (&a[0], N * sizeof (float)))
+      abort ();
 
     for (i = 0; i < N; i++)
     {
This page took 0.090762 seconds and 5 git commands to generate.