public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Mohamed Sayed <mohamedsayed22198@gmail.com>
To: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH]: libgompd add parallel handle functions
Date: Mon, 6 Jun 2022 17:13:24 +0200	[thread overview]
Message-ID: <CAKS6CCrNnQbfL-Pa=nAcQ9_mmhcwB93PdAirir3O45MRS8yyeQ@mail.gmail.com> (raw)
In-Reply-To: <CAKS6CCp=N2NKZLY1pBAs1rVeO2xy5rpsH=jn6zSi=ufserdWqg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1116 bytes --]

This is the final diff

On Mon, Jun 6, 2022 at 1:48 AM Mohamed Sayed <mohamedsayed22198@gmail.com>
wrote:

> This patch adds parallel region handles specified in section 5.5.3.
> From examining libgomp code, I found that struct gomp_team describes the
> parallel region.
> The Thread handle gives the address of gomp_thread so, I tried to
> access *team
> gomp_thread->ts->team.
> The parallel handle is the team pointer in team state.
> I have a question about ompd_get_task_parallel_handle
> https://www.openmp.org/spec-html/5.0/openmpsu218.html
> How can i reach gomp_team from gomp_task
> And the union in gomp_task has two entries gomp_sem_t and gomp_team
>
> libgomp/ChangeLog
>
> 2022-06-06  Mohamed Sayed  <mohamedsayed22198@gmail.com>
>
>
> * Makefile.am: (libgompd_la_SOURCES): Add ompd-parallel.c.
> * Makefile.in: Regenerate.
> * libgompd.map: Add ompd_get_curr_parallel_handle,
> ompd_get_enclosing_parallel_handle, ompd_rel_parallel_handle
> and ompd_parallel_handle_compare symbol versions.
> * ompd-support.h:() : Add gompd_access (gomp_team_state, team) and
> gompd_access (gomp_team, prev_ts).
>
>

