1 #include "kmp_config.h"
2
3 #if USE_ITT_BUILD
4 /*
5 * kmp_itt.cpp -- ITT Notify interface.
6 */
7
8 //===----------------------------------------------------------------------===//
9 //
10 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
11 // See https://llvm.org/LICENSE.txt for license information.
12 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
13 //
14 //===----------------------------------------------------------------------===//
15
main(int argc,char * argv[])16 #include "kmp_itt.h"
17
18 #if KMP_DEBUG
19 #include "kmp_itt.inl"
20 #endif
21
22 #if USE_ITT_NOTIFY
23
24 #include "ittnotify_config.h"
25 __itt_global __kmp_ittapi_clean_global;
26 extern __itt_global __kmp_itt__ittapi_global;
27 kmp_int32 __kmp_barrier_domain_count;
28 kmp_int32 __kmp_region_domain_count;
29 __itt_domain *__kmp_itt_barrier_domains[KMP_MAX_FRAME_DOMAINS];
30 __itt_domain *__kmp_itt_region_domains[KMP_MAX_FRAME_DOMAINS];
31 __itt_domain *__kmp_itt_imbalance_domains[KMP_MAX_FRAME_DOMAINS];
32 kmp_int32 __kmp_itt_region_team_size[KMP_MAX_FRAME_DOMAINS];
33 __itt_domain *metadata_domain = NULL;
34 __itt_string_handle *string_handle_imbl = NULL;
35 __itt_string_handle *string_handle_loop = NULL;
36 __itt_string_handle *string_handle_sngl = NULL;
37
38 #include "kmp_i18n.h"
39 #include "kmp_str.h"
40 #include "kmp_version.h"
41
42 KMP_BUILD_ASSERT(sizeof(kmp_itt_mark_t) == sizeof(__itt_mark_type));
43
44 /* Previously used warnings:
45
46 KMP_WARNING( IttAllNotifDisabled );
47 KMP_WARNING( IttObjNotifDisabled );
48 KMP_WARNING( IttMarkNotifDisabled );
49 KMP_WARNING( IttUnloadLibFailed, libittnotify );
50 */
51
52 kmp_int32 __kmp_itt_prepare_delay = 0;
53 kmp_bootstrap_lock_t __kmp_itt_debug_lock =
54 KMP_BOOTSTRAP_LOCK_INITIALIZER(__kmp_itt_debug_lock);
55
56 #endif // USE_ITT_NOTIFY
57
58 void __kmp_itt_reset() {
59 #if USE_ITT_NOTIFY
60 __kmp_itt__ittapi_global = __kmp_ittapi_clean_global;
61 #endif
62 }
63
64 void __kmp_itt_initialize() {
65
66 // ITTNotify library is loaded and initialized at first call to any ittnotify
67 // function, so we do not need to explicitly load it any more. Just report OMP
68 // RTL version to ITTNotify.
69
70 #if USE_ITT_NOTIFY
71 // Backup a clean global state
72 __kmp_ittapi_clean_global = __kmp_itt__ittapi_global;
73
74 // Report OpenMP RTL version.
75 kmp_str_buf_t buf;
76 __itt_mark_type version;
77 __kmp_str_buf_init(&buf);
78 __kmp_str_buf_print(&buf, "OMP RTL Version %d.%d.%d", __kmp_version_major,
79 __kmp_version_minor, __kmp_version_build);
80 if (__itt_api_version_ptr != NULL) {
81 __kmp_str_buf_print(&buf, ":%s", __itt_api_version());
82 }
83 version = __itt_mark_create(buf.str);
84 __itt_mark(version, NULL);
85 __kmp_str_buf_free(&buf);
86 #endif
87
88 } // __kmp_itt_initialize
89
90 void __kmp_itt_destroy() {
91 #if USE_ITT_NOTIFY
92 __kmp_itt_fini_ittlib();
93 #endif
94 } // __kmp_itt_destroy
95
96 extern "C" void __itt_error_handler(__itt_error_code err, va_list args) {
97
98 switch (err) {
99 case __itt_error_no_module: {
100 char const *library = va_arg(args, char const *);
101 #if KMP_OS_WINDOWS
102 int sys_err = va_arg(args, int);
103 kmp_msg_t err_code = KMP_SYSERRCODE(sys_err);
104 __kmp_msg(kmp_ms_warning, KMP_MSG(IttLoadLibFailed, library), err_code,
105 __kmp_msg_null);
106 if (__kmp_generate_warnings == kmp_warnings_off) {
107 __kmp_str_free(&err_code.str);
108 }
109 #else
110 char const *sys_err = va_arg(args, char const *);
111 kmp_msg_t err_code = KMP_SYSERRMESG(sys_err);
112 __kmp_msg(kmp_ms_warning, KMP_MSG(IttLoadLibFailed, library), err_code,
113 __kmp_msg_null);
114 if (__kmp_generate_warnings == kmp_warnings_off) {
115 __kmp_str_free(&err_code.str);
116 }
117 #endif
118 } break;
119 case __itt_error_no_symbol: {
120 char const *library = va_arg(args, char const *);
121 char const *symbol = va_arg(args, char const *);
122 KMP_WARNING(IttLookupFailed, symbol, library);
123 } break;
124 case __itt_error_unknown_group: {
125 char const *var = va_arg(args, char const *);
126 char const *group = va_arg(args, char const *);
127 KMP_WARNING(IttUnknownGroup, var, group);
128 } break;
129 case __itt_error_env_too_long: {
130 char const *var = va_arg(args, char const *);
131 size_t act_len = va_arg(args, size_t);
132 size_t max_len = va_arg(args, size_t);
133 KMP_WARNING(IttEnvVarTooLong, var, (unsigned long)act_len,
134 (unsigned long)max_len);
135 } break;
136 case __itt_error_cant_read_env: {
137 char const *var = va_arg(args, char const *);
138 int sys_err = va_arg(args, int);
139 kmp_msg_t err_code = KMP_ERR(sys_err);
140 __kmp_msg(kmp_ms_warning, KMP_MSG(CantGetEnvVar, var), err_code,
141 __kmp_msg_null);
142 if (__kmp_generate_warnings == kmp_warnings_off) {
143 __kmp_str_free(&err_code.str);
144 }
145 } break;
146 case __itt_error_system: {
147 char const *func = va_arg(args, char const *);
148 int sys_err = va_arg(args, int);
149 kmp_msg_t err_code = KMP_SYSERRCODE(sys_err);
150 __kmp_msg(kmp_ms_warning, KMP_MSG(IttFunctionError, func), err_code,
151 __kmp_msg_null);
152 if (__kmp_generate_warnings == kmp_warnings_off) {
153 __kmp_str_free(&err_code.str);
154 }
155 } break;
156 default: {
157 KMP_WARNING(IttUnknownError, err);
158 }
159 }
160 } // __itt_error_handler
161
162 #endif /* USE_ITT_BUILD */
163