You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

log.h 9.3 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /**
  2. * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef INC_FRAMEWORK_COMMON_DEBUG_LOG_H_
  17. #define INC_FRAMEWORK_COMMON_DEBUG_LOG_H_
  18. #include <string>
  19. #include <sstream>
  20. #include "framework/common/string_util.h"
  21. #include "framework/common/util.h"
  22. #include "framework/common/debug/ge_log.h"
  23. #include "external/ge/ge_api_error_codes.h"
  24. #if !defined(__ANDROID__) && !defined(ANDROID)
  25. #define DOMI_LOGE(fmt, ...) GE_LOG_ERROR(GE_MODULE_NAME, (ge::FAILED), fmt, ##__VA_ARGS__)
  26. #else
  27. #include <android/log.h>
  28. #if defined(BUILD_VERSION_PERF)
  29. #define DOMI_LOGE(fmt, ...)
  30. #else
  31. // The Android system has strict log control. Do not modify the log.
  32. #define DOMI_LOGE(fmt, ...) \
  33. __android_log_print(ANDROID_LOG_ERROR, "NPU_FMK", "%s %s(%d)::" #fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
  34. #endif
  35. #endif
  36. // ge marco
  37. #define GE_LOGI_IF(condition, ...) \
  38. if ((condition)) { \
  39. GELOGI(__VA_ARGS__); \
  40. }
  41. #define GE_LOGW_IF(condition, ...) \
  42. if ((condition)) { \
  43. GELOGW(__VA_ARGS__); \
  44. }
  45. #define GE_LOGE_IF(condition, ...) \
  46. if ((condition)) { \
  47. GELOGE((ge::FAILED), __VA_ARGS__); \
  48. }
  49. // If expr is not SUCCESS, print the log and return the same value
  50. #define GE_CHK_STATUS_RET(expr, ...) \
  51. do { \
  52. const ge::Status _chk_status = (expr); \
  53. if (_chk_status != ge::SUCCESS) { \
  54. GELOGE((ge::FAILED), __VA_ARGS__); \
  55. return _chk_status; \
  56. } \
  57. } while (false)
  58. // If expr is not SUCCESS, print the log and do not execute return
  59. #define GE_CHK_STATUS(expr, ...) \
  60. do { \
  61. const ge::Status _chk_status = (expr); \
  62. if (_chk_status != ge::SUCCESS) { \
  63. GELOGE(_chk_status, __VA_ARGS__); \
  64. } \
  65. } while (false)
  66. // If expr is not SUCCESS, return the same value
  67. #define GE_CHK_STATUS_RET_NOLOG(expr) \
  68. do { \
  69. const ge::Status _chk_status = (expr); \
  70. if (_chk_status != ge::SUCCESS) { \
  71. return _chk_status; \
  72. } \
  73. } while (false)
  74. // If expr is not GRAPH_SUCCESS, print the log and return FAILED
  75. #define GE_CHK_GRAPH_STATUS_RET(expr, ...) \
  76. do { \
  77. if ((expr) != ge::GRAPH_SUCCESS) { \
  78. REPORT_CALL_ERROR("E19999", "Operator graph failed"); \
  79. GELOGE(ge::FAILED, __VA_ARGS__); \
  80. return (FAILED); \
  81. } \
  82. } while (false)
  83. // If expr is not SUCCESS, print the log and execute a custom statement
  84. #define GE_CHK_STATUS_EXEC(expr, exec_expr, ...) \
  85. do { \
  86. const ge::Status _chk_status = (expr); \
  87. GE_CHK_BOOL_EXEC(_chk_status == SUCCESS, exec_expr, __VA_ARGS__); \
  88. } while (false)
  89. // If expr is not true, print the log and return the specified status
  90. #define GE_CHK_BOOL_RET_STATUS(expr, _status, ...) \
  91. do { \
  92. const bool b = (expr); \
  93. if (!b) { \
  94. REPORT_INNER_ERROR("E19999", __VA_ARGS__); \
  95. GELOGE((_status), __VA_ARGS__); \
  96. return (_status); \
  97. } \
  98. } while (false)
  99. // If expr is not true, print the log and return the specified status
  100. #define GE_CHK_BOOL_RET_STATUS_NOLOG(expr, _status, ...) \
  101. do { \
  102. const bool b = (expr); \
  103. if (!b) { \
  104. return (_status); \
  105. } \
  106. } while (false)
  107. // If expr is not true, print the log and execute a custom statement
  108. #define GE_CHK_BOOL_EXEC(expr, exec_expr, ...) \
  109. { \
  110. const bool b = (expr); \
  111. if (!b) { \
  112. GELOGE(ge::FAILED, __VA_ARGS__); \
  113. exec_expr; \
  114. } \
  115. }
  116. // -----------------runtime related macro definitions-------------------------------
  117. // If expr is not RT_ERROR_NONE, print the log
  118. #define GE_CHK_RT(expr) \
  119. do { \
  120. const rtError_t _rt_err = (expr); \
  121. if (_rt_err != RT_ERROR_NONE) { \
  122. GELOGE(ge::RT_FAILED, "Call rt api failed, ret: 0x%X", _rt_err); \
  123. } \
  124. } while (false)
  125. // If expr is not RT_ERROR_NONE, print the log and execute the exec_expr expression
  126. #define GE_CHK_RT_EXEC(expr, exec_expr) \
  127. do { \
  128. const rtError_t _rt_ret = (expr); \
  129. if (_rt_ret != RT_ERROR_NONE) { \
  130. GELOGE(ge::RT_FAILED, "Call rt api failed, ret: 0x%X", _rt_ret); \
  131. exec_expr; \
  132. } \
  133. } while (false)
  134. // If expr is not RT_ERROR_NONE, print the log and return
  135. #define GE_CHK_RT_RET(expr) \
  136. do { \
  137. const rtError_t _rt_ret = (expr); \
  138. if (_rt_ret != RT_ERROR_NONE) { \
  139. REPORT_CALL_ERROR("E19999", "Call %s fail, ret: 0x%X", #expr, _rt_ret); \
  140. GELOGE(ge::RT_FAILED, "Call rt api failed, ret: 0x%X", _rt_ret); \
  141. return RT_ERROR_TO_GE_STATUS(_rt_ret); \
  142. } \
  143. } while (false)
  144. // If expr is true, execute exec_expr without printing logs
  145. #define GE_IF_BOOL_EXEC(expr, exec_expr) \
  146. { \
  147. if (expr) { \
  148. exec_expr; \
  149. } \
  150. }
  151. // If make_shared is abnormal, print the log and execute the statement
  152. #define GE_MAKE_SHARED(exec_expr0, exec_expr1) \
  153. try { \
  154. exec_expr0; \
  155. } catch (const std::bad_alloc &) { \
  156. GELOGE(ge::FAILED, "Make shared failed"); \
  157. exec_expr1; \
  158. }
  159. #define GE_ERRORLOG_AND_ERRORMSG(_status, errormsg) \
  160. { \
  161. GELOGE((_status), "[Check][InnerData]%s", (errormsg)); \
  162. REPORT_INNER_ERROR("E19999", "%s", (errormsg)); \
  163. }
  164. #define GE_WARNINGLOG_AND_ERRORMSG(errormsg) \
  165. { \
  166. GELOGW("%s", (errormsg)); \
  167. ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {(errormsg)}); \
  168. }
  169. #define GE_CHK_LOG_AND_ERRORMSG(expr, _status, errormsg) \
  170. do { \
  171. const bool b = (expr); \
  172. if (!b) { \
  173. GELOGE((_status), "%s", (errormsg)); \
  174. ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {(errormsg)}); \
  175. return (_status); \
  176. } \
  177. } while (false)
  178. namespace ge {
  179. template <typename T>
  180. GE_FUNC_VISIBILITY std::string FmtToStr(const T &t) {
  181. std::string fmt;
  182. std::stringstream st;
  183. st << "[" << t << "]";
  184. fmt = st.str();
  185. return fmt;
  186. }
  187. } // namespace ge
  188. #endif // INC_FRAMEWORK_COMMON_DEBUG_LOG_H_

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示