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

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