Update implementation of OMPT to the specification OpenMP 5.0 Preview 1 (TR4).
The code is tested to work with latest clang, GNU and Intel compiler. The implementation
is optimized for low overhead when no tool is attached shifting the cost to execution with
tool attached.
This patch does not implement OMPT for libomptarget.
Patch by Simon Convent and Joachim Protze
Differential Revision: https://reviews.llvm.org/D38185
llvm-svn: 317085
diff --git a/openmp/runtime/src/kmp_cancel.cpp b/openmp/runtime/src/kmp_cancel.cpp
index efc67fc..71c71ec 100644
--- a/openmp/runtime/src/kmp_cancel.cpp
+++ b/openmp/runtime/src/kmp_cancel.cpp
@@ -12,6 +12,9 @@
#include "kmp_i18n.h"
#include "kmp_io.h"
#include "kmp_str.h"
+#if OMPT_SUPPORT
+#include "ompt-specific.h"
+#endif
#if OMP_40_ENABLED
@@ -51,11 +54,25 @@
kmp_int32 old = KMP_COMPARE_AND_STORE_RET32(
&(this_team->t.t_cancel_request), cancel_noreq, cncl_kind);
if (old == cancel_noreq || old == cncl_kind) {
- // printf("__kmpc_cancel: this_team->t.t_cancel_request=%d @ %p\n",
- // this_team->t.t_cancel_request,
- // &(this_team->t.t_cancel_request));
- // we do not have a cancellation request in this team or we do have
- // one that matches the current request -> cancel
+// we do not have a cancellation request in this team or we do have
+// one that matches the current request -> cancel
+#if OMPT_SUPPORT && OMPT_OPTIONAL
+ if (ompt_enabled.ompt_callback_cancel) {
+ ompt_data_t *task_data;
+ __ompt_get_task_info_internal(0, NULL, &task_data, NULL, NULL,
+ NULL);
+ ompt_cancel_flag_t type = ompt_cancel_parallel;
+ if (cncl_kind == cancel_parallel)
+ type = ompt_cancel_parallel;
+ else if (cncl_kind == cancel_loop)
+ type = ompt_cancel_do;
+ else if (cncl_kind == cancel_sections)
+ type = ompt_cancel_sections;
+ ompt_callbacks.ompt_callback(ompt_callback_cancel)(
+ task_data, type | ompt_cancel_activated,
+ OMPT_GET_RETURN_ADDRESS(0));
+ }
+#endif
return 1 /* true */;
}
break;
@@ -75,8 +92,18 @@
kmp_int32 old = KMP_COMPARE_AND_STORE_RET32(
&(taskgroup->cancel_request), cancel_noreq, cncl_kind);
if (old == cancel_noreq || old == cncl_kind) {
- // we do not have a cancellation request in this taskgroup or we do
- // have one that matches the current request -> cancel
+// we do not have a cancellation request in this taskgroup or we do
+// have one that matches the current request -> cancel
+#if OMPT_SUPPORT && OMPT_OPTIONAL
+ if (ompt_enabled.ompt_callback_cancel) {
+ ompt_data_t *task_data;
+ __ompt_get_task_info_internal(0, NULL, &task_data, NULL, NULL,
+ NULL);
+ ompt_callbacks.ompt_callback(ompt_callback_cancel)(
+ task_data, ompt_cancel_taskgroup | ompt_cancel_activated,
+ OMPT_GET_RETURN_ADDRESS(0));
+ }
+#endif
return 1 /* true */;
}
} else {
@@ -134,8 +161,25 @@
KMP_DEBUG_ASSERT(this_team);
if (this_team->t.t_cancel_request) {
if (cncl_kind == this_team->t.t_cancel_request) {
- // the request in the team structure matches the type of
- // cancellation point so we can cancel
+// the request in the team structure matches the type of
+// cancellation point so we can cancel
+#if OMPT_SUPPORT && OMPT_OPTIONAL
+ if (ompt_enabled.ompt_callback_cancel) {
+ ompt_data_t *task_data;
+ __ompt_get_task_info_internal(0, NULL, &task_data, NULL, NULL,
+ NULL);
+ ompt_cancel_flag_t type = ompt_cancel_parallel;
+ if (cncl_kind == cancel_parallel)
+ type = ompt_cancel_parallel;
+ else if (cncl_kind == cancel_loop)
+ type = ompt_cancel_do;
+ else if (cncl_kind == cancel_sections)
+ type = ompt_cancel_sections;
+ ompt_callbacks.ompt_callback(ompt_callback_cancel)(
+ task_data, type | ompt_cancel_detected,
+ OMPT_GET_RETURN_ADDRESS(0));
+ }
+#endif
return 1 /* true */;
}
KMP_ASSERT(0 /* false */);
@@ -158,7 +202,18 @@
taskgroup = task->td_taskgroup;
if (taskgroup) {
- // return the current status of cancellation for the taskgroup
+// return the current status of cancellation for the taskgroup
+#if OMPT_SUPPORT && OMPT_OPTIONAL
+ if (ompt_enabled.ompt_callback_cancel &&
+ !!taskgroup->cancel_request) {
+ ompt_data_t *task_data;
+ __ompt_get_task_info_internal(0, NULL, &task_data, NULL, NULL,
+ NULL);
+ ompt_callbacks.ompt_callback(ompt_callback_cancel)(
+ task_data, ompt_cancel_taskgroup | ompt_cancel_detected,
+ OMPT_GET_RETURN_ADDRESS(0));
+ }
+#endif
return !!taskgroup->cancel_request;
} else {
// if a cancellation point is encountered by a task that does not