18 #include "ompt-specific.h"
25 #define THREAD_LOCAL __declspec(thread)
27 #define THREAD_LOCAL __thread
30 #define OMPT_WEAK_ATTRIBUTE KMP_WEAK_ATTRIBUTE_INTERNAL
36 #define LWT_FROM_TEAM(team) (team)->t.ompt_serialized_team_info
38 #define OMPT_THREAD_ID_BITS 16
51 ompt_team_info_t *__ompt_get_teaminfo(
int depth,
int *size) {
52 kmp_info_t *thr = ompt_get_thread();
55 kmp_team *team = thr->th.th_team;
59 ompt_lw_taskteam_t *next_lwt = LWT_FROM_TEAM(team), *lwt = NULL;
73 team = team->t.t_parent;
75 next_lwt = LWT_FROM_TEAM(team);
89 return &lwt->ompt_team_info;
93 *size = team->t.t_nproc;
96 return &team->t.ompt_team_info;
103 ompt_task_info_t *__ompt_get_task_info_object(
int depth) {
104 ompt_task_info_t *info = NULL;
105 kmp_info_t *thr = ompt_get_thread();
108 kmp_taskdata_t *taskdata = thr->th.th_current_task;
109 ompt_lw_taskteam_t *lwt = NULL,
110 *next_lwt = LWT_FROM_TEAM(taskdata->td_team);
119 if (!lwt && taskdata) {
124 taskdata = taskdata->td_parent;
126 next_lwt = LWT_FROM_TEAM(taskdata->td_team);
134 info = &lwt->ompt_task_info;
135 }
else if (taskdata) {
136 info = &taskdata->ompt_task_info;
143 ompt_task_info_t *__ompt_get_scheduling_taskinfo(
int depth) {
144 ompt_task_info_t *info = NULL;
145 kmp_info_t *thr = ompt_get_thread();
148 kmp_taskdata_t *taskdata = thr->th.th_current_task;
150 ompt_lw_taskteam_t *lwt = NULL,
151 *next_lwt = LWT_FROM_TEAM(taskdata->td_team);
160 if (!lwt && taskdata) {
162 if (taskdata->ompt_task_info.scheduling_parent) {
163 taskdata = taskdata->ompt_task_info.scheduling_parent;
164 }
else if (next_lwt) {
169 taskdata = taskdata->td_parent;
171 next_lwt = LWT_FROM_TEAM(taskdata->td_team);
179 info = &lwt->ompt_task_info;
180 }
else if (taskdata) {
181 info = &taskdata->ompt_task_info;
196 ompt_data_t *__ompt_get_thread_data_internal() {
197 if (__kmp_get_gtid() >= 0) {
198 kmp_info_t *thread = ompt_get_thread();
201 return &(thread->th.ompt_thread_info.thread_data);
210 void __ompt_thread_assign_wait_id(
void *variable) {
211 kmp_info_t *ti = ompt_get_thread();
214 ti->th.ompt_thread_info.wait_id = (ompt_wait_id_t)(uintptr_t)variable;
217 int __ompt_get_state_internal(ompt_wait_id_t *omp_wait_id) {
218 kmp_info_t *ti = ompt_get_thread();
222 *omp_wait_id = ti->th.ompt_thread_info.wait_id;
223 return ti->th.ompt_thread_info.state;
225 return ompt_state_undefined;
232 int __ompt_get_parallel_info_internal(
int ancestor_level,
233 ompt_data_t **parallel_data,
235 if (__kmp_get_gtid() >= 0) {
236 ompt_team_info_t *info;
238 info = __ompt_get_teaminfo(ancestor_level, team_size);
240 info = __ompt_get_teaminfo(ancestor_level, NULL);
243 *parallel_data = info ? &(info->parallel_data) : NULL;
255 void __ompt_lw_taskteam_init(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
int gtid,
256 ompt_data_t *ompt_pid,
void *codeptr) {
259 lwt->ompt_team_info.parallel_data = *ompt_pid;
260 lwt->ompt_team_info.master_return_address = codeptr;
261 lwt->ompt_task_info.task_data.value = 0;
262 lwt->ompt_task_info.frame.enter_frame = ompt_data_none;
263 lwt->ompt_task_info.frame.exit_frame = ompt_data_none;
264 lwt->ompt_task_info.scheduling_parent = NULL;
269 void __ompt_lw_taskteam_link(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
270 int on_heap,
bool always) {
271 ompt_lw_taskteam_t *link_lwt = lwt;
273 thr->th.th_team->t.t_serialized >
277 (ompt_lw_taskteam_t *)__kmp_allocate(
sizeof(ompt_lw_taskteam_t));
279 link_lwt->heap = on_heap;
282 ompt_team_info_t tmp_team = lwt->ompt_team_info;
283 link_lwt->ompt_team_info = *OMPT_CUR_TEAM_INFO(thr);
284 *OMPT_CUR_TEAM_INFO(thr) = tmp_team;
286 ompt_task_info_t tmp_task = lwt->ompt_task_info;
287 link_lwt->ompt_task_info = *OMPT_CUR_TASK_INFO(thr);
288 *OMPT_CUR_TASK_INFO(thr) = tmp_task;
291 ompt_lw_taskteam_t *my_parent =
292 thr->th.th_team->t.ompt_serialized_team_info;
293 link_lwt->parent = my_parent;
294 thr->th.th_team->t.ompt_serialized_team_info = link_lwt;
296 if (ompd_state & OMPD_ENABLE_BP) {
297 ompd_bp_parallel_begin();
303 *OMPT_CUR_TEAM_INFO(thr) = lwt->ompt_team_info;
305 if (ompd_state & OMPD_ENABLE_BP) {
306 ompd_bp_parallel_begin();
309 *OMPT_CUR_TASK_INFO(thr) = lwt->ompt_task_info;
313 void __ompt_lw_taskteam_unlink(kmp_info_t *thr) {
314 ompt_lw_taskteam_t *lwtask = thr->th.th_team->t.ompt_serialized_team_info;
317 if (ompd_state & OMPD_ENABLE_BP) {
318 ompd_bp_parallel_end();
321 thr->th.th_team->t.ompt_serialized_team_info = lwtask->parent;
323 ompt_team_info_t tmp_team = lwtask->ompt_team_info;
324 lwtask->ompt_team_info = *OMPT_CUR_TEAM_INFO(thr);
325 *OMPT_CUR_TEAM_INFO(thr) = tmp_team;
327 ompt_task_info_t tmp_task = lwtask->ompt_task_info;
328 lwtask->ompt_task_info = *OMPT_CUR_TASK_INFO(thr);
329 *OMPT_CUR_TASK_INFO(thr) = tmp_task;
343 int __ompt_get_task_info_internal(
int ancestor_level,
int *type,
344 ompt_data_t **task_data,
345 ompt_frame_t **task_frame,
346 ompt_data_t **parallel_data,
348 if (__kmp_get_gtid() < 0)
351 if (ancestor_level < 0)
355 ompt_task_info_t *info = NULL;
356 ompt_team_info_t *team_info = NULL;
357 kmp_info_t *thr = ompt_get_thread();
358 int level = ancestor_level;
361 kmp_taskdata_t *taskdata = thr->th.th_current_task;
362 if (taskdata == NULL)
364 kmp_team *team = thr->th.th_team, *prev_team = NULL;
367 ompt_lw_taskteam_t *lwt = NULL,
368 *next_lwt = LWT_FROM_TEAM(taskdata->td_team),
371 while (ancestor_level > 0) {
381 if (!lwt && taskdata) {
383 if (taskdata->ompt_task_info.scheduling_parent) {
384 taskdata = taskdata->ompt_task_info.scheduling_parent;
385 }
else if (next_lwt) {
390 taskdata = taskdata->td_parent;
393 team = team->t.t_parent;
395 next_lwt = LWT_FROM_TEAM(taskdata->td_team);
403 info = &lwt->ompt_task_info;
404 team_info = &lwt->ompt_team_info;
406 *type = ompt_task_implicit;
408 }
else if (taskdata) {
409 info = &taskdata->ompt_task_info;
410 team_info = &team->t.ompt_team_info;
412 if (taskdata->td_parent) {
413 *type = (taskdata->td_flags.tasktype ? ompt_task_explicit
414 : ompt_task_implicit) |
415 TASK_TYPE_DETAILS_FORMAT(taskdata);
417 *type = ompt_task_initial;
422 *task_data = info ? &info->task_data : NULL;
426 *task_frame = info ? &info->frame : NULL;
429 *parallel_data = team_info ? &(team_info->parallel_data) : NULL;
433 *thread_num = __kmp_get_tid();
437 *thread_num = prev_team->t.t_master_tid;
445 int __ompt_get_task_memory_internal(
void **addr,
size_t *size,
int blocknum) {
449 kmp_info_t *thr = ompt_get_thread();
453 kmp_taskdata_t *taskdata = thr->th.th_current_task;
454 kmp_task_t *task = KMP_TASKDATA_TO_TASK(taskdata);
456 if (taskdata->td_flags.tasktype != TASK_EXPLICIT)
460 int64_t ret_size = taskdata->td_size_alloc -
sizeof(kmp_taskdata_t);
463 if (taskdata->td_flags.destructors_thunk)
464 ret_addr = &task->data1 + 1;
466 ret_addr = &task->part_id + 1;
468 ret_size -= (
char *)(ret_addr) - (
char *)(task);
473 *size = (size_t)ret_size;
481 void __ompt_team_assign_id(kmp_team_t *team, ompt_data_t ompt_pid) {
482 team->t.ompt_team_info.parallel_data = ompt_pid;
489 static uint64_t __ompt_get_unique_id_internal() {
490 static uint64_t thread = 1;
491 static THREAD_LOCAL uint64_t ID = 0;
493 uint64_t new_thread = KMP_TEST_THEN_INC64((kmp_int64 *)&thread);
494 ID = new_thread << (
sizeof(uint64_t) * 8 - OMPT_THREAD_ID_BITS);
499 ompt_sync_region_t __ompt_get_barrier_kind(
enum barrier_type bt,
501 if (bt == bs_forkjoin_barrier)
502 return ompt_sync_region_barrier_implicit;
504 if (bt != bs_plain_barrier)
505 return ompt_sync_region_barrier_implementation;
507 if (!thr->th.th_ident)
508 return ompt_sync_region_barrier;
510 kmp_int32 flags = thr->th.th_ident->flags;
513 return ompt_sync_region_barrier_explicit;
516 return ompt_sync_region_barrier_implicit;
518 return ompt_sync_region_barrier_implementation;