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 13 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
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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. // If expr is not true, print the log and execute a custom statement
  117. #define GE_CHK_BOOL_EXEC_WARN(expr, exec_expr, ...) \
  118. { \
  119. const bool b = (expr); \
  120. if (!b) { \
  121. GELOGW(__VA_ARGS__); \
  122. exec_expr; \
  123. } \
  124. }
  125. // If expr is not true, print the log and execute a custom statement
  126. #define GE_CHK_BOOL_EXEC_INFO(expr, exec_expr, ...) \
  127. { \
  128. const bool b = (expr); \
  129. if (!b) { \
  130. GELOGI(__VA_ARGS__); \
  131. exec_expr; \
  132. } \
  133. }
  134. // If expr is not true, print the log and execute a custom statement
  135. #define GE_CHK_BOOL_TRUE_EXEC_INFO(expr, exec_expr, ...) \
  136. { \
  137. const bool b = (expr); \
  138. if (b) { \
  139. GELOGI(__VA_ARGS__); \
  140. exec_expr; \
  141. } \
  142. }
  143. // If expr is true, print logs and execute custom statements
  144. #define GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(expr, exec_expr, ...) \
  145. { \
  146. const bool b = (expr); \
  147. if (b) { \
  148. GELOGE(ge::FAILED, __VA_ARGS__); \
  149. exec_expr; \
  150. } \
  151. }
  152. // If expr is true, print the Information log and execute a custom statement
  153. #define GE_CHK_TRUE_EXEC_INFO(expr, exec_expr, ...) \
  154. { \
  155. const bool b = (expr); \
  156. if (b) { \
  157. GELOGI(__VA_ARGS__); \
  158. exec_expr; \
  159. } \
  160. }
  161. // If expr is not SUCCESS, print the log and execute the expression + return
  162. #define GE_CHK_BOOL_TRUE_RET_VOID(expr, exec_expr, ...) \
  163. { \
  164. const bool b = (expr); \
  165. if (b) { \
  166. GELOGE(ge::FAILED, __VA_ARGS__); \
  167. exec_expr; \
  168. return; \
  169. } \
  170. }
  171. // If expr is not SUCCESS, print the log and execute the expression + return _status
  172. #define GE_CHK_BOOL_TRUE_EXEC_RET_STATUS(expr, _status, exec_expr, ...) \
  173. { \
  174. const bool b = (expr); \
  175. if (b) { \
  176. REPORT_INNER_ERROR("E19999", __VA_ARGS__); \
  177. GELOGE(ge::FAILED, __VA_ARGS__); \
  178. exec_expr; \
  179. return (_status); \
  180. } \
  181. }
  182. // If expr is not true, execute a custom statement
  183. #define GE_CHK_BOOL_EXEC_NOLOG(expr, exec_expr) \
  184. { \
  185. const bool b = (expr); \
  186. if (!b) { \
  187. exec_expr; \
  188. } \
  189. }
  190. // -----------------runtime related macro definitions-------------------------------
  191. // If expr is not RT_ERROR_NONE, print the log
  192. #define GE_CHK_RT(expr) \
  193. do { \
  194. const rtError_t _rt_err = (expr); \
  195. if (_rt_err != RT_ERROR_NONE) { \
  196. GELOGE(ge::RT_FAILED, "Call rt api failed, ret: 0x%X", _rt_err); \
  197. } \
  198. } while (false)
  199. // If expr is not RT_ERROR_NONE, print the log and execute the exec_expr expression
  200. #define GE_CHK_RT_EXEC(expr, exec_expr) \
  201. do { \
  202. const rtError_t _rt_ret = (expr); \
  203. if (_rt_ret != RT_ERROR_NONE) { \
  204. GELOGE(ge::RT_FAILED, "Call rt api failed, ret: 0x%X", _rt_ret); \
  205. exec_expr; \
  206. } \
  207. } while (false)
  208. // If expr is not RT_ERROR_NONE, print the log and return
  209. #define GE_CHK_RT_RET(expr) \
  210. do { \
  211. const rtError_t _rt_ret = (expr); \
  212. if (_rt_ret != RT_ERROR_NONE) { \
  213. REPORT_CALL_ERROR("E19999", "Call %s fail, ret: 0x%X", #expr, _rt_ret); \
  214. GELOGE(ge::RT_FAILED, "Call rt api failed, ret: 0x%X", _rt_ret); \
  215. return RT_ERROR_TO_GE_STATUS(_rt_ret); \
  216. } \
  217. } while (false)
  218. // If expr is true, execute exec_expr without printing logs
  219. #define GE_IF_BOOL_EXEC(expr, exec_expr) \
  220. { \
  221. if (expr) { \
  222. exec_expr; \
  223. } \
  224. }
  225. // If make_shared is abnormal, print the log and execute the statement
  226. #define GE_MAKE_SHARED(exec_expr0, exec_expr1) \
  227. try { \
  228. exec_expr0; \
  229. } catch (const std::bad_alloc &) { \
  230. GELOGE(ge::FAILED, "Make shared failed"); \
  231. exec_expr1; \
  232. }
  233. #define GE_ERRORLOG_AND_ERRORMSG(_status, errormsg) \
  234. { \
  235. GELOGE((_status), "[Check][InnerData]%s", (errormsg)); \
  236. REPORT_INNER_ERROR("E19999", "%s", (errormsg)); \
  237. }
  238. #define GE_WARNINGLOG_AND_ERRORMSG(errormsg) \
  239. { \
  240. GELOGW("%s", (errormsg)); \
  241. ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {(errormsg)}); \
  242. }
  243. #define GE_CHK_LOG_AND_ERRORMSG(expr, _status, errormsg) \
  244. do { \
  245. const bool b = (expr); \
  246. if (!b) { \
  247. GELOGE((_status), "%s", (errormsg)); \
  248. ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {(errormsg)}); \
  249. return (_status); \
  250. } \
  251. } while (false)
  252. namespace ge {
  253. template <typename T>
  254. GE_FUNC_VISIBILITY std::string FmtToStr(const T &t) {
  255. std::string fmt;
  256. std::stringstream st;
  257. st << "[" << t << "]";
  258. fmt = st.str();
  259. return fmt;
  260. }
  261. } // namespace ge
  262. #endif // INC_FRAMEWORK_COMMON_DEBUG_LOG_H_

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