[PATCH] libgomp: Add OMPD functions in 5.5.6 and related data types.

y2s1982 y2s1982@gmail.com
Sat Jul 11 22:05:36 GMT 2020


This patch adds function definition described in the section 5.5.6 of
the OpenMP API Specificiation 5.0. It also partially defines some of the
handler data types related to the section.

2020-07-11  Tony Sim  <y2s1982@gmail.com>

libgomp/ChangeLog:

	* libgompd.h (ompd_thread_handle_t): Add.
	(ompd_parallel_handle_t): Add.
	(ompd_task_handle_t): Add.
	* ompd-parallel.c: New file.

---
 libgomp/libgompd.h      |  17 ++++++
 libgomp/ompd-parallel.c | 125 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 142 insertions(+)
 create mode 100644 libgomp/ompd-parallel.c

diff --git a/libgomp/libgompd.h b/libgomp/libgompd.h
index 495995e00d3..557f1c36ec2 100644
--- a/libgomp/libgompd.h
+++ b/libgomp/libgompd.h
@@ -47,4 +47,21 @@ typedef struct _ompd_aspace_handle {
   ompd_size_t ref_count;
 } ompd_address_space_handle_t;
 
+typedef struct _ompd_thread_handle {
+  ompd_parallel_handle_t *ph;
+  ompd_thread_context_t *thread_context;
+  ompd_address_t thread; /* Stores gomp_thread *.  */
+}ompd_thread_handle_t;
+
+typedef struct _ompd_parallel_handle{
+  ompd_address_space_handle_t *ah;
+  ompd_parallel_handle_t *enclosing_ph;
+  ompd_size_t enclosed_ph;
+  ompd_address_t thread_pool; /* Stores gomp_thread_pool *.  */
+}ompd_parallel_handle_t;
+
+typedef struct _ompd_task_handle{
+  ompd_parallel_handle_t *ph;
+}ompd_task_handle_t;
+
 #endif /* LIBGOMPD_H */
diff --git a/libgomp/ompd-parallel.c b/libgomp/ompd-parallel.c
new file mode 100644
index 00000000000..ca2de726238
--- /dev/null
+++ b/libgomp/ompd-parallel.c
@@ -0,0 +1,125 @@
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Yoosuk Sim <y2s1982@gmail.com>.
+
+   This file is part of the GNU Offloading and Multi Processing Library
+   (libgomp).
+
+   Libgomp is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* This file contains function definition related to OMPD's Parallel Region
+   Handles.  The specification is defined in the section 5.5.6 of the OpenMP
+   API Specification 5.0.  */
+
+#include "omp-tools.h"
+#include "libgomp.h"
+#include "libgompd.h"
+
+ompd_rc_t
+ompd_get_curr_parallel_handle (ompd_thread_handle_t *th,
+			       ompd_parallel_handle_t **ph)
+{
+  if (!th)
+    return ompd_rc_stale_handle;
+  if (!ph)
+    return ompd_rc_bad_input;
+
+  if (((struct gomp_thread *)th->thread.address)->ts.team != NULL)
+    return ompd_rc_error;
+
+  *ph = th->ph;
+  return ompd_rc_ok;
+}
+
+ompd_rc_t
+ompd_get_enclosing_parallel_handle (ompd_parallel_handle_t *ph,
+				    ompd_parallel_handle_t **enclosing_ph)
+{
+  if (!ph)
+    return ompd_rc_stale_handle;
+  if (!enclosing_ph)
+    return ompd_rc_bad_input;
+  if (!ph->enclosing_ph)
+    return ompd_rc_unavailable;
+
+  ompd_rc_t ret = ompd_rc_error;
+  ompd_size_t i = 0;
+  struct gomp_thread_pool * pool =
+  (struct gomp_thread_pool *)ph->thread_pool.address;
+  for (i = 0; i < pool->threads_used && ret == ompd_rc_error; i++)
+  {
+    if (pool->threads[i]->ts.team == NULL)
+      ret = ompd_rc_ok;
+  }
+  if (ret != ompd_rc_ok)
+    return ret;
+
+  *enclosing_ph = ph->enclosing_ph;
+  return ompd_rc_ok;
+}
+
+ompd_rc_t
+ompd_get_task_parallel_handle (ompd_task_handle_t *th,
+			       ompd_parallel_handle_t **ph)
+{
+  if (!th || !th->ph)
+    return ompd_rc_stale_handle;
+  if (!ph)
+    return ompd_rc_bad_input;
+
+  ompd_rc_t ret = ompd_rc_error;
+  ompd_size_t i = 0;
+  struct gomp_thread_pool * pool =
+  (struct gomp_thread_pool *)th->ph->thread_pool.address;
+  for (i = 0; i < pool->threads_used && ret == ompd_rc_error; i++)
+  {
+    if (pool->threads[i]->ts.team == NULL)
+      ret = ompd_rc_ok;
+  }
+  if (ret != ompd_rc_ok)
+    return ret;
+
+  *ph = th->ph;
+  return ompd_rc_ok;
+}
+
+ompd_rc_t ompd_rel_parallel_handle (ompd_parallel_handle_t *ph)
+{
+  if (ph->enclosed_ph > 0)
+    return ompd_rc_unavailable;
+
+  gompd_callbacks.free_memory (ph);
+  return ompd_rc_ok;
+}
+
+ompd_rc_t
+ompd_parallel_handle_compare (ompd_parallel_handle_t *lhs,
+			      ompd_parallel_handle_t *rhs, int *cmp_value)
+{
+  int compare = 1;
+
+  /* FIXME: Properly follow the implementation details on ordering parallel
+     region.  */
+  if (lhs->ah != rhs->ah
+      || lhs->thread_pool.address != rhs->thread_pool.address)
+    compare = 0;
+
+  *cmp_value = compare;
+  return ompd_rc_ok;
+}
-- 
2.27.0



More information about the Gcc-patches mailing list