]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Extract 'goacc_enter_exit_data_internal' from 'libgomp/oacc-mem.c:GOACC_enter_exit_data'
authorThomas Schwinge <thomas@codesourcery.com>
Tue, 8 Jun 2021 15:39:25 +0000 (17:39 +0200)
committerThomas Schwinge <thomas@codesourcery.com>
Thu, 10 Jun 2021 11:29:52 +0000 (13:29 +0200)
libgomp/
* oacc-mem.c (goacc_enter_exit_data_internal): New function,
extracted from...
(GOACC_enter_exit_data): ... here.
(GOACC_declare): Use it.

Co-Authored-By: Andrew Stubbs <ams@codesourcery.com>
libgomp/oacc-mem.c

index 056600aca5248b0a079b01e7ba7ec34e47effe2a..f6173b91fddaa3396bfe3781edd6acf2f7860855 100644 (file)
@@ -1320,56 +1320,22 @@ goacc_exit_data_internal (struct gomp_device_descr *acc_dev, size_t mapnum,
   gomp_mutex_unlock (&acc_dev->lock);
 }
 
-void
-GOACC_enter_exit_data (int flags_m, size_t mapnum, void **hostaddrs,
-                      size_t *sizes, unsigned short *kinds, int async,
-                      int num_waits, ...)
+static void
+goacc_enter_exit_data_internal (int flags_m, size_t mapnum, void **hostaddrs,
+                               size_t *sizes, unsigned short *kinds,
+                               bool data_enter, int async, int num_waits,
+                               va_list *ap)
 {
   int flags = GOACC_FLAGS_UNMARSHAL (flags_m);
 
   struct goacc_thread *thr;
   struct gomp_device_descr *acc_dev;
-  bool data_enter = false;
-  size_t i;
 
   goacc_lazy_initialize ();
 
   thr = goacc_thread ();
   acc_dev = thr->dev;
 
-  /* Determine if this is an "acc enter data".  */
-  for (i = 0; i < mapnum; ++i)
-    {
-      unsigned char kind = kinds[i] & 0xff;
-
-      if (kind == GOMP_MAP_POINTER
-         || kind == GOMP_MAP_TO_PSET
-         || kind == GOMP_MAP_STRUCT)
-       continue;
-
-      if (kind == GOMP_MAP_FORCE_ALLOC
-         || kind == GOMP_MAP_FORCE_PRESENT
-         || kind == GOMP_MAP_ATTACH
-         || kind == GOMP_MAP_FORCE_TO
-         || kind == GOMP_MAP_TO
-         || kind == GOMP_MAP_ALLOC)
-       {
-         data_enter = true;
-         break;
-       }
-
-      if (kind == GOMP_MAP_RELEASE
-         || kind == GOMP_MAP_DELETE
-         || kind == GOMP_MAP_DETACH
-         || kind == GOMP_MAP_FORCE_DETACH
-         || kind == GOMP_MAP_FROM
-         || kind == GOMP_MAP_FORCE_FROM)
-       break;
-
-      gomp_fatal (">>>> GOACC_enter_exit_data UNHANDLED kind 0x%.2x",
-                     kind);
-    }
-
   bool profiling_p = GOACC_PROFILING_DISPATCH_P (true);
 
   acc_prof_info prof_info;
@@ -1433,13 +1399,7 @@ GOACC_enter_exit_data (int flags_m, size_t mapnum, void **hostaddrs,
     }
 
   if (num_waits)
-    {
-      va_list ap;
-
-      va_start (ap, num_waits);
-      goacc_wait (async, num_waits, &ap);
-      va_end (ap);
-    }
+    goacc_wait (async, num_waits, ap);
 
   goacc_aq aq = get_goacc_asyncqueue (async);
 
@@ -1462,6 +1422,52 @@ GOACC_enter_exit_data (int flags_m, size_t mapnum, void **hostaddrs,
     }
 }
 
