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
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
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. DOMI_LOGE(__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 _status = (expr); \
  56. if (_status != ge::SUCCESS) { \
  57. DOMI_LOGE(__VA_ARGS__); \
  58. return _status; \
  59. } \
  60. } while (0);
  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 _status = (expr); \
  65. if (_status != ge::SUCCESS) { \
  66. DOMI_LOGE(__VA_ARGS__); \
  67. } \
  68. } while (0);
  69. // If expr is not SUCCESS, return the same value
  70. #define GE_CHK_STATUS_RET_NOLOG(expr) \
  71. do { \
  72. const ge::Status _status = (expr); \
  73. if (_status != ge::SUCCESS) { \
  74. return _status; \
  75. } \
  76. } while (0);
  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. DOMI_LOGE(__VA_ARGS__); \
  82. return FAILED; \
  83. } \
  84. } while (0);
  85. // If expr is not SUCCESS, print the log and execute a custom statement
  86. #define GE_CHK_STATUS_EXEC(expr, exec_expr, ...) \
  87. do { \
  88. const ge::Status _status = (expr); \
  89. GE_CHK_BOOL_EXEC(_status == SUCCESS, exec_expr, __VA_ARGS__); \
  90. } while (0);
  91. // If expr is not true, print the log and return the specified status
  92. #define GE_CHK_BOOL_RET_STATUS(expr, _status, ...) \
  93. do { \
  94. bool b = (expr); \
  95. if (!b) { \
  96. REPORT_INNER_ERROR("E19999", __VA_ARGS__); \
  97. GELOGE(_status, __VA_ARGS__); \
  98. return _status; \
  99. } \
  100. } while (0);
  101. // If expr is not true, print the log and return the specified status
  102. #define GE_CHK_BOOL_RET_STATUS_NOLOG(expr, _status, ...) \
  103. do { \
  104. bool b = (expr); \
  105. if (!b) { \
  106. return _status; \
  107. } \
  108. } while (0);
  109. // If expr is not true, print the log and execute a custom statement
  110. #define GE_CHK_BOOL_EXEC(expr, exec_expr, ...) \
  111. { \
  112. bool b = (expr); \
  113. if (!b) { \
  114. DOMI_LOGE(__VA_ARGS__); \
  115. exec_expr; \
  116. } \
  117. }
  118. // If expr is not true, print the log and execute a custom statement
  119. #define GE_CHK_BOOL_EXEC_WARN(expr, exec_expr, ...) \
  120. { \
  121. bool b = (expr); \
  122. if (!b) { \
  123. GELOGW(__VA_ARGS__); \
  124. exec_expr; \
  125. } \
  126. }
  127. // If expr is not true, print the log and execute a custom statement
  128. #define GE_CHK_BOOL_EXEC_INFO(expr, exec_expr, ...) \
  129. { \
  130. bool b = (expr); \
  131. if (!b) { \
  132. GELOGI(__VA_ARGS__); \
  133. exec_expr; \
  134. } \
  135. }
  136. // If expr is not true, print the log and execute a custom statement
  137. #define GE_CHK_BOOL_TRUE_EXEC_INFO(expr, exec_expr, ...) \
  138. { \
  139. bool b = (expr); \
  140. if (b) { \
  141. GELOGI(__VA_ARGS__); \
  142. exec_expr; \
  143. } \
  144. }
  145. // If expr is true, print logs and execute custom statements
  146. #define GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(expr, exec_expr, ...) \
  147. { \
  148. bool b = (expr); \
  149. if (b) { \
  150. DOMI_LOGE(__VA_ARGS__); \
  151. exec_expr; \
  152. } \
  153. }
  154. // If expr is true, print the Information log and execute a custom statement
  155. #define GE_CHK_TRUE_EXEC_INFO(expr, exec_expr, ...) \
  156. { \
  157. bool b = (expr); \
  158. if (b) { \
  159. GELOGI(__VA_ARGS__); \
  160. exec_expr; \
  161. } \
  162. }
  163. // If expr is not SUCCESS, print the log and execute the expression + return
  164. #define GE_CHK_BOOL_TRUE_RET_VOID(expr, exec_expr, ...) \
  165. { \
  166. bool b = (expr); \
  167. if (b) { \
  168. DOMI_LOGE(__VA_ARGS__); \
  169. exec_expr; \
  170. return; \
  171. } \
  172. }
  173. // If expr is not SUCCESS, print the log and execute the expression + return _status
  174. #define GE_CHK_BOOL_TRUE_EXEC_RET_STATUS(expr, _status, exec_expr, ...) \
  175. { \
  176. bool b = (expr); \
  177. if (b) { \
  178. REPORT_INNER_ERROR("E19999", __VA_ARGS__); \
  179. DOMI_LOGE(__VA_ARGS__); \
  180. exec_expr; \
  181. return _status; \
  182. } \
  183. }
  184. // If expr is not true, execute a custom statement
  185. #define GE_CHK_BOOL_EXEC_NOLOG(expr, exec_expr) \
  186. { \
  187. bool b = (expr); \
  188. if (!b) { \
  189. exec_expr; \
  190. } \
  191. }
  192. // -----------------runtime related macro definitions-------------------------------
  193. // If expr is not RT_ERROR_NONE, print the log
  194. #define GE_CHK_RT(expr) \
  195. do { \
  196. rtError_t _rt_ret = (expr); \
  197. if (_rt_ret != RT_ERROR_NONE) { \
  198. DOMI_LOGE("Call rt api failed, ret: 0x%X", _rt_ret); \
  199. } \
  200. } while (0);
  201. // If expr is not RT_ERROR_NONE, print the log and execute the exec_expr expression
  202. #define GE_CHK_RT_EXEC(expr, exec_expr) \
  203. { \
  204. rtError_t _rt_ret = (expr); \
  205. if (_rt_ret != RT_ERROR_NONE) { \
  206. DOMI_LOGE("Call rt api failed, ret: 0x%X", _rt_ret); \
  207. exec_expr; \
  208. } \
  209. }
  210. // If expr is not RT_ERROR_NONE, print the log and return
  211. #define GE_CHK_RT_RET(expr) \
  212. do { \
  213. rtError_t _rt_ret = (expr); \
  214. if (_rt_ret != RT_ERROR_NONE) { \
  215. REPORT_CALL_ERROR("E19999", "Call %s fail, ret: 0x%X when %s", #expr, _rt_ret, __FUNCTION__); \
  216. DOMI_LOGE("Call rt api failed, ret: 0x%X", _rt_ret); \
  217. return RT_ERROR_TO_GE_STATUS(_rt_ret); \
  218. } \
  219. } while (0);
  220. // If expr is true, execute exec_expr without printing logs
  221. #define GE_IF_BOOL_EXEC(expr, exec_expr) \
  222. { \
  223. if (expr) { \
  224. exec_expr; \
  225. } \
  226. }
  227. // If make_shared is abnormal, print the log and execute the statement
  228. #define GE_MAKE_SHARED(exec_expr0, exec_expr1) \
  229. try { \
  230. exec_expr0; \
  231. } catch (const std::bad_alloc &) { \
  232. DOMI_LOGE("Make shared failed"); \
  233. exec_expr1; \
  234. }
  235. #define GE_ERRORLOG_AND_ERRORMSG(_status, errormsg) \
  236. { \
  237. GELOGE(_status, "[Check][InnerData]%s", errormsg); \
  238. REPORT_INNER_ERROR("E19999", "%s", errormsg); \
  239. }
  240. #define GE_WARNINGLOG_AND_ERRORMSG(errormsg) \
  241. { \
  242. GELOGW("%s", errormsg); \
  243. ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {errormsg}); \
  244. }
  245. #define GE_CHK_LOG_AND_ERRORMSG(expr, _status, errormsg) \
  246. do { \
  247. bool b = (expr); \
  248. if (!b) { \
  249. GELOGE(_status, "%s", errormsg); \
  250. ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {errormsg}); \
  251. return _status; \
  252. } \
  253. } while (0)
  254. template <typename T>
  255. GE_FUNC_VISIBILITY std::string FmtToStr(const T &t) {
  256. std::string fmt;
  257. std::stringstream st;
  258. st << "[" << t << "]";
  259. fmt = st.str();
  260. return fmt;
  261. }
  262. #endif // INC_FRAMEWORK_COMMON_DEBUG_LOG_H_

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