[OpenACC] Consolidate 'async'/'wait' code in 'libgomp/oacc-async.c'

Message ID 87eexa23jy.fsf@euler.schwinge.homeip.net
State New
Headers show
Series
  • [OpenACC] Consolidate 'async'/'wait' code in 'libgomp/oacc-async.c'
Related show

Commit Message

Thomas Schwinge Dec. 11, 2019, 5:08 p.m.
Hi!

As a preparational patch/general refactoring, see attached "[OpenACC]
Consolidate 'async'/'wait' code in 'libgomp/oacc-async.c'"; committed to
trunk in r279232.


Grüße
 Thomas

Patch

From 2b04bb7b4c9a13b6eadc7d9723245dd58f0f4f04 Mon Sep 17 00:00:00 2001
From: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Wed, 11 Dec 2019 16:49:08 +0000
Subject: [PATCH] [OpenACC] Consolidate 'async'/'wait' code in
 'libgomp/oacc-async.c'

	libgomp/
	* oacc-parallel.c (GOACC_wait, goacc_wait): Move...
	* oacc-async.c: ... here.
	* oacc-int.h (goacc_wait): Declare.
	* libgomp_g.h: Update

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@279232 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog       |  5 +++
 libgomp/libgomp_g.h     |  5 ++-
 libgomp/oacc-async.c    | 71 ++++++++++++++++++++++++++++++++++++++++
 libgomp/oacc-int.h      |  1 +
 libgomp/oacc-parallel.c | 72 -----------------------------------------
 5 files changed, 81 insertions(+), 73 deletions(-)

diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index 404722e20e3..f7d9ae98616 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,5 +1,10 @@ 
 2019-12-11  Thomas Schwinge  <thomas@codesourcery.com>
 
+	* oacc-parallel.c (GOACC_wait, goacc_wait): Move...
+	* oacc-async.c: ... here.
+	* oacc-int.h (goacc_wait): Declare.
+	* libgomp_g.h: Update
+
 	PR libgomp/92854
 	* testsuite/libgomp.oacc-c-c++-common/acc_map_data-device_already-1.c:
 	New file.
diff --git a/libgomp/libgomp_g.h b/libgomp/libgomp_g.h
index dfb55fb66dc..beb1689180d 100644
--- a/libgomp/libgomp_g.h
+++ b/libgomp/libgomp_g.h
@@ -357,6 +357,10 @@  extern void GOMP_teams (unsigned int, unsigned int);
 extern void GOMP_teams_reg (void (*) (void *), void *, unsigned, unsigned,
 			    unsigned);
 
+/* oacc-async.c */
+
+extern void GOACC_wait (int, int, ...);
+
 /* oacc-parallel.c */
 
 extern void GOACC_parallel_keyed (int, void (*) (void *), size_t,
@@ -370,7 +374,6 @@  extern void GOACC_enter_exit_data (int, size_t, void **,
 				   size_t *, unsigned short *, int, int, ...);
 extern void GOACC_update (int, size_t, void **, size_t *,
 			  unsigned short *, int, int, ...);
-extern void GOACC_wait (int, int, ...);
 extern int GOACC_get_num_threads (void);
 extern int GOACC_get_thread_num (void);
 extern void GOACC_declare (int, size_t, void **, size_t *, unsigned short *);
diff --git a/libgomp/oacc-async.c b/libgomp/oacc-async.c
index 2b24ae7adc2..6dfc3bdeb8e 100644
--- a/libgomp/oacc-async.c
+++ b/libgomp/oacc-async.c
@@ -354,6 +354,77 @@  acc_wait_all_async (int async)
     gomp_fatal ("wait all async(%d) failed", async);
 }
 
+void
+GOACC_wait (int async, int num_waits, ...)
+{
+  goacc_lazy_initialize ();
+
+  struct goacc_thread *thr = goacc_thread ();
+
+  /* No nesting.  */
+  assert (thr->prof_info == NULL);
+  assert (thr->api_info == NULL);
+  acc_prof_info prof_info;
+  acc_api_info api_info;
+  bool profiling_p = GOACC_PROFILING_SETUP_P (thr, &prof_info, &api_info);
+  if (profiling_p)
+    {
+      prof_info.async = async;
+      prof_info.async_queue = prof_info.async;
+    }
+
+  if (num_waits)
+    {
+      va_list ap;
+
+      va_start (ap, num_waits);
+      goacc_wait (async, num_waits, &ap);
+      va_end (ap);
+    }
+  else if (async == acc_async_sync)
+    acc_wait_all ();
+  else
+    acc_wait_all_async (async);
+
+  if (profiling_p)
+    {
+      thr->prof_info = NULL;
+      thr->api_info = NULL;
+    }
+}
+
+attribute_hidden void
+goacc_wait (int async, int num_waits, va_list *ap)
+{
+  while (num_waits--)
+    {
+      int qid = va_arg (*ap, int);
+
+      /* Waiting on ACC_ASYNC_NOVAL maps to 'wait all'.  */
+      if (qid == acc_async_noval)
+	{
+	  if (async == acc_async_sync)
+	    acc_wait_all ();
+	  else
+	    acc_wait_all_async (async);
+	  break;
+	}
+
+      if (acc_async_test (qid))
+	continue;
+
+      if (async == acc_async_sync)
+	acc_wait (qid);
+      else if (qid == async)
+	/* If we're waiting on the same asynchronous queue as we're
+	   launching on, the queue itself will order work as
+	   required, so there's no need to wait explicitly.  */
+	;
+      else
+	acc_wait_async (qid, async);
+    }
+}
+
 attribute_hidden void
 goacc_async_free (struct gomp_device_descr *devicep,
 		  struct goacc_asyncqueue *aq, void *ptr)
