kmp_itt.cpp 4.8 KB

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