LLVM OpenMP 22.0.0git
ompt-specific.h
Go to the documentation of this file.
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#if OMPT_SUPPORT
19/*****************************************************************************
20 * forward declarations
21 ****************************************************************************/
22
23/// Entrypoint used by libomptarget to register callbacks in libomp, if not
24/// done already
26
27void __ompt_team_assign_id(kmp_team_t *team, ompt_data_t ompt_pid);
28void __ompt_thread_assign_wait_id(void *variable);
29
31 ompt_data_t *ompt_pid, void *codeptr);
32
34 int on_heap, bool always = false);
35
37
39
40ompt_data_t *__ompt_get_task_data();
41
42ompt_data_t *__ompt_get_target_task_data();
43
45
46int __ompt_get_parallel_info_internal(int ancestor_level,
47 ompt_data_t **parallel_data,
48 int *team_size);
49
50int __ompt_get_task_info_internal(int ancestor_level, int *type,
51 ompt_data_t **task_data,
52 ompt_frame_t **task_frame,
53 ompt_data_t **parallel_data, int *thread_num);
54
56
57// __ompt_task_init:
58// Initialize OMPT fields maintained by a task. This will only be called after
59// ompt_start_tool, so we already know whether ompt is enabled or not.
60
61static inline void __ompt_task_init(kmp_taskdata_t *task, int tid) {
62 // The calls to __ompt_task_init already have the ompt_enabled condition.
63 task->ompt_task_info.task_data.value = 0;
64 task->ompt_task_info.frame.exit_frame = ompt_data_none;
65 task->ompt_task_info.frame.enter_frame = ompt_data_none;
66 task->ompt_task_info.frame.exit_frame_flags =
67 task->ompt_task_info.frame.enter_frame_flags = OMPT_FRAME_FLAGS_RUNTIME;
68 task->ompt_task_info.dispatch_chunk.start = 0;
69 task->ompt_task_info.dispatch_chunk.iterations = 0;
70}
71
72/*
73 * Unused currently
74static uint64_t __ompt_get_get_unique_id_internal();
75*/
76
77ompt_sync_region_t __ompt_get_barrier_kind(enum barrier_type, kmp_info_t *);
78
79/*****************************************************************************
80 * macros
81 ****************************************************************************/
82
83#define OMPT_CUR_TASK_INFO(thr) (&((thr)->th.th_current_task->ompt_task_info))
84#define OMPT_CUR_TASK_DATA(thr) \
85 (&((thr)->th.th_current_task->ompt_task_info.task_data))
86#define OMPT_CUR_TEAM_INFO(thr) (&((thr)->th.th_team->t.ompt_team_info))
87#define OMPT_CUR_TEAM_DATA(thr) \
88 (&((thr)->th.th_team->t.ompt_team_info.parallel_data))
89
90#define OMPT_HAVE_WEAK_ATTRIBUTE KMP_HAVE_WEAK_ATTRIBUTE
91#define OMPT_HAVE_PSAPI KMP_HAVE_PSAPI
92#define OMPT_STR_MATCH(haystack, needle) __kmp_str_match(haystack, 0, needle)
93
94inline void *__ompt_load_return_address(int gtid) {
95 kmp_info_t *thr = __kmp_threads[gtid];
96 void *return_address = thr->th.ompt_thread_info.return_address;
97 thr->th.ompt_thread_info.return_address = NULL;
98 return return_address;
99}
100
101/*#define OMPT_STORE_RETURN_ADDRESS(gtid) \
102 if (ompt_enabled.enabled && gtid >= 0 && __kmp_threads[gtid] && \
103 !__kmp_threads[gtid]->th.ompt_thread_info.return_address) \
104 __kmp_threads[gtid]->th.ompt_thread_info.return_address = \
105 __builtin_extract_return_addr(__builtin_return_address(0))*/
106#define OMPT_STORE_RETURN_ADDRESS(gtid) \
107 OmptReturnAddressGuard ReturnAddressGuard{ \
108 gtid, __builtin_extract_return_addr(__builtin_return_address(0))};
109#define OMPT_LOAD_RETURN_ADDRESS(gtid) __ompt_load_return_address(gtid)
110#define OMPT_LOAD_OR_GET_RETURN_ADDRESS(gtid) \
111 ((ompt_enabled.enabled && gtid >= 0 && __kmp_threads[gtid] && \
112 __kmp_threads[gtid]->th.ompt_thread_info.return_address) \
113 ? __ompt_load_return_address(gtid) \
114 : __builtin_extract_return_addr(__builtin_return_address(0)))
115
116#define OMPT_GET_DISPATCH_CHUNK(chunk, lb, ub, incr) \
117 do { \
118 if (incr > 0) { \
119 chunk.start = static_cast<uint64_t>(lb); \
120 chunk.iterations = static_cast<uint64_t>(((ub) - (lb)) / (incr) + 1); \
121 } else { \
122 chunk.start = static_cast<uint64_t>(ub); \
123 chunk.iterations = static_cast<uint64_t>(((lb) - (ub)) / -(incr) + 1); \
124 } \
125 } while (0)
126
127//******************************************************************************
128// inline functions
129//******************************************************************************
130
131inline kmp_info_t *ompt_get_thread_gtid(int gtid) {
132 return (gtid >= 0) ? __kmp_thread_from_gtid(gtid) : NULL;
133}
134
135inline kmp_info_t *ompt_get_thread() {
136 int gtid = __kmp_get_gtid();
137 return ompt_get_thread_gtid(gtid);
138}
139
140inline void ompt_set_thread_state(kmp_info_t *thread, ompt_state_t state) {
141 if (thread)
142 thread->th.ompt_thread_info.state = state;
143}
144
145inline const char *ompt_get_runtime_version() {
147}
148
149inline ompt_work_t ompt_get_work_schedule(enum sched_type schedule) {
150 switch (SCHEDULE_WITHOUT_MODIFIERS(schedule)) {
154 return ompt_work_loop_static;
157 return ompt_work_loop_dynamic;
162 return ompt_work_loop_guided;
163 default:
164 return ompt_work_loop_other;
165 }
166}
167
168class OmptReturnAddressGuard {
169private:
170 bool SetAddress{false};
171 int Gtid;
172
173public:
174 OmptReturnAddressGuard(int Gtid, void *ReturnAddress) : Gtid(Gtid) {
175 if (ompt_enabled.enabled && Gtid >= 0 && __kmp_threads[Gtid] &&
176 !__kmp_threads[Gtid]->th.ompt_thread_info.return_address) {
177 SetAddress = true;
178 __kmp_threads[Gtid]->th.ompt_thread_info.return_address = ReturnAddress;
179 }
180 }
181 ~OmptReturnAddressGuard() {
182 if (SetAddress)
183 __kmp_threads[Gtid]->th.ompt_thread_info.return_address = NULL;
184 }
185};
186
187#endif // OMPT_SUPPORT
188
189// macros providing the OMPT callbacks for reduction clause
190#if OMPT_SUPPORT && OMPT_OPTIONAL
191#define OMPT_REDUCTION_DECL(this_thr, gtid) \
192 ompt_data_t *my_task_data = OMPT_CUR_TASK_DATA(this_thr); \
193 ompt_data_t *my_parallel_data = OMPT_CUR_TEAM_DATA(this_thr); \
194 void *return_address = OMPT_LOAD_RETURN_ADDRESS(gtid);
195#define OMPT_REDUCTION_BEGIN \
196 if (ompt_enabled.enabled && ompt_enabled.ompt_callback_reduction) { \
197 ompt_callbacks.ompt_callback(ompt_callback_reduction)( \
198 ompt_sync_region_reduction, ompt_scope_begin, my_parallel_data, \
199 my_task_data, return_address); \
200 }
201#define OMPT_REDUCTION_END \
202 if (ompt_enabled.enabled && ompt_enabled.ompt_callback_reduction) { \
203 ompt_callbacks.ompt_callback(ompt_callback_reduction)( \
204 ompt_sync_region_reduction, ompt_scope_end, my_parallel_data, \
205 my_task_data, return_address); \
206 }
207#else // OMPT_SUPPORT && OMPT_OPTIONAL
208#define OMPT_REDUCTION_DECL(this_thr, gtid)
209#define OMPT_REDUCTION_BEGIN
210#define OMPT_REDUCTION_END
211#endif // ! OMPT_SUPPORT && OMPT_OPTIONAL
212
213#endif
sched_type
Describes the loop schedule to be used for a parallel for loop.
Definition: kmp.h:350
@ kmp_sch_guided_simd
guided with chunk adjustment
Definition: kmp.h:371
@ kmp_sch_guided_chunked
guided unspecialized
Definition: kmp.h:355
@ kmp_sch_dynamic_chunked
Definition: kmp.h:354
@ kmp_sch_guided_analytical_chunked
Definition: kmp.h:365
@ kmp_sch_static_balanced
Definition: kmp.h:362
@ kmp_sch_static_greedy
Definition: kmp.h:361
@ kmp_sch_static_chunked
Definition: kmp.h:352
@ kmp_sch_guided_iterative_chunked
Definition: kmp.h:364
@ kmp_sch_static_steal
Definition: kmp.h:367
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t size
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type
kmp_info_t ** __kmp_threads
Definition: kmp_global.cpp:447
#define SCHEDULE_WITHOUT_MODIFIERS(s)
Definition: kmp.h:443
barrier_type
Definition: kmp.h:2161
#define __kmp_get_gtid()
Definition: kmp.h:3600
static kmp_info_t * __kmp_thread_from_gtid(int gtid)
Definition: kmp.h:3634
union KMP_ALIGN_CACHE kmp_info kmp_info_t
char const __kmp_version_lib_ver[]
#define KMP_VERSION_MAGIC_LEN
Definition: kmp_version.h:32
ompt_callbacks_active_t ompt_enabled
#define OMPT_FRAME_FLAGS_RUNTIME
void __ompt_thread_assign_wait_id(void *variable)
ompt_team_info_t * __ompt_get_teaminfo(int depth, int *size)
void __ompt_lw_taskteam_init(ompt_lw_taskteam_t *lwt, kmp_info_t *thr, int gtid, ompt_data_t *ompt_pid, void *codeptr)
ompt_data_t * __ompt_get_target_task_data()
int __ompt_get_task_info_internal(int ancestor_level, int *type, ompt_data_t **task_data, ompt_frame_t **task_frame, ompt_data_t **parallel_data, int *thread_num)
ompt_data_t * __ompt_get_task_data()
void __ompt_lw_taskteam_link(ompt_lw_taskteam_t *lwt, kmp_info_t *thr, int on_heap, bool always)
ompt_task_info_t * __ompt_get_task_info_object(int depth)
void __ompt_team_assign_id(kmp_team_t *team, ompt_data_t ompt_pid)
void __ompt_force_initialization()
void __ompt_lw_taskteam_unlink(kmp_info_t *thr)
ompt_sync_region_t __ompt_get_barrier_kind(enum barrier_type bt, kmp_info_t *thr)
ompt_data_t * __ompt_get_thread_data_internal()
int __ompt_get_parallel_info_internal(int ancestor_level, ompt_data_t **parallel_data, int *team_size)
Definition: kmp.h:3233