[PATCH] libgomp: Add OMPD functions defined in Thread Handles.

2020-07-30 Thread y2s1982 via Gcc-patches
This patch adds functions defined in the section 5.5.5 Thread Handles in
OpenMP API Specification 5.0. It currently omits CUDA support, and
hard-codes the offset and sizeof values. I would appreciate any
suggestions.

2020-07-30  Tony Sim  

libgomp/ChangeLog:

* Makefile.am (libgompd_la_SOURCES): Add ompd-thread.c.
* Makefile.in: Regenerate.
* libgompd.h (ompd_thread_handle_t): Add definition.
(ompd_parallel_handle_t): Add definition.
* ompd-thread.c: New file.

---
 libgomp/Makefile.am   |   2 +-
 libgomp/Makefile.in   |   5 +-
 libgomp/libgompd.h|  12 +++
 libgomp/ompd-thread.c | 203 ++
 4 files changed, 219 insertions(+), 3 deletions(-)
 create mode 100644 libgomp/ompd-thread.c

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index fe0a92122ea..0e6f2d1c830 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -90,7 +90,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
oacc-mem.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
 
-libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-thread.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index f74d5f3ac8e..137ce35dfc1 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -235,7 +235,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
$(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
 libgompd_la_LIBADD =
-am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo
+am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo ompd-thread.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@)
@@ -593,7 +593,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 $(am__append_4)
-libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-thread.c
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -819,6 +819,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-target.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-lib.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-proc.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-thread.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@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/priority_queue.Plo@am__quote@
diff --git a/libgomp/libgompd.h b/libgomp/libgompd.h
index 495995e00d3..98a2f74b983 100644
--- a/libgomp/libgompd.h
+++ b/libgomp/libgompd.h
@@ -47,4 +47,16 @@ 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_address_space_handle_t *ah;
+  ompd_thread_context_t *tcontext;
+  ompd_address_t *thread;
+} ompd_thread_handle_t;
+
+typedef struct _ompd_parallel_handle {
+  ompd_address_space_handle_t *ah;
+  ompd_address_t *tpool;
+} ompd_parallel_handle_t;
+
 #endif /* LIBGOMPD_H */
diff --git a/libgomp/ompd-thread.c b/libgomp/ompd-thread.c
new file mode 100644
index 000..281cd7e2520
--- /dev/null
+++ b/libgomp/ompd-thread.c
@@ -0,0 +1,203 @@
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Yoosuk Sim .
+
+   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
+   .  */
+
+/* This file contains OMPD function definitions related to threads, as defined
+   in the section 5.5.5 in the OpenMP API Specification 5.0.  */
+
+#include 

Re: [PATCH] libgomp: Add helper functions for memory handling.

2020-07-27 Thread y2s1982 via Gcc-patches
Hello Jakub,

Thanks for the reply. I apparently need further clarification.

On Mon, Jul 27, 2020 at 12:36 PM Jakub Jelinek  wrote:

> On Sat, Jul 25, 2020 at 11:03:27AM -0400, y2s1982 via Gcc-patches wrote:
> > This patch adds few helper functions aims to improve readability of
> > fetching addresses, sizes, and values. It also proposes a syntax for
> > querying these information through the callback functions, similar to
> > that of LLVM implementation. The syntax format is _ > name>, or __. '_' is the
> > delimiter between fields. '', as currently defined in the
> > enum, is either gompd_query_address or gompd_query_size: the first
> > handles address or offset queries while the second handles the size of
> > the variable/member. '' refers to the variable type, and
> > '' refers to the data type of the member of the variable.
> > This code is incomplete: in particular, it currently lacks CUDA support,
> > as well as segment handling, and inlining of the functions.
>
> That assumes on the libgomp.so.1 side you want to add all the magic symbols
> to the dynamic! symbol table.  We do not want that, it is a big waste of
> system resources that way.
> Rather than that, as I said several times, there should be a single
> variable, perhaps with generated content, with a compact format of data on
> which the two libraries agree on and libgompd should parse and use
> information from that single variable.
>

I do know you have said this several times, and I thought I understood it,
but it seems I am wrong each time. I just want to clarify my understanding
and what I had intended on doing on this and would like further explanation
on what you would like to see happen more specifically so that I may make
less mistakes.

My assumption in this patch was that, as the ompd_callback_symbol_addr_fn_t
callback function takes 2 context addresses and string query as input, and
ompd_address_t address as an output, I should give it:
  - the context addresses, which I assumed would contain a single data in
compact form generated from the tool's side having size, offset, and
address information,
  - and a string, which is basically a query that needs to be interpreted
by the callback function to determine which part of the data it needs to
use to generate to the returning pointer.
I wasn't sure what role the filename input played in this.
This seemed to fit what you meant by having a single compact data that
contains all the information while resolving my ongoing mystery as to what
the callback was expecting to have as the string identifying the symbol. To
further clarify, I assumed the callback would do string manipulation and
comparison to identify which information is being requested, refer to the
single data contained in appropriate context, and return the address
information.

I am more than willing to scrap my bad idea for a better one. I am
sincerely interested in learning better ways to implement and improve
myself. I just need to know more specifics of the design, particularly:
- where the compact data is stored (I assumed context, which means it might
not be defined in the library side, but should it be in the handle or
global to library?),
- how the information necessary for the compact data is gathered (if it is
done on the library side, should I just use the ompd_callback_sizeof_fn_t
to obtain primitive sizes, and from there, just build the offset
information for each variable members? How about variable address?)
- how the ompd_callback_symbol_addr_fn_t callback function would likely use
it given its arguments (input of 2 contexts, 1 file name, 1 string to
output 1 address),
- what are the expected strings for the callback that would correspond to
each variable (here, I assume, the types would be gomp_thread,
gompd_thread_pool, gomp_team, etc.) or each member of said variables,
(these, at least I expected, should be documented and agreed on between
library and tool),
among other things.


