LLVM OpenMP* Runtime Library
ompt-specific.h
1 /*
2  * ompt-specific.h - header of OMPT internal functions implementation
3  */
4 
5 //===----------------------------------------------------------------------===//
6 //
7 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8 // See https://llvm.org/LICENSE.txt for license information.
9 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef OMPT_SPECIFIC_H
14 #define OMPT_SPECIFIC_H
15 
16 #include "kmp.h"
17 
18 /*****************************************************************************
19  * forward declarations
20  ****************************************************************************/
21 
22 void __ompt_team_assign_id(kmp_team_t *team, ompt_data_t ompt_pid);
23 void __ompt_thread_assign_wait_id(void *variable);
24 
25 void __ompt_lw_taskteam_init(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
26  int gtid, ompt_data_t *ompt_pid, void *codeptr);
27 
28 void __ompt_lw_taskteam_link(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
29  int on_heap);
30 
31 void __ompt_lw_taskteam_unlink(kmp_info_t *thr);
32 
33 ompt_team_info_t *__ompt_get_teaminfo(int depth, int *size);
34 
35 ompt_task_info_t *__ompt_get_task_info_object(int depth);
36 
37 int __ompt_get_parallel_info_internal(int ancestor_level,
38  ompt_data_t **parallel_data,
39  int *team_size);
40 
41 int __ompt_get_task_info_internal(int ancestor_level, int *type,
42  ompt_data_t **task_data,
43  ompt_frame_t **task_frame,
44  ompt_data_t **parallel_data, int *thread_num);
45 
46 ompt_data_t *__ompt_get_thread_data_internal();
47 
48 /*
49  * Unused currently
50 static uint64_t __ompt_get_get_unique_id_internal();
51 */
52 
53 ompt_sync_region_t __ompt_get_barrier_kind(enum barrier_type, kmp_info_t *);
54 
55 /*****************************************************************************
56  * macros
57  ****************************************************************************/
58 
59 #define OMPT_CUR_TASK_INFO(thr) (&(thr->th.th_current_task->ompt_task_info))
60 #define OMPT_CUR_TASK_DATA(thr) \
61  (&(thr->th.th_current_task->ompt_task_info.task_data))
62 #define OMPT_CUR_TEAM_INFO(thr) (&(thr->th.th_team->t.ompt_team_info))
63 #define OMPT_CUR_TEAM_DATA(thr) \
64  (&(thr->th.th_team->t.ompt_team_info.parallel_data))
65 
66 #define OMPT_HAVE_WEAK_ATTRIBUTE KMP_HAVE_WEAK_ATTRIBUTE
67 #define OMPT_HAVE_PSAPI KMP_HAVE_PSAPI
68 #define OMPT_STR_MATCH(haystack, needle) __kmp_str_match(haystack, 0, needle)
69 
70 inline void *__ompt_load_return_address(int gtid) {
71  kmp_info_t *thr = __kmp_threads[gtid];
72  void *return_address = thr->th.ompt_thread_info.return_address;
73  thr->th.ompt_thread_info.return_address = NULL;
74  return return_address;
75 }
76 
77 #define OMPT_STORE_RETURN_ADDRESS(gtid) \
78  if (ompt_enabled.enabled && gtid >= 0 && __kmp_threads[gtid] && \
79  !__kmp_threads[gtid]->th.ompt_thread_info.return_address) \
80  __kmp_threads[gtid]->th.ompt_thread_info.return_address = \
81  __builtin_return_address(0)
82 #define OMPT_LOAD_RETURN_ADDRESS(gtid) __ompt_load_return_address(gtid)
83 
84 //******************************************************************************
85 // inline functions
86 //******************************************************************************
87 
88 inline kmp_info_t *ompt_get_thread_gtid(int gtid) {
89  return (gtid >= 0) ? __kmp_thread_from_gtid(gtid) : NULL;
90 }
91 
92 inline kmp_info_t *ompt_get_thread() {
93  int gtid = __kmp_get_gtid();
94  return ompt_get_thread_gtid(gtid);
95 }
96 
97 inline void ompt_set_thread_state(kmp_info_t *thread, ompt_state_t state) {
98  thread->th.ompt_thread_info.state = state;
99 }
100 
101 inline const char *ompt_get_runtime_version() {
102  return &__kmp_version_lib_ver[KMP_VERSION_MAGIC_LEN];
103 }
104 
105 #endif