aboutsummaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorJonathan Peyton <jonathan.l.peyton@intel.com>2019-04-03 18:53:26 +0000
committerJonathan Peyton <jonathan.l.peyton@intel.com>2019-04-03 18:53:26 +0000
commit3d280aa4197396c33ee236b9c979e079b3020e9d (patch)
tree6c85408f2d71c3b2890a006d1790fb51b4b5f967 /runtime/src
parentcf0276b9ab4dba5d77a131fcf4061e5e2172d8eb (diff)
[OpenMP][Stats] Fix stats gathering for distribute and team clause
The distribute clause needs an explicit push of a timer. The teams clause needs a timer added and also, similarly to parallel, exchanged with the serial timer when encountered so that serial regions are counted properly. Differential Revision: https://reviews.llvm.org/D59801 git-svn-id: https://llvm.org/svn/llvm-project/openmp/trunk@357621 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/kmp_csupport.cpp15
-rw-r--r--runtime/src/kmp_dispatch.cpp6
-rw-r--r--runtime/src/kmp_runtime.cpp48
-rw-r--r--runtime/src/kmp_sched.cpp56
-rw-r--r--runtime/src/kmp_stats.cpp1
-rw-r--r--runtime/src/kmp_stats.h13
6 files changed, 107 insertions, 32 deletions
diff --git a/runtime/src/kmp_csupport.cpp b/runtime/src/kmp_csupport.cpp
index 4cc8757..93ecb81 100644
--- a/runtime/src/kmp_csupport.cpp
+++ b/runtime/src/kmp_csupport.cpp
@@ -382,7 +382,15 @@ void __kmpc_fork_teams(ident_t *loc, kmp_int32 argc, kmpc_micro microtask,
va_list ap;
va_start(ap, microtask);
+#if KMP_STATS_ENABLED
KMP_COUNT_BLOCK(OMP_TEAMS);
+ stats_state_e previous_state = KMP_GET_THREAD_STATE();
+ if (previous_state == stats_state_e::SERIAL_REGION) {
+ KMP_EXCHANGE_PARTITIONED_TIMER(OMP_teams_overhead);
+ } else {
+ KMP_PUSH_PARTITIONED_TIMER(OMP_teams_overhead);
+ }
+#endif
// remember teams entry point and nesting level
this_thr->th.th_teams_microtask = microtask;
@@ -442,6 +450,13 @@ void __kmpc_fork_teams(ident_t *loc, kmp_int32 argc, kmpc_micro microtask,
this_thr->th.th_teams_level = 0;
*(kmp_int64 *)(&this_thr->th.th_teams_size) = 0L;
va_end(ap);
+#if KMP_STATS_ENABLED
+ if (previous_state == stats_state_e::SERIAL_REGION) {
+ KMP_EXCHANGE_PARTITIONED_TIMER(OMP_serial);
+ } else {
+ KMP_POP_PARTITIONED_TIMER();
+ }
+#endif // KMP_STATS_ENABLED
}
#endif /* OMP_40_ENABLED */
diff --git a/runtime/src/kmp_dispatch.cpp b/runtime/src/kmp_dispatch.cpp
index 564e73b..ee786ae 100644
--- a/runtime/src/kmp_dispatch.cpp
+++ b/runtime/src/kmp_dispatch.cpp
@@ -283,6 +283,12 @@ void __kmp_dispatch_init_algorithm(ident_t *loc, int gtid,
}
}
+#if KMP_STATS_ENABLED
+ if (KMP_MASTER_GTID(gtid)) {
+ KMP_COUNT_VALUE(OMP_loop_dynamic_total_iterations, tc);
+ }
+#endif
+
pr->u.p.lb = lb;
pr->u.p.ub = ub;
pr->u.p.st = st;
diff --git a/runtime/src/kmp_runtime.cpp b/runtime/src/kmp_runtime.cpp
index 369aff9..6b6ebee 100644
--- a/runtime/src/kmp_runtime.cpp
+++ b/runtime/src/kmp_runtime.cpp
@@ -2285,9 +2285,25 @@ int __kmp_fork_call(ident_t *loc, int gtid,
team->t.t_id, team->t.t_pkfn));
} // END of timer KMP_fork_call block
+#if KMP_STATS_ENABLED && OMP_40_ENABLED
+ // If beginning a teams construct, then change thread state
+ stats_state_e previous_state = KMP_GET_THREAD_STATE();
+ if (!ap) {
+ KMP_SET_THREAD_STATE(stats_state_e::TEAMS_REGION);
+ }
+#endif
+
if (!team->t.t_invoke(gtid)) {
KMP_ASSERT2(0, "cannot invoke microtask for MASTER thread");
}
+
+#if KMP_STATS_ENABLED && OMP_40_ENABLED
+ // If was beginning of a teams construct, then reset thread state
+ if (!ap) {
+ KMP_SET_THREAD_STATE(previous_state);
+ }
+#endif
+
KA_TRACE(20, ("__kmp_fork_call: T#%d(%d:0) done microtask = %p\n", gtid,
team->t.t_id, team->t.t_pkfn));
KMP_MB(); /* Flush all pending memory write invalidates. */
@@ -7106,21 +7122,33 @@ int __kmp_invoke_task_func(int gtid) {
}
#endif
- {
- KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
- KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
- rc =
- __kmp_invoke_microtask((microtask_t)TCR_SYNC_PTR(team->t.t_pkfn), gtid,
- tid, (int)team->t.t_argc, (void **)team->t.t_argv
+#if KMP_STATS_ENABLED
+ stats_state_e previous_state = KMP_GET_THREAD_STATE();
+ if (previous_state == stats_state_e::TEAMS_REGION) {
+ KMP_PUSH_PARTITIONED_TIMER(OMP_teams);
+ } else {
+ KMP_PUSH_PARTITIONED_TIMER(OMP_parallel);
+ }
+ KMP_SET_THREAD_STATE(IMPLICIT_TASK);
+#endif
+
+ rc = __kmp_invoke_microtask((microtask_t)TCR_SYNC_PTR(team->t.t_pkfn), gtid,
+ tid, (int)team->t.t_argc, (void **)team->t.t_argv
#if OMPT_SUPPORT
- ,
- exit_runtime_p
+ ,
+ exit_runtime_p
#endif
- );
+ );
#if OMPT_SUPPORT
- *exit_runtime_p = NULL;
+ *exit_runtime_p = NULL;
#endif
+
+#if KMP_STATS_ENABLED
+ if (previous_state == stats_state_e::TEAMS_REGION) {
+ KMP_SET_THREAD_STATE(previous_state);
}
+ KMP_POP_PARTITIONED_TIMER();
+#endif
#if USE_ITT_BUILD
if (__itt_stack_caller_create_ptr) {
diff --git a/runtime/src/kmp_sched.cpp b/runtime/src/kmp_sched.cpp
index b8b0433..b53a2cc 100644
--- a/runtime/src/kmp_sched.cpp
+++ b/runtime/src/kmp_sched.cpp
@@ -38,6 +38,29 @@ char const *traits_t<long>::spec = "ld";
//-------------------------------------------------------------------------
#endif
+#if KMP_STATS_ENABLED
+#define KMP_STATS_LOOP_END(stat) \
+ { \
+ kmp_int64 t; \
+ kmp_int64 u = (kmp_int64)(*pupper); \
+ kmp_int64 l = (kmp_int64)(*plower); \
+ kmp_int64 i = (kmp_int64)incr; \
+ if (i == 1) { \
+ t = u - l + 1; \
+ } else if (i == -1) { \
+ t = l - u + 1; \
+ } else if (i > 0) { \
+ t = (u - l) / i + 1; \
+ } else { \
+ t = (l - u) / (-i) + 1; \
+ } \
+ KMP_COUNT_VALUE(stat, t); \
+ KMP_POP_PARTITIONED_TIMER(); \
+ }
+#else
+#define KMP_STATS_LOOP_END(stat) /* Nothing */
+#endif
+
template <typename T>
static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
kmp_int32 schedtype, kmp_int32 *plastiter,
@@ -151,6 +174,7 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
&(task_info->task_data), 0, codeptr);
}
#endif
+ KMP_STATS_LOOP_END(OMP_loop_static_iterations);
return;
}
@@ -202,6 +226,7 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
&(task_info->task_data), *pstride, codeptr);
}
#endif
+ KMP_STATS_LOOP_END(OMP_loop_static_iterations);
return;
}
nth = team->t.t_nproc;
@@ -231,6 +256,7 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
&(task_info->task_data), *pstride, codeptr);
}
#endif
+ KMP_STATS_LOOP_END(OMP_loop_static_iterations);
return;
}
@@ -246,6 +272,12 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
trip_count = (UT)(*plower - *pupper) / (-incr) + 1;
}
+#if KMP_STATS_ENABLED
+ if (KMP_MASTER_GTID(gtid)) {
+ KMP_COUNT_VALUE(OMP_loop_static_total_iterations, trip_count);
+ }
+#endif
+
if (__kmp_env_consistency_check) {
/* tripcount overflow? */
if (trip_count == 0 && *pupper != *plower) {
@@ -388,26 +420,7 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
}
#endif
-#if KMP_STATS_ENABLED
- {
- kmp_int64 t;
- kmp_int64 u = (kmp_int64)(*pupper);
- kmp_int64 l = (kmp_int64)(*plower);
- kmp_int64 i = (kmp_int64)incr;
- /* compute trip count */
- if (i == 1) {
- t = u - l + 1;
- } else if (i == -1) {
- t = l - u + 1;
- } else if (i > 0) {
- t = (u - l) / i + 1;
- } else {
- t = (l - u) / (-i) + 1;
- }
- KMP_COUNT_VALUE(OMP_loop_static_iterations, t);
- KMP_POP_PARTITIONED_TIMER();
- }
-#endif
+ KMP_STATS_LOOP_END(OMP_loop_static_iterations);
return;
}
@@ -419,6 +432,8 @@ static void __kmp_dist_for_static_init(ident_t *loc, kmp_int32 gtid,
typename traits_t<T>::signed_t incr,
typename traits_t<T>::signed_t chunk) {
KMP_COUNT_BLOCK(OMP_DISTRIBUTE);
+ KMP_PUSH_PARTITIONED_TIMER(OMP_distribute);
+ KMP_PUSH_PARTITIONED_TIMER(OMP_distribute_scheduling);
typedef typename traits_t<T>::unsigned_t UT;
typedef typename traits_t<T>::signed_t ST;
kmp_uint32 tid;
@@ -648,6 +663,7 @@ end:;
}
#endif
KE_TRACE(10, ("__kmpc_dist_for_static_init: T#%d return\n", gtid));
+ KMP_STATS_LOOP_END(OMP_distribute_iterations);
return;
}
diff --git a/runtime/src/kmp_stats.cpp b/runtime/src/kmp_stats.cpp
index 650a614..71f2dd9 100644
--- a/runtime/src/kmp_stats.cpp
+++ b/runtime/src/kmp_stats.cpp
@@ -546,7 +546,6 @@ static std::string generateFilename(char const *prototype,
// of __kmp_stats_global_output
void kmp_stats_output_module::init() {
- fprintf(stderr, "*** Stats enabled OpenMP* runtime ***\n");
char *statsFileName = getenv("KMP_STATS_FILE");
eventsFileName = getenv("KMP_STATS_EVENTS_FILE");
plotFileName = getenv("KMP_STATS_PLOT_FILE");
diff --git a/runtime/src/kmp_stats.h b/runtime/src/kmp_stats.h
index 79192b3..ee95658 100644
--- a/runtime/src/kmp_stats.h
+++ b/runtime/src/kmp_stats.h
@@ -69,7 +69,8 @@ enum stats_state_e {
TASKYIELD,
TASKGROUP,
IMPLICIT_TASK,
- EXPLICIT_TASK
+ EXPLICIT_TASK,
+ TEAMS_REGION
};
/*!
@@ -137,10 +138,14 @@ enum stats_state_e {
macro (OMP_worker_thread_life, stats_flags_e::logEvent, arg) \
macro (OMP_parallel, stats_flags_e::logEvent, arg) \
macro (OMP_parallel_overhead, stats_flags_e::logEvent, arg) \
+ macro (OMP_teams, stats_flags_e::logEvent, arg) \
+ macro (OMP_teams_overhead, stats_flags_e::logEvent, arg) \
macro (OMP_loop_static, 0, arg) \
macro (OMP_loop_static_scheduling, 0, arg) \
macro (OMP_loop_dynamic, 0, arg) \
macro (OMP_loop_dynamic_scheduling, 0, arg) \
+ macro (OMP_distribute, 0, arg) \
+ macro (OMP_distribute_scheduling, 0, arg) \
macro (OMP_critical, 0, arg) \
macro (OMP_critical_wait, 0, arg) \
macro (OMP_single, 0, arg) \
@@ -163,8 +168,14 @@ enum stats_state_e {
arg) \
macro (OMP_loop_static_iterations, \
stats_flags_e::noUnits | stats_flags_e::noTotal, arg) \
+ macro (OMP_loop_static_total_iterations, \
+ stats_flags_e::noUnits | stats_flags_e::noTotal, arg) \
macro (OMP_loop_dynamic_iterations, \
stats_flags_e::noUnits | stats_flags_e::noTotal, arg) \
+ macro (OMP_loop_dynamic_total_iterations, \
+ stats_flags_e::noUnits | stats_flags_e::noTotal, arg) \
+ macro (OMP_distribute_iterations, \
+ stats_flags_e::noUnits | stats_flags_e::noTotal, arg) \
KMP_FOREACH_DEVELOPER_TIMER(macro, arg)
// clang-format on