>
> So I'm afraid pretty much nothing from this patch is really usable.
>
> > +#define FOREACH_QUERYTYPE(TYPE)\
> > + TYPE (gompd_query_address)\
> > + TYPE (gompd_query_size)\
> > +
> Why the final \ ?  There should be space before the \ too.
> > +
> >  extern ompd_callbacks_t gompd_callbacks;
> >
> >  typedef struct _ompd_aspace_handle {
> > @@ -47,4 +53,51 @@ typedef struct _ompd_aspace_handle {
> >ompd_size_t ref_count;
> >  } ompd_address_space_handle_t;
> >
> > +typedef enum gompd_query_type {
> > +#define GENERATE_ENUM(ENUM) ENUM,
> > +  FOREACH_QUERYTYPE (GENERATE_ENUM)
> > +#undef GENERATE_ENUM
> > +} query_type;
>
> It is unclear what you want to achieve through this, right now it is
> a very fancy way to say
> typedef enum gompd_query_type {
>   gompd_query_address,
&g

[PATCH] libgomp: Add helper functions for memory handling.

2020-07-25 Thread y2s1982 via Gcc-patches
This patch adds few helper functions aims to improve readability of
fetching addresses, sizes, and values. It also proposes a syntax for
querying these information through the callback functions, similar to
that of LLVM implementation. The syntax format is _, or __. '_' is the
delimiter between fields. '', as currently defined in the
enum, is either gompd_query_address or gompd_query_size: the first
handles address or offset queries while the second handles the size of
the variable/member. '' refers to the variable type, and
'' refers to the data type of the member of the variable.
This code is incomplete: in particular, it currently lacks CUDA support,
as well as segment handling, and inlining of the functions.

This updated patch includes some bug fixes.

2020-07-20  Tony Sim  

libgomp/ChangeLog:

* Makefile.am (libgompd_la_SOURCES): Add ompd-helper.c.
* Makefile.in: Regenerate.
* libgompd.h (FOREACH_QUERYTYPE): Add macro for query types.
(query_type): Add enum for query types.
(gompd_getQueryStringSize): Add declaration.
(gompd_getQueryString): Add declaration.
(gompd_getAddress): Add declaration.
(gompd_getSize): Add declaration.
(gompd_getValue): Add declaration.
(gompd_getVariableAddress): Add declaration.
(gompd_getVariableSize): Add declaration.
(gompd_getVariableValue): Add declaration.
(gompd_getMemberAddress): Add declaration.
(gompd_getMemberSize): Add declaration.
(gompd_getMemberValue): Add declaration.
* ompd-helper.c: New file.

---
 libgomp/Makefile.am   |   2 +-
 libgomp/Makefile.in   |   5 +-
 libgomp/libgompd.h|  53 ++
 libgomp/ompd-helper.c | 222 ++
 4 files changed, 279 insertions(+), 3 deletions(-)
 create mode 100644 libgomp/ompd-helper.c

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index fe0a92122ea..d126bc655fc 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -90,7 +90,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
oacc-mem.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
 
-libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-helper.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index f74d5f3ac8e..fdd488ca98e 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -235,7 +235,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
$(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
 libgompd_la_LIBADD =
-am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo
+am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo ompd-helper.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@)
@@ -593,7 +593,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 $(am__append_4)
-libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-helper.c
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -817,6 +817,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-plugin.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-profiling.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-target.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-helper.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-lib.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-proc.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordered.Plo@am__quote@
diff --git a/libgomp/libgompd.h b/libgomp/libgompd.h
index 495995e00d3..9d34803797a 100644
--- a/libgomp/libgompd.h
+++ b/libgomp/libgompd.h
@@ -30,12 +30,18 @@
 #define LIBGOMPD_H 1
 
 #include "omp-tools.h"
+#include 
 
 #define ompd_stringify(x) ompd_str2(x)
 #define ompd_str2(x) #x
 
 #define OMPD_VERSION 201811
 
+#define FOREACH_QUERYTYPE(TYPE)\
+   TYPE (gompd_query_address)\
+   TYPE (gompd_query_size)\
+
+
 extern ompd_callbacks_t gompd_callbacks;
 
 typedef struct _ompd_aspace_handle {
@@ -47,4 +53,51 @@ typedef struct _ompd_aspace_handle {
   ompd_size_t ref_count;
 } ompd_address_space_handle_t;
 
+typedef enum gompd_query_type {
+#define GENERATE_ENUM(ENUM) ENUM,
+  FOREACH_QUERYTYPE (GENERATE_ENUM)
+#undef GENERATE_ENUM
+} query_type;
+
+ompd_rc_t gompd_getQueryStringSize (size_t *, query_type, const char*,
+   const char *);
+
+ompd_rc_t gompd_getQueryString (char **, query_type, const char*, const 

[PATCH] libgomp: Add helper functions for memory handling.

2020-07-20 Thread y2s1982 via Gcc-patches
This patch adds few helper functions aims to improve readability of
fetching addresses, sizes, and values. It also proposes a syntax for
querying these information through the callback functions, similar to
that of LLVM implementation. The syntax format is _, or __. '_' is the
delimiter between fields. '', as currently defined in the
enum, is either gompd_query_address or gompd_query_size: the first
handles address or offset queries while the second handles the size of
the variable/member. '' refers to the variable type, and
'' refers to the data type of the member of the variable.
This code is incomplete: in particular, it currently lacks CUDA support,
as well as segment handling, and inlining of the functions.

2020-07-20  Tony Sim  

libgomp/ChangeLog:

* Makefile.am (libgompd_la_SOURCES): Add ompd-helper.c.
* Makefile.in: Regenerate.
* libgompd.h (FOREACH_QUERYTYPE): Add macro for query types.
(query_type): Add enum for query types.
(gompd_getQueryStringSize): Add declaration.
(gompd_getQueryString): Add declaration.
(gompd_getAddress): Add declaration.
(gompd_getSize): Add declaration.
(gompd_getValue): Add declaration.
(gompd_getVariableAddress): Add declaration.
(gompd_getVariableSize): Add declaration.
(gompd_getVariableValue): Add declaration.
(gompd_getMemberAddress): Add declaration.
(gompd_getMemberSize): Add declaration.
(gompd_getMemberValue): Add declaration.
* ompd-helper.c: New file.

---
 libgomp/Makefile.am   |   2 +-
 libgomp/Makefile.in   |   5 +-
 libgomp/libgompd.h|  53 ++
 libgomp/ompd-helper.c | 228 ++
 4 files changed, 285 insertions(+), 3 deletions(-)
 create mode 100644 libgomp/ompd-helper.c

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index fe0a92122ea..d126bc655fc 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -90,7 +90,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
oacc-mem.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
 
-libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-helper.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index f74d5f3ac8e..fdd488ca98e 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -235,7 +235,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
$(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
 libgompd_la_LIBADD =
-am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo
+am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo ompd-helper.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@)
@@ -593,7 +593,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 $(am__append_4)
-libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-helper.c
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -817,6 +817,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-plugin.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-profiling.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-target.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-helper.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-lib.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-proc.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordered.Plo@am__quote@
diff --git a/libgomp/libgompd.h b/libgomp/libgompd.h
index 495995e00d3..69bf3573d3c 100644
--- a/libgomp/libgompd.h
+++ b/libgomp/libgompd.h
@@ -30,12 +30,18 @@
 #define LIBGOMPD_H 1
 
 #include "omp-tools.h"
+#include 
 
 #define ompd_stringify(x) ompd_str2(x)
 #define ompd_str2(x) #x
 
 #define OMPD_VERSION 201811
 
+#define FOREACH_QUERYTYPE(TYPE)\
+   TYPE (gompd_query_address)\
+   TYPE (gompd_query_size)\
+
+
 extern ompd_callbacks_t gompd_callbacks;
 
 typedef struct _ompd_aspace_handle {
@@ -47,4 +53,51 @@ typedef struct _ompd_aspace_handle {
   ompd_size_t ref_count;
 } ompd_address_space_handle_t;
 
+typedef enum gompd_query_type {
+#define GENERATE_ENUM(ENUM) ENUM,
+  FOREACH_QUERYTYPE (GENERATE_ENUM)
+#undef GENERATE_ENUM
+} query_type;
+
+ompd_rc_t gompd_getQueryStringSize (size_t *, query_type, const char*,
+   const char *);
+
+ompd_rc_t gompd_getQueryString (char **, query_type, const char*, const char 
*);
+
+ompd_rc_t gompd_getAddress 

Re: [PATCH] libgomp: Add OMPD Address Space Information functions.

2020-07-14 Thread y2s1982 via Gcc-patches
Hello Jakub,

I remember now why I had gompd_env_info as a global variable. It was meant
to be in libgomp.so.1. It was mistakenly placed in libgompd.h; it was
supposed to be in libgomp.h.

I am having trouble connecting the dots and need help. To expose a
variable, such as the gompd_env_info, so that a callback function can then
fetch it based on a name string passed in as an argument, is it sufficient
to just create a global variable in libgomp.h?
Does it need to be included in the .map file as a symbol? Or would
callbacks already have pointers to the variable and simply use switch to
fetch the values?
I looked at nm command and readelf command, too, and although I didn't
check everything, I only found function symbols as defined in the .map. I
couldn't find any variables, and I wasn't sure if I was looking at the
right place.

Thanks again for your help.

Cheers,

Tony Sim


On Tue, Jul 14, 2020 at 5:57 AM Jakub Jelinek  wrote:

> On Thu, Jul 09, 2020 at 07:01:00PM -0400, y2s1982 via Gcc-patches wrote:
> > --- a/libgomp/libgompd.h
> > +++ b/libgomp/libgompd.h
> > @@ -47,4 +47,19 @@ typedef struct _ompd_aspace_handle {
> >ompd_size_t ref_count;
> >  } ompd_address_space_handle_t;
> >
> > +struct gompd_env
> > +{
> > +  /* TODO: when the struct is better defined, turn it into a compact
> form.
> > + LINK:
> https://gcc.gnu.org/pipermail/gcc-patches/2020-July/549698.html
> > + For now, keep it as a struct.  */
> > +
> > +  /* Environment set version number.  */
> > +  ompd_word_t gompd_env_version;
> > +  /* Represents _OPENMP that is in mm format.  */
> > +  ompd_word_t openmp_version;
> > +};
> > +
> > +/* TODO: when gompd_env is better defined, turn it into a compact
> form.  */
> > +extern struct gompd_env gompd_env_info;
>
> I don't think you want this to be a global var.
>
>
> > --- a/libgomp/ompd-lib.c
> > +++ b/libgomp/ompd-lib.c
> > @@ -31,6 +31,17 @@
> >
> >  ompd_callbacks_t gompd_callbacks;
> >  static int ompd_initialized = 0;
> > +struct gompd_env gompd_env_info;
>
> Again.
>
> > +
> > +ompd_rc_t
> > +gompd_set_environment ()
> > +{
> > +  /* TODO: Turn this placeholder function to handle OMPD environment
> variables
> > + when it becomes compact.  */
> > +  struct gompd_env temp_env = { 202007, 201811 };
> > +  gompd_env_info = temp_env;
> > +  return ompd_rc_ok;
> > +}
> >
> >  ompd_rc_t
> >  ompd_get_api_version (ompd_word_t *version)
> > @@ -57,6 +68,7 @@ ompd_initialize (ompd_word_t api_version, const
> ompd_callbacks_t *callbacks)
> >  return ompd_rc_error;
> >
> >gompd_callbacks = *callbacks;
> > +  gompd_set_environment ();
>
> And you shouldn't call it here, but instead in ompd_process_initialize
> and put the struct into the handle.
>
> The thing is, the same OMPD library can e.g. handle a 64-bit and 32-bit
> process, or one with older and one with newer libgomp.so.1.
>
> Jakub
>
>


[PATCH] libgomp: Add OMPD Address Space Information functions.

2020-07-14 Thread y2s1982 via Gcc-patches
This patch adds Address Space Information function implementations as
defined in section 5.5.4 of OpenMP API Specification 5.0. It also
defines a struct that stores various information used by OMPD.

This patch addressed all feedbacks.

2020-07-14  Tony Sim  

libgomp/ChangeLog:

* Makefile.am (libgompd_la_OBJECTS): Add ompd-addr.c.
* Makefile.in: Regenerate.
* libgompd.h (gompd_set_environment): Declare.
(gompd_env): Define.
(ompd_address_space_handle_t): Add new member variable.
* ompd-proc.c (gompd_set_environment): Define.
(ompd_process_initialize): Sets new handle member variable.
* ompd-addr.c: New file.

---
 libgomp/Makefile.am |  2 +-
 libgomp/Makefile.in |  5 +--
 libgomp/libgompd.h  | 15 
 libgomp/ompd-addr.c | 83 +
 libgomp/ompd-proc.c | 11 ++
 5 files changed, 113 insertions(+), 3 deletions(-)
 create mode 100644 libgomp/ompd-addr.c

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index fe0a92122ea..0a4a9c10eb9 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -90,7 +90,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
oacc-mem.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
 
-libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-addr.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 2b487e00499..9ceb2c6e460 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -235,7 +235,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
$(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
 libgompd_la_LIBADD =
-am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo
+am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo ompd-addr.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@)
@@ -592,7 +592,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 $(am__append_4)
-libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-addr.c
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -816,6 +816,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-plugin.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-profiling.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-target.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-addr.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-lib.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-proc.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordered.Plo@am__quote@
diff --git a/libgomp/libgompd.h b/libgomp/libgompd.h
index 495995e00d3..9130de4dc36 100644
--- a/libgomp/libgompd.h
+++ b/libgomp/libgompd.h
@@ -38,6 +38,20 @@
 
 extern ompd_callbacks_t gompd_callbacks;
 
+typedef struct gompd_environment_variables
+{
+  /* TODO: when the struct is better defined, turn it into a compact form.
+ LINK: https://gcc.gnu.org/pipermail/gcc-patches/2020-July/549698.html
+ For now, keep it as a struct.  */
+
+  /* Environment set version number.  */
+  ompd_word_t gompd_env_version;
+  /* Represents _OPENMP that is in mm format.  */
+  ompd_word_t openmp_version;
+} gompd_env;
+
+ompd_rc_t gompd_set_environment (gompd_env **) __GOMPD_NOTHROW;
+
 typedef struct _ompd_aspace_handle {
   ompd_address_space_context_t *context;
   ompd_device_t kind;
@@ -45,6 +59,7 @@ typedef struct _ompd_aspace_handle {
   void *id;
   ompd_address_space_handle_t *process_reference;
   ompd_size_t ref_count;
+  gompd_env *env;
 } ompd_address_space_handle_t;
 
 #endif /* LIBGOMPD_H */
diff --git a/libgomp/ompd-addr.c b/libgomp/ompd-addr.c
new file mode 100644
index 000..281d02b1902
--- /dev/null
+++ b/libgomp/ompd-addr.c
@@ -0,0 +1,83 @@
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Yoosuk Sim .
+
+   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 

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

2020-07-14 Thread y2s1982 via Gcc-patches
Hello Jakub,


On Tue, Jul 14, 2020 at 6:07 AM Jakub Jelinek  wrote:

> On Sat, Jul 11, 2020 at 06:05:36PM -0400, y2s1982 wrote:
> > 2020-07-11  Tony Sim  
> >
> > libgomp/ChangeLog:
> >
> >   * libgompd.h (ompd_thread_handle_t): Add.
> >   (ompd_parallel_handle_t): Add.
> >   (ompd_task_handle_t): Add.
> >   * ompd-parallel.c: New file.
>
> So you add a new file, but don't add it to Makefile.am - that means
> nothing will compile it.

> +}ompd_thread_handle_t;
>
> Formatting, space after }
> > +
> > +typedef struct _ompd_parallel_handle{
>
> and space bef before { (etc.).
> > +  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 */
> > +  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;
>
> Formatting, = should never be at the end of line.  And no space between
> * and pool, so:
>   struct gomp_thread_pool *pool
> = (struct gomp_thread_pool *) ph->thread_pool.address;
>
Ah! I was hoping to find some information on this. I kept looking around the
code base but the formatting wasn't consistent. Thank you for spelling this
out for me.

>
> > +  for (i = 0; i < pool->threads_used && ret == ompd_rc_error; i++)
> > +  {
> > +if (pool->threads[i]->ts.team == NULL)
> > +  ret = ompd_rc_ok;
> > +  }
>
> Like I said on other patches, { would need to be indented by 2 spaces from
> for, but as the body contains a single statement, just leave the {}s out
> completely and then it can stay as is.
>
Yes, of course. I am sorry, my old habbit is dieing hard. I will keep it in
mind.


>
> More important, I don't see any function that would initialize
> e.g. threads_used, etc., IMNSHO you should start with those and
> there write the reading of those from the inferior.
>

I started from parallel only because it seemed easier haha.
Okay, I will get working on the thread section, which was just previous to
this section.
Does this mean I should scrap this patch for now and submit something on
this section after the thread section is completed?

And, unless that routine copies everything from the inferior, which is risky
> because it can change there any time, I think the above is not really what
> you want, you instead want to read it from the inferior.
>

When you say inferior, are you referring to the gomp_thread and
gomp_thread_pool?

The debugged process (if it is a process and not e.g. a core file) is not in
> the same address space as the debugger (that loads the OMPD library), so
> even if you get pointers copied from the debugged process, you can't
> dereference them, but need to use the callbacks to read the corresponding
> memory.
>

Okay. I was afraid I might have made a mistake with this regard. The use of
callbacks was to make the debugging process decoupled, right? I think I
remember reading the example of running the process and debugging in a
different machine.

Thank you again for the help.

Cheers,

Tony Sim

>
> Jakub
>
>


Re: [PATCH] libgomp: Add OMPD Address Space Information functions.

2020-07-14 Thread y2s1982 via Gcc-patches
Hello Jakub,

Thank you for the detailed information. I will make those changes right
away.

Cheers,

Tony Sim

On Tue, Jul 14, 2020 at 5:57 AM Jakub Jelinek  wrote:

> On Thu, Jul 09, 2020 at 07:01:00PM -0400, y2s1982 via Gcc-patches wrote:
> > --- a/libgomp/libgompd.h
> > +++ b/libgomp/libgompd.h
> > @@ -47,4 +47,19 @@ typedef struct _ompd_aspace_handle {
> >ompd_size_t ref_count;
> >  } ompd_address_space_handle_t;
> >
> > +struct gompd_env
> > +{
> > +  /* TODO: when the struct is better defined, turn it into a compact
> form.
> > + LINK:
> https://gcc.gnu.org/pipermail/gcc-patches/2020-July/549698.html
> > + For now, keep it as a struct.  */
> > +
> > +  /* Environment set version number.  */
> > +  ompd_word_t gompd_env_version;
> > +  /* Represents _OPENMP that is in mm format.  */
> > +  ompd_word_t openmp_version;
> > +};
> > +
> > +/* TODO: when gompd_env is better defined, turn it into a compact
> form.  */
> > +extern struct gompd_env gompd_env_info;
>
> I don't think you want this to be a global var.
>
> > +  ompd_size_t macro_length = 6; /* _OPENMP format: mm.  */
>
> So use omp_version_len = strlen ("mm");
> and no comment is needed (the compiler will optimize it into constant)
> or omp_version_len = sizeof ("yyymm") - 1;
>
> > +  char *tmp = "GNU OpenMP Runtime implementing OpenMP 5.0 ";
> > +  ompd_size_t tmp_length = strlen (tmp);
>
> Use name instead of tmp in both vars?
>
> > --- a/libgomp/ompd-lib.c
> > +++ b/libgomp/ompd-lib.c
> > @@ -31,6 +31,17 @@
> >
> >  ompd_callbacks_t gompd_callbacks;
> >  static int ompd_initialized = 0;
> > +struct gompd_env gompd_env_info;
>
> Again.
>
> > +
> > +ompd_rc_t
> > +gompd_set_environment ()
> > +{
> > +  /* TODO: Turn this placeholder function to handle OMPD environment
> variables
> > + when it becomes compact.  */
> > +  struct gompd_env temp_env = { 202007, 201811 };
> > +  gompd_env_info = temp_env;
> > +  return ompd_rc_ok;
> > +}
> >
> >  ompd_rc_t
> >  ompd_get_api_version (ompd_word_t *version)
> > @@ -57,6 +68,7 @@ ompd_initialize (ompd_word_t api_version, const
> ompd_callbacks_t *callbacks)
> >  return ompd_rc_error;
> >
> >gompd_callbacks = *callbacks;
> > +  gompd_set_environment ();
>
> And you shouldn't call it here, but instead in ompd_process_initialize
> and put the struct into the handle.
>
> The thing is, the same OMPD library can e.g. handle a 64-bit and 32-bit
> process, or one with older and one with newer libgomp.so.1.
>
> Jakub
>
>


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

2020-07-11 Thread y2s1982 via Gcc-patches
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  

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 000..ca2de726238
--- /dev/null
+++ b/libgomp/ompd-parallel.c
@@ -0,0 +1,125 @@
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Yoosuk Sim .
+
+   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
+   .  */
+
+/* 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 

[PATCH] libgomp: Add OMPD Address Space Information functions.

2020-07-09 Thread y2s1982 via Gcc-patches
This patch adds Address Space Information function implementations as
defined in section 5.5.4 of OpenMP API Specification 5.0. It also
defines a struct that stores various information used by OMPD.

2020-07-09  Tony Sim  

libgomp/ChangeLog:

* Makefile.am (libgompd_la_OBJECTS): Add ompd-addr.c.
* Makefile.in: Regenerate.
* libgompd.h (struct gompd_env): Add an extern declaration.
* ompd-lib.c (struct gompd_env): Define.
(gompd_set_environment): Define a placeholder function.
(ompd_initialize): Add a call to gompd_set_environment.
* ompd-addr.c: New file.

---
 libgomp/Makefile.am |  2 +-
 libgomp/Makefile.in |  5 +--
 libgomp/libgompd.h  | 15 +
 libgomp/ompd-addr.c | 81 +
 libgomp/ompd-lib.c  | 12 +++
 5 files changed, 112 insertions(+), 3 deletions(-)
 create mode 100644 libgomp/ompd-addr.c

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index fe0a92122ea..0a4a9c10eb9 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -90,7 +90,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
oacc-mem.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
 
-libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-addr.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 2b487e00499..9ceb2c6e460 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -235,7 +235,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
$(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
 libgompd_la_LIBADD =
-am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo
+am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo ompd-addr.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@)
@@ -592,7 +592,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 $(am__append_4)
-libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-addr.c
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -816,6 +816,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-plugin.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-profiling.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-target.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-addr.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-lib.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-proc.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordered.Plo@am__quote@
diff --git a/libgomp/libgompd.h b/libgomp/libgompd.h
index 495995e00d3..36cb858589e 100644
--- a/libgomp/libgompd.h
+++ b/libgomp/libgompd.h
@@ -47,4 +47,19 @@ typedef struct _ompd_aspace_handle {
   ompd_size_t ref_count;
 } ompd_address_space_handle_t;
 
+struct gompd_env
+{
+  /* TODO: when the struct is better defined, turn it into a compact form.
+ LINK: https://gcc.gnu.org/pipermail/gcc-patches/2020-July/549698.html
+ For now, keep it as a struct.  */
+
+  /* Environment set version number.  */
+  ompd_word_t gompd_env_version;
+  /* Represents _OPENMP that is in mm format.  */
+  ompd_word_t openmp_version;
+};
+
+/* TODO: when gompd_env is better defined, turn it into a compact form.  */
+extern struct gompd_env gompd_env_info;
+
 #endif /* LIBGOMPD_H */
diff --git a/libgomp/ompd-addr.c b/libgomp/ompd-addr.c
new file mode 100644
index 000..b751d64ce28
--- /dev/null
+++ b/libgomp/ompd-addr.c
@@ -0,0 +1,81 @@
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Yoosuk Sim .
+
+   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 

Re: [PATCH] libgomp: Add OMPD Address Space Information functions.

2020-07-08 Thread y2s1982 . via Gcc-patches
Hello Jakub,

Thank you again for detailed feedback. I had few questions.

On Wed, Jul 8, 2020 at 4:42 PM Jakub Jelinek  wrote:

> On Wed, Jul 08, 2020 at 03:30:35PM -0400, y2s1982 wrote:
> > +ompd_rc_t
> > +ompd_get_omp_version (ompd_address_space_handle_t *address_space,
> > +   ompd_word_t *omp_version)
> > +{
> > +  if (omp_version == NULL)
> > +return ompd_rc_bad_input;
> > +  if (address_space == NULL)
> > +return ompd_rc_stale_handle;
> > +
> > +  /* _OPENMP macro is defined to have mm integer.  */
> > +  ompd_size_t macro_length = sizeof (int);
> > +
> > +  ompd_rc_t ret = ompd_rc_ok;
> > +
> > +  struct ompd_address_t addr;
> > +  ret = gompd_callbacks.symbol_addr_lookup (address_space->context,
> NULL,
> > + "openmp_version", , NULL);
>
> This can't be right.  There is no openmp_version variable in libgomp.so.1
> (and I don't think we should add it).
> As I said multiple times before, you should add one (read-only) data
> variable to libgomp.so.1 that will encode a lot of information that OMPD
> needs and the version should be in there.
>

I do remember, though I obviously understood wrongly. Sorry about that.
I had assumed it might have something to do with ICV but didn't realize it
would also
apply to other variables. In all honesty, I was looking for _OPENMP macro;
I assumed
such information would be stored somewhere already and thought
symbol_addr_lookup() would find it somehow. I saw mentions of it on
ChangeLog,
testsuits, and in one string, but I couldn't find the actual macro. As for
openmp_version,
I (wrongly) made the assumption looking at the omp_lib.h.in. I should learn
more
about .in file's syntax and what they do.

To place a variable in libgomp.so.1, should I define a related struct and
declare a global
extern variable of the struct in omp.h and define it in some related .c
file?
Can I then simply use the name of the declared variable as the name (where
"openmp_version" currently  is) to find the struct? As for the value for
_OPENMP version,
where can I find it, or should OMPD maintain its own values for it?


> > +ompd_rc_t
> > +ompd_get_omp_version_string (ompd_address_space_handle_t *address_space,
> > +  const char **string)
> > +{
> > +  if (string == NULL)
> > +return ompd_rc_bad_input;
> > +
> > +  if (address_space == NULL)
> > +return ompd_rc_stale_handle;
> > +
> > +  ompd_word_t omp_version;
> > +  ompd_rc_t ret = ompd_get_omp_version (address_space, _version);
> > +  if (ret != ompd_rc_ok)
> > +return ret;
> > +
> > +  char *tmp = "GNU OpenMP Runtime implementing OpenMP 5.0 "
> > + ompd_stringify (omp_version);
>
> This will append "omp_version" to the string literal, won't it?
> That is not what you want in there, you instead want the value.
>

Oh I see. Thanks for pointing that out. I am still learning how macro
expansion works.

Cheers,

Tony

>
> Jakub
>
>


[PATCH] libgomp: Add OMPD Address Space Information functions.

2020-07-08 Thread y2s1982 via Gcc-patches
This patch adds Address Space Information function implementations as
defined in section 5.5.4 of OpenMP API Specification 5.0.

2020-07-08  Tony Sim  

libgomp/ChangeLog:

* Makefile.am (libgompd_la_OBJECTS): Add ompd-addr.c.
* Makefile.in: Regenerate.
* ompd-addr.c: New file.

---
 libgomp/Makefile.am |  2 +-
 libgomp/Makefile.in |  5 +--
 libgomp/ompd-addr.c | 88 +
 3 files changed, 92 insertions(+), 3 deletions(-)
 create mode 100644 libgomp/ompd-addr.c

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index fe0a92122ea..0a4a9c10eb9 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -90,7 +90,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
oacc-mem.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
 
-libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-addr.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 2b487e00499..9ceb2c6e460 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -235,7 +235,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
$(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
 libgompd_la_LIBADD =
-am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo
+am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo ompd-addr.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@)
@@ -592,7 +592,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 $(am__append_4)
-libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-addr.c
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -816,6 +816,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-plugin.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-profiling.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-target.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-addr.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-lib.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-proc.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordered.Plo@am__quote@
diff --git a/libgomp/ompd-addr.c b/libgomp/ompd-addr.c
new file mode 100644
index 000..f1f3b8071c1
--- /dev/null
+++ b/libgomp/ompd-addr.c
@@ -0,0 +1,88 @@
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Yoosuk Sim .
+
+   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
+   .  */
+
+/* This file contains function definitions for OMPD's Address Space Information
+   functions defined in the OpenMP 5.0 API Documentation, 5.5.4.  */
+
+#include 
+#include 
+#include "omp-tools.h"
+#include "libgompd.h"
+
+ompd_rc_t
+ompd_get_omp_version (ompd_address_space_handle_t *address_space,
+ ompd_word_t *omp_version)
+{
+  if (omp_version == NULL)
+return ompd_rc_bad_input;
+  if (address_space == NULL)
+return ompd_rc_stale_handle;
+
+  /* _OPENMP macro is defined to have mm integer.  */
+  ompd_size_t macro_length = sizeof (int);
+
+  ompd_rc_t ret = ompd_rc_ok;
+
+  struct ompd_address_t addr;
+  ret = gompd_callbacks.symbol_addr_lookup (address_space->context, NULL,
+   "openmp_version", , NULL);
+  if (ret != ompd_rc_ok)
+return ret;
+
+  ret = gompd_callbacks.read_memory (address_space->context, NULL, ,
+macro_length, (void *) omp_version);
+  return ompd_rc_ok;
+}
+
+ompd_rc_t

Re: [PATCH] libgomp: Add OMPD process functions and datatypes.

2020-07-08 Thread y2s1982 . via Gcc-patches
Hello

On Wed, Jul 8, 2020 at 5:08 AM Jakub Jelinek  wrote:

> On Tue, Jul 07, 2020 at 02:52:37PM -0400, y2s1982 . via Gcc-patches wrote:
> > I have re-read the documentation trying to find a different solution.
> > In particular, ompd_device_initialize states that
> > ompd_device_t kind, ompd_size_t sizeof_id, and void *id represents
> > a device identifier. To dig further, I read up on the ompd_device_t. A
> > passage from ompd_device_t says that the OMPD library and a tool that
> uses
> > it must agree on the format of the object that is passed.
> > It also says that ompd_device_t is a pointer to where the device
> identifier
> > is stored and the size of the device identifier. I am not sure how this
> > works to ompd_device_initialize as those two information seems to be
> > supplied separately: *id and sizeof_id. In fact, ompd-type.h provides 4
> > examples, 2 of which are host and cuda, and they all simply contain
> unique
> > numerical values.  So does this mean that I should just decide on what
> the
> > library and tool will use for device id data type and simply stick to it?
> >
> > Otherwise, Is it possible to know the proper data type to cast the void
> *id
> > based on the device type (host/cuda)?
>
> Looking at libompd, it ignores sizeof_id completely and saves id (the
> pointer) in its device context, but doesn't ever do anything with it, so
> effectively ignores it completely.
>
> I think starting with devices it not a good idea, just return failure from
> ompd_device_initialize for now and get back to it much later, when
> handling of parallel, host teams, task etc. is all done.
> Because communicating with devices will need also communication with the
> libgomp plugins.
>

Thank you for the guidance. I have uploaded an updated patch where
ompd_device_initialize() ultimately returns an error. I have also added
FIXME
for future planning.

Tony

>
> Jakub
>
>


[PATCH] libgomp: Add skeletal OMPD process functions and datatypes.

2020-07-08 Thread y2s1982 via Gcc-patches
This patch adds OMPD functions defined in 5.5.2 of the OpenMP 5.0 API
documentation. It adds per-process and per-device functions, defines
related handle data types. It also introduces ompd-types.h to Makefile.

2020-07-08  Tony Sim  

libgomp/ChangeLog:

* Makefile.am (libgompd_la_SOURCES): Add ompd-proc.c.
(nodist_libsubinclude_HEADERS): Add ompd-types.h.
* Makefile.in: Regenerate.
* libgompd.h (ompd_address_space_handle_t): Add definition.
* ompd-proc.c: New file.
* ompd-types.h: New file.

---
 libgomp/Makefile.am  |   4 +-
 libgomp/Makefile.in  |  11 ++--
 libgomp/libgompd.h   |   9 +++
 libgomp/ompd-proc.c  | 130 +++
 libgomp/ompd-types.h |  90 ++
 5 files changed, 237 insertions(+), 7 deletions(-)
 create mode 100644 libgomp/ompd-proc.c
 create mode 100644 libgomp/ompd-types.h

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index e15a838e55c..fe0a92122ea 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -90,7 +90,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
oacc-mem.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
 
-libgompd_la_SOURCES = ompd-lib.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
@@ -99,7 +99,7 @@ libgomp_la_SOURCES += openacc.f90
 endif
 
 nodist_noinst_HEADERS = libgomp_f.h
-nodist_libsubinclude_HEADERS = omp.h omp-tools.h openacc.h acc_prof.h
+nodist_libsubinclude_HEADERS = omp.h omp-tools.h ompd-types.h openacc.h 
acc_prof.h
 if USE_FORTRAN
 nodist_finclude_HEADERS = omp_lib.h omp_lib.f90 omp_lib.mod omp_lib_kinds.mod \
openacc_lib.h openacc.f90 openacc.mod openacc_kinds.mod
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index af897d6c6ba..2b487e00499 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -235,7 +235,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
$(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
 libgompd_la_LIBADD =
-am_libgompd_la_OBJECTS = ompd-lib.lo
+am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.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@)
@@ -574,10 +574,10 @@ nodist_toolexeclib_HEADERS = libgomp.spec
 libgomp_version_info = -version-info $(libtool_VERSION)
 libgompd_version_info = -version-info $(libtool_VERSION)
 libgomp_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \
-$(lt_host_flags)
+   $(lt_host_flags)
 
 libgompd_la_LDFLAGS = $(libgompd_version_info) $(libgompd_version_script) \
-$(lt_host_flags)
+   $(lt_host_flags)
 
 libgomp_la_DEPENDENCIES = $(libgomp_version_dep)
 libgompd_la_DEPENDENCIES = $(libgompd_version_dep)
@@ -592,7 +592,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 $(am__append_4)
-libgompd_la_SOURCES = ompd-lib.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -628,7 +628,7 @@ libgompd_la_SOURCES = ompd-lib.c
 @PLUGIN_GCN_TRUE@libgomp_plugin_gcn_la_LIBADD = libgomp.la $(PLUGIN_GCN_LIBS)
 @PLUGIN_GCN_TRUE@libgomp_plugin_gcn_la_LIBTOOLFLAGS = --tag=disable-static
 nodist_noinst_HEADERS = libgomp_f.h
-nodist_libsubinclude_HEADERS = omp.h omp-tools.h openacc.h acc_prof.h
+nodist_libsubinclude_HEADERS = omp.h omp-tools.h ompd-types.h openacc.h 
acc_prof.h
 @USE_FORTRAN_TRUE@nodist_finclude_HEADERS = omp_lib.h omp_lib.f90 omp_lib.mod 
omp_lib_kinds.mod \
 @USE_FORTRAN_TRUE@ openacc_lib.h openacc.f90 openacc.mod openacc_kinds.mod
 
@@ -817,6 +817,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-profiling.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-target.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-lib.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-proc.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@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/priority_queue.Plo@am__quote@
diff --git a/libgomp/libgompd.h b/libgomp/libgompd.h
index 3a428e1c1e4..495995e00d3 100644
--- a/libgomp/libgompd.h
+++ b/libgomp/libgompd.h
@@ -38,4 +38,13 @@
 
 extern ompd_callbacks_t gompd_callbacks;
 
+typedef struct _ompd_aspace_handle {
+  ompd_address_space_context_t *context;
+  ompd_device_t kind;
+  ompd_size_t sizeof_id;
+  void *id;
+  ompd_address_space_handle_t *process_reference;
+  ompd_size_t ref_count;
+} ompd_address_space_handle_t;
+
 #endif /* 

Re: [PATCH] libgomp: Add OMPD process functions and datatypes.

2020-07-07 Thread y2s1982 . via Gcc-patches
Hello,

On Tue, Jul 7, 2020 at 7:46 AM Jakub Jelinek  wrote:

> On Tue, Jul 07, 2020 at 07:38:13AM -0400, y2s1982 . wrote:
> > > I have no idea what this function is doing, but e.g. from aliasing
> point of
> > > view trying to access something as short/int/long long is dangerous,
> and
> > > there might be alignment implications too.
> > >
> >
> > This function is used in ompd_device_initialize(). The initializing
> function
> > receives a void *id and ompd_size_t sizeof_id. My first attempt tried to
> > just
> > preserve both information as is, but I wasn't sure how the void * would
> > ultimately be read. In the second attempt, I tried to cast the value,
> based
> > on
> > the sizeof_id, and store it in a large enough type. This does assume the
> > void * is pointing at a numerical value.
> > What would be the best way to handle the void *id?
>
> Well, you should know what it is and only depending on that handle it.
> If it e.g. would be string, you'd want to use memcpy to copy it somewhere,
> or parse immediately, etc.
>

I have re-read the documentation trying to find a different solution.
In particular, ompd_device_initialize states that
ompd_device_t kind, ompd_size_t sizeof_id, and void *id represents
a device identifier. To dig further, I read up on the ompd_device_t. A
passage from ompd_device_t says that the OMPD library and a tool that uses
it must agree on the format of the object that is passed.
It also says that ompd_device_t is a pointer to where the device identifier
is stored and the size of the device identifier. I am not sure how this
works to ompd_device_initialize as those two information seems to be
supplied separately: *id and sizeof_id. In fact, ompd-type.h provides 4
examples, 2 of which are host and cuda, and they all simply contain unique
numerical values.  So does this mean that I should just decide on what the
library and tool will use for device id data type and simply stick to it?

Otherwise, Is it possible to know the proper data type to cast the void *id
based on the device type (host/cuda)?

Tony


Re: [PATCH] libgomp: Add OMPD process functions and datatypes.

2020-07-07 Thread y2s1982 . via Gcc-patches
Hello Jakub,

Thank you for the review. I had some questions.

On Tue, Jul 7, 2020 at 4:13 AM Jakub Jelinek  wrote:

> On Fri, Jul 03, 2020 at 10:43:55PM -0400, y2s1982 via Gcc-patches wrote:
>
> > +  switch (id_size)
> > +{
> > +case 1:
> > +  *output_id = (_gompd_device_id) *((__UINT8_TYPE__ *) input_id);
> > +  break;
> > +case 2:
> > +  *output_id = (_gompd_device_id) *((__UINT16_TYPE__ *) input_id);
>
> I have no idea what this function is doing, but e.g. from aliasing point of
> view trying to access something as short/int/long long is dangerous, and
> there might be alignment implications too.
>

This function is used in ompd_device_initialize(). The initializing function
receives a void *id and ompd_size_t sizeof_id. My first attempt tried to
just
preserve both information as is, but I wasn't sure how the void * would
ultimately be read. In the second attempt, I tried to cast the value, based
on
the sizeof_id, and store it in a large enough type. This does assume the
void * is pointing at a numerical value.
What would be the best way to handle the void *id?

>
>
> > --- /dev/null
> > +++ b/libgomp/ompd-types.h
>
> ompd-types.h is an installed header I think, so Makefile.am should install
> it.
>
Is this similar to how omp-tools.h was handled before?

Cheers,

Tony


>
> Jakub
>
>


[PATCH] libgomp: Add OMPD process functions and datatypes.

2020-07-03 Thread y2s1982 via Gcc-patches
This patch adds OMPD functions defined in 5.5.2 of the OpenMP 5.0 API
documentation. It adds per-process and per-device functions, defines
related handle data types, and adds a helper function for storing device
id.

2020-07-03  Tony Sim  

libgomp/ChangeLog:

* Makefile.am (libgompd_la_OBJECTS): Add ompd-proc.c and
 ompd-helper.c
* Makefile.in: Regenerate.
* libgompd.h (ompd_address_space_handle_t): Define.
(_gompd_device_id): Define.
* ompd-helper.c: New file.
* ompd-helper.h: New file.
* ompd-proc.c: New file.
* ompd-types.h: New file.

---
 libgomp/Makefile.am   |   2 +-
 libgomp/Makefile.in   |  10 ++--
 libgomp/libgompd.h|  10 
 libgomp/ompd-helper.c |  58 +
 libgomp/ompd-helper.h |  37 +
 libgomp/ompd-proc.c   | 117 ++
 libgomp/ompd-types.h  |  90 
 7 files changed, 319 insertions(+), 5 deletions(-)
 create mode 100644 libgomp/ompd-helper.c
 create mode 100644 libgomp/ompd-helper.h
 create mode 100644 libgomp/ompd-proc.c
 create mode 100644 libgomp/ompd-types.h

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index e15a838e55c..4306951046f 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -90,7 +90,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
oacc-mem.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
 
-libgompd_la_SOURCES = ompd-lib.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-helper.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index af897d6c6ba..dc0f3b58ebe 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -235,7 +235,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
$(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
 libgompd_la_LIBADD =
-am_libgompd_la_OBJECTS = ompd-lib.lo
+am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo ompd-helper.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@)
@@ -574,10 +574,10 @@ nodist_toolexeclib_HEADERS = libgomp.spec
 libgomp_version_info = -version-info $(libtool_VERSION)
 libgompd_version_info = -version-info $(libtool_VERSION)
 libgomp_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \
-$(lt_host_flags)
+   $(lt_host_flags)
 
 libgompd_la_LDFLAGS = $(libgompd_version_info) $(libgompd_version_script) \
-$(lt_host_flags)
+   $(lt_host_flags)
 
 libgomp_la_DEPENDENCIES = $(libgomp_version_dep)
 libgompd_la_DEPENDENCIES = $(libgompd_version_dep)
@@ -592,7 +592,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 $(am__append_4)
-libgompd_la_SOURCES = ompd-lib.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-helper.c
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -816,7 +816,9 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-plugin.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-profiling.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-target.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-helper.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-lib.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-proc.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@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/priority_queue.Plo@am__quote@
diff --git a/libgomp/libgompd.h b/libgomp/libgompd.h
index 3a428e1c1e4..f1338e7b3e4 100644
--- a/libgomp/libgompd.h
+++ b/libgomp/libgompd.h
@@ -38,4 +38,14 @@
 
 extern ompd_callbacks_t gompd_callbacks;
 
+typedef __UINT64_TYPE__ _gompd_device_id;
+
+typedef struct _ompd_aspace_handle {
+  ompd_address_space_context_t *context;
+  ompd_device_t kind;
+  _gompd_device_id id;
+  ompd_address_space_handle_t *process_reference;
+  ompd_size_t ref_count;
+} ompd_address_space_handle_t;
+
 #endif /* LIBGOMPD_H */
diff --git a/libgomp/ompd-helper.c b/libgomp/ompd-helper.c
new file mode 100644
index 000..949b9cf771e
--- /dev/null
+++ b/libgomp/ompd-helper.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Yoosuk Sim .
+
+   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 

Re: [PATCH] libgomp: Add OMPD per-process functions.

2020-07-03 Thread y2s1982 . via Gcc-patches
Hello,

I believe I misused the write_memory() function. This function is currently
used
in ompd_device_initialize() to write a block of memory that represents the
id of
the device, stored in the handle as a pointer. I would need to resubmit the
patch
but I have some questions regarding the issue.

Re-reading the documentation, it seems the callback function is used to
write to the OpenMP program described in the context, which may be a
different device than the host, like a SMX, which would have its own
dedicated memory.
They way it is currently written, I fear it might just corrupt some random
memory block
somewhere in target device instead of writing to the handle if the
device_context
somewhere other than the host.

I am not sure how best to store that information. It is passed in as a void
*id with
the accompanying ompd_size_t sizeof_id variable. Would it be safe to assume
all variable information will be safely stored in the unsigned long long,
do some
casting based on the sizeof_id, and store it in unsigned long long member
variable?

Cheers,

Tony Sim


On Fri, Jul 3, 2020 at 1:49 PM y2s1982  wrote:

> This patch adds OMPD process and device handling functions and related
> data structures as described in the OMP 5.0 API documentation, section
> 5.5.2.
>
> 2020-07-03  Tony Sim  
>
> libgomp/ChangeLog:
>
> * Makefile.am (libgompd_la_SOURCES): Add ompd-proc.c
> * Makefile.in: Regenerate.
> * libgompd.h (ompd_address_space_handle_t): Add definition.
> * ompd-proc.c: New file.
> * ompd-types.h: New file.
>
> ---
>  libgomp/Makefile.am  |   2 +-
>  libgomp/Makefile.in  |   9 +--
>  libgomp/libgompd.h   |   9 +++
>  libgomp/ompd-proc.c  | 132 +++
>  libgomp/ompd-types.h |  90 +
>  5 files changed, 237 insertions(+), 5 deletions(-)
>  create mode 100644 libgomp/ompd-proc.c
>  create mode 100644 libgomp/ompd-types.h
>
> diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
> index e15a838e55c..e5556ef61e5 100644
> --- a/libgomp/Makefile.am
> +++ b/libgomp/Makefile.am
> @@ -90,7 +90,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c
> critical.c env.c error.c \
> oacc-mem.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
>
> -libgompd_la_SOURCES = ompd-lib.c
> +libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
>
>  include $(top_srcdir)/plugin/Makefrag.am
>
> diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
> index af897d6c6ba..f0f91761a0d 100644
> --- a/libgomp/Makefile.in
> +++ b/libgomp/Makefile.in
> @@ -235,7 +235,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo
> critical.lo \
> $(am__objects_1)
>  libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
>  libgompd_la_LIBADD =
> -am_libgompd_la_OBJECTS = ompd-lib.lo
> +am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.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@)
> @@ -574,10 +574,10 @@ nodist_toolexeclib_HEADERS = libgomp.spec
>  libgomp_version_info = -version-info $(libtool_VERSION)
>  libgompd_version_info = -version-info $(libtool_VERSION)
>  libgomp_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \
> -$(lt_host_flags)
> +   $(lt_host_flags)
>
>  libgompd_la_LDFLAGS = $(libgompd_version_info) $(libgompd_version_script)
> \
> -$(lt_host_flags)
> +   $(lt_host_flags)
>
>  libgomp_la_DEPENDENCIES = $(libgomp_version_dep)
>  libgompd_la_DEPENDENCIES = $(libgompd_version_dep)
> @@ -592,7 +592,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 $(am__append_4)
> -libgompd_la_SOURCES = ompd-lib.c
> +libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
>
>  # Nvidia PTX OpenACC plugin.
>  @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info
> $(libtool_VERSION)
> @@ -817,6 +817,7 @@ distclean-compile:
>  @AMDEP_TRUE@@am__include@ @am__quote@
> ./$(DEPDIR)/oacc-profiling.Plo@am__quote@
>  @AMDEP_TRUE@@am__include@ @am__quote@
> ./$(DEPDIR)/oacc-target.Plo@am__quote@
>  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-lib.Plo@am__quote@
> +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-proc.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@
>  @AMDEP_TRUE@@am__include@ @am__quote@
> ./$(DEPDIR)/priority_queue.Plo@am__quote@
> diff --git a/libgomp/libgompd.h b/libgomp/libgompd.h
> index 3a428e1c1e4..495995e00d3 100644
> --- a/libgomp/libgompd.h
> +++ b/libgomp/libgompd.h
> @@ -38,4 +38,13 @@
>
>  extern ompd_callbacks_t gompd_callbacks;
>
> +typedef struct _ompd_aspace_handle {
> +  ompd_address_space_context_t *context;
> +  

[PATCH] libgomp: Add OMPD per-process functions.

2020-07-03 Thread y2s1982 via Gcc-patches
This patch adds OMPD process and device handling functions and related
data structures as described in the OMP 5.0 API documentation, section
5.5.2.

2020-07-03  Tony Sim  

libgomp/ChangeLog:

* Makefile.am (libgompd_la_SOURCES): Add ompd-proc.c
* Makefile.in: Regenerate.
* libgompd.h (ompd_address_space_handle_t): Add definition.
* ompd-proc.c: New file.
* ompd-types.h: New file.

---
 libgomp/Makefile.am  |   2 +-
 libgomp/Makefile.in  |   9 +--
 libgomp/libgompd.h   |   9 +++
 libgomp/ompd-proc.c  | 132 +++
 libgomp/ompd-types.h |  90 +
 5 files changed, 237 insertions(+), 5 deletions(-)
 create mode 100644 libgomp/ompd-proc.c
 create mode 100644 libgomp/ompd-types.h

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index e15a838e55c..e5556ef61e5 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -90,7 +90,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
oacc-mem.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
 
-libgompd_la_SOURCES = ompd-lib.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index af897d6c6ba..f0f91761a0d 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -235,7 +235,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
$(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
 libgompd_la_LIBADD =
-am_libgompd_la_OBJECTS = ompd-lib.lo
+am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.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@)
@@ -574,10 +574,10 @@ nodist_toolexeclib_HEADERS = libgomp.spec
 libgomp_version_info = -version-info $(libtool_VERSION)
 libgompd_version_info = -version-info $(libtool_VERSION)
 libgomp_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \
-$(lt_host_flags)
+   $(lt_host_flags)
 
 libgompd_la_LDFLAGS = $(libgompd_version_info) $(libgompd_version_script) \
-$(lt_host_flags)
+   $(lt_host_flags)
 
 libgomp_la_DEPENDENCIES = $(libgomp_version_dep)
 libgompd_la_DEPENDENCIES = $(libgompd_version_dep)
@@ -592,7 +592,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 $(am__append_4)
-libgompd_la_SOURCES = ompd-lib.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -817,6 +817,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-profiling.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-target.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-lib.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-proc.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@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/priority_queue.Plo@am__quote@
diff --git a/libgomp/libgompd.h b/libgomp/libgompd.h
index 3a428e1c1e4..495995e00d3 100644
--- a/libgomp/libgompd.h
+++ b/libgomp/libgompd.h
@@ -38,4 +38,13 @@
 
 extern ompd_callbacks_t gompd_callbacks;
 
+typedef struct _ompd_aspace_handle {
+  ompd_address_space_context_t *context;
+  ompd_device_t kind;
+  ompd_size_t sizeof_id;
+  void *id;
+  ompd_address_space_handle_t *process_reference;
+  ompd_size_t ref_count;
+} ompd_address_space_handle_t;
+
 #endif /* LIBGOMPD_H */
diff --git a/libgomp/ompd-proc.c b/libgomp/ompd-proc.c
new file mode 100644
index 000..39feba056f2
--- /dev/null
+++ b/libgomp/ompd-proc.c
@@ -0,0 +1,132 @@
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Yoosuk Sim .
+
+   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 

[PATCH] libgomp: defined OMPD library-wide functions.

2020-07-01 Thread y2s1982 via Gcc-patches
This patch provides an initial set of definition for the rest of library-wide 
OMPD functions.

It addresses all feedbacks.

2020-07-01  Tony Sim  

libgomp/ChangeLog:

* libgompd.h: Include omp-tools.h.
(gompd_callbacks): New extern declaration.
* ompd-lib.c (gompd_callbacks): New declaration.
(ompd_initialized): New declaration.
(ompd_initialize): Checks callbacks and assigns it to gompd_callbacks.
(ompd_finalize): Add new function.

---
 libgomp/libgompd.h |  4 
 libgomp/ompd-lib.c | 16 ++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/libgomp/libgompd.h b/libgomp/libgompd.h
index 9782828bff5..3a428e1c1e4 100644
--- a/libgomp/libgompd.h
+++ b/libgomp/libgompd.h
@@ -29,9 +29,13 @@
 #ifndef LIBGOMPD_H
 #define LIBGOMPD_H 1
 
+#include "omp-tools.h"
+
 #define ompd_stringify(x) ompd_str2(x)
 #define ompd_str2(x) #x
 
 #define OMPD_VERSION 201811
 
+extern ompd_callbacks_t gompd_callbacks;
+
 #endif /* LIBGOMPD_H */
diff --git a/libgomp/ompd-lib.c b/libgomp/ompd-lib.c
index f0ae9e85a7e..d5350e1045c 100644
--- a/libgomp/ompd-lib.c
+++ b/libgomp/ompd-lib.c
@@ -29,6 +29,9 @@
 #include "omp-tools.h"
 #include "libgompd.h"
 
+ompd_callbacks_t gompd_callbacks;
+static int ompd_initialized = 0;
+
 ompd_rc_t
 ompd_get_api_version (ompd_word_t *version)
 {
@@ -47,15 +50,24 @@ ompd_get_version_string (const char **string)
 ompd_rc_t
 ompd_initialize (ompd_word_t api_version, const ompd_callbacks_t *callbacks)
 {
-  static int ompd_initialized = 0;
+  if (!callbacks)
+return ompd_rc_bad_input;
 
   if (ompd_initialized)
 return ompd_rc_error;
 
+  gompd_callbacks = *callbacks;
+
   (void) api_version;
-  (void) callbacks;
 
   ompd_initialized = 1;
 
   return ompd_rc_ok;
 }
+
+ompd_rc_t
+ompd_finalize (void)
+{
+  ompd_initialized = 0;
+  return ompd_rc_ok;
+}
-- 
2.27.0



Re: [PATCH] libgomp: added simple functions and tests for OMPD

2020-06-26 Thread y2s1982 . via Gcc-patches
Hello,

On Fri, Jun 26, 2020 at 1:08 PM Jakub Jelinek  wrote:

> On Fri, Jun 26, 2020 at 12:57:59PM -0400, y2s1982 . wrote:
> > > >   * env.c(ompd_dll_locations_valid): Define with no compiler
> > > optimization.
> > >
> > > Again, missing space.
> > >
> > > The contrib/mklog.py, which I use to generate these messages, seems to
> > generate the statement without a space after the filename and before the
> (.
> > It seems like an easy fix of just adding a space like the following:
> >   diff --git a/contrib/mklog.py b/contrib/mklog.py
> >   index 243edbb15c5..0b01cde6fca 100755
> >   --- a/contrib/mklog.py
> >   +++ b/contrib/mklog.py
> >   @@ -215,7 +215,7 @@ def generate_changelog(data, no_functions=False,
> > fill_pr_titles=False):
> >if functions:
> >out += '\t* %s (%s):\n' % (relative_path,
> > functions[0])
> >for fn in functions[1:]:
> >   -out += '\t(%s):\n' % fn
> >   +   out += '\t (%s):\n' % fn
> >else:
> >   out += '\t* %s:\n' % relative_path
> >   out += '\n'
>
> That is strange.  The missing space I'm complaining about, e.g. between
> env.c and (, is there in the above snippet, that is
> '\t* %s (%s):\n'
>^- this one
> and the space you are adding to mklog.py is undesirable, when one modifies
> multiple functions, it should look like:
> * env.c (foo): Something.
> (bar): Something else.
> rather than
> * env.c (foo): Something.
>  (bar): Something else.
>

I see. I was thinking that doesn't make much sense, too, but when tested,
it placed
a space between the filename and the (.  I wasn't sure what to make of it.
Maybe my editor is somehow manipulating spaces and tabs when loading the
patch
for final editing or maybe the script I made is doing something more than
just pasting
the output of the contrib/mklog.py to the patch.
Thanks for pointing it out. I will investigate further.

Cheers,

Tony Sim

>
> Jakub
>
>


Re: [PATCH] libgomp: added simple functions and tests for OMPD

2020-06-26 Thread y2s1982 . via Gcc-patches
Hello,

On Fri, Jun 26, 2020 at 5:03 AM Jakub Jelinek  wrote:

> Thanks, just nits, no need to repost, just commit it after you make those
> changes.
>
> On Thu, Jun 25, 2020 at 05:58:23PM -0400, y2s1982 via Gcc-patches wrote:
>
> >   * Makefile.am(toolexeclib_LTLIBRARIES): Add libgompd.la.
>
> Missing space between am and (.
>
> >   * env.c(ompd_dll_locations_valid): Define with no compiler
> optimization.
>
> Again, missing space.
>
> The contrib/mklog.py, which I use to generate these messages, seems to
generate the statement without a space after the filename and before the (.
It seems like an easy fix of just adding a space like the following:
  diff --git a/contrib/mklog.py b/contrib/mklog.py
  index 243edbb15c5..0b01cde6fca 100755
  --- a/contrib/mklog.py
  +++ b/contrib/mklog.py
  @@ -215,7 +215,7 @@ def generate_changelog(data, no_functions=False,
fill_pr_titles=False):
   if functions:
   out += '\t* %s (%s):\n' % (relative_path,
functions[0])
   for fn in functions[1:]:
  -out += '\t(%s):\n' % fn
  +   out += '\t (%s):\n' % fn
   else:
  out += '\t* %s:\n' % relative_path
  out += '\n'

Would it be okay for me to make this patch? I wasn't sure of the exact
procedure that I might have to do prior to sending in a patch.

Cheers,

Tony Sim


> Jakub
>
>


[PATCH] libgomp: added simple functions and tests for OMPD

2020-06-25 Thread y2s1982 via Gcc-patches
From: y2s82 <1997371+y2...@users.noreply.github.com>

This patch adds some unit tests for omp-tools.h header. It also adds some simple
functions variables related to OMPD API versions and dll locations.
It also partially defines the OMPD initialization function.
More OMPD configuration is also added into Makefile.am.

This patch addresses all feedbacks.

2020-06-25  Tony Sim  

libgomp/ChangeLog:

* Makefile.am(toolexeclib_LTLIBRARIES): Add libgompd.la.
(libgompd_la_LDFLAGS, libgompd_la_DEPENDENCIES, libgompd_la_LINK,
libgompd_la_SOURCES, libgompd_version_dep, libgompd_version_script,
libgompd.ver-sun, libgompd.ver, libgompd_version_info): Set.
* Makefile.in: Regenerate.
* config/darwin/plugin-suffix.h (SONAME_SUFFIX): Remove ().
* config/hpux/plugin-suffix.h (SONAME_SUFFIX): Remove ().
* config/posix/plugin-suffix.h (SONAME_SUFFIX): Remove ().
* env.c(ompd_dll_locations_valid): Define with no compiler optimization.
(initialize_env): Call ompd_dll_locations_valid as needed.
(strong_alias): Alias ompd_dll_locations_valid to initialize_env
when possible.
* libgomp.map: Add OMPD_5.0 symbols version.
* omp-tools.h: Declare ompd_dll_locations as an extern.
* testsuite/Makefile.in: Regenerate.
* libgompd.h: New file.
* libgompd.map: New file.
* ompd-lib.c: New file.
* testsuite/libgomp.ompd/header-1.c: New test.
* testsuite/libgomp.ompd/header-order-1.c: New test.
* testsuite/libgomp.ompd/header-order-2.c: New test.
* testsuite/libgomp.ompd/ompd.exp: New test.

---
 libgomp/Makefile.am   | 29 -
 libgomp/Makefile.in   | 39 +++-
 libgomp/config/darwin/plugin-suffix.h |  2 +-
 libgomp/config/hpux/plugin-suffix.h   |  2 +-
 libgomp/config/posix/plugin-suffix.h  |  2 +-
 libgomp/env.c | 21 +++
 libgomp/libgomp.map   |  6 ++
 libgomp/libgompd.h| 37 +++
 libgomp/libgompd.map  | 49 +++
 libgomp/omp-tools.h   |  2 +-
 libgomp/ompd-lib.c| 61 +++
 libgomp/testsuite/Makefile.in |  1 +
 libgomp/testsuite/libgomp.ompd/header-1.c | 10 +++
 .../testsuite/libgomp.ompd/header-order-1.c   | 11 
 .../testsuite/libgomp.ompd/header-order-2.c   | 11 
 libgomp/testsuite/libgomp.ompd/ompd.exp   | 38 
 16 files changed, 312 insertions(+), 9 deletions(-)
 create mode 100644 libgomp/libgompd.h
 create mode 100644 libgomp/libgompd.map
 create mode 100644 libgomp/ompd-lib.c
 create mode 100644 libgomp/testsuite/libgomp.ompd/header-1.c
 create mode 100644 libgomp/testsuite/libgomp.ompd/header-order-1.c
 create mode 100644 libgomp/testsuite/libgomp.ompd/header-order-2.c
 create mode 100644 libgomp/testsuite/libgomp.ompd/ompd.exp

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index 4d31f4cef46..e15a838e55c 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -20,7 +20,7 @@ AM_CPPFLAGS = $(addprefix -I, $(search_path))
 AM_CFLAGS = $(XCFLAGS)
 AM_LDFLAGS = $(XLDFLAGS) $(SECTION_LDFLAGS) $(OPT_LDFLAGS)
 
-toolexeclib_LTLIBRARIES = libgomp.la
+toolexeclib_LTLIBRARIES = libgomp.la libgompd.la
 nodist_toolexeclib_HEADERS = libgomp.spec
 
 if LIBGOMP_BUILD_VERSIONED_SHLIB
@@ -31,14 +31,21 @@ PREPROCESS = $(subst -Wc$(comma), , $(COMPILE)) -E
 libgomp.ver: $(top_srcdir)/libgomp.map
$(EGREP) -v '#(#| |$$)' $< | \
  $(PREPROCESS) -P -include config.h - > $@ || (rm -f $@ ; exit 1)
+libgompd.ver: $(top_srcdir)/libgompd.map
+   $(EGREP) -v '#(#| |$$)' $< | \
+ $(PREPROCESS) -P -include config.h - > $@ || (rm -f $@ ; exit 1)
 
 if LIBGOMP_BUILD_VERSIONED_SHLIB_GNU
 libgomp_version_script = -Wl,--version-script,libgomp.ver
+libgompd_version_script = -Wl,--version-script,libgompd.ver
 libgomp_version_dep = libgomp.ver
+libgompd_version_dep = libgompd.ver
 endif
 if LIBGOMP_BUILD_VERSIONED_SHLIB_SUN
 libgomp_version_script = -Wl,-M,libgomp.ver-sun
+libgompd_version_script = -Wl,-M,libgompd.ver-sun
 libgomp_version_dep = libgomp.ver-sun
+libgompd_version_dep = libgompd.ver-sun
 libgomp.ver-sun : libgomp.ver \
$(top_srcdir)/../contrib/make_sunver.pl \
$(libgomp_la_OBJECTS) $(libgomp_la_LIBADD)
@@ -48,16 +55,32 @@ libgomp.ver-sun : libgomp.ver \
 `echo $(libgomp_la_LIBADD) | \
sed 's,/\([^/.]*\)\.la,/.libs/\1.a,g'` \
 > $@ || (rm -f $@ ; exit 1)
+libgompd.ver-sun : libgompd.ver \
+   $(top_srcdir)/../contrib/make_sunver.pl \
+   $(libgompd_la_OBJECTS) $(libgompd_la_LIBADD)
+   perl $(top_srcdir)/../contrib/make_sunver.pl \
+ libgompd.ver \
+ $(libgompd_la_OBJECTS:%.lo=.libs/%.o) \
+`echo $(libgompd_la_LIBADD) 

Re: [PATCH] libgomp: added simple functions and tests for OMPD

2020-06-25 Thread y2s1982 . via Gcc-patches
>
>
> > --- /dev/null
> > +++ b/libgomp/libgompd.map
> > @@ -0,0 +1,49 @@
> > +OMPD_5.0 {
> > +  global:
> > + ompd_dll_locations_valid;
>
> ompd_dll_locations and ompd_dll_locations_valid both need to be exported,
> but not from libgompd.so.1 but from libgomp.so.1, so they need to go into
> libgomp.map and be defined somewhere in libgomp.so.1, so likely env.c.
> Include omp-tools.h and plugin-suffix.h in there and move
> ompd_dll_locations
> definition in there (into the #ifndef LIBGOMP_OFFLOADED_ONLY section)
> and for ompd_dll_locations_valid, e.g. make it an alias to
> initialize_env or for the time being just an empty function with
> __attribute__((noipa)) that initialize_env
> calls and I'll help with making it an alias afterwards.
>

Also, for libgomp.map, which block should I place the ompd_dll_locations
and ompd_dll_locations_valid?
Should I make a new block for OMPD_5.0, or should I place them in one of
existing blocks like GOMP_5.0 or OMP_5.0.1?


Re: [PATCH] libgomp: added simple functions and tests for OMPD

2020-06-25 Thread y2s1982 . via Gcc-patches
Hello Jakub,

Thank you for the feedback. I can't believe I made some careless mistakes.
I am also very interested in learning some new techniques mentioned. I had
some questions about them.

On Thu, Jun 25, 2020 at 4:28 AM Jakub Jelinek  wrote:

>
> > --- /dev/null
> > +++ b/libgomp/libgompd.map
> > @@ -0,0 +1,49 @@
> > +OMPD_5.0 {
> > +  global:
> > + ompd_dll_locations_valid;
>
> ompd_dll_locations and ompd_dll_locations_valid both need to be exported,
> but not from libgompd.so.1 but from libgomp.so.1, so they need to go into
> libgomp.map and be defined somewhere in libgomp.so.1, so likely env.c.
>
Ah, so code in env.c gets executed before OMPD gets started?

Include omp-tools.h and plugin-suffix.h in there and move ompd_dll_locations
> definition in there (into the #ifndef LIBGOMP_OFFLOADED_ONLY section)
> and for ompd_dll_locations_valid, e.g. make it an alias to
> initialize_env or for the time being just an empty function with
> __attribute__((noipa)) that initialize_env
> calls and I'll help with making it an alias afterwards.

I got curious about making a function alias and started looking around.
Can it be as simple as #define ompd_dll_location_valid initialize_env?
Or should I use something like ialias_call (fn) fn, defined in libgomp.h?
The latter seems like a wrapper that expands differently depending on the
condition,
and since I wasn't sure what gomp_ialias does, I wasn't sure if that was
the way to go.


>
>
> > diff --git a/libgomp/omp-tools.h b/libgomp/omp-tools.h
> > index 394c33e40dd..b6b8c5295a5 100644
> > --- a/libgomp/omp-tools.h
> > +++ b/libgomp/omp-tools.h
> > @@ -101,7 +101,7 @@ typedef struct ompd_device_type_sizes_t {
> >  } ompd_device_type_sizes_t;
> >
> >
> > -const char **ompd_dll_locations;
> > +//const char **ompd_dll_locations;
>
> Extern declaration would be
> extern const char **ompd_dll_locations;
>
Okay.  I do have an issue:
extern const char **ompd_dll_locations; and const char*
ompd_dll_locations[2]; seems to clash with each other.
At least it was when I had it defined in omp-lib.c.  It stopped giving me
errors when it was moved to env.c.
It seems giving the letter a different name and then assigning the value to
the first seems to work, but I was wondering
if there was a better solution.


>
>
> > +ompd_rc_t
> > +ompd_initialize (ompd_word_t api_version, const ompd_callbacks_t
> *callbacks)
> > +{
> > +  /* initialized flag */
>
> You don't need to comment everything the function is doing, I think the
> comments don't say anything that isn't obvious from it.
> Comment only for larger blocks of code where it might not be obvious what
> the code is doing and the comment adds added value; comments should be
> usually full sentences, starting with capital letter, ending with . and
> two spaces after the .
> Or one can add function comments (comments before function definition) that
> explain what the function does, what are the arguments etc., but in the
> case of functions documented in the standard it seems pointless,
> the best documentation is the standard.
>
> You don't use the callbacks argument yet, but you will need it later,
> so instead of adding an unused attribute to it, just add
>   (void) callbacks;
> for now to shut up warnings.
>
Okay. I will do the same for the api_version argument, too.
For the next patch, I had some questions about this function. It seems I
need to declare an address space
for callbacks. Where does this address space get stored?


>
> Otherwise LGTM.
>
> Jakub
>
> One of the things I wanted to do was create more unit tests.
Should I try making unit tests for the API version functions, focusing on
the formatting of the string?
Would that be something useful for maintaining consistency?

Thank you always for helping me learn more about the project and giving me
great suggestions.

Cheers,

Tony Sim


[PATCH] libgomp: added simple functions and tests for OMPD

2020-06-24 Thread y2s1982 via Gcc-patches
This patch adds some unit tests for omp-tools.h header. It also adds some simple
functions related to OMPD API versions. It also partially defines the OMPD
initialization function. More OMPD configuration is also added into Makefile.am.

2020-06-24  Tony Sim  

libgomp/ChangeLog:

* Makefile.am(toolexeclib_LTLIBRARIES): Add libgompd.la.
(libgompd_la_LDFLAGS, libgompd_la_DEPENDENCIES, libgompd_la_LINK,
libgompd_la_SOURCES, libgompd_version_dep, libgompd_version_script,
libgompd.ver-sun, libgompd.ver, libgompd_version_info): Set.
* Makefile.in: Regnerate.
* config/darwin/plugin-suffix.h (SONAME_SUFFIX): Remove ().
* config/hpux/plugin-suffix.h (SONAME_SUFFIX): Remove ().
* config/posix/plugin-suffix.h (SONAME_SUFFIX): Remove ().
* omp-tools.h: Comment out ompd_dll_locations.
* testsuite/Makefile.in: Regnerate.
* libgompd.h: New file.
* libgompd.map: New file.
* libgompd.s: New file.
* ompd-lib.c: New file.
* testsuite/libgomp.ompd/header-1.c: New test.
* testsuite/libgomp.ompd/header-order-1.c: New test.
* testsuite/libgomp.ompd/header-order-2.c: New test.
* testsuite/libgomp.ompd/ompd.exp: New test.

---
 libgomp/Makefile.am   | 29 +++-
 libgomp/Makefile.in   | 39 ++-
 libgomp/config/darwin/plugin-suffix.h |  2 +-
 libgomp/config/hpux/plugin-suffix.h   |  2 +-
 libgomp/config/posix/plugin-suffix.h  |  2 +-
 libgomp/libgompd.h| 37 +++
 libgomp/libgompd.map  | 49 ++
 libgomp/libgompd.s|  1 +
 libgomp/omp-tools.h   |  2 +-
 libgomp/ompd-lib.c| 66 +++
 libgomp/testsuite/Makefile.in |  1 +
 libgomp/testsuite/libgomp.ompd/header-1.c | 10 +++
 .../testsuite/libgomp.ompd/header-order-1.c   | 11 
 .../testsuite/libgomp.ompd/header-order-2.c   | 11 
 libgomp/testsuite/libgomp.ompd/ompd.exp   | 38 +++
 15 files changed, 291 insertions(+), 9 deletions(-)
 create mode 100644 libgomp/libgompd.h
 create mode 100644 libgomp/libgompd.map
 create mode 100644 libgomp/libgompd.s
 create mode 100644 libgomp/ompd-lib.c
 create mode 100644 libgomp/testsuite/libgomp.ompd/header-1.c
 create mode 100644 libgomp/testsuite/libgomp.ompd/header-order-1.c
 create mode 100644 libgomp/testsuite/libgomp.ompd/header-order-2.c
 create mode 100644 libgomp/testsuite/libgomp.ompd/ompd.exp

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index 4d31f4cef46..e15a838e55c 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -20,7 +20,7 @@ AM_CPPFLAGS = $(addprefix -I, $(search_path))
 AM_CFLAGS = $(XCFLAGS)
 AM_LDFLAGS = $(XLDFLAGS) $(SECTION_LDFLAGS) $(OPT_LDFLAGS)
 
-toolexeclib_LTLIBRARIES = libgomp.la
+toolexeclib_LTLIBRARIES = libgomp.la libgompd.la
 nodist_toolexeclib_HEADERS = libgomp.spec
 
 if LIBGOMP_BUILD_VERSIONED_SHLIB
@@ -31,14 +31,21 @@ PREPROCESS = $(subst -Wc$(comma), , $(COMPILE)) -E
 libgomp.ver: $(top_srcdir)/libgomp.map
$(EGREP) -v '#(#| |$$)' $< | \
  $(PREPROCESS) -P -include config.h - > $@ || (rm -f $@ ; exit 1)
+libgompd.ver: $(top_srcdir)/libgompd.map
+   $(EGREP) -v '#(#| |$$)' $< | \
+ $(PREPROCESS) -P -include config.h - > $@ || (rm -f $@ ; exit 1)
 
 if LIBGOMP_BUILD_VERSIONED_SHLIB_GNU
 libgomp_version_script = -Wl,--version-script,libgomp.ver
+libgompd_version_script = -Wl,--version-script,libgompd.ver
 libgomp_version_dep = libgomp.ver
+libgompd_version_dep = libgompd.ver
 endif
 if LIBGOMP_BUILD_VERSIONED_SHLIB_SUN
 libgomp_version_script = -Wl,-M,libgomp.ver-sun
+libgompd_version_script = -Wl,-M,libgompd.ver-sun
 libgomp_version_dep = libgomp.ver-sun
+libgompd_version_dep = libgompd.ver-sun
 libgomp.ver-sun : libgomp.ver \
$(top_srcdir)/../contrib/make_sunver.pl \
$(libgomp_la_OBJECTS) $(libgomp_la_LIBADD)
@@ -48,16 +55,32 @@ libgomp.ver-sun : libgomp.ver \
 `echo $(libgomp_la_LIBADD) | \
sed 's,/\([^/.]*\)\.la,/.libs/\1.a,g'` \
 > $@ || (rm -f $@ ; exit 1)
+libgompd.ver-sun : libgompd.ver \
+   $(top_srcdir)/../contrib/make_sunver.pl \
+   $(libgompd_la_OBJECTS) $(libgompd_la_LIBADD)
+   perl $(top_srcdir)/../contrib/make_sunver.pl \
+ libgompd.ver \
+ $(libgompd_la_OBJECTS:%.lo=.libs/%.o) \
+`echo $(libgompd_la_LIBADD) | \
+   sed 's,/\([^/.]*\)\.la,/.libs/\1.a,g'` \
+> $@ || (rm -f $@ ; exit 1)
 endif
 else
 libgomp_version_script =
+libgompd_version_script =
 libgomp_version_dep =
+libgompd_version_dep =
 endif
 libgomp_version_info = -version-info $(libtool_VERSION)
+libgompd_version_info = -version-info $(libtool_VERSION)
 libgomp_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \
-

Re: [PATCH] libgomp: added simple functions and tests for OMPD

2020-06-24 Thread y2s1982 . via Gcc-patches
Hello,

Thank you for the tips. I have some follow up questions. :)

On Wed, Jun 24, 2020 at 5:25 AM Jakub Jelinek  wrote:

> > libgomp/ChangeLog:
> >
> >   * Makefile.am (toolexeclib_LTLIBRARIES and related): Add
> libgompd.la.
>
> Please spell out all the changes.  I.e.
> * Makefile.am (toolexeclib_LTLIBRARIES): Add libgompd.la.
> (libgompd_la_LDFLAGS, libgompd_la_DEPENDENCIES, libgompd_la_LINK,
> libgompd_la_SOURCES): Set.
>
Okay. Thank you for the clarification.

> +libgompd_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \
> > +$(lt_host_flags)
> > +libgompd_la_DEPENDENCIES = $(libgomp_version_dep)
> > +libgompd_la_LINK = $(LINK) $(libgomp_la_LDFLAGS)
>
> You actually want to use libgompd_la_LDFLAGS, libgompd_version_dep,
> libgompd_version_script, libgompd_version_info etc. (and set those
> variables
> next to the libgomp ones).
> And introduce libgompd.map version script which will have the exported
> symbols in for now OMPD_5.0 symbol version.
> So
> OMPD_5.0 {
>   global:
> ...;
>
>   local:
> *;
> };
>

Oh I wasn't sure how everything worked yet, so I thought to borrow libomp
scripts as a placeholder for now.
I will change them to libompd scripts.
As for mapping, could you point me to an example that has global: and
local: object as above?


>
> > +libgompd_la_SOURCES = libgompd.c
>
> Not sure if you want to call the source file libgompd.c, that would make
> sense only if you want to have all of OMPD implemented in a single file.
> If you need multiple, I'd suggest ompd-*.c where the * would be something
> short/descriptive to name a set of related functions.
>
Okay. I will start splitting them up.


>
> > +++ b/libgomp/libgompd.c
> > @@ -0,0 +1,46 @@
> > +#include 
> > +#include 
> > +#include "omp-tools.h"
> > +#include "libgompd.h"
> > +//#include "plugin-suffix.h"
>
> So, what actually includes that header?  Otherwise it can't compile.
>
I forgot to uncomment that. I put that in there to see other compilation
errors.  I am still having trouble generating compilation errors using make.
I tried creating a separate directory outside of the source, calling
../gcc/configure, and trying make libgomp.
It did not generate any output other than "make: Nothing to do be for
'../gcc/libgomp'".  I wasn't sure what else to try.



> > +
> > +ompd_rc_t ompd_get_api_version(ompd_word_t *version)
> > +{
> > +*version = OMPD_VERSION;
> > +return ompd_rc_ok;
> > +}
>
> Formatting.  The GNU Coding Conventions say it should be
> ompd_rc_t
> ompd_get_api_version (ompd_word_t *version)
> {
>   *version = OMPD_VERSION;
>   return ompd_rc_ok;
> }

(i.e. function name should be at the start of line for easy grepping,
> there should be a single space before (, no space after the ( or
> before ) as you have in other functions, indentation level is 2
> (see indent program defaults).
>

Thank you. I will try harder to follow the formatting.  When you say
indentation level, do you mean the number of spaces?


>
> > +
> > +ompd_rc_t ompd_get_version_string(const char **string)
> > +{
> > +string = str(OMPD_VERSION);
> > +return ompd_rc_ok;
> > +}
>
> This doesn't do anything outside of the function.  You need
>   *string =

and put there something more descriptive than just the version,
> perhaps
>   *string = "GNU OpenMP Runtime implementing OpenMP 5.0 " str
> (OMPD_VERSION);
> I don't see a str macro defined, and it should have a different name, str
> is
> too generic.
> libgomp.h defines (conditionally):
> # define ialias_str1(x) ialias_str2(x)
> # define ialias_str2(x) #x
> which does what you want, but you need it unconditionally and call it some
> other way (stringify and stringify1?, define right above the function?).
>
> > +
> > +ompd_rc_t ompd_initialize ( ompd_word_t api_version, const
> ompd_callbacks_t *callbacks )
> > +{
> > +/* initialized flag */
> > +static int ompd_initialized = 0;
> > +
> > +if (ompd_initialized)
> > +return ompd_rc_error;
> > +
> > +/* compute library name and locations */
> > +const char *prefix = "libgompd.";
> > +const char *suffix = SONAME_SUFFIX (1);
> > +size_t prefix_len, suffix_len;
> > +prefix_len = strlen(prefix);
> > +suffix_len = strlen(suffix);
>
> Formatting (in addition to what has been said above, e.g. space before (.
> But, this doesn't really belong here anyway, ompd_dll_locations needs to be
> initialized not in ompd_initialize, but far before that.
> Either it should be just a const variable, which I think with
> const char *ompd_dll_locations[2] = { "libgompd" SONAME_SUFFIX (1), NULL };
> is possible, or some library constructor needs to initializa it and then
> pass through (or call) the mandated breakpoint so that the debugger can be
> sure it is initialized.
> Then the debugger will use the variable, load the libgompd library and only
> after that actually call ompd_initialize.
>

Thank you for the clarification. Should I change the 

[PATCH] libgomp: added simple functions and tests for OMPD

2020-06-23 Thread y2s1982 via Gcc-patches
This patch adds some unit tests for omp-tools.h header. It also adds some simple
functions related to OMPD API versions. It also partially defines the OMPD
initialization function.

2020-06-23  Tony Sim  

libgomp/ChangeLog:

* Makefile.am (toolexeclib_LTLIBRARIES and related): Add libgompd.la.
* Makefile.in: Regenerate.
* config/darwin/plugin-suffix.h (SONAME_SUFFIX): Removed ().
* config/hpux/plugin-suffix.h (SONAME_SUFFIX): Removed ().
* config/posix/plugin-suffix.h (SONAME_SUFFIX): Removed ().
* testsuite/Makefile.in: Regenerate.
* libgompd.c: New file.
* libgompd.h: New file.
* testsuite/libgomp.ompd/header-1.c: New test.
* testsuite/libgomp.ompd/header-order-1.c: New test.
* testsuite/libgomp.ompd/header-order-2.c: New test.
* testsuite/libgomp.ompd/ompd.exp: New test.

---
 libgomp/Makefile.am   |  8 +++-
 libgomp/Makefile.in   | 20 ++--
 libgomp/config/darwin/plugin-suffix.h |  2 +-
 libgomp/config/hpux/plugin-suffix.h   |  2 +-
 libgomp/config/posix/plugin-suffix.h  |  2 +-
 libgomp/libgompd.c| 46 +++
 libgomp/libgompd.h|  7 +++
 libgomp/testsuite/Makefile.in |  1 +
 libgomp/testsuite/libgomp.ompd/header-1.c |  6 +++
 .../testsuite/libgomp.ompd/header-order-1.c   |  7 +++
 .../testsuite/libgomp.ompd/header-order-2.c   |  7 +++
 libgomp/testsuite/libgomp.ompd/ompd.exp   | 38 +++
 12 files changed, 139 insertions(+), 7 deletions(-)
 create mode 100644 libgomp/libgompd.c
 create mode 100644 libgomp/libgompd.h
 create mode 100644 libgomp/testsuite/libgomp.ompd/header-1.c
 create mode 100644 libgomp/testsuite/libgomp.ompd/header-order-1.c
 create mode 100644 libgomp/testsuite/libgomp.ompd/header-order-2.c
 create mode 100644 libgomp/testsuite/libgomp.ompd/ompd.exp

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index 4d31f4cef46..c26c26c59a4 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -20,7 +20,7 @@ AM_CPPFLAGS = $(addprefix -I, $(search_path))
 AM_CFLAGS = $(XCFLAGS)
 AM_LDFLAGS = $(XLDFLAGS) $(SECTION_LDFLAGS) $(OPT_LDFLAGS)
 
-toolexeclib_LTLIBRARIES = libgomp.la
+toolexeclib_LTLIBRARIES = libgomp.la libgompd.la
 nodist_toolexeclib_HEADERS = libgomp.spec
 
 if LIBGOMP_BUILD_VERSIONED_SHLIB
@@ -67,6 +67,12 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
oacc-mem.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
 
+libgompd_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \
+$(lt_host_flags)
+libgompd_la_DEPENDENCIES = $(libgomp_version_dep)
+libgompd_la_LINK = $(LINK) $(libgomp_la_LDFLAGS)
+libgompd_la_SOURCES = libgompd.c
+
 include $(top_srcdir)/plugin/Makefrag.am
 
 if USE_FORTRAN
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 3ca1be0d73e..c4c9e437e94 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -234,6 +234,9 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
teams.lo allocator.lo oacc-profiling.lo oacc-target.lo \
$(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
+libgompd_la_LIBADD =
+am_libgompd_la_OBJECTS = libgompd.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@)
 am__v_P_0 = false
@@ -282,7 +285,8 @@ am__v_FCLD_0 = @echo "  FCLD" $@;
 am__v_FCLD_1 = 
 SOURCES = $(libgomp_plugin_gcn_la_SOURCES) \
$(libgomp_plugin_hsa_la_SOURCES) \
-   $(libgomp_plugin_nvptx_la_SOURCES) $(libgomp_la_SOURCES)
+   $(libgomp_plugin_nvptx_la_SOURCES) $(libgomp_la_SOURCES) \
+   $(libgompd_la_SOURCES)
 AM_V_DVIPS = $(am__v_DVIPS_@AM_V@)
 am__v_DVIPS_ = $(am__v_DVIPS_@AM_DEFAULT_V@)
 am__v_DVIPS_0 = @echo "  DVIPS   " $@;
@@ -548,8 +552,8 @@ libsubincludedir = 
$(libdir)/gcc/$(target_alias)/$(gcc_version)/include
 AM_CPPFLAGS = $(addprefix -I, $(search_path))
 AM_CFLAGS = $(XCFLAGS)
 AM_LDFLAGS = $(XLDFLAGS) $(SECTION_LDFLAGS) $(OPT_LDFLAGS)
-toolexeclib_LTLIBRARIES = libgomp.la $(am__append_1) $(am__append_2) \
-   $(am__append_3)
+toolexeclib_LTLIBRARIES = libgomp.la libgompd.la $(am__append_1) \
+   $(am__append_2) $(am__append_3)
 nodist_toolexeclib_HEADERS = libgomp.spec
 
 # -Wc is only a libtool option.
@@ -576,6 +580,12 @@ 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 $(am__append_4)
+libgompd_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \
+$(lt_host_flags)
+
+libgompd_la_DEPENDENCIES = $(libgomp_version_dep)
+libgompd_la_LINK = $(LINK) $(libgomp_la_LDFLAGS)
+libgompd_la_SOURCES = libgompd.c

[PATCH] libgomp: added partial omp-tools.h for OMPD.

2020-06-13 Thread y2s1982 via Gcc-patches
This patch adds a partial omp-tools.h from OpenMP which describes function
prototypes and data types used for OMPD.

All feedback has been addressed.

2020-06-13  Tony Sim  

libgomp/ChangeLog:

* Makefile.am (nodist_libsubinclude_HEADERS): Add omp-tools.h.
* Makefile.in: Regenerate.
* omp-tools.h: New file.

---
 libgomp/Makefile.am |   2 +-
 libgomp/Makefile.in |   8 +-
 libgomp/omp-tools.h | 295 
 3 files changed, 300 insertions(+), 5 deletions(-)
 create mode 100644 libgomp/omp-tools.h

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index b84156291e8..217e6728d1c 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -74,7 +74,7 @@ libgomp_la_SOURCES += openacc.f90
 endif
 
 nodist_noinst_HEADERS = libgomp_f.h
-nodist_libsubinclude_HEADERS = omp.h openacc.h acc_prof.h
+nodist_libsubinclude_HEADERS = omp.h omp-tools.h openacc.h acc_prof.h
 if USE_FORTRAN
 nodist_finclude_HEADERS = omp_lib.h omp_lib.f90 omp_lib.mod omp_lib_kinds.mod \
openacc_lib.h openacc.f90 openacc.mod openacc_kinds.mod
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 5ff2ac14db9..c844afd7f0d 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -16,7 +16,7 @@
 
 # Plugins for offload execution, Makefile.am fragment.
 #
-# Copyright (C) 2014-2019 Free Software Foundation, Inc.
+# Copyright (C) 2014-2020 Free Software Foundation, Inc.
 #
 # Contributed by Mentor Embedded.
 #
@@ -573,8 +573,8 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
affinity.c target.c splay-tree.c libgomp-plugin.c \
oacc-parallel.c oacc-host.c oacc-init.c oacc-mem.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 \
-   $(am__append_4)
+   affinity-fmt.c teams.c allocator.c oacc-profiling.c \
+   oacc-target.c $(am__append_4)
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -610,7 +610,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
 @PLUGIN_GCN_TRUE@libgomp_plugin_gcn_la_LIBADD = libgomp.la $(PLUGIN_GCN_LIBS)
 @PLUGIN_GCN_TRUE@libgomp_plugin_gcn_la_LIBTOOLFLAGS = --tag=disable-static
 nodist_noinst_HEADERS = libgomp_f.h
-nodist_libsubinclude_HEADERS = omp.h openacc.h acc_prof.h
+nodist_libsubinclude_HEADERS = omp.h omp-tools.h openacc.h acc_prof.h
 @USE_FORTRAN_TRUE@nodist_finclude_HEADERS = omp_lib.h omp_lib.f90 omp_lib.mod 
omp_lib_kinds.mod \
 @USE_FORTRAN_TRUE@ openacc_lib.h openacc.f90 openacc.mod openacc_kinds.mod
 
diff --git a/libgomp/omp-tools.h b/libgomp/omp-tools.h
new file mode 100644
index 000..394c33e40dd
--- /dev/null
+++ b/libgomp/omp-tools.h
@@ -0,0 +1,295 @@
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Yoosuk Sim .
+
+   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
+   .  */
+
+/* This file contains prototypes of functions and data types defined
+   in the OMPD standard.  */
+
+#ifndef _OMP_TOOLS_H
+#define _OMP_TOOLS_H
+
+#ifdef __cplusplus
+extern "C" {
+# define __GOMPD_NOTHROW throw ()
+#else
+# define __GOMPD_NOTHROW __attribute__((__nothrow__))
+#endif
+
+typedef __UINT64_TYPE__ ompd_size_t;
+
+typedef __UINT64_TYPE__ ompd_wait_id_t;
+
+typedef __UINT64_TYPE__ ompd_addr_t;
+typedef __INT64_TYPE__ ompd_word_t;
+typedef __UINT64_TYPE__ ompd_seg_t;
+
+typedef __UINT64_TYPE__ ompd_device_t;
+
+typedef __UINT64_TYPE__ ompd_thread_id_t;
+
+typedef enum ompd_scope_t {
+  ompd_scope_global = 1,
+  ompd_scope_address_space = 2,
+  ompd_scope_thread = 3,
+  ompd_scope_parallel = 4,
+  ompd_scope_implicit_task = 5,
+  ompd_scope_task = 6
+} ompd_scope_t;
+
+typedef __UINT64_TYPE__ ompd_icv_id_t;
+
+typedef enum ompd_rc_t {
+  ompd_rc_ok = 0,
+  ompd_rc_unavailable = 1,
+  ompd_rc_stale_handle = 2,
+  ompd_rc_bad_input = 3,
+  ompd_rc_error = 4,
+  ompd_rc_unsupported = 5,
+  ompd_rc_needs_state_tracking = 

Re: [PATCH] libgomp: added a partial omp-tools.h for OMPD

2020-06-13 Thread y2s1982 . via Gcc-patches
Hi Jakub,

When I compiled the header after adding the missing typedefs, I got
warnings about nothrow attribute being ignored on typedef function
declarations.
Should I remove them from typedef function declarations?

Cheers,

Tony Sim


On Sat, Jun 13, 2020 at 10:15 AM y2s1982 .  wrote:

> Hi Jakub,
>
> Thank you for the valuable feedback. I especially liked the tip on how to
> compile the header.
> I will make a new patch and submit it.
>
> Cheers,
>
> Tony Sim
>
> On Sat, Jun 13, 2020 at 5:13 AM Jakub Jelinek  wrote:
>
>> On Sat, Jun 13, 2020 at 11:06:52AM +0200, Jakub Jelinek via Gcc-patches
>> wrote:
>> > On Fri, Jun 12, 2020 at 07:51:32PM -0400, y2s1982 wrote:
>> > > This patch adds a partial omp-tools.h from OpenMP project which
>> > > declares function prototypes and typedefs used in OMPD.
>> > >
>> > > This patch also addressed all feedback.
>> > >
>> > > 2020-06-12  Tony Sim  
>> > >
>> > > libgomp/ChangeLog:
>> > >
>> > > * Makefile.am: Added new header.
>> >
>> > This should give more details, like:
>> >   * Makefile.am (nodist_libsubinclude_HEADERS): Add omp-tools.h.
>> >
>> > > * Makefile.in: Regenerate.
>> > > * omp-tools.h: New file.
>> >
>> > Otherwise LGTM, but as we discussed, for now please push it to your
>> > stable repository and we'll put it into GCC mainline when it is complete
>> > or at least mostly complete.
>>
>> Actually, have you tried to compile the header?
>> echo '#include "omp-tools.h"' | gcc -S -xc - -o /tmp/omp-tools.s
>> ?  I think you are missing some typedefs.
>>
>> E.g. in OpenMP/sources I see
>> typedef uint64_t ompd_size_t;
>>
>> typedef uint64_t ompd_wait_id_t;
>>
>> typedef uint64_t ompd_addr_t;
>> typedef int64_t ompd_word_t;
>> typedef uint64_t ompd_seg_t;
>>
>> typedef uint64_t ompd_device_t;
>> and I think from these you only have ompd_wait_id_t...
>> For int64_t replacement use __INT64_TYPE__...
>>
>> Jakub
>>
>>


Re: [PATCH] libgomp: added a partial omp-tools.h for OMPD

2020-06-13 Thread y2s1982 . via Gcc-patches
Hi Jakub,

Thank you for the valuable feedback. I especially liked the tip on how to
compile the header.
I will make a new patch and submit it.

Cheers,

Tony Sim

On Sat, Jun 13, 2020 at 5:13 AM Jakub Jelinek  wrote:

> On Sat, Jun 13, 2020 at 11:06:52AM +0200, Jakub Jelinek via Gcc-patches
> wrote:
> > On Fri, Jun 12, 2020 at 07:51:32PM -0400, y2s1982 wrote:
> > > This patch adds a partial omp-tools.h from OpenMP project which
> > > declares function prototypes and typedefs used in OMPD.
> > >
> > > This patch also addressed all feedback.
> > >
> > > 2020-06-12  Tony Sim  
> > >
> > > libgomp/ChangeLog:
> > >
> > > * Makefile.am: Added new header.
> >
> > This should give more details, like:
> >   * Makefile.am (nodist_libsubinclude_HEADERS): Add omp-tools.h.
> >
> > > * Makefile.in: Regenerate.
> > > * omp-tools.h: New file.
> >
> > Otherwise LGTM, but as we discussed, for now please push it to your
> > stable repository and we'll put it into GCC mainline when it is complete
> > or at least mostly complete.
>
> Actually, have you tried to compile the header?
> echo '#include "omp-tools.h"' | gcc -S -xc - -o /tmp/omp-tools.s
> ?  I think you are missing some typedefs.
>
> E.g. in OpenMP/sources I see
> typedef uint64_t ompd_size_t;
>
> typedef uint64_t ompd_wait_id_t;
>
> typedef uint64_t ompd_addr_t;
> typedef int64_t ompd_word_t;
> typedef uint64_t ompd_seg_t;
>
> typedef uint64_t ompd_device_t;
> and I think from these you only have ompd_wait_id_t...
> For int64_t replacement use __INT64_TYPE__...
>
> Jakub
>
>


[PATCH] libgomp: added a partial omp-tools.h for OMPD

2020-06-12 Thread y2s1982 via Gcc-patches
This patch adds a partial omp-tools.h from OpenMP project which
declares function prototypes and typedefs used in OMPD.

This patch also addressed all feedback.

2020-06-12  Tony Sim  

libgomp/ChangeLog:

* Makefile.am: Added new header.
* Makefile.in: Regenerate.
* omp-tools.h: New file.

---
 libgomp/Makefile.am |   2 +-
 libgomp/Makefile.in |   8 +-
 libgomp/omp-tools.h | 261 
 3 files changed, 266 insertions(+), 5 deletions(-)
 create mode 100644 libgomp/omp-tools.h

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index b84156291e8..217e6728d1c 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -74,7 +74,7 @@ libgomp_la_SOURCES += openacc.f90
 endif
 
 nodist_noinst_HEADERS = libgomp_f.h
-nodist_libsubinclude_HEADERS = omp.h openacc.h acc_prof.h
+nodist_libsubinclude_HEADERS = omp.h omp-tools.h openacc.h acc_prof.h
 if USE_FORTRAN
 nodist_finclude_HEADERS = omp_lib.h omp_lib.f90 omp_lib.mod omp_lib_kinds.mod \
openacc_lib.h openacc.f90 openacc.mod openacc_kinds.mod
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 5ff2ac14db9..c844afd7f0d 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -16,7 +16,7 @@
 
 # Plugins for offload execution, Makefile.am fragment.
 #
-# Copyright (C) 2014-2019 Free Software Foundation, Inc.
+# Copyright (C) 2014-2020 Free Software Foundation, Inc.
 #
 # Contributed by Mentor Embedded.
 #
@@ -573,8 +573,8 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
affinity.c target.c splay-tree.c libgomp-plugin.c \
oacc-parallel.c oacc-host.c oacc-init.c oacc-mem.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 \
-   $(am__append_4)
+   affinity-fmt.c teams.c allocator.c oacc-profiling.c \
+   oacc-target.c $(am__append_4)
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -610,7 +610,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
 @PLUGIN_GCN_TRUE@libgomp_plugin_gcn_la_LIBADD = libgomp.la $(PLUGIN_GCN_LIBS)
 @PLUGIN_GCN_TRUE@libgomp_plugin_gcn_la_LIBTOOLFLAGS = --tag=disable-static
 nodist_noinst_HEADERS = libgomp_f.h
-nodist_libsubinclude_HEADERS = omp.h openacc.h acc_prof.h
+nodist_libsubinclude_HEADERS = omp.h omp-tools.h openacc.h acc_prof.h
 @USE_FORTRAN_TRUE@nodist_finclude_HEADERS = omp_lib.h omp_lib.f90 omp_lib.mod 
omp_lib_kinds.mod \
 @USE_FORTRAN_TRUE@ openacc_lib.h openacc.f90 openacc.mod openacc_kinds.mod
 
diff --git a/libgomp/omp-tools.h b/libgomp/omp-tools.h
new file mode 100644
index 000..f6d45287aa6
--- /dev/null
+++ b/libgomp/omp-tools.h
@@ -0,0 +1,261 @@
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Yoosuk Sim .
+
+   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
+   .  */
+
+/* This file contains prototypes of functions and data types defined
+   in the OMPD standard.  */
+
+#ifndef _OMP_TOOLS_H
+#define _OMP_TOOLS_H
+
+#ifdef __cplusplus
+extern "C" {
+# define __GOMPD_NOTHROW throw ()
+#else
+# define __GOMPD_NOTHROW __attribute__((__nothrow__))
+#endif
+
+typedef __UINT64_TYPE__ ompd_wait_id_t;
+
+typedef struct ompd_address_t {
+  ompd_seg_t segment;
+  ompd_addr_t address;
+} ompd_address_t;
+
+typedef struct ompd_frame_info_t {
+  ompd_address_t frame_address;
+  ompd_word_t frame_flag;
+} ompd_frame_info_t;
+
+typedef struct _ompd_aspace_handle ompd_address_space_handle_t;
+typedef struct _ompd_thread_handle ompd_thread_handle_t;
+typedef struct _ompd_parallel_handle ompd_parallel_handle_t;
+typedef struct _ompd_task_handle ompd_task_handle_t;
+
+typedef struct _ompd_aspace_cont ompd_address_space_context_t;
+typedef struct _ompd_thread_cont ompd_thread_context_t;
+
+typedef struct ompd_device_type_sizes_t {
+  __UINT8_TYPE__ sizeof_char;
+  __UINT8_TYPE__ sizeof_short;
+  __UINT8_TYPE__ sizeof_int;
+  

[PATCH] libgomp: added partial omp-tools.h for OMPD

2020-06-12 Thread y2s1982 via Gcc-patches
This patch adds partial omp-tools.h continaing OMPD-specific functions and data 
types.

2020-06-12  Tony Sim 

libgomp/ChangeLog:

* omp-tools.h: New file

---
 libgomp/omp-tools.h | 278 
 1 file changed, 278 insertions(+)
 create mode 100644 libgomp/omp-tools.h

diff --git a/libgomp/omp-tools.h b/libgomp/omp-tools.h
new file mode 100644
index 000..2ac23cde51f
--- /dev/null
+++ b/libgomp/omp-tools.h
@@ -0,0 +1,278 @@
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Yoosuk Sim .
+
+   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
+   .  */
+
+/* This file contains prototypes of functions and data types defined 
+   in ompt and ompd standard */
+
+#ifndef _OMP_TOOLS_H
+#define _OMP_TOOLS_H
+
+#ifdef __cplusplus
+extern "C" {
+# define __GOMPD_NOTHROW throw ()
+#else
+# define __GOMPD_NOTHROW __attribute__((__nothrow__))
+#endif
+
+typedef uint64_t ompt_wait_id_t;
+
+typedef struct ompd_address_t {
+  ompd_seg_t segment;
+  ompd_addr_t address;
+} ompd_address_t;
+
+typedef struct ompd_frame_info_t {
+  ompd_address_t frame_address;
+  ompd_word_t frame_flag;
+} ompd_frame_info_t;
+
+typedef struct _ompd_aspace_handle ompd_address_space_handle_t;
+typedef struct _ompd_thread_handle ompd_thread_handle_t;
+typedef struct _ompd_parallel_handle ompd_parallel_handle_t;
+typedef struct _ompd_task_handle ompd_task_handle_t;
+
+typedef struct _ompd_aspace_cont ompd_address_space_context_t;
+typedef struct _ompd_thread_cont ompd_thread_context_t;
+
+typedef struct ompd_device_type_sizes_t {
+  uint8_t sizeof_char;
+  uint8_t sizeof_short;
+  uint8_t sizeof_int;
+  uint8_t sizeof_long;
+  uint8_t sizeof_long_long;
+  uint8_t sizeof_pointer;
+} ompd_device_type_sizes_t;
+
+
+const char **ompd_dll_locations;
+
+void ompd_dll_locations_valid (void) __GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_memory_alloc_fn_t) (ompd_size_t nbytes,
+ void **ptr) 
__GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_memory_free_fn_t) (void *ptr) 
__GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_get_thread_context_for_thread_id_fn_t) (
+ompd_address_space_context_t *address_space_context, ompd_thread_id_t kind,
+ompd_size_t sizeof_thread_id, const void *thread_id,
+ompd_thread_context_t **thread_context) __GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_sizeof_fn_t) (
+ompd_address_space_context_t *address_space_context,
+ompd_device_type_sizes_t *sizes) __GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_symbol_addr_fn_t) (
+ompd_address_space_context_t *address_space_context,
+ompd_thread_context_t *thread_context, const char *symbol_name,
+ompd_address_t *symbol_addr, const char *file_name) __GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_memory_read_fn_t) (
+ompd_address_space_context_t *address_space_context,
+ompd_thread_context_t *thread_context, const ompd_address_t *addr,
+ompd_size_t nbytes, void *buffer) __GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_memory_write_fn_t) (
+ompd_address_space_context_t *address_space_context,
+ompd_thread_context_t *thread_context, const ompd_address_t *addr,
+ompd_size_t nbytes, const void *buffer) __GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_device_host_fn_t) (
+ompd_address_space_context_t *address_space_context, const void *input,
+ompd_size_t unit_size, ompd_size_t count, void *output) __GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_print_string_fn_t) (const char *string,
+ int category) 
__GOMPD_NOTHROW;
+
+typedef struct ompd_callbacks_t {
+  ompd_callback_memory_alloc_fn_t alloc_memory;
+  ompd_callback_memory_free_fn_t free_memory;
+  ompd_callback_print_string_fn_t print_string;
+  ompd_callback_sizeof_fn_t sizeof_type;
+  ompd_callback_symbol_addr_fn_t symbol_addr_lookup;
+  ompd_callback_memory_read_fn_t read_memory;
+