[-- Attachment #2: diff.txt --]
[-- Type: text/plain, Size: 8669 bytes --]

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index 6d913a93e7f..4e215450b25 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -94,7 +94,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c env.c error.c \
 	priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \
 	oacc-target.c ompd-support.c
 
-libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c
+libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c ompd-parallel.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 40f896b5f03..ab66ad1c8f0 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -233,7 +233,8 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo critical.lo \
 	affinity-fmt.lo teams.lo allocator.lo oacc-profiling.lo \
 	oacc-target.lo ompd-support.lo $(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
-am_libgompd_la_OBJECTS = ompd-init.lo ompd-helper.lo ompd-icv.lo
+am_libgompd_la_OBJECTS = ompd-init.lo ompd-helper.lo ompd-icv.lo \
+	ompd-parallel.lo
 libgompd_la_OBJECTS = $(am_libgompd_la_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -583,7 +584,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c env.c \
 	oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \
 	affinity-fmt.c teams.c allocator.c oacc-profiling.c \
 	oacc-target.c ompd-support.c $(am__append_7)
-libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c
+libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c ompd-parallel.c
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info $(libtool_VERSION)
@@ -800,6 +801,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-helper.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-icv.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-init.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-parallel.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-support.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordered.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parallel.Plo@am__quote@
diff --git a/libgomp/libgompd.map b/libgomp/libgompd.map
index 85bdc3695f6..1662dc56962 100644
--- a/libgomp/libgompd.map
+++ b/libgomp/libgompd.map
@@ -16,6 +16,10 @@ OMPD_5.1 {
     ompd_thread_handle_compare;
     ompd_get_thread_id;
     ompd_get_device_from_thread;
+    ompd_get_curr_parallel_handle;
+    ompd_get_enclosing_parallel_handle;
+    ompd_rel_parallel_handle;
+    ompd_parallel_handle_compare;
   local:
     *;
 };
diff --git a/libgomp/ompd-parallel.c b/libgomp/ompd-parallel.c
new file mode 100644
index 00000000000..3a278f7428a
--- /dev/null
+++ b/libgomp/ompd-parallel.c
@@ -0,0 +1,144 @@
+/* Copyright (C) The GNU Toolchain Authors.
+   Contributed by Mohamed Sayed <mohamedsayed22198@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 the implementation of functions defined in
+   section 5.5.6.  */
+
+#include "ompd-helper.h"
+
+ompd_rc_t 
+ompd_get_curr_parallel_handle (ompd_thread_handle_t *thread_handle, 
+			       ompd_parallel_handle_t **parallel_handle)
+{
+  if (thread_handle == NULL)
+    return ompd_rc_stale_handle;
+
+  CHECK (thread_handle->ah);
+
+  ompd_address_space_context_t *context = thread_handle->ah->context;
+  ompd_thread_context_t *thread_context = thread_handle->thread_context;
+
+  if (thread_context == NULL)
+    return ompd_rc_stale_handle;
+
+  ompd_address_t symbol_address = thread_handle->th;
+  ompd_address_t temp_symbol_address = {OMPD_SEGMENT_UNSPECIFIED, 0};
+  ompd_word_t temp_offset;
+  ompd_rc_t ret;
+
+  /* get ts offset.  */
+  GET_VALUE (context, thread_context, "gompd_access_gomp_thread_ts",
+  	     temp_offset, temp_offset, target_sizes.sizeof_long_long, 1, ret,
+             temp_symbol_address);
+
+  symbol_address.address += temp_offset;
+
+  /* get team offset.  */
+  GET_VALUE (context, thread_context, "gompd_access_gomp_team_state_team",
+  	     temp_offset, temp_offset, target_sizes.sizeof_long_long, 1, ret,
+             temp_symbol_address);
+
+  symbol_address.address += temp_offset;
+
+  ret = callbacks->read_memory (context, thread_context,
+  				&symbol_address, target_sizes.sizeof_pointer,
+  				&symbol_address.address);
+
+  CHECK_RET (ret); 
+  ret = callbacks->alloc_memory (sizeof (ompd_parallel_handle_t),
+  				 (void **) (parallel_handle));
+  CHECK_RET (ret); 
+
+  (*parallel_handle)->ah = thread_handle->ah;
+  (*parallel_handle)->th = symbol_address;
+  return ompd_rc_ok;                 		
+}
+
+ompd_rc_t
+ompd_get_enclosing_parallel_handle (ompd_parallel_handle_t *parallel_handle,
+				    ompd_parallel_handle_t **enc_par_handle)
+{
+  if (parallel_handle == NULL)
+    return ompd_rc_stale_handle;
+
+  CHECK (parallel_handle->ah);
+
+  ompd_address_space_context_t *context = parallel_handle->ah->context;  
+  ompd_address_t symbol_address = parallel_handle->th;
+  ompd_address_t temp_symbol_address = {OMPD_SEGMENT_UNSPECIFIED, 0};
+  ompd_word_t temp_offset;
+  ompd_rc_t ret;
+
+  /* get prev_ts offset.  */
+  GET_VALUE (context, NULL, "gompd_access_gomp_team_prev_ts",
+  	     temp_offset, temp_offset, target_sizes.sizeof_long_long, 1, ret,
+             temp_symbol_address);
+
+  symbol_address.address += temp_offset;
+
+  /* get team offset.  */
+  GET_VALUE (context, NULL, "gompd_access_gomp_team_state_team",
+  	     temp_offset, temp_offset, target_sizes.sizeof_long_long, 1, ret,
+             temp_symbol_address);
+
+  symbol_address.address += temp_offset;
+
+  ret = callbacks->read_memory (context, NULL, &symbol_address,
+                                target_sizes.sizeof_pointer,
+                                &symbol_address.address);
+  CHECK_RET (ret); 
+  ret = callbacks->alloc_memory (sizeof (ompd_parallel_handle_t),
+                                 (void **) (enc_par_handle));
+  CHECK_RET (ret);
+
+  (*enc_par_handle)->ah = parallel_handle->ah;
+  (*enc_par_handle)->th = symbol_address; 
+  return ompd_rc_ok;
+}
+
+ompd_rc_t
+ompd_rel_parallel_handle (ompd_parallel_handle_t *parallel_handle)
+{
+  if (parallel_handle == NULL)
+    return ompd_rc_stale_handle;
+
+  ompd_rc_t ret = callbacks->free_memory ((void *) (parallel_handle));
+
+  CHECK_RET (ret); 
+  return ompd_rc_ok;
+}
+
+ompd_rc_t 
+ompd_parallel_handle_compare (ompd_parallel_handle_t *parallel_handle_1,
+			      ompd_parallel_handle_t *parallel_handle_2,
+			      int *cmp_value)
+{
+  if (parallel_handle_1 == NULL || parallel_handle_2 == NULL)
+    return ompd_rc_stale_handle;
+
+  if (cmp_value == NULL)
+    return ompd_rc_bad_input;
+
+  if (parallel_handle_1->ah->kind != parallel_handle_2->ah->kind)
+    return ompd_rc_bad_input;
+
+  *cmp_value = parallel_handle_1->th.address - parallel_handle_2->th.address;
+  return ompd_rc_ok;
+}
diff --git a/libgomp/ompd-support.h b/libgomp/ompd-support.h
index 39d55161132..48a2e6133f5 100644
--- a/libgomp/ompd-support.h
+++ b/libgomp/ompd-support.h
@@ -83,12 +83,15 @@ extern __UINT64_TYPE__ gompd_state;
   gompd_access (gomp_thread_pool, threads) \
   gompd_access (gomp_thread, ts) \
   gompd_access (gomp_team_state, team_id) \
-  gompd_access (gomp_task, icv)
+  gompd_access (gomp_task, icv) \
+  gompd_access (gomp_team_state, team) \
+  gompd_access (gomp_team, prev_ts)
 
 #define GOMPD_SIZES(gompd_size) \
   gompd_size (gomp_thread) \
   gompd_size (gomp_task_icv) \
-  gompd_size (gomp_task)
+  gompd_size (gomp_task) 
+  
 
 #ifdef HAVE_ATTRIBUTE_VISIBILITY
 #pragma GCC visibility pop

  reply	other threads:[~2022-06-06 15:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-05 23:48 Mohamed Sayed
2022-06-06 15:13 ` Mohamed Sayed [this message]
2022-06-06 17:34   ` Jakub Jelinek
2022-06-06 17:12 ` Jakub Jelinek
2022-06-06 17:32   ` Mohamed Atef
2022-06-06 17:59     ` Jakub Jelinek

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='CAKS6CCrNnQbfL-Pa=nAcQ9_mmhcwB93PdAirir3O45MRS8yyeQ@mail.gmail.com' \
    --to=mohamedsayed22198@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).