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 12 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
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 "runtime/rt.h"
  21. #include "common/string_util.h"
  22. #include "common/util.h"
  23. #include "common/util/error_manager/error_manager.h"
  24. #include "framework/common/debug/ge_log.h"
  25. #include "ge/ge_api_error_codes.h"
  26. #if !defined(__ANDROID__) && !defined(ANDROID)
  27. #define DOMI_LOGE(...) GE_LOG_ERROR(GE_MODULE_NAME, ge::FAILED, __VA_ARGS__)
  28. #else
  29. #include <android/log.h>
  30. #if defined(BUILD_VERSION_PERF)
  31. #define DOMI_LOGE(fmt, ...)
  32. #else
  33. // The Android system has strict log control. Do not modify the log.
  34. #define DOMI_LOGE(fmt, ...) \
  35. __android_log_print(ANDROID_LOG_ERROR, "NPU_FMK", "%s %s(%d)::" #fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
  36. #endif
  37. #endif
  38. // ge marco
  39. #define GE_LOGI_IF(condition, ...) \
  40. if ((condition)) { \
  41. GELOGI(__VA_ARGS__); \
  42. }
  43. #define GE_LOGW_IF(condition, ...) \
  44. if ((condition)) { \
  45. GELOGW(__VA_ARGS__); \
  46. }
  47. #define GE_LOGE_IF(condition, ...) \
  48. if ((condition)) { \
  49. DOMI_LOGE(__VA_ARGS__); \
  50. }
  51. // If expr is not SUCCESS, print the log and return the same value
  52. #define GE_CHK_STATUS_RET(expr, ...) \
  53. do { \
  54. const ge::Status _status = (expr); \
  55. if (_status != ge::SUCCESS) { \
  56. DOMI_LOGE(__VA_ARGS__); \
  57. return _status; \
  58. } \
  59. } while (0);
  60. // If expr is not SUCCESS, print the log and do not execute return
  61. #define GE_CHK_STATUS(expr, ...) \
  62. do { \
  63. const ge::Status _status = (expr); \
  64. if (_status != ge::SUCCESS) { \
  65. DOMI_LOGE(__VA_ARGS__); \
  66. } \
  67. } while (0);
  68. // If expr is not SUCCESS, return the same value
  69. #define GE_CHK_STATUS_RET_NOLOG(expr) \
  70. do { \
  71. const ge::Status _status = (expr); \
  72. if (_status != ge::SUCCESS) { \
  73. return _status; \
  74. } \
  75. } while (0);
  76. // If expr is not GRAPH_SUCCESS, print the log and return FAILED
  77. #define GE_CHK_GRAPH_STATUS_RET(expr, ...) \
  78. do { \
  79. if ((expr) != ge::GRAPH_SUCCESS) { \
  80. DOMI_LOGE(__VA_ARGS__); \
  81. return FAILED; \
  82. } \
  83. } while (0);
  84. // If expr is not SUCCESS, print the log and execute a custom statement
  85. #define GE_CHK_STATUS_EXEC(expr, exec_expr, ...) \
  86. do { \
  87. const ge::Status _status = (expr); \
  88. GE_CHK_BOOL_EXEC(_status == SUCCESS, exec_expr, __VA_ARGS__); \
  89. } while (0);
  90. // If expr is not true, print the log and return the specified status
  91. #define GE_CHK_BOOL_RET_STATUS(expr, _status, ...) \
  92. do { \
  93. bool b = (expr); \
  94. if (!b) { \
  95. GELOGE(_status, __VA_ARGS__); \
  96. return _status; \
  97. } \
  98. } while (0);
  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. bool b = (expr); \
  103. if (!b) { \
  104. return _status; \
  105. } \
  106. } while (0);
  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. bool b = (expr); \
  111. if (!b) { \
  112. DOMI_LOGE(__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. 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. 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. 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. bool b = (expr); \
  147. if (b) { \
  148. DOMI_LOGE(__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. 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. bool b = (expr); \
  165. if (b) { \
  166. DOMI_LOGE(__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. bool b = (expr); \
  175. if (b) { \
  176. DOMI_LOGE(__VA_ARGS__); \
  177. exec_expr; \
  178. return _status; \
  179. } \
  180. }
  181. // If expr is not true, execute a custom statement
  182. #define GE_CHK_BOOL_EXEC_NOLOG(expr, exec_expr) \
  183. { \
  184. bool b = (expr); \
  185. if (!b) { \
  186. exec_expr; \
  187. } \
  188. }
  189. // -----------------runtime related macro definitions-------------------------------
  190. // If expr is not RT_ERROR_NONE, print the log
  191. #define GE_CHK_RT(expr) \
  192. do { \
  193. rtError_t _rt_ret = (expr); \
  194. if (_rt_ret != RT_ERROR_NONE) { \
  195. DOMI_LOGE("Call rt api failed, ret: 0x%X", _rt_ret); \
  196. } \
  197. } while (0);
  198. // If expr is not RT_ERROR_NONE, print the log and execute the exec_expr expression
  199. #define GE_CHK_RT_EXEC(expr, exec_expr) \
  200. { \
  201. rtError_t _rt_ret = (expr); \
  202. if (_rt_ret != RT_ERROR_NONE) { \
  203. DOMI_LOGE("Call rt api failed, ret: 0x%X", _rt_ret); \
  204. exec_expr; \
  205. } \
  206. }
  207. // If expr is not RT_ERROR_NONE, print the log and return
  208. #define GE_CHK_RT_RET(expr) \
  209. do { \
  210. rtError_t _rt_ret = (expr); \
  211. if (_rt_ret != RT_ERROR_NONE) { \
  212. DOMI_LOGE("Call rt api failed, ret: 0x%X", _rt_ret); \
  213. return RT_ERROR_TO_GE_STATUS(_rt_ret); \
  214. } \
  215. } while (0);
  216. // If expr is true, execute exec_expr without printing logs
  217. #define GE_IF_BOOL_EXEC(expr, exec_expr) \
  218. { \
  219. if (expr) { \
  220. exec_expr; \
  221. } \
  222. }
  223. // If make_shared is abnormal, print the log and execute the statement
  224. #define GE_MAKE_SHARED(exec_expr0, exec_expr1) \
  225. try { \
  226. exec_expr0; \
  227. } catch (const std::bad_alloc &) { \
  228. DOMI_LOGE("Make shared failed"); \
  229. exec_expr1; \
  230. }
  231. #define GE_ERRORLOG_AND_ERRORMSG(_status, errormsg) \
  232. { \
  233. GELOGE(_status, "%s", errormsg); \
  234. ErrorManager::GetInstance().ATCReportErrMessage("E10043", {"reason"}, {errormsg}); \
  235. }
  236. #define GE_CHK_LOG_AND_ERRORMSG(expr, _status, errormsg) \
  237. do { \
  238. bool b = (expr); \
  239. if (!b) { \
  240. GELOGE(_status, "%s", errormsg); \
  241. ErrorManager::GetInstance().ATCReportErrMessage("E10043", {"reason"}, {errormsg}); \
  242. return _status; \
  243. } \
  244. } while (0)
  245. template <typename T>
  246. std::string FmtToStr(const T &t) {
  247. std::string fmt;
  248. std::stringstream st;
  249. st << "[" << t << "]";
  250. fmt = st.str();
  251. return fmt;
  252. }
  253. #endif // INC_FRAMEWORK_COMMON_DEBUG_LOG_H_

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