Skip to content

Commit 8bcdbcf

Browse files
kaloyan-ignatovjprotze
authored andcommitted
[OpenMP][OMPT] Change handling of target-related tool data in libomp
- store target_data in ompt_task_info_t to prevent data loss across scheduling of target region (both for deferred and undeferred target tasks) - target_task_data is already in ompt_task_info_t, replace previous implementation which returned the wrong value - combine queries for target_data and target_task_data and directly return ompt_task_info_t - return correct task_data, OpenMP standard defines task_data in target callbacks as belonging to the generating (encountering) task
1 parent 6372651 commit 8bcdbcf

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

openmp/runtime/src/ompt-general.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -886,10 +886,12 @@ static ompt_interface_fn_t ompt_fn_lookup(const char *s) {
886886
return NULL;
887887
}
888888

889-
static ompt_data_t *ompt_get_task_data() { return __ompt_get_task_data(); }
889+
static ompt_data_t *ompt_get_task_data() {
890+
return __ompt_get_generating_task();
891+
}
890892

891-
static ompt_data_t *ompt_get_target_task_data() {
892-
return __ompt_get_target_task_data();
893+
static ompt_task_info_t *ompt_get_task_info_target() {
894+
return __ompt_get_task_info_target();
893895
}
894896

895897
/// Lookup function to query libomp callbacks registered by the tool
@@ -900,7 +902,7 @@ static ompt_interface_fn_t ompt_libomp_target_fn_lookup(const char *s) {
900902

901903
provide_fn(ompt_get_callback);
902904
provide_fn(ompt_get_task_data);
903-
provide_fn(ompt_get_target_task_data);
905+
provide_fn(ompt_get_task_info_target);
904906
#undef provide_fn
905907

906908
#define ompt_interface_fn(fn, type, code) \

openmp/runtime/src/ompt-internal.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ typedef struct ompt_callbacks_active_s {
5757
(info->td_flags.merged_if0 ? ompt_task_mergeable : 0x0)
5858

5959
typedef struct {
60-
ompt_frame_t frame;
60+
// liboffload only uses task_data and target_data. They must be the first
61+
// elements!
6162
ompt_data_t task_data;
63+
ompt_data_t target_data;
64+
ompt_frame_t frame;
6265
struct kmp_taskdata *scheduling_parent;
6366
int thread_num;
6467
ompt_dispatch_chunk_t dispatch_chunk;

openmp/runtime/src/ompt-specific.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,30 @@ void __ompt_lw_taskteam_unlink(kmp_info_t *thr) {
346346
// task support
347347
//----------------------------------------------------------
348348

349-
ompt_data_t *__ompt_get_task_data() {
349+
ompt_data_t *__ompt_get_generating_task() {
350350
kmp_info_t *thr = ompt_get_thread();
351-
ompt_data_t *task_data = thr ? OMPT_CUR_TASK_DATA(thr) : NULL;
352-
return task_data;
351+
if (thr) {
352+
kmp_taskdata_t *taskdata = thr->th.th_current_task;
353+
if (taskdata == NULL)
354+
return NULL;
355+
if (taskdata->td_flags.target)
356+
return &(taskdata->td_parent->ompt_task_info.task_data);
357+
else
358+
return &(taskdata->ompt_task_info.task_data);
359+
}
360+
return NULL;
353361
}
354362

355-
ompt_data_t *__ompt_get_target_task_data() {
356-
return &__kmp_threads[__kmp_get_gtid()]->th.ompt_thread_info.target_task_data;
363+
ompt_task_info_t *__ompt_get_task_info_target() {
364+
kmp_info_t *thr = ompt_get_thread();
365+
if (thr) {
366+
kmp_taskdata_t *taskdata = thr->th.th_current_task;
367+
if (taskdata == NULL)
368+
return NULL;
369+
if (taskdata->td_flags.target)
370+
return &taskdata->ompt_task_info;
371+
}
372+
return NULL;
357373
}
358374

359375
int __ompt_get_task_info_internal(int ancestor_level, int *type,

openmp/runtime/src/ompt-specific.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ void __ompt_lw_taskteam_unlink(kmp_info_t *thr);
3737

3838
ompt_team_info_t *__ompt_get_teaminfo(int depth, int *size);
3939

40-
ompt_data_t *__ompt_get_task_data();
40+
ompt_data_t *__ompt_get_generating_task();
4141

42-
ompt_data_t *__ompt_get_target_task_data();
42+
ompt_task_info_t *__ompt_get_task_info_target();
4343

4444
ompt_task_info_t *__ompt_get_task_info_object(int depth);
4545

openmp/runtime/test/ompt/callback.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,8 @@ static void on_ompt_callback_error(ompt_severity_t severity,
10181018
codeptr_ra);
10191019
}
10201020

1021+
#ifndef SKIP_CALLBACK_REGISTRATION
1022+
10211023
int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num,
10221024
ompt_data_t *tool_data) {
10231025
ompt_set_callback = (ompt_set_callback_t)lookup("ompt_set_callback");
@@ -1094,6 +1096,7 @@ ompt_start_tool_result_t *ompt_start_tool(unsigned int omp_version,
10941096
#ifdef __cplusplus
10951097
}
10961098
#endif
1099+
#endif // ifndef SKIP_CALLBACK_REGISTRATION
10971100
#endif // ifndef USE_PRIVATE_TOOL
10981101
#ifdef _OMPT_TESTS
10991102
#undef _OMPT_TESTS

0 commit comments

Comments
 (0)