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
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
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /**
  2. * Copyright 2019-2020 Huawei Technologies Co., Ltd
  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 <securec.h>
  21. #include "runtime/rt.h"
  22. #include "common/string_util.h"
  23. #include "common/util.h"
  24. #include "common/util/error_manager/error_manager.h"
  25. #include "framework/common/debug/ge_log.h"
  26. #include "ge/ge_api_error_codes.h"
  27. #if !defined(__ANDROID__) && !defined(ANDROID)
  28. #define DOMI_LOGE(fmt, ...) GE_LOG_ERROR(GE_MODULE_NAME, ge::FAILED, fmt, ##__VA_ARGS__)
  29. #else
  30. #include <android/log.h>
  31. #if defined(BUILD_VERSION_PERF)
  32. #define DOMI_LOGE(fmt, ...)
  33. #else
  34. // The Android system has strict log control. Do not modify the log.
  35. #define DOMI_LOGE(fmt, ...) \
  36. __android_log_print(ANDROID_LOG_ERROR, "NPU_FMK", "%s %s(%d)::" #fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
  37. #endif
  38. #endif
  39. // ge marco
  40. #define GE_LOGI_IF(condition, ...) \
  41. if ((condition)) { \
  42. GELOGI(__VA_ARGS__); \
  43. }
  44. #define GE_LOGW_IF(condition, ...) \
  45. if ((condition)) { \
  46. GELOGW(__VA_ARGS__); \
  47. }
  48. #define GE_LOGE_IF(condition, ...) \
  49. if ((condition)) { \
  50. GELOGE(ge::FAILED, __VA_ARGS__); \
  51. }
  52. // If expr is not SUCCESS, print the log and return the same value
  53. #define GE_CHK_STATUS_RET(expr, ...) \
  54. do { \
  55. const ge::Status _chk_status = (expr); \
  56. if (_chk_status != ge::SUCCESS) { \
  57. GELOGE(ge::FAILED, __VA_ARGS__); \
  58. return _chk_status; \
  59. } \
  60. } while (false)
  61. // If expr is not SUCCESS, print the log and do not execute return
  62. #define GE_CHK_STATUS(expr, ...) \
  63. do { \
  64. const ge::Status _chk_status = (expr); \
  65. if (_chk_status != ge::SUCCESS) { \
  66. GELOGE(ge::FAILED, __VA_ARGS__); \
  67. } \
  68. } while (false)
  69. // If expr is not SUCCESS, return the same value
  70. #define GE_CHK_STATUS_RET_NOLOG(expr) \
  71. do { \
  72. const ge::Status _chk_status = (expr); \
  73. if (_chk_status != ge::SUCCESS) { \
  74. return _chk_status; \
  75. } \
  76. } while (false)
  77. // If expr is not GRAPH_SUCCESS, print the log and return FAILED
  78. #define GE_CHK_GRAPH_STATUS_RET(expr, ...) \
  79. do { \
  80. if ((expr) != ge::GRAPH_SUCCESS) { \
  81. REPORT_CALL_ERROR("E19999", "Operator graph failed"); \
  82. GELOGE(ge::FAILED, __VA_ARGS__); \
  83. return FAILED; \
  84. } \
  85. } while (false)
  86. // If expr is not SUCCESS, print the log and execute a custom statement
  87. #define GE_CHK_STATUS_EXEC(expr, exec_expr, ...) \
  88. do { \
  89. const ge::Status _chk_status = (expr); \
  90. GE_CHK_BOOL_EXEC(_chk_status == SUCCESS, exec_expr, __VA_ARGS__); \
  91. } while (false)
  92. // If expr is not true, print the log and return the specified status
  93. #define GE_CHK_BOOL_RET_STATUS(expr, _status, ...) \
  94. do { \
  95. const bool b = (expr); \
  96. if (!b) { \
  97. REPORT_INNER_ERROR("E19999", __VA_ARGS__); \
  98. GELOGE(_status, __VA_ARGS__); \
  99. return _status; \
  100. } \
  101. } while (false)
  102. // If expr is not true, print the log and return the specified status
  103. #define GE_CHK_BOOL_RET_STATUS_NOLOG(expr, _status, ...) \
  104. do { \
  105. const bool b = (expr); \
  106. if (!b) { \
  107. return _status; \
  108. } \
  109. } while (false)
  110. // If expr is not true, print the log and execute a custom statement
  111. #define GE_CHK_BOOL_EXEC(expr, exec_expr, ...) \
  112. { \
  113. const bool b = (expr); \
  114. if (!b) { \
  115. GELOGE(ge::FAILED, __VA_ARGS__); \
  116. exec_expr; \
  117. } \
  118. }
  119. // If expr is not true, print the log and execute a custom statement
  120. #define GE_CHK_BOOL_EXEC_WARN(expr, exec_expr, ...) \
  121. { \
  122. const bool b = (expr); \
  123. if (!b) { \
  124. GELOGW(__VA_ARGS__); \
  125. exec_expr; \
  126. } \
  127. }
  128. // If expr is not true, print the log and execute a custom statement
  129. #define GE_CHK_BOOL_EXEC_INFO(expr, exec_expr, ...) \
  130. { \
  131. const bool b = (expr); \
  132. if (!b) { \
  133. GELOGI(__VA_ARGS__); \
  134. exec_expr; \
  135. } \
  136. }
  137. // If expr is not true, print the log and execute a custom statement
  138. #define GE_CHK_BOOL_TRUE_EXEC_INFO(expr, exec_expr, ...) \
  139. { \
  140. const bool b = (expr); \
  141. if (b) { \
  142. GELOGI(__VA_ARGS__); \
  143. exec_expr; \
  144. } \
  145. }
  146. // If expr is true, print logs and execute custom statements
  147. #define GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(expr, exec_expr, ...) \
  148. { \
  149. const bool b = (expr); \
  150. if (b) { \
  151. GELOGE(ge::FAILED, __VA_ARGS__); \
  152. exec_expr; \
  153. } \
  154. }
  155. // If expr is true, print the Information log and execute a custom statement
  156. #define GE_CHK_TRUE_EXEC_INFO(expr, exec_expr, ...) \
  157. { \
  158. const bool b = (expr); \
  159. if (b) { \
  160. GELOGI(__VA_ARGS__); \
  161. exec_expr; \
  162. } \
  163. }
  164. // If expr is not SUCCESS, print the log and execute the expression + return
  165. #define GE_CHK_BOOL_TRUE_RET_VOID(expr, exec_expr, ...) \
  166. { \
  167. const bool b = (expr); \
  168. if (b) { \
  169. GELOGE(ge::FAILED, __VA_ARGS__); \
  170. exec_expr; \
  171. return; \
  172. } \
  173. }
  174. // If expr is not SUCCESS, print the log and execute the expression + return _status
  175. #define GE_CHK_BOOL_TRUE_EXEC_RET_STATUS(expr, _status, exec_expr, ...) \
  176. { \
  177. const bool b = (expr); \
  178. if (b) { \
  179. REPORT_INNER_ERROR("E19999", __VA_ARGS__); \
  180. GELOGE(ge::FAILED, __VA_ARGS__); \
  181. exec_expr; \
  182. return _status; \
  183. } \
  184. }
  185. // If expr is not true, execute a custom statement
  186. #define GE_CHK_BOOL_EXEC_NOLOG(expr, exec_expr) \
  187. { \
  188. const bool b = (expr); \
  189. if (!b) { \
  190. exec_expr; \
  191. } \
  192. }
  193. // -----------------runtime related macro definitions-------------------------------
  194. // If expr is not RT_ERROR_NONE, print the log
  195. #define GE_CHK_RT(expr) \
  196. do { \
  197. const rtError_t _rt_ret = (expr); \
  198. if (_rt_ret != RT_ERROR_NONE) { \
  199. GELOGE(ge::FAILED, "Call rt api failed, ret: 0x%X", _rt_ret); \
  200. } \
  201. } while (false)
  202. // If expr is not RT_ERROR_NONE, print the log and execute the exec_expr expression
  203. #define GE_CHK_RT_EXEC(expr, exec_expr) \
  204. do { \
  205. const rtError_t _rt_ret = (expr); \
  206. if (_rt_ret != RT_ERROR_NONE) { \
  207. GELOGE(ge::FAILED, "Call rt api failed, ret: 0x%X", _rt_ret); \
  208. exec_expr; \
  209. } \
  210. } while (false)
  211. // If expr is not RT_ERROR_NONE, print the log and return
  212. #define GE_CHK_RT_RET(expr) \
  213. do { \
  214. const rtError_t _rt_ret = (expr); \
  215. if (_rt_ret != RT_ERROR_NONE) { \
  216. REPORT_CALL_ERROR("E19999", "Call %s fail, ret: 0x%X", #expr, _rt_ret); \
  217. GELOGE(ge::FAILED, "Call rt api failed, ret: 0x%X", _rt_ret); \
  218. return RT_ERROR_TO_GE_STATUS(_rt_ret); \
  219. } \
  220. } while (false)
  221. // If expr is true, execute exec_expr without printing logs
  222. #define GE_IF_BOOL_EXEC(expr, exec_expr) \
  223. { \
  224. if (expr) { \
  225. exec_expr; \
  226. } \
  227. }
  228. // If make_shared is abnormal, print the log and execute the statement
  229. #define GE_MAKE_SHARED(exec_expr0, exec_expr1) \
  230. try { \
  231. exec_expr0; \
  232. } catch (const std::bad_alloc &) { \
  233. GELOGE(ge::FAILED, "Make shared failed"); \
  234. exec_expr1; \
  235. }
  236. #define GE_ERRORLOG_AND_ERRORMSG(_status, errormsg) \
  237. { \
  238. GELOGE(_status, "[Check][InnerData]%s", errormsg); \
  239. REPORT_INNER_ERROR("E19999", "%s", errormsg); \
  240. }
  241. #define GE_WARNINGLOG_AND_ERRORMSG(errormsg) \
  242. { \
  243. GELOGW("%s", errormsg); \
  244. ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {errormsg}); \
  245. }
  246. #define GE_CHK_LOG_AND_ERRORMSG(expr, _status, errormsg) \
  247. do { \
  248. const bool b = (expr); \
  249. if (!b) { \
  250. GELOGE(_status, "%s", errormsg); \
  251. ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {errormsg}); \
  252. return _status; \
  253. } \
  254. } while (false)
  255. template <typename T>
  256. GE_FUNC_VISIBILITY std::string FmtToStr(const T &t) {
  257. std::string fmt;
  258. std::stringstream st;
  259. st << "[" << t << "]";
  260. fmt = st.str();
  261. return fmt;
  262. }
  263. #endif // INC_FRAMEWORK_COMMON_DEBUG_LOG_H_

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