| 1 |
// clang-format off |
| 2 |
// RUN: %libomp-compile-and-run | FileCheck %s |
| 3 |
// REQUIRES: ompt |
| 4 |
// clang-format on |
| 5 |
|
| 6 |
#define USE_PRIVATE_TOOL 1 |
| 7 |
#include "callback.h" |
| 8 |
|
| 9 |
__attribute__((noinline)) int foo(int x) { |
| 10 |
#pragma omp parallel num_threads(2) |
| 11 |
{ |
| 12 |
#pragma omp atomic |
| 13 |
x++; |
| 14 |
} |
| 15 |
return x; |
| 16 |
} |
| 17 |
|
| 18 |
__attribute__((noinline)) int bar(int x) { |
| 19 |
#pragma omp parallel num_threads(2) |
| 20 |
{ |
| 21 |
#pragma omp critical |
| 22 |
x++; |
| 23 |
} |
| 24 |
return x; |
| 25 |
} |
| 26 |
|
| 27 |
int main() { |
| 28 |
int y; |
| 29 |
y = foo(y); |
| 30 |
y = bar(y); |
| 31 |
y = foo(y); |
| 32 |
return 0; |
| 33 |
|
| 34 |
// clang-format off |
| 35 |
// CHECK-NOT: {{^}}0: Could not register callback |
| 36 |
// CHECK: 0: NULL_POINTER=[[NULL:.*$]] |
| 37 |
|
| 38 |
// First call to foo |
| 39 |
// CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_parallel_begin |
| 40 |
// CHECK-SAME: {{.*}}codeptr_ra=[[RETURN_ADDRESS:(0x)?[0-f]+]] |
| 41 |
|
| 42 |
// Call to bar |
| 43 |
// CHECK: {{^}}[[MASTER_ID]]: ompt_event_parallel_begin |
| 44 |
|
| 45 |
// Second call to foo |
| 46 |
// CHECK: {{^}}[[MASTER_ID]]: ompt_event_parallel_begin |
| 47 |
// CHECK-SAME: {{.*}}codeptr_ra=[[RETURN_ADDRESS]] |
| 48 |
// clang-format on |
| 49 |
} |
| 50 |
|
| 51 |
static void on_ompt_callback_thread_begin(ompt_thread_t thread_type, |
| 52 |
ompt_data_t *thread_data) { |
| 53 |
if (thread_data->ptr) |
| 54 |
printf("%s\n", "0: thread_data initially not null"); |
| 55 |
thread_data->value = ompt_get_unique_id(); |
| 56 |
printf("%" PRIu64 ":" _TOOL_PREFIX |
| 57 |
" ompt_event_thread_begin: thread_type=%s=%d, thread_id=%" PRIu64 "\n", |
| 58 |
ompt_get_thread_data()->value, ompt_thread_t_values[thread_type], |
| 59 |
thread_type, thread_data->value); |
| 60 |
} |
| 61 |
|
| 62 |
static void on_ompt_callback_parallel_begin( |
| 63 |
ompt_data_t *encountering_task_data, |
| 64 |
const ompt_frame_t *encountering_task_frame, ompt_data_t *parallel_data, |
| 65 |
uint32_t requested_team_size, int flag, const void *codeptr_ra) { |
| 66 |
if (parallel_data->ptr) |
| 67 |
printf("0: parallel_data initially not null\n"); |
| 68 |
parallel_data->value = ompt_get_unique_id(); |
| 69 |
int invoker = flag & 0xF; |
| 70 |
const char *event = (flag & ompt_parallel_team) ? "parallel" : "teams"; |
| 71 |
const char *size = (flag & ompt_parallel_team) ? "team_size" : "num_teams"; |
| 72 |
printf("%" PRIu64 ":" _TOOL_PREFIX |
| 73 |
" ompt_event_%s_begin: parent_task_id=%" PRIu64 |
| 74 |
", parent_task_frame.exit=%p, parent_task_frame.reenter=%p, " |
| 75 |
"parallel_id=%" PRIu64 ", requested_%s=%" PRIu32 |
| 76 |
", codeptr_ra=%p, invoker=%d\n", |
| 77 |
ompt_get_thread_data()->value, event, encountering_task_data->value, |
| 78 |
encountering_task_frame->exit_frame.ptr, |
| 79 |
encountering_task_frame->enter_frame.ptr, parallel_data->value, size, |
| 80 |
requested_team_size, codeptr_ra, invoker); |
| 81 |
} |
| 82 |
|
| 83 |
int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num, |
| 84 |
ompt_data_t *tool_data) { |
| 85 |
ompt_set_callback = (ompt_set_callback_t)lookup("ompt_set_callback"); |
| 86 |
ompt_get_unique_id = (ompt_get_unique_id_t)lookup("ompt_get_unique_id"); |
| 87 |
ompt_get_thread_data = (ompt_get_thread_data_t)lookup("ompt_get_thread_data"); |
| 88 |
|
| 89 |
register_ompt_callback(ompt_callback_thread_begin); |
| 90 |
register_ompt_callback(ompt_callback_parallel_begin); |
| 91 |
printf("0: NULL_POINTER=%p\n", (void *)NULL); |
| 92 |
return 1; // success |
| 93 |
} |
| 94 |
|
| 95 |
void ompt_finalize(ompt_data_t *tool_data) {} |
| 96 |
|
| 97 |
ompt_start_tool_result_t *ompt_start_tool(unsigned int omp_version, |
| 98 |
const char *runtime_version) { |
| 99 |
static ompt_start_tool_result_t ompt_start_tool_result = {&ompt_initialize, |
| 100 |
&ompt_finalize, 0}; |
| 101 |
return &ompt_start_tool_result; |
| 102 |
} |