diff --git a/libgomp/oacc-int.h b/libgomp/oacc-int.h
index 9dc6c8a5713..81cb15c605f 100644
--- a/libgomp/oacc-int.h
+++ b/libgomp/oacc-int.h
@@ -113,6 +113,7 @@  void goacc_restore_bind (void);
 void goacc_lazy_initialize (void);
 void goacc_host_init (void);
 
+void goacc_wait (int, int, va_list *);
 void goacc_init_asyncqueues (struct gomp_device_descr *);
 bool goacc_fini_asyncqueues (struct gomp_device_descr *);
 void goacc_async_free (struct gomp_device_descr *, struct goacc_asyncqueue *,
diff --git a/libgomp/oacc-parallel.c b/libgomp/oacc-parallel.c
index 68a60de24fa..1faca5d562f 100644
--- a/libgomp/oacc-parallel.c
+++ b/libgomp/oacc-parallel.c
@@ -111,8 +111,6 @@  handle_ftn_pointers (size_t mapnum, void **hostaddrs, size_t *sizes,
     }
 }
 
-static void goacc_wait (int async, int num_waits, va_list *ap);
-
 
 /* Launch a possibly offloaded function with FLAGS.  FN is the host fn
    address.  MAPNUM, HOSTADDRS, SIZES & KINDS  describe the memory
@@ -814,38 +812,6 @@  GOACC_enter_exit_data (int flags_m, size_t mapnum,
     }
 }
 
-static void
-goacc_wait (int async, int num_waits, va_list *ap)
-{
-  while (num_waits--)
-    {
-      int qid = va_arg (*ap, int);
-
-      /* Waiting on ACC_ASYNC_NOVAL maps to 'wait all'.  */
-      if (qid == acc_async_noval)
-	{
-	  if (async == acc_async_sync)
-	    acc_wait_all ();
-	  else
-	    acc_wait_all_async (async);
-	  break;
-	}
-
-      if (acc_async_test (qid))
-	continue;
-
-      if (async == acc_async_sync)
-	acc_wait (qid);
-      else if (qid == async)
-	/* If we're waiting on the same asynchronous queue as we're
-	   launching on, the queue itself will order work as
-	   required, so there's no need to wait explicitly.  */
-	;
-      else
-	acc_wait_async (qid, async);
-    }
-}
-
 void
 GOACC_update (int flags_m, size_t mapnum,
 	      void **hostaddrs, size_t *sizes, unsigned short *kinds,
@@ -1002,44 +968,6 @@  GOACC_update (int flags_m, size_t mapnum,
     }
 }
 
-void
-GOACC_wait (int async, int num_waits, ...)
-{
-  goacc_lazy_initialize ();
-
-  struct goacc_thread *thr = goacc_thread ();
-
-  /* No nesting.  */
-  assert (thr->prof_info == NULL);
-  assert (thr->api_info == NULL);
-  acc_prof_info prof_info;
-  acc_api_info api_info;
-  bool profiling_p = GOACC_PROFILING_SETUP_P (thr, &prof_info, &api_info);
-  if (profiling_p)
-    {
-      prof_info.async = async;
-      prof_info.async_queue = prof_info.async;
-    }
-
-  if (num_waits)
-    {
-      va_list ap;
-
-      va_start (ap, num_waits);
-      goacc_wait (async, num_waits, &ap);
-      va_end (ap);
-    }
-  else if (async == acc_async_sync)
-    acc_wait_all ();
-  else
-    acc_wait_all_async (async);
-
-  if (profiling_p)
-    {
-      thr->prof_info = NULL;
-      thr->api_info = NULL;
-    }
-}
 
 /* Legacy entry point (GCC 5).  */
 
-- 
2.17.1