Skip to content

Commit ba02586

Browse files
vladaindjicjpeyton52
authored andcommitted
[OpenMP][OMPT][GOMP] task frame support in KMP_API_NAME_GOMP_PARALLEL_SECTIONS
KMP_API_NAME_GOMP_PARALLEL_SECTIONS function was missing the task frame support. This patch introduced a fix responsible to set properly the exit_frame of the innermost implicit task that corresponds to the parallel section construct, as well as the enter_frame of the task that encloses the mentioned implicit task. This patch also introduced a simple test case sections_serialized.c that contains serialized parallel section construct and validates whether the mentioned task frames are set correctly. Differential Revision: https://reviews.llvm.org/D112205
1 parent 6fe949c commit ba02586

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

openmp/runtime/src/kmp_gsupport.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,13 @@ void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_SECTIONS)(void (*task)(void *),
15221522
KA_TRACE(20, ("GOMP_parallel_sections: T#%d\n", gtid));
15231523

15241524
#if OMPT_SUPPORT
1525+
ompt_frame_t *task_frame;
1526+
kmp_info_t *thr;
1527+
if (ompt_enabled.enabled) {
1528+
thr = __kmp_threads[gtid];
1529+
task_frame = &(thr->th.th_current_task->ompt_task_info.frame);
1530+
task_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1531+
}
15251532
OMPT_STORE_RETURN_ADDRESS(gtid);
15261533
#endif
15271534

@@ -1537,9 +1544,31 @@ void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_SECTIONS)(void (*task)(void *),
15371544

15381545
KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
15391546
}
1547+
1548+
#if OMPT_SUPPORT
1549+
ompt_frame_t *child_frame;
1550+
if (ompt_enabled.enabled) {
1551+
child_frame = &(thr->th.th_current_task->ompt_task_info.frame);
1552+
child_frame->exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1553+
}
1554+
#endif
1555+
15401556
task(data);
1557+
1558+
#if OMPT_SUPPORT
1559+
if (ompt_enabled.enabled) {
1560+
child_frame->exit_frame = ompt_data_none;
1561+
}
1562+
#endif
1563+
15411564
KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)();
15421565
KA_TRACE(20, ("GOMP_parallel_sections exit: T#%d\n", gtid));
1566+
1567+
#if OMPT_SUPPORT
1568+
if (ompt_enabled.enabled) {
1569+
task_frame->enter_frame = ompt_data_none;
1570+
}
1571+
#endif
15431572
}
15441573

15451574
#define PARALLEL_LOOP(func, schedule, ompt_pre, ompt_post) \
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: %libomp-compile-and-run | %sort-threads | FileCheck %s
2+
// REQUIRES: ompt
3+
4+
#include "callback.h"
5+
#include <omp.h>
6+
7+
int main()
8+
{
9+
#pragma omp parallel sections num_threads(1)
10+
{
11+
#pragma omp section
12+
{
13+
// implicit task info
14+
print_ids(0);
15+
// initial task info
16+
print_ids(1);
17+
}
18+
}
19+
20+
// Check if libomp supports the callbacks for this test.
21+
// CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_create'
22+
// CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_implicit_task'
23+
24+
25+
// CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]]
26+
// CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_initial_task_begin: parallel_id=[[INITIAL_PARALLEL_ID:[0-9]+]], task_id=[[INITIAL_TASK_ID:[0-9]+]], actual_parallelism=1, index=1, flags=1
27+
28+
// region 0
29+
// CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_parallel_begin
30+
// CHECK-SAME: parent_task_frame.exit=[[NULL]], parent_task_frame.reenter=[[INITIAL_TASK_FRAME_ENTER:0x[0-f]+]],
31+
// CHECK-SAME: parallel_id=[[PARALLEL_ID:[0-9]+]]
32+
33+
// CHECK: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_begin: parallel_id=[[PARALLEL_ID]], task_id=[[TASK_ID:[0-9]+]]
34+
35+
// information about implicit task (exit frame should be set, while enter should be NULL)
36+
// CHECK: {{^}}[[MASTER_ID]]: task level 0: parallel_id=[[PARALLEL_ID]], task_id=[[TASK_ID]]
37+
// CHECK-SAME: exit_frame={{0x[0-f]+}}
38+
// CHECK-SAME: reenter_frame=[[NULL]]
39+
// CHECK-SAME: task_type=ompt_task_implicit
40+
41+
// information about initial task (exit frame should be NULL, while enter frame shoule be set)
42+
// CHECK: {{^}}[[MASTER_ID]]: task level 1: parallel_id=[[INITIAL_PARALLEL_ID]], task_id=[[INITIAL_TASK_ID]]
43+
// CHECK-SAME: exit_frame=[[NULL]]
44+
// CHECK-SAME: reenter_frame=[[INITIAL_TASK_FRAME_ENTER]]
45+
// CHECK-SAME: task_type=ompt_task_initial
46+
47+
return 0;
48+
}

0 commit comments

Comments
 (0)