Skip to content

Commit 7a72856

Browse files
authored
[OpenMP] Use new OMPT state and sync kinds for barrier events (#95602)
This change makes the runtime use new OMPT state and sync kinds introduced in OpenMP 5.1 in place of the deprecated implicit state and sync kinds. Events from implicit barriers use different enumerators for workshare, parallel, and teams.
1 parent b22fa90 commit 7a72856

26 files changed

+507
-539
lines changed

openmp/runtime/src/include/omp-tools.h.var

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
/* implicit barrier at the end of worksharing */ \
7979
macro (ompt_state_wait_barrier_implicit, 0x013) /* implicit barrier */ \
8080
macro (ompt_state_wait_barrier_explicit, 0x014) /* explicit barrier */ \
81+
macro (ompt_state_wait_barrier_implementation, 0x015) /* implementation barrier */ \
82+
macro (ompt_state_wait_barrier_teams, 0x016) /* teams barrier */ \
8183
\
8284
/* task wait states (32..63) */ \
8385
macro (ompt_state_wait_taskwait, 0x020) /* waiting at a taskwait */ \

openmp/runtime/src/kmp_barrier.cpp

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,25 @@ static int __kmp_barrier_template(enum barrier_type bt, int gtid, int is_split,
18051805
// It is OK to report the barrier state after the barrier begin callback.
18061806
// According to the OMPT specification, a compliant implementation may
18071807
// even delay reporting this state until the barrier begins to wait.
1808-
this_thr->th.ompt_thread_info.state = ompt_state_wait_barrier;
1808+
auto *ompt_thr_info = &this_thr->th.ompt_thread_info;
1809+
switch (barrier_kind) {
1810+
case ompt_sync_region_barrier_explicit:
1811+
ompt_thr_info->state = ompt_state_wait_barrier_explicit;
1812+
break;
1813+
case ompt_sync_region_barrier_implicit_workshare:
1814+
ompt_thr_info->state = ompt_state_wait_barrier_implicit_workshare;
1815+
break;
1816+
case ompt_sync_region_barrier_implicit_parallel:
1817+
ompt_thr_info->state = ompt_state_wait_barrier_implicit_parallel;
1818+
break;
1819+
case ompt_sync_region_barrier_teams:
1820+
ompt_thr_info->state = ompt_state_wait_barrier_teams;
1821+
break;
1822+
case ompt_sync_region_barrier_implementation:
1823+
[[fallthrough]];
1824+
default:
1825+
ompt_thr_info->state = ompt_state_wait_barrier_implementation;
1826+
}
18091827
}
18101828
#endif
18111829

@@ -2213,20 +2231,24 @@ void __kmp_join_barrier(int gtid) {
22132231
codeptr = team->t.ompt_team_info.master_return_address;
22142232
my_task_data = OMPT_CUR_TASK_DATA(this_thr);
22152233
my_parallel_data = OMPT_CUR_TEAM_DATA(this_thr);
2234+
ompt_sync_region_t sync_kind = ompt_sync_region_barrier_implicit_parallel;
2235+
ompt_state_t ompt_state = ompt_state_wait_barrier_implicit_parallel;
2236+
if (this_thr->th.ompt_thread_info.parallel_flags & ompt_parallel_league) {
2237+
sync_kind = ompt_sync_region_barrier_teams;
2238+
ompt_state = ompt_state_wait_barrier_teams;
2239+
}
22162240
if (ompt_enabled.ompt_callback_sync_region) {
22172241
ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
2218-
ompt_sync_region_barrier_implicit, ompt_scope_begin, my_parallel_data,
2219-
my_task_data, codeptr);
2242+
sync_kind, ompt_scope_begin, my_parallel_data, my_task_data, codeptr);
22202243
}
22212244
if (ompt_enabled.ompt_callback_sync_region_wait) {
22222245
ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
2223-
ompt_sync_region_barrier_implicit, ompt_scope_begin, my_parallel_data,
2224-
my_task_data, codeptr);
2246+
sync_kind, ompt_scope_begin, my_parallel_data, my_task_data, codeptr);
22252247
}
22262248
if (!KMP_MASTER_TID(ds_tid))
22272249
this_thr->th.ompt_thread_info.task_data = *OMPT_CUR_TASK_DATA(this_thr);
22282250
#endif
2229-
this_thr->th.ompt_thread_info.state = ompt_state_wait_barrier_implicit;
2251+
this_thr->th.ompt_thread_info.state = ompt_state;
22302252
}
22312253
#endif
22322254

