public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: y2s1982 <y2s1982@gmail.com>
To: mjambor@suse.cz, jakub@redhat.com
Cc: gcc-patches@gcc.gnu.org, y2s1982 <y2s1982@gmail.com>
Subject: [PATCH] libgomp: Add OMPD functions in 5.5.6 and related data types.
Date: Sat, 11 Jul 2020 18:05:36 -0400	[thread overview]
Message-ID: <20200711220536.2728898-1-y2s1982@gmail.com> (raw)

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


             reply	other threads:[~2020-07-11 22:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-11 22:05 y2s1982 [this message]
2020-07-14 10:07 ` Jakub Jelinek
2020-07-14 15:10   ` y2s1982

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200711220536.2728898-1-y2s1982@gmail.com \
    --to=y2s1982@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=mjambor@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).