LLVM OpenMP* Runtime Library
ompt-internal.h
1 /*
2  * ompt-internal.h - header of OMPT internal data structures
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_INTERNAL_H__
14 #define __OMPT_INTERNAL_H__
15 
16 #include "ompt-event-specific.h"
17 #include "omp-tools.h"
18 
19 #define OMPT_VERSION 1
20 
21 #define _OMP_EXTERN extern "C"
22 
23 #define OMPT_INVOKER(x) \
24  ((x == fork_context_gnu) ? ompt_parallel_invoker_program \
25  : ompt_parallel_invoker_runtime)
26 
27 #define ompt_callback(e) e##_callback
28 
29 #define ompt_emi_callback(e) e##_emi_callback
30 
31 #define ompt_emi_callback_type(e) e##_emi_t
32 
33 #define ompt_emi_wrapper(e) e##_emi_wrapper
34 
35 #define ompt_emi_event(e) e##_emi
36 
37 /* Struct to collect host callback pointers */
38 typedef struct ompt_callbacks_internal_s {
39 #define ompt_event_macro(event, callback, eventid) \
40  callback ompt_callback(event);
41 
42  FOREACH_OMPT_HOST_EVENT(ompt_event_macro)
43 
44 #undef ompt_event_macro
45 } ompt_callbacks_internal_t;
46 
47 /* Struct to collect target callback pointers */
48 typedef struct ompt_target_callbacks_internal_s {
49 #define ompt_event_macro(event, callback, eventid) \
50  callback ompt_callback(event);
51 
52  FOREACH_OMPT_51_TARGET_EVENT(ompt_event_macro)
53 
54 #undef ompt_event_macro
55 } ompt_target_callbacks_internal_t;
56 
57 /* Struct to collect noemi callback pointers */
58 typedef struct ompt_callbacks_internal_noemi_s {
59 #define ompt_event_macro(event, callback, eventid) \
60  callback ompt_callback(event);
61 
62  FOREACH_OMPT_NOEMI_EVENT(ompt_event_macro)
63 
64 #undef ompt_event_macro
65 } ompt_callbacks_internal_noemi_t;
66 
67 /* Bitmap to mark OpenMP 5.1 host events as registered*/
68 typedef struct ompt_callbacks_active_s {
69  unsigned int enabled : 1;
70 #define ompt_event_macro(event, callback, eventid) unsigned int event : 1;
71 
72  FOREACH_OMPT_HOST_EVENT(ompt_event_macro)
73 
74 #undef ompt_event_macro
75 } ompt_callbacks_active_t;
76 
77 /* Bitmap to mark OpenMP 5.1 target events as registered*/
78 typedef struct ompt_target_callbacks_active_s {
79  unsigned int enabled : 1;
80 #define ompt_event_macro(event, callback, eventid) unsigned int event : 1;
81 
82  FOREACH_OMPT_51_TARGET_EVENT(ompt_event_macro)
83 
84 #undef ompt_event_macro
85 } ompt_target_callbacks_active_t;
86 
87 #define TASK_TYPE_DETAILS_FORMAT(info) \
88  ((info->td_flags.task_serial || info->td_flags.tasking_ser) \
89  ? ompt_task_undeferred \
90  : 0x0) | \
91  ((!(info->td_flags.tiedness)) ? ompt_task_untied : 0x0) | \
92  (info->td_flags.final ? ompt_task_final : 0x0) | \
93  (info->td_flags.merged_if0 ? ompt_task_mergeable : 0x0)
94 
95 typedef struct {
96  ompt_frame_t frame;
97  ompt_data_t task_data;
98  struct kmp_taskdata *scheduling_parent;
99  int thread_num;
100 } ompt_task_info_t;
101 
102 typedef struct {
103  ompt_data_t parallel_data;
104  void *master_return_address;
105 } ompt_team_info_t;
106 
107 typedef struct ompt_lw_taskteam_s {
108  ompt_team_info_t ompt_team_info;
109  ompt_task_info_t ompt_task_info;
110  int heap;
111  struct ompt_lw_taskteam_s *parent;
112 } ompt_lw_taskteam_t;
113 
114 typedef struct {
115  ompt_data_t thread_data;
116  ompt_data_t task_data; /* stored here from implicit barrier-begin until
117  implicit-task-end */
118  void *return_address; /* stored here on entry of runtime */
119  ompt_state_t state;
120  ompt_wait_id_t wait_id;
121  int ompt_task_yielded;
122  int parallel_flags; // information for the last parallel region invoked
123  void *idle_frame;
124 } ompt_thread_info_t;
125 
126 extern ompt_callbacks_internal_t ompt_callbacks;
127 extern ompt_target_callbacks_internal_t ompt_target_callbacks;
128 extern ompt_callbacks_internal_noemi_t ompt_callbacks_noemi;
129 
130 #if OMPT_SUPPORT && OMPT_OPTIONAL
131 #if USE_FAST_MEMORY
132 #define KMP_OMPT_DEPS_ALLOC __kmp_fast_allocate
133 #define KMP_OMPT_DEPS_FREE __kmp_fast_free
134 #else
135 #define KMP_OMPT_DEPS_ALLOC __kmp_thread_malloc
136 #define KMP_OMPT_DEPS_FREE __kmp_thread_free
137 #endif
138 #endif /* OMPT_SUPPORT && OMPT_OPTIONAL */
139 
140 #ifdef __cplusplus
141 extern "C" {
142 #endif
143 
144 void ompt_pre_init(void);
145 void ompt_post_init(void);
146 void ompt_fini(void);
147 
148 #define OMPT_GET_RETURN_ADDRESS(level) __builtin_return_address(level)
149 #define OMPT_GET_FRAME_ADDRESS(level) __builtin_frame_address(level)
150 
151 int __kmp_control_tool(uint64_t command, uint64_t modifier, void *arg);
152 
153 extern ompt_callbacks_active_t ompt_enabled;
154 extern ompt_target_callbacks_active_t ompt_target_enabled;
155 
156 #if KMP_OS_WINDOWS
157 #define UNLIKELY(x) (x)
158 #define OMPT_NOINLINE __declspec(noinline)
159 #else
160 #define UNLIKELY(x) __builtin_expect(!!(x), 0)
161 #define OMPT_NOINLINE __attribute__((noinline))
162 #endif
163 
164 #ifdef __cplusplus
165 }
166 #endif
167 
168 #endif