@@ -2488,8 +2510,10 @@ void __kmp_fork_barrier(int gtid, int tid) {
24882510
}
24892511

24902512
#if OMPT_SUPPORT
2513+
ompt_state_t ompt_state = this_thr->th.ompt_thread_info.state;
24912514
if (ompt_enabled.enabled &&
2492-
this_thr->th.ompt_thread_info.state == ompt_state_wait_barrier_implicit) {
2515+
(ompt_state == ompt_state_wait_barrier_teams ||
2516+
ompt_state == ompt_state_wait_barrier_implicit_parallel)) {
24932517
int ds_tid = this_thr->th.th_info.ds.ds_tid;
24942518
ompt_data_t *task_data = (team)
24952519
? OMPT_CUR_TASK_DATA(this_thr)
@@ -2501,15 +2525,16 @@ void __kmp_fork_barrier(int gtid, int tid) {
25012525
(ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait) ||
25022526
ompt_callbacks.ompt_callback(ompt_callback_sync_region)))
25032527
codeptr = team ? team->t.ompt_team_info.master_return_address : NULL;
2528+
ompt_sync_region_t sync_kind = ompt_sync_region_barrier_implicit_parallel;
2529+
if (this_thr->th.ompt_thread_info.parallel_flags & ompt_parallel_league)
2530+
sync_kind = ompt_sync_region_barrier_teams;
25042531
if (ompt_enabled.ompt_callback_sync_region_wait) {
25052532
ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
2506-
ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, task_data,
2507-
codeptr);
2533+
sync_kind, ompt_scope_end, NULL, task_data, codeptr);
25082534
}
25092535
if (ompt_enabled.ompt_callback_sync_region) {
25102536
ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
2511-
ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, task_data,
2512-
codeptr);
2537+
sync_kind, ompt_scope_end, NULL, task_data, codeptr);
25132538
}
25142539
#endif
25152540
if (!KMP_MASTER_TID(ds_tid) && ompt_enabled.ompt_callback_implicit_task) {

openmp/runtime/src/kmp_runtime.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7745,7 +7745,7 @@ int __kmp_invoke_task_func(int gtid) {
77457745
);
77467746
#if OMPT_SUPPORT
77477747
*exit_frame_p = NULL;
7748-
this_thr->th.ompt_thread_info.parallel_flags |= ompt_parallel_team;
7748+
this_thr->th.ompt_thread_info.parallel_flags = ompt_parallel_team;
77497749
#endif
77507750

77517751
#if KMP_STATS_ENABLED
@@ -7843,7 +7843,7 @@ int __kmp_invoke_teams_master(int gtid) {
78437843
#endif
78447844
__kmp_teams_master(gtid);
78457845
#if OMPT_SUPPORT
7846-
this_thr->th.ompt_thread_info.parallel_flags |= ompt_parallel_league;
7846+
this_thr->th.ompt_thread_info.parallel_flags = ompt_parallel_league;
78477847
#endif
78487848
__kmp_run_after_invoked_task(gtid, 0, this_thr, team);
78497849
return 1;
@@ -8126,8 +8126,10 @@ void __kmp_internal_join(ident_t *id, int gtid, kmp_team_t *team) {
81268126

81278127
__kmp_join_barrier(gtid); /* wait for everyone */
81288128
#if OMPT_SUPPORT
8129+
ompt_state_t ompt_state = this_thr->th.ompt_thread_info.state;
81298130
if (ompt_enabled.enabled &&
8130-
this_thr->th.ompt_thread_info.state == ompt_state_wait_barrier_implicit) {
8131+
(ompt_state == ompt_state_wait_barrier_teams ||
8132+
ompt_state == ompt_state_wait_barrier_implicit_parallel)) {
81318133
int ds_tid = this_thr->th.th_info.ds.ds_tid;
81328134
ompt_data_t *task_data = OMPT_CUR_TASK_DATA(this_thr);
81338135
this_thr->th.ompt_thread_info.state = ompt_state_overhead;
@@ -8138,15 +8140,16 @@ void __kmp_internal_join(ident_t *id, int gtid, kmp_team_t *team) {
81388140
ompt_callbacks.ompt_callback(ompt_callback_sync_region)))
81398141
codeptr = OMPT_CUR_TEAM_INFO(this_thr)->master_return_address;
81408142

8143+
ompt_sync_region_t sync_kind = ompt_sync_region_barrier_implicit_parallel;
8144+
if (this_thr->th.ompt_thread_info.parallel_flags & ompt_parallel_league)
8145+
sync_kind = ompt_sync_region_barrier_teams;
81418146
if (ompt_enabled.ompt_callback_sync_region_wait) {
81428147
ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
8143-
ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, task_data,
8144-
codeptr);
8148+
sync_kind, ompt_scope_end, NULL, task_data, codeptr);
81458149
}
81468150
if (ompt_enabled.ompt_callback_sync_region) {
81478151
ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
8148-
ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, task_data,
8149-
codeptr);
8152+
sync_kind, ompt_scope_end, NULL, task_data, codeptr);
81508153
}
81518154
#endif
81528155
if (!KMP_MASTER_TID(ds_tid) && ompt_enabled.ompt_callback_implicit_task) {

openmp/runtime/src/kmp_wait_release.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,19 +323,21 @@ static void __ompt_implicit_task_end(kmp_info_t *this_thr,
323323
ompt_state_t ompt_state,
324324
ompt_data_t *tId) {
325325
int ds_tid = this_thr->th.th_info.ds.ds_tid;
326-
if (ompt_state == ompt_state_wait_barrier_implicit) {
326+
if (ompt_state == ompt_state_wait_barrier_implicit_parallel ||
327+
ompt_state == ompt_state_wait_barrier_teams) {
327328
this_thr->th.ompt_thread_info.state = ompt_state_overhead;
328329
#if OMPT_OPTIONAL
329330
void *codeptr = NULL;
331+
ompt_sync_region_t sync_kind = ompt_sync_region_barrier_implicit_parallel;
332+
if (this_thr->th.ompt_thread_info.parallel_flags & ompt_parallel_league)
333+
sync_kind = ompt_sync_region_barrier_teams;
330334
if (ompt_enabled.ompt_callback_sync_region_wait) {
331335
ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
332-
ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, tId,
333-
codeptr);
336+
sync_kind, ompt_scope_end, NULL, tId, codeptr);
334337
}
335338
if (ompt_enabled.ompt_callback_sync_region) {
336339
ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
337-
ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, tId,
338-
codeptr);
340+
sync_kind, ompt_scope_end, NULL, tId, codeptr);
339341
}
340342
#endif
341343
if (!KMP_MASTER_TID(ds_tid)) {
@@ -455,7 +457,9 @@ final_spin=FALSE)
455457
ompt_data_t *tId;
456458
if (ompt_enabled.enabled) {
457459
ompt_entry_state = this_thr->th.ompt_thread_info.state;
458-
if (!final_spin || ompt_entry_state != ompt_state_wait_barrier_implicit ||
460+
if (!final_spin ||
461+
(ompt_entry_state != ompt_state_wait_barrier_implicit_parallel &&
462+
ompt_entry_state != ompt_state_wait_barrier_teams) ||
459463
KMP_MASTER_TID(this_thr->th.th_info.ds.ds_tid)) {
460464
ompt_lw_taskteam_t *team = NULL;
461465
if (this_thr->th.th_team)

openmp/runtime/src/ompt-specific.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -503,22 +503,23 @@ static uint64_t __ompt_get_unique_id_internal() {
503503

504504
ompt_sync_region_t __ompt_get_barrier_kind(enum barrier_type bt,
505505
kmp_info_t *thr) {
506-
if (bt == bs_forkjoin_barrier)
507-
return ompt_sync_region_barrier_implicit;
506+
if (bt == bs_forkjoin_barrier) {
507+
if (thr->th.ompt_thread_info.parallel_flags & ompt_parallel_league)
508+
return ompt_sync_region_barrier_teams;
509+
else
510+
return ompt_sync_region_barrier_implicit_parallel;
511+
}
508512

509-
if (bt != bs_plain_barrier)
513+
if (bt != bs_plain_barrier || !thr->th.th_ident)
510514
return ompt_sync_region_barrier_implementation;
511515

512-
if (!thr->th.th_ident)
513-
return ompt_sync_region_barrier;
514-
515516
kmp_int32 flags = thr->th.th_ident->flags;
516517

517518
if ((flags & KMP_IDENT_BARRIER_EXPL) != 0)
518519
return ompt_sync_region_barrier_explicit;
519520

520521
if ((flags & KMP_IDENT_BARRIER_IMPL) != 0)
521-
return ompt_sync_region_barrier_implicit;
522+
return ompt_sync_region_barrier_implicit_workshare;
522523

523524
return ompt_sync_region_barrier_implementation;
524525
}

0 commit comments

Comments
 (0)