Message ID | 20200709230100.3614328-1-y2s1982@gmail.com |
---|---|
State | New |
Headers | show |
Series | libgomp: Add OMPD Address Space Information functions. | expand |
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 yyyymm 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: yyyymm. */ So use omp_version_len = strlen ("yyyymm"); 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
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 <jakub@redhat.com> 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 yyyymm 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: yyyymm. */ > > So use omp_version_len = strlen ("yyyymm"); > 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 > >
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 <jakub@redhat.com> 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 yyyymm 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 > >
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 yyyymm 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 00000000000..b751d64ce28 --- /dev/null +++ b/libgomp/ompd-addr.c @@ -0,0 +1,81 @@ +/* Copyright (C) 2020 Free Software Foundation, Inc. + Contributed by Yoosuk Sim <y2s1982@gmail.com>. + + This file is part of the GNU Offloading and Multi Processing Library + (libgomp). + + Libgomp is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + <http://www.gnu.org/licenses/>. */ + +/* This file contains function definitions for OMPD's Address Space Information + functions defined in the OpenMP 5.0 API Documentation, 5.5.4. */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#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; + + *omp_version = gompd_env_info.openmp_version; + + return ompd_rc_ok; +} + +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_size_t macro_length = 6; /* _OPENMP format: yyyymm. */ + ompd_word_t omp_version; + ompd_rc_t ret = ompd_get_omp_version (address_space, &omp_version); + if (ret != ompd_rc_ok) + return ret; + + char *tmp = "GNU OpenMP Runtime implementing OpenMP 5.0 "; + ompd_size_t tmp_length = strlen (tmp); + + size_t total_length = tmp_length + macro_length + 1; + + char *t = NULL; + ret = gompd_callbacks.alloc_memory (total_length, (void *) t); + if (ret != ompd_rc_ok) + return ret; + + memcpy (t, tmp, tmp_length); + snprintf (t + tmp_length, macro_length, "%ld", omp_version); + + *string = t; + + return ret; +} diff --git a/libgomp/ompd-lib.c b/libgomp/ompd-lib.c index d5350e1045c..1b4f5cf0472 100644 --- 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; + +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 (); (void) api_version;