[OpenMP][OMPT] Distinguish different barrier kinds
authorJonathan Peyton <jonathan.l.peyton@intel.com>
Thu, 28 Feb 2019 20:55:39 +0000 (20:55 +0000)
committerJonathan Peyton <jonathan.l.peyton@intel.com>
Thu, 28 Feb 2019 20:55:39 +0000 (20:55 +0000)
This change makes the runtime decide the intended use of each barrier
invocation, for the OMPT synchronization tool callbacks.  The OpenMP 5.0
specification defines four possible barrier kinds -- implicit, explicit,
implementation, and just normal barrier.

Patch by Hansang Bae

Differential Revision: https://reviews.llvm.org/D58247

llvm-svn: 355140

openmp/runtime/src/kmp_barrier.cpp
openmp/runtime/src/kmp_runtime.cpp
openmp/runtime/src/kmp_wait_release.h
openmp/runtime/src/ompt-specific.cpp
openmp/runtime/src/ompt-specific.h
openmp/runtime/test/ompt/synchronization/barrier/implicit_task_data.c

index ecb115a..0fd96e7 100644 (file)
@@ -1297,6 +1297,7 @@ static int __kmp_barrier_template(enum barrier_type bt, int gtid, int is_split,
   ompt_data_t *my_task_data;
   ompt_data_t *my_parallel_data;
   void *return_address;
+  ompt_sync_region_t barrier_kind;
 #endif
 
   KA_TRACE(15, ("__kmp_barrier: T#%d(%d:%d) has arrived\n", gtid,
@@ -1309,15 +1310,16 @@ static int __kmp_barrier_template(enum barrier_type bt, int gtid, int is_split,
     my_task_data = OMPT_CUR_TASK_DATA(this_thr);
     my_parallel_data = OMPT_CUR_TEAM_DATA(this_thr);
     return_address = OMPT_LOAD_RETURN_ADDRESS(gtid);
+    barrier_kind = __ompt_get_barrier_kind(bt, this_thr);
     if (ompt_enabled.ompt_callback_sync_region) {
       ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
-          ompt_sync_region_barrier, ompt_scope_begin, my_parallel_data,
-          my_task_data, return_address);
+          barrier_kind, ompt_scope_begin, my_parallel_data, my_task_data,
+          return_address);
     }
     if (ompt_enabled.ompt_callback_sync_region_wait) {
       ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
-          ompt_sync_region_barrier, ompt_scope_begin, my_parallel_data,
-          my_task_data, return_address);
+          barrier_kind, ompt_scope_begin, my_parallel_data, my_task_data,
+          return_address);
     }
 #endif
     // It is OK to report the barrier state after the barrier begin callback.
@@ -1575,13 +1577,13 @@ static int __kmp_barrier_template(enum barrier_type bt, int gtid, int is_split,
 #if OMPT_OPTIONAL
     if (ompt_enabled.ompt_callback_sync_region_wait) {
       ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
-          ompt_sync_region_barrier, ompt_scope_end, my_parallel_data,
-          my_task_data, return_address);
+          barrier_kind, ompt_scope_end, my_parallel_data, my_task_data,
+          return_address);
     }
     if (ompt_enabled.ompt_callback_sync_region) {
       ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
-          ompt_sync_region_barrier, ompt_scope_end, my_parallel_data,
-          my_task_data, return_address);
+          barrier_kind, ompt_scope_end, my_parallel_data, my_task_data,
+          return_address);
     }
 #endif
     this_thr->th.ompt_thread_info.state = ompt_state_work_parallel;
@@ -1729,12 +1731,12 @@ void __kmp_join_barrier(int gtid) {
     my_parallel_data = OMPT_CUR_TEAM_DATA(this_thr);
     if (ompt_enabled.ompt_callback_sync_region) {
       ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
-          ompt_sync_region_barrier, ompt_scope_begin, my_parallel_data,
+          ompt_sync_region_barrier_implicit, ompt_scope_begin, my_parallel_data,
           my_task_data, codeptr);
     }
     if (ompt_enabled.ompt_callback_sync_region_wait) {
       ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
-          ompt_sync_region_barrier, ompt_scope_begin, my_parallel_data,
+          ompt_sync_region_barrier_implicit, ompt_scope_begin, my_parallel_data,
           my_task_data, codeptr);
     }
     if (!KMP_MASTER_TID(ds_tid))
