diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am index 6d913a93e7f..4e215450b25 100644 --- a/libgomp/Makefile.am +++ b/libgomp/Makefile.am @@ -94,7 +94,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c env.c error.c \ priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \ oacc-target.c ompd-support.c -libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c +libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c ompd-parallel.c include $(top_srcdir)/plugin/Makefrag.am diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in index 40f896b5f03..ab66ad1c8f0 100644 --- a/libgomp/Makefile.in +++ b/libgomp/Makefile.in @@ -233,7 +233,8 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo critical.lo \ affinity-fmt.lo teams.lo allocator.lo oacc-profiling.lo \ oacc-target.lo ompd-support.lo $(am__objects_1) libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS) -am_libgompd_la_OBJECTS = ompd-init.lo ompd-helper.lo ompd-icv.lo +am_libgompd_la_OBJECTS = ompd-init.lo ompd-helper.lo ompd-icv.lo \ + ompd-parallel.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@) @@ -583,7 +584,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 ompd-support.c $(am__append_7) -libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c +libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c ompd-parallel.c # Nvidia PTX OpenACC plugin. @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info $(libtool_VERSION) @@ -800,6 +801,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-helper.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-icv.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-init.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-parallel.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-support.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@ diff --git a/libgomp/libgompd.map b/libgomp/libgompd.map index 85bdc3695f6..1662dc56962 100644 --- a/libgomp/libgompd.map +++ b/libgomp/libgompd.map @@ -16,6 +16,10 @@ OMPD_5.1 { ompd_thread_handle_compare; ompd_get_thread_id; ompd_get_device_from_thread; + ompd_get_curr_parallel_handle; + ompd_get_enclosing_parallel_handle; + ompd_rel_parallel_handle; + ompd_parallel_handle_compare; local: *; }; diff --git a/libgomp/ompd-parallel.c b/libgomp/ompd-parallel.c new file mode 100644 index 00000000000..3a278f7428a --- /dev/null +++ b/libgomp/ompd-parallel.c @@ -0,0 +1,144 @@ +/* Copyright (C) The GNU Toolchain Authors. + Contributed by Mohamed Sayed . + 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 the implementation of functions defined in + section 5.5.6. */ + +#include "ompd-helper.h" + +ompd_rc_t +ompd_get_curr_parallel_handle (ompd_thread_handle_t *thread_handle, + ompd_parallel_handle_t **parallel_handle) +{ + if (thread_handle == NULL) + return ompd_rc_stale_handle; + + CHECK (thread_handle->ah); + + ompd_address_space_context_t *context = thread_handle->ah->context; + ompd_thread_context_t *thread_context = thread_handle->thread_context; + + if (thread_context == NULL) + return ompd_rc_stale_handle; + + ompd_address_t symbol_address = thread_handle->th; + ompd_address_t temp_symbol_address = {OMPD_SEGMENT_UNSPECIFIED, 0}; + ompd_word_t temp_offset; + ompd_rc_t ret; + + /* get ts offset. */ + GET_VALUE (context, thread_context, "gompd_access_gomp_thread_ts", + temp_offset, temp_offset, target_sizes.sizeof_long_long, 1, ret, + temp_symbol_address); + + symbol_address.address += temp_offset; + + /* get team offset. */ + GET_VALUE (context, thread_context, "gompd_access_gomp_team_state_team", + temp_offset, temp_offset, target_sizes.sizeof_long_long, 1, ret, + temp_symbol_address); + + symbol_address.address += temp_offset; + + ret = callbacks->read_memory (context, thread_context, + &symbol_address, target_sizes.sizeof_pointer, + &symbol_address.address); + + CHECK_RET (ret); + ret = callbacks->alloc_memory (sizeof (ompd_parallel_handle_t), + (void **) (parallel_handle)); + CHECK_RET (ret); + + (*parallel_handle)->ah = thread_handle->ah; + (*parallel_handle)->th = symbol_address; + return ompd_rc_ok; +} + +ompd_rc_t +ompd_get_enclosing_parallel_handle (ompd_parallel_handle_t *parallel_handle, + ompd_parallel_handle_t **enc_par_handle) +{ + if (parallel_handle == NULL) + return ompd_rc_stale_handle; + + CHECK (parallel_handle->ah); + + ompd_address_space_context_t *context = parallel_handle->ah->context; + ompd_address_t symbol_address = parallel_handle->th; + ompd_address_t temp_symbol_address = {OMPD_SEGMENT_UNSPECIFIED, 0}; + ompd_word_t temp_offset; + ompd_rc_t ret; + + /* get prev_ts offset. */ + GET_VALUE (context, NULL, "gompd_access_gomp_team_prev_ts", + temp_offset, temp_offset, target_sizes.sizeof_long_long, 1, ret, + temp_symbol_address); + + symbol_address.address += temp_offset; + + /* get team offset. */ + GET_VALUE (context, NULL, "gompd_access_gomp_team_state_team", + temp_offset, temp_offset, target_sizes.sizeof_long_long, 1, ret, + temp_symbol_address); + + symbol_address.address += temp_offset; + + ret = callbacks->read_memory (context, NULL, &symbol_address, + target_sizes.sizeof_pointer, + &symbol_address.address); + CHECK_RET (ret); + ret = callbacks->alloc_memory (sizeof (ompd_parallel_handle_t), + (void **) (enc_par_handle)); + CHECK_RET (ret); + + (*enc_par_handle)->ah = parallel_handle->ah; + (*enc_par_handle)->th = symbol_address; + return ompd_rc_ok; +} + +ompd_rc_t +ompd_rel_parallel_handle (ompd_parallel_handle_t *parallel_handle) +{ + if (parallel_handle == NULL) + return ompd_rc_stale_handle; + + ompd_rc_t ret = callbacks->free_memory ((void *) (parallel_handle)); + + CHECK_RET (ret); + return ompd_rc_ok; +} + +ompd_rc_t +ompd_parallel_handle_compare (ompd_parallel_handle_t *parallel_handle_1, + ompd_parallel_handle_t *parallel_handle_2, + int *cmp_value) +{ + if (parallel_handle_1 == NULL || parallel_handle_2 == NULL) + return ompd_rc_stale_handle; + + if (cmp_value == NULL) + return ompd_rc_bad_input; + + if (parallel_handle_1->ah->kind != parallel_handle_2->ah->kind) + return ompd_rc_bad_input; + + *cmp_value = parallel_handle_1->th.address - parallel_handle_2->th.address; + return ompd_rc_ok; +} diff --git a/libgomp/ompd-support.h b/libgomp/ompd-support.h index 39d55161132..48a2e6133f5 100644 --- a/libgomp/ompd-support.h +++ b/libgomp/ompd-support.h @@ -83,12 +83,15 @@ extern __UINT64_TYPE__ gompd_state; gompd_access (gomp_thread_pool, threads) \ gompd_access (gomp_thread, ts) \ gompd_access (gomp_team_state, team_id) \ - gompd_access (gomp_task, icv) + gompd_access (gomp_task, icv) \ + gompd_access (gomp_team_state, team) \ + gompd_access (gomp_team, prev_ts) #define GOMPD_SIZES(gompd_size) \ gompd_size (gomp_thread) \ gompd_size (gomp_task_icv) \ - gompd_size (gomp_task) + gompd_size (gomp_task) + #ifdef HAVE_ATTRIBUTE_VISIBILITY #pragma GCC visibility pop