+void
+GOACC_enter_exit_data (int flags_m, size_t mapnum, void **hostaddrs,
+                      size_t *sizes, unsigned short *kinds, int async,
+                      int num_waits, ...)
+{
+  /* Determine if this is an OpenACC "enter data".  */
+  bool data_enter = false;
+  for (size_t i = 0; i < mapnum; ++i)
+    {
+      unsigned char kind = kinds[i] & 0xff;
+
+      if (kind == GOMP_MAP_POINTER
+         || kind == GOMP_MAP_TO_PSET
+         || kind == GOMP_MAP_STRUCT)
+       continue;
+
+      if (kind == GOMP_MAP_FORCE_ALLOC
+         || kind == GOMP_MAP_FORCE_PRESENT
+         || kind == GOMP_MAP_ATTACH
+         || kind == GOMP_MAP_FORCE_TO
+         || kind == GOMP_MAP_TO
+         || kind == GOMP_MAP_ALLOC)
+       {
+         data_enter = true;
+         break;
+       }
+
+      if (kind == GOMP_MAP_RELEASE
+         || kind == GOMP_MAP_DELETE
+         || kind == GOMP_MAP_DETACH
+         || kind == GOMP_MAP_FORCE_DETACH
+         || kind == GOMP_MAP_FROM
+         || kind == GOMP_MAP_FORCE_FROM)
+       break;
+
+      gomp_fatal (">>>> GOACC_enter_exit_data UNHANDLED kind 0x%.2x",
+                     kind);
+    }
+
+  va_list ap;
+  va_start (ap, num_waits);
+  goacc_enter_exit_data_internal (flags_m, mapnum, hostaddrs, sizes, kinds,
+                                 data_enter, async, num_waits, &ap);
+  va_end (ap);
+}
+
 void
 GOACC_declare (int flags_m, size_t mapnum,
               void **hostaddrs, size_t *sizes, unsigned short *kinds)
@@ -1475,34 +1481,28 @@ GOACC_declare (int flags_m, size_t mapnum,
 
       switch (kind)
        {
+       case GOMP_MAP_ALLOC:
+         if (acc_is_present (hostaddrs[i], sizes[i]))
+           continue;
+         /* FALLTHRU */
        case GOMP_MAP_FORCE_ALLOC:
-       case GOMP_MAP_FORCE_FROM:
+       case GOMP_MAP_TO:
        case GOMP_MAP_FORCE_TO:
+         goacc_enter_exit_data_internal (flags_m, 1, &hostaddrs[i], &sizes[i],
+                                         &kinds[i], true, GOMP_ASYNC_SYNC, 0, NULL);
+         break;
+
+       case GOMP_MAP_FROM:
+       case GOMP_MAP_FORCE_FROM:
        case GOMP_MAP_RELEASE:
        case GOMP_MAP_DELETE:
-         GOACC_enter_exit_data (flags_m, 1, &hostaddrs[i], &sizes[i],
-                                &kinds[i], GOMP_ASYNC_SYNC, 0);
+         goacc_enter_exit_data_internal (flags_m, 1, &hostaddrs[i], &sizes[i],
+                                         &kinds[i], false, GOMP_ASYNC_SYNC, 0, NULL);
          break;
 
        case GOMP_MAP_FORCE_DEVICEPTR:
          break;
 
-       case GOMP_MAP_ALLOC:
-         if (!acc_is_present (hostaddrs[i], sizes[i]))
-           GOACC_enter_exit_data (flags_m, 1, &hostaddrs[i], &sizes[i],
-                                  &kinds[i], GOMP_ASYNC_SYNC, 0);
-         break;
-
-       case GOMP_MAP_TO:
-         GOACC_enter_exit_data (flags_m, 1, &hostaddrs[i], &sizes[i],
-                                &kinds[i], GOMP_ASYNC_SYNC, 0);
-         break;
-
-       case GOMP_MAP_FROM:
-         GOACC_enter_exit_data (flags_m, 1, &hostaddrs[i], &sizes[i],
-                                &kinds[i], GOMP_ASYNC_SYNC, 0);
-         break;
-
        case GOMP_MAP_FORCE_PRESENT:
          if (!acc_is_present (hostaddrs[i], sizes[i]))
            gomp_fatal ("[%p,%ld] is not mapped", hostaddrs[i],