@@ -2017,11 +2019,13 @@ void __kmp_fork_barrier(int gtid, int tid) {
       codeptr = team->t.ompt_team_info.master_return_address;
     if (ompt_enabled.ompt_callback_sync_region_wait) {
       ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
-          ompt_sync_region_barrier, ompt_scope_end, NULL, task_data, codeptr);
+          ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, task_data,
+          codeptr);
     }
     if (ompt_enabled.ompt_callback_sync_region) {
       ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
-          ompt_sync_region_barrier, ompt_scope_end, NULL, task_data, codeptr);
+          ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, task_data,
+          codeptr);
     }
 #endif
     if (!KMP_MASTER_TID(ds_tid) && ompt_enabled.ompt_callback_implicit_task) {
index e6b673b..2d337b4 100644 (file)
@@ -7370,11 +7370,13 @@ void __kmp_internal_join(ident_t *id, int gtid, kmp_team_t *team) {
 
     if (ompt_enabled.ompt_callback_sync_region_wait) {
       ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
-          ompt_sync_region_barrier, ompt_scope_end, NULL, task_data, codeptr);
+          ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, task_data,
+          codeptr);
     }
     if (ompt_enabled.ompt_callback_sync_region) {
       ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
-          ompt_sync_region_barrier, ompt_scope_end, NULL, task_data, codeptr);
+          ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, task_data,
+          codeptr);
     }
 #endif
     if (!KMP_MASTER_TID(ds_tid) && ompt_enabled.ompt_callback_implicit_task) {
index d1120d4..048e74e 100644 (file)
@@ -129,11 +129,13 @@ static void __ompt_implicit_task_end(kmp_info_t *this_thr,
     void *codeptr = NULL;
     if (ompt_enabled.ompt_callback_sync_region_wait) {
       ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
-          ompt_sync_region_barrier, ompt_scope_end, NULL, tId, codeptr);
+          ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, tId,
+          codeptr);
     }
     if (ompt_enabled.ompt_callback_sync_region) {
       ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
-          ompt_sync_region_barrier, ompt_scope_end, NULL, tId, codeptr);
+          ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, tId,
+          codeptr);
     }
 #endif
     if (!KMP_MASTER_TID(ds_tid)) {
index acd2389..f65048f 100644 (file)
@@ -448,3 +448,25 @@ static uint64_t __ompt_get_unique_id_internal() {
   }
   return ++ID;
 }
+
+ompt_sync_region_t __ompt_get_barrier_kind(enum barrier_type bt,
+                                           kmp_info_t *thr) {
+  if (bt == bs_forkjoin_barrier)
+    return ompt_sync_region_barrier_implicit;
+
+  if (bt != bs_plain_barrier)
+    return ompt_sync_region_barrier_implementation;
+
+  if (!thr->th.th_ident)
+    return ompt_sync_region_barrier;
+
+  kmp_int32 flags = thr->th.th_ident->flags;
+
+  if ((flags & KMP_IDENT_BARRIER_EXPL) != 0)
+    return ompt_sync_region_barrier_explicit;
+
+  if ((flags & KMP_IDENT_BARRIER_IMPL) != 0)
+    return ompt_sync_region_barrier_implicit;
+
+  return ompt_sync_region_barrier_implementation;
+}
index 25901df..86fd928 100644 (file)
@@ -50,6 +50,8 @@ ompt_data_t *__ompt_get_thread_data_internal();
 static uint64_t __ompt_get_get_unique_id_internal();
 */
 
+ompt_sync_region_t __ompt_get_barrier_kind(enum barrier_type, kmp_info_t *);
+
 /*****************************************************************************
  * macros
  ****************************************************************************/
index c933e89..71c2b15 100644 (file)
@@ -80,11 +80,11 @@ on_ompt_callback_sync_region(
   {
     case ompt_scope_begin:
       task_data->value = ompt_get_unique_id();
-      if(kind == ompt_sync_region_barrier)
+      if (kind == ompt_sync_region_barrier_implicit)
         printf("%" PRIu64 ": ompt_event_barrier_begin: parallel_id=%" PRIu64 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", ompt_get_thread_data()->value, parallel_data->value, task_data->value, codeptr_ra);
       break;
     case ompt_scope_end:
-      if(kind == ompt_sync_region_barrier)
+      if (kind == ompt_sync_region_barrier_implicit)
         printf("%" PRIu64 ": ompt_event_barrier_end: parallel_id=%" PRIu64 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", ompt_get_thread_data()->value, (parallel_data)?parallel_data->value:0, task_data->value, codeptr_ra);
       break;
   }
@@ -101,11 +101,15 @@ on_ompt_callback_sync_region_wait(
   switch(endpoint)
   {
     case ompt_scope_begin:
-      if(kind == ompt_sync_region_barrier)
-          printf("%" PRIu64 ": ompt_event_wait_barrier_begin: parallel_id=%" PRIu64 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", ompt_get_thread_data()->value, parallel_data->value, task_data->value, codeptr_ra);
+      if (kind == ompt_sync_region_barrier_implicit)
+        printf("%" PRIu64
+               ": ompt_event_wait_barrier_begin: parallel_id=%" PRIu64
+               ", task_id=%" PRIu64 ", codeptr_ra=%p\n",
+               ompt_get_thread_data()->value, parallel_data->value,
+               task_data->value, codeptr_ra);
       break;
     case ompt_scope_end:
-      if(kind == ompt_sync_region_barrier)
+      if (kind == ompt_sync_region_barrier_implicit)
         printf("%" PRIu64 ": ompt_event_wait_barrier_end: parallel_id=%" PRIu64 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", ompt_get_thread_data()->value, (parallel_data)?parallel_data->value:0, task_data->value, codeptr_ra);
       break;
   }