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 <y2s1...@gmail.com> 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 /* LIBGOMPD_H */ diff --git a/libgomp/ompd-proc.c b/libgomp/ompd-proc.c new file mode 100644 index 00000000000..c0b2f11bdb4 --- /dev/null +++ b/libgomp/ompd-proc.c @@ -0,0 +1,130 @@ +/* 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 per-process functions + defined in the OpenMP 5.0 API Documentation, 5.5.2. */ + +#include <stdlib.h> +#include "omp-tools.h" +#include "libgompd.h" +#include "ompd-types.h" + +ompd_rc_t +ompd_process_initialize (ompd_address_space_context_t *context, + ompd_address_space_handle_t **handle) +{ + ompd_rc_t ret; + + if (handle == NULL) + return ompd_rc_stale_handle; + if (context == NULL) + return ompd_rc_bad_input; + + void *p = NULL; + ret = gompd_callbacks.alloc_memory (sizeof (ompd_address_space_handle_t), p); + if (ret != ompd_rc_ok) + return ret; + + *handle = p; + (*handle)->context = context; + (*handle)->kind = OMPD_DEVICE_KIND_HOST; + (*handle)->id = NULL; + (*handle)->sizeof_id = 0; + (*handle)->process_reference = NULL; + (*handle)->ref_count = 0; + + return ret; +} + +ompd_rc_t +ompd_device_initialize (ompd_address_space_handle_t *process_handle, + ompd_address_space_context_t *device_context, + ompd_device_t kind, ompd_size_t sizeof_id, void *id, + ompd_address_space_handle_t **device_handle) +{ + /* FIXME: implementation require more association with gomp-plugin. */ + + ompd_rc_t ret; + + if (process_handle == NULL || device_handle == NULL) + return ompd_rc_stale_handle; + + if (device_context == NULL || id == NULL) + return ompd_rc_bad_input; + + void *p = NULL; + ret = gompd_callbacks.alloc_memory (sizeof (ompd_address_space_handle_t), p); + if (ret != ompd_rc_ok) + return ret; + + *device_handle = p; + p = NULL; + + ret = gompd_callbacks.alloc_memory (sizeof_id, p); + if (ret != ompd_rc_ok) + return ret; + + (*device_handle)->id = p; + + /* FIXME: implementation requires decision on id handling. */ + + (*device_handle)->sizeof_id = sizeof_id; + (*device_handle)->context = device_context; + (*device_handle)->kind = kind; + (*device_handle)->ref_count = 0; + (*device_handle)->process_reference = process_handle; + process_handle->ref_count++; + + /* FIXME: currently returning error until implementation is fixed. */ + return ompd_rc_error; +} + +ompd_rc_t +ompd_rel_address_space_handle (ompd_address_space_handle_t *handle) +{ + ompd_rc_t ret; + if (handle == NULL || handle->context == NULL) + return ompd_rc_stale_handle; + + if (handle->ref_count != 0) + return ompd_rc_unavailable; + + if (handle->process_reference) + { + if (handle->process_reference->ref_count == 0) + return ompd_rc_error; + handle->process_reference->ref_count--; + } + + if (handle->id) + { + ret = gompd_callbacks.free_memory (handle->id); + if (ret != ompd_rc_ok) + return ret; + } + + ret = gompd_callbacks.free_memory (handle); + return ret; +} diff --git a/libgomp/ompd-types.h b/libgomp/ompd-types.h new file mode 100644 index 00000000000..4a9aec18ebc --- /dev/null +++ b/libgomp/ompd-types.h @@ -0,0 +1,90 @@ +/* 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 various library-defined data types for OMPD library. */ + +#ifndef OMPD_TYPES_H +#define OMPD_TYPES_H 1 + +#include "omp-tools.h" + +#define OMPD_TYPES_VERSION 20180906 /* YYYYMMDD Format */ + +/* Kinds of device threads */ +#define OMPD_THREAD_ID_PTHREAD ((ompd_thread_id_t) 0) +#define OMPD_THREAD_ID_LWP ((ompd_thread_id_t) 1) +#define OMPD_THREAD_ID_WINTHREAD ((ompd_thread_id_t) 2) +#define OMPD_THREAD_ID_CUDALOGICAL ((ompd_thread_id_t) 3) +/* The range of non-standard implementation defined values */ +#define OMPD_THREAD_ID_LO ((ompd_thread_id_t) 1000000) +#define OMPD_THREAD_ID_HI ((ompd_thread_id_t) 1100000) + +/* Target Cuda device-specific thread identification */ +typedef struct ompd_dim3_t { + ompd_addr_t x; + ompd_addr_t y; + ompd_addr_t z; +} ompd_dim3_t; + +typedef struct ompd_cudathread_coord_t { + ompd_addr_t cudaDevId; + ompd_addr_t cudaContext; + ompd_addr_t warpSize; + ompd_addr_t gridId; + ompd_dim3_t gridDim; + ompd_dim3_t blockDim; + ompd_dim3_t blockIdx; + ompd_dim3_t threadIdx; +} ompd_cudathread_coord_t; + +/* Memory Access Segment definitions for Host and Target Devices */ +#define OMPD_SEGMENT_UNSPECIFIED ((ompd_seg_t) 0) + +/* Cuda-specific values consistent with those defined in cudadebugger.h */ +#define OMPD_SEGMENT_CUDA_PTX_UNSPECIFIED ((ompd_seg_t) 0) +#define OMPD_SEGMENT_CUDA_PTX_CODE ((ompd_seg_t) 1) +#define OMPD_SEGMENT_CUDA_PTX_REG ((ompd_seg_t) 2) +#define OMPD_SEGMENT_CUDA_PTX_SREG ((ompd_seg_t) 3) +#define OMPD_SEGMENT_CUDA_PTX_CONST ((ompd_seg_t) 4) +#define OMPD_SEGMENT_CUDA_PTX_GLOBAL ((ompd_seg_t) 5) +#define OMPD_SEGMENT_CUDA_PTX_LOCAL ((ompd_seg_t) 6) +#define OMPD_SEGMENT_CUDA_PTX_PARAM ((ompd_seg_t) 7) +#define OMPD_SEGMENT_CUDA_PTX_SHARED ((ompd_seg_t) 8) +#define OMPD_SEGMENT_CUDA_PTX_SURF ((ompd_seg_t) 9) +#define OMPD_SEGMENT_CUDA_PTX_TEX ((ompd_seg_t) 10) +#define OMPD_SEGMENT_CUDA_PTX_TEXSAMPLER ((ompd_seg_t) 11) +#define OMPD_SEGMENT_CUDA_PTX_GENERIC ((ompd_seg_t) 12) +#define OMPD_SEGMENT_CUDA_PTX_IPARAM ((ompd_seg_t) 13) +#define OMPD_SEGMENT_CUDA_PTX_OPARAM ((ompd_seg_t) 14) +#define OMPD_SEGMENT_CUDA_PTX_FRAME ((ompd_seg_t) 15) + +/* Kinds of device device address spaces */ +#define OMPD_DEVICE_KIND_HOST ((ompd_device_t) 1) +#define OMPD_DEVICE_KIND_CUDA ((ompd_device_t) 2) +/* The range of non-standard implementation defined values */ +#define OMPD_DEVICE_IMPL_LO ((ompd_device_t) 1000000) +#define OMPD_DEVICE_IMPL_HI ((ompd_device_t) 1100000) + +#endif /* OMPD_TYPES_H */ -- 2.27.0