Skip to content

Commit 2464f1c

Browse files
[OpenMP][OMPT] Add missing callbacks for asynchronous target tasks (llvm#93472)
- The first hidden-helper-thread did not trigger thread-begin - The "detaching" from a target-task when waiting for completion missed to call task-switch - Target tasks identified themself as explicit task Co-authored-by: Kaloyan Ignatov <[email protected]>
1 parent fb300eb commit 2464f1c

File tree

6 files changed

+29
-15
lines changed

6 files changed

+29
-15
lines changed

openmp/runtime/src/kmp.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,11 +2675,12 @@ typedef struct kmp_tasking_flags { /* Total struct must be exactly 32 bits */
26752675
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
26762676
/* Same fields as in the #else branch, but in reverse order */
26772677
#if OMPX_TASKGRAPH
2678-
unsigned reserved31 : 6;
2678+
unsigned reserved31 : 5;
26792679
unsigned onced : 1;
26802680
#else
2681-
unsigned reserved31 : 7;
2681+
unsigned reserved31 : 6;
26822682
#endif
2683+
unsigned target : 1;
26832684
unsigned native : 1;
26842685
unsigned freed : 1;
26852686
unsigned complete : 1;
@@ -2728,11 +2729,12 @@ typedef struct kmp_tasking_flags { /* Total struct must be exactly 32 bits */
27282729
unsigned complete : 1; /* 1==complete, 0==not complete */
27292730
unsigned freed : 1; /* 1==freed, 0==allocated */
27302731
unsigned native : 1; /* 1==gcc-compiled task, 0==intel */
2732+
unsigned target : 1;
27312733
#if OMPX_TASKGRAPH
27322734
unsigned onced : 1; /* 1==ran once already, 0==never ran, record & replay purposes */
2733-
unsigned reserved31 : 6; /* reserved for library use */
2735+
unsigned reserved31 : 5; /* reserved for library use */
27342736
#else
2735-
unsigned reserved31 : 7; /* reserved for library use */
2737+
unsigned reserved31 : 6; /* reserved for library use */
27362738
#endif
27372739
#endif
27382740
} kmp_tasking_flags_t;

openmp/runtime/src/kmp_runtime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3972,7 +3972,7 @@ int __kmp_register_root(int initial_thread) {
39723972
__kmp_root_counter++;
39733973

39743974
#if OMPT_SUPPORT
3975-
if (!initial_thread && ompt_enabled.enabled) {
3975+
if (ompt_enabled.enabled) {
39763976

39773977
kmp_info_t *root_thread = ompt_get_thread();
39783978

openmp/runtime/src/kmp_taskdeps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ kmp_int32 __kmpc_omp_task_with_deps(ident_t *loc_ref, kmp_int32 gtid,
739739
&(current_task->ompt_task_info.task_data),
740740
&(current_task->ompt_task_info.frame),
741741
&(new_taskdata->ompt_task_info.task_data),
742-
ompt_task_explicit | TASK_TYPE_DETAILS_FORMAT(new_taskdata), 1,
742+
TASK_TYPE_DETAILS_FORMAT(new_taskdata), 1,
743743
OMPT_LOAD_OR_GET_RETURN_ADDRESS(gtid));
744744
}
745745

openmp/runtime/src/kmp_tasking.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,7 @@ static void __kmpc_omp_task_begin_if0_template(ident_t *loc_ref, kmp_int32 gtid,
811811
ompt_callbacks.ompt_callback(ompt_callback_task_create)(
812812
&(parent_info->task_data), &(parent_info->frame),
813813
&(taskdata->ompt_task_info.task_data),
814-
ompt_task_explicit | TASK_TYPE_DETAILS_FORMAT(taskdata), 0,
815-
return_address);
814+
TASK_TYPE_DETAILS_FORMAT(taskdata), 0, return_address);
816815
}
817816
__ompt_task_start(task, current_task, gtid);
818817
}
@@ -1156,6 +1155,11 @@ static void __kmp_task_finish(kmp_int32 gtid, kmp_task_t *task,
11561155
// Note: no need to translate gtid to its shadow. If the current thread is a
11571156
// hidden helper one, then the gtid is already correct. Otherwise, hidden
11581157
// helper threads are disabled, and gtid refers to a OpenMP thread.
1158+
#if OMPT_SUPPORT
1159+
if (ompt) {
1160+
__ompt_task_finish(task, resumed_task, ompt_task_switch);
1161+
}
1162+
#endif
11591163
__kmpc_give_task(task, __kmp_tid_from_gtid(gtid));
11601164
if (KMP_HIDDEN_HELPER_THREAD(gtid))
11611165
__kmp_hidden_helper_worker_thread_signal();
@@ -1711,6 +1715,7 @@ kmp_task_t *__kmpc_omp_target_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
17111715
auto &input_flags = reinterpret_cast<kmp_tasking_flags_t &>(flags);
17121716
// target task is untied defined in the specification
17131717
input_flags.tiedness = TASK_UNTIED;
1718+
input_flags.target = 1;
17141719

17151720
if (__kmp_enable_hidden_helper)
17161721
input_flags.hidden_helper = TRUE;
@@ -1942,6 +1947,11 @@ __kmp_invoke_task(kmp_int32 gtid, kmp_task_t *task,
19421947
#endif
19431948
__kmp_task_finish<false>(gtid, task, current_task);
19441949
}
1950+
#if OMPT_SUPPORT
1951+
else if (UNLIKELY(ompt_enabled.enabled && taskdata->td_flags.target)) {
1952+
__ompt_task_finish(task, current_task, ompt_task_switch);
1953+
}
1954+
#endif
19451955

19461956
KA_TRACE(
19471957
30,
@@ -1974,7 +1984,8 @@ kmp_int32 __kmpc_omp_task_parts(ident_t *loc_ref, kmp_int32 gtid,
19741984
if (ompt_enabled.ompt_callback_task_create) {
19751985
ompt_callbacks.ompt_callback(ompt_callback_task_create)(
19761986
&(parent->ompt_task_info.task_data), &(parent->ompt_task_info.frame),
1977-
&(new_taskdata->ompt_task_info.task_data), ompt_task_explicit, 0,
1987+
&(new_taskdata->ompt_task_info.task_data),
1988+
TASK_TYPE_DETAILS_FORMAT(new_taskdata), 0,
19781989
OMPT_GET_RETURN_ADDRESS(0));
19791990
}
19801991
}
@@ -2132,7 +2143,7 @@ kmp_int32 __kmpc_omp_task(ident_t *loc_ref, kmp_int32 gtid,
21322143
&(parent->ompt_task_info.task_data),
21332144
&(parent->ompt_task_info.frame),
21342145
&(new_taskdata->ompt_task_info.task_data),
2135-
ompt_task_explicit | TASK_TYPE_DETAILS_FORMAT(new_taskdata), 0,
2146+
TASK_TYPE_DETAILS_FORMAT(new_taskdata), 0,
21362147
OMPT_LOAD_RETURN_ADDRESS(gtid));
21372148
}
21382149
} else {
@@ -2193,8 +2204,7 @@ kmp_int32 __kmp_omp_taskloop_task(ident_t *loc_ref, kmp_int32 gtid,
21932204
ompt_callbacks.ompt_callback(ompt_callback_task_create)(
21942205
&(parent->ompt_task_info.task_data), &(parent->ompt_task_info.frame),
21952206
&(new_taskdata->ompt_task_info.task_data),
2196-
ompt_task_explicit | TASK_TYPE_DETAILS_FORMAT(new_taskdata), 0,
2197-
codeptr_ra);
2207+
TASK_TYPE_DETAILS_FORMAT(new_taskdata), 0, codeptr_ra);
21982208
}
21992209
}
22002210
#endif

openmp/runtime/src/ompt-internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ typedef struct ompt_callbacks_active_s {
5050
: 0x0) | \
5151
((!(info->td_flags.tiedness)) ? ompt_task_untied : 0x0) | \
5252
(info->td_flags.final ? ompt_task_final : 0x0) | \
53+
(info->td_flags.target \
54+
? ompt_task_target \
55+
: (info->td_flags.tasktype ? ompt_task_explicit \
56+
: ompt_task_implicit)) | \
5357
(info->td_flags.merged_if0 ? ompt_task_mergeable : 0x0)
5458

5559
typedef struct {

openmp/runtime/src/ompt-specific.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,7 @@ int __ompt_get_task_info_internal(int ancestor_level, int *type,
421421
team_info = &team->t.ompt_team_info;
422422
if (type) {
423423
if (taskdata->td_parent) {
424-
*type = (taskdata->td_flags.tasktype ? ompt_task_explicit
425-
: ompt_task_implicit) |
426-
TASK_TYPE_DETAILS_FORMAT(taskdata);
424+
*type = TASK_TYPE_DETAILS_FORMAT(taskdata);
427425
} else {
428426
*type = ompt_task_initial;
429427
}

0 commit comments

Comments
 (0)