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