summaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/openmp/ompt-general.cpp
diff options
context:
space:
mode:
authormikhnenko <[email protected]>2025-07-15 20:05:43 +0300
committermikhnenko <[email protected]>2025-07-15 20:52:16 +0300
commita40bd4f45bbc18fd95b1596e655b8942ceb2cf4b (patch)
treebce599ca02c778c277198de6d131d37db71997d0 /contrib/libs/cxxsupp/openmp/ompt-general.cpp
parent728e0eaef4dc1f1152d2c3a4cc1bbdf597f3ef3d (diff)
Update contrib/libs/cxxsupp/openmp to 20.1.7
commit_hash:722dd5fe79203d22ad4a0be288ac0caeb6b3dd68
Diffstat (limited to 'contrib/libs/cxxsupp/openmp/ompt-general.cpp')
-rw-r--r--contrib/libs/cxxsupp/openmp/ompt-general.cpp92
1 files changed, 78 insertions, 14 deletions
diff --git a/contrib/libs/cxxsupp/openmp/ompt-general.cpp b/contrib/libs/cxxsupp/openmp/ompt-general.cpp
index 0bee7e77c81..cd738f066fc 100644
--- a/contrib/libs/cxxsupp/openmp/ompt-general.cpp
+++ b/contrib/libs/cxxsupp/openmp/ompt-general.cpp
@@ -10,10 +10,11 @@
//
//===----------------------------------------------------------------------===//
+#include "kmp_utils.h"
+
/*****************************************************************************
* system include files
****************************************************************************/
-
#include <assert.h>
#include <stdint.h>
@@ -104,12 +105,17 @@ static ompt_start_tool_result_t *ompt_start_tool_result = NULL;
#if KMP_OS_WINDOWS
static HMODULE ompt_tool_module = NULL;
+static HMODULE ompt_archer_module = NULL;
#define OMPT_DLCLOSE(Lib) FreeLibrary(Lib)
#else
static void *ompt_tool_module = NULL;
+static void *ompt_archer_module = NULL;
#define OMPT_DLCLOSE(Lib) dlclose(Lib)
#endif
+/// Used to track the initializer and the finalizer provided by libomptarget
+static ompt_start_tool_result_t *libomptarget_ompt_result = NULL;
+
/*****************************************************************************
* forward declarations
****************************************************************************/
@@ -371,6 +377,7 @@ ompt_try_start_tool(unsigned int omp_version, const char *runtime_version) {
"Tool was started and is using the OMPT interface.\n");
OMPT_VERBOSE_INIT_PRINT(
"----- END LOGGING OF TOOL REGISTRATION -----\n");
+ ompt_archer_module = h;
return ret;
}
OMPT_VERBOSE_INIT_CONTINUED_PRINT(
@@ -378,6 +385,7 @@ ompt_try_start_tool(unsigned int omp_version, const char *runtime_version) {
} else {
OMPT_VERBOSE_INIT_CONTINUED_PRINT("Failed: %s\n", dlerror());
}
+ OMPT_DLCLOSE(h);
}
}
#endif
@@ -456,7 +464,7 @@ void ompt_pre_init() {
if (verbose_init && verbose_file != stderr && verbose_file != stdout)
fclose(verbose_file);
#if OMPT_DEBUG
- printf("ompt_pre_init(): ompt_enabled = %d\n", ompt_enabled);
+ printf("ompt_pre_init(): ompt_enabled = %d\n", ompt_enabled.enabled);
#endif
}
@@ -495,8 +503,8 @@ void ompt_post_init() {
ompt_callbacks.ompt_callback(ompt_callback_thread_begin)(
ompt_thread_initial, __ompt_get_thread_data_internal());
}
- ompt_data_t *task_data;
- ompt_data_t *parallel_data;
+ ompt_data_t *task_data = nullptr;
+ ompt_data_t *parallel_data = nullptr;
__ompt_get_task_info_internal(0, NULL, &task_data, NULL, &parallel_data,
NULL);
if (ompt_enabled.ompt_callback_implicit_task) {
@@ -509,14 +517,17 @@ void ompt_post_init() {
}
void ompt_fini() {
- if (ompt_enabled.enabled
-#if OMPD_SUPPORT
- && ompt_start_tool_result && ompt_start_tool_result->finalize
-#endif
- ) {
- ompt_start_tool_result->finalize(&(ompt_start_tool_result->tool_data));
+ if (ompt_enabled.enabled) {
+ if (ompt_start_tool_result && ompt_start_tool_result->finalize) {
+ ompt_start_tool_result->finalize(&(ompt_start_tool_result->tool_data));
+ }
+ if (libomptarget_ompt_result && libomptarget_ompt_result->finalize) {
+ libomptarget_ompt_result->finalize(NULL);
+ }
}
+ if (ompt_archer_module)
+ OMPT_DLCLOSE(ompt_archer_module);
if (ompt_tool_module)
OMPT_DLCLOSE(ompt_tool_module);
memset(&ompt_enabled, 0, sizeof(ompt_enabled));
@@ -687,7 +698,7 @@ OMPT_API_ROUTINE int ompt_get_num_places(void) {
#else
if (!KMP_AFFINITY_CAPABLE())
return 0;
- return __kmp_affinity_num_masks;
+ return __kmp_affinity.num_masks;
#endif
}
@@ -698,16 +709,16 @@ OMPT_API_ROUTINE int ompt_get_place_proc_ids(int place_num, int ids_size,
return 0;
#else
int i, count;
- int tmp_ids[ids_size];
+ SimpleVLA<int> tmp_ids(ids_size);
for (int j = 0; j < ids_size; j++)
tmp_ids[j] = 0;
if (!KMP_AFFINITY_CAPABLE())
return 0;
- if (place_num < 0 || place_num >= (int)__kmp_affinity_num_masks)
+ if (place_num < 0 || place_num >= (int)__kmp_affinity.num_masks)
return 0;
/* TODO: Is this safe for asynchronous call from signal handler during runtime
* shutdown? */
- kmp_affin_mask_t *mask = KMP_CPU_INDEX(__kmp_affinity_masks, place_num);
+ kmp_affin_mask_t *mask = KMP_CPU_INDEX(__kmp_affinity.masks, place_num);
count = 0;
KMP_CPU_SET_ITERATE(i, mask) {
if ((!KMP_CPU_ISSET(i, __kmp_affin_fullMask)) ||
@@ -869,5 +880,58 @@ static ompt_interface_fn_t ompt_fn_lookup(const char *s) {
FOREACH_OMPT_INQUIRY_FN(ompt_interface_fn)
+#undef ompt_interface_fn
+
return NULL;
}
+
+static ompt_data_t *ompt_get_task_data() { return __ompt_get_task_data(); }
+
+static ompt_data_t *ompt_get_target_task_data() {
+ return __ompt_get_target_task_data();
+}
+
+/// Lookup function to query libomp callbacks registered by the tool
+static ompt_interface_fn_t ompt_libomp_target_fn_lookup(const char *s) {
+#define provide_fn(fn) \
+ if (strcmp(s, #fn) == 0) \
+ return (ompt_interface_fn_t)fn;
+
+ provide_fn(ompt_get_callback);
+ provide_fn(ompt_get_task_data);
+ provide_fn(ompt_get_target_task_data);
+#undef provide_fn
+
+#define ompt_interface_fn(fn, type, code) \
+ if (strcmp(s, #fn) == 0) \
+ return (ompt_interface_fn_t)ompt_callbacks.ompt_callback(fn);
+
+ FOREACH_OMPT_DEVICE_EVENT(ompt_interface_fn)
+ FOREACH_OMPT_EMI_EVENT(ompt_interface_fn)
+ FOREACH_OMPT_NOEMI_EVENT(ompt_interface_fn)
+#undef ompt_interface_fn
+
+ return (ompt_interface_fn_t)0;
+}
+
+/// This function is called by the libomptarget connector to assign
+/// callbacks already registered with libomp.
+_OMP_EXTERN void ompt_libomp_connect(ompt_start_tool_result_t *result) {
+ OMPT_VERBOSE_INIT_PRINT("libomp --> OMPT: Enter ompt_libomp_connect\n");
+
+ // Ensure libomp callbacks have been added if not already
+ __ompt_force_initialization();
+
+ if (ompt_enabled.enabled && result) {
+ OMPT_VERBOSE_INIT_PRINT("libomp --> OMPT: Connecting with libomptarget\n");
+ // Pass in the libomp lookup function so that the already registered
+ // functions can be extracted and assigned to the callbacks in
+ // libomptarget
+ result->initialize(ompt_libomp_target_fn_lookup,
+ /* initial_device_num */ 0, /* tool_data */ nullptr);
+ // Track the object provided by libomptarget so that the finalizer can be
+ // called during OMPT finalization
+ libomptarget_ompt_result = result;
+ }
+ OMPT_VERBOSE_INIT_PRINT("libomp --> OMPT: Exit ompt_libomp_connect\n");
+}