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 <y2s1...@gmail.com> 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 00000000000..f1f3b8071c1 --- /dev/null +++ b/libgomp/ompd-addr.c @@ -0,0 +1,88 @@ +/* Copyright (C) 2020 Free Software Foundation, Inc. + Contributed by Yoosuk Sim <y2s1...@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 <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; + + /* _OPENMP macro is defined to have yyyymm 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", &addr, NULL); + if (ret != ompd_rc_ok) + return ret; + + ret = gompd_callbacks.read_memory (address_space->context, NULL, &addr, + macro_length, (void *) omp_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_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_stringify (omp_version); + size_t s = strlen (tmp) + 1; + + char *t = NULL; + ret = gompd_callbacks.alloc_memory (s, (void *) t); + if (ret != ompd_rc_ok) + return ret; + + strcpy (t, tmp); + + *string = t; + + return ret; +} -- 2.27.0