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 <y2s1...@gmail.com> 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 yyyymm 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 00000000000..281d02b1902 --- /dev/null +++ b/libgomp/ompd-addr.c @@ -0,0 +1,83 @@ +/* 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 <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; + + /* TODO: once environment values are encoded, make a function to decode + and fetch variables. */ + *omp_version = address_space->env->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 = strlen ("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 *description = "GNU OpenMP Runtime implementing OpenMP 5.0 "; + ompd_size_t description_length = strlen (description); + + size_t total_length = description_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, description, description_length); + snprintf (t + description_length, macro_length, "%ld", omp_version); + + *string = t; + + return ret; +} diff --git a/libgomp/ompd-proc.c b/libgomp/ompd-proc.c index 32c0e2ed530..dd054952cd6 100644 --- a/libgomp/ompd-proc.c +++ b/libgomp/ompd-proc.c @@ -54,10 +54,21 @@ ompd_process_initialize (ompd_address_space_context_t *context, (*handle)->sizeof_id = 0; (*handle)->process_reference = NULL; (*handle)->ref_count = 0; + gompd_set_environment (&(*handle)->env); return ret; } +ompd_rc_t +gompd_set_environment (gompd_env **env) +{ + /* TODO: Turn this placeholder function to handle OMPD environment variables + when it becomes compact. */ + gompd_env temp_env = { 202007, 201811 }; + **env = temp_env; + return ompd_rc_ok; +} + ompd_rc_t ompd_device_initialize (ompd_address_space_handle_t *process_handle, ompd_address_space_context_t *device_context, -- 2.27.0