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 16 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 "cce/cce_def.hpp"
  20. #include "common/string_util.h"
  21. #include "common/util.h"
  22. #include "dlog/log.h"
  23. #include "framework/common/debug/ge_log.h"
  24. #include "ge/ge_api_error_codes.h"
  25. using cce::CC_STATUS_SUCCESS;
  26. using cce::ccStatus_t;
  27. #define GE_LOGE(...) DAV_LOGE("GE", __VA_ARGS__)
  28. // ge marco
  29. #define GE_LOGI_IF(condition, ...) \
  30. if ((condition)) { \
  31. GELOGI(__VA_ARGS__); \
  32. }
  33. #define GE_LOGW_IF(condition, ...) \
  34. if ((condition)) { \
  35. GELOGW(__VA_ARGS__); \
  36. }
  37. #define GE_LOGE_IF(condition, ...) \
  38. if ((condition)) { \
  39. GE_LOGE(__VA_ARGS__); \
  40. }
  41. // If expr is not SUCCESS, print the log and return the same value
  42. #define GE_CHK_STATUS_RET(expr, ...) \
  43. do { \
  44. const ge::Status _status = (expr); \
  45. if (_status != ge::SUCCESS) { \
  46. GE_LOGE(__VA_ARGS__); \
  47. return _status; \
  48. } \
  49. } while (0);
  50. // If expr is not SUCCESS, print the log and do not execute return
  51. #define GE_CHK_STATUS(expr, ...) \
  52. do { \
  53. const ge::Status _status = (expr); \
  54. if (_status != ge::SUCCESS) { \
  55. GE_LOGE(__VA_ARGS__); \
  56. } \
  57. } while (0);
  58. // If expr is not SUCCESS, return the same value
  59. #define GE_CHK_STATUS_RET_NOLOG(expr) \
  60. do { \
  61. const ge::Status _status = (expr); \
  62. if (_status != ge::SUCCESS) { \
  63. return _status; \
  64. } \
  65. } while (0);
  66. // If expr is not SUCCESS, print the log and execute a custom statement
  67. #define GE_CHK_STATUS_EXEC(expr, exec_expr, ...) \
  68. do { \
  69. const ge::Status _status = (expr); \
  70. GE_CHK_BOOL_EXEC(_status == SUCCESS, exec_expr, __VA_ARGS__); \
  71. } while (0);
  72. // If expr is not true, print the log and return the specified status
  73. #define GE_CHK_BOOL_RET_STATUS(expr, _status, ...) \
  74. do { \
  75. bool b = (expr); \
  76. if (!b) { \
  77. std::string msg; \
  78. (void)msg.append(ge::StringUtils::FormatString(__VA_ARGS__)); \
  79. (void)msg.append( \
  80. ge::StringUtils::FormatString(" Error Code:0x%X(%s)", _status, GET_ERRORNO_STR(_status).c_str())); \
  81. GE_LOGE("%s", msg.c_str()); \
  82. return _status; \
  83. } \
  84. } while (0);
  85. // If expr is not true, print the Info log and return the specified status
  86. #define GE_CHK_BOOL_RET_STATUS_LOGI(expr, _status, ...) \
  87. do { \
  88. bool b = (expr); \
  89. if (!b) { \
  90. std::string msg; \
  91. (void)msg.append(StringUtils::FormatString(__VA_ARGS__)); \
  92. (void)msg.append( \
  93. StringUtils::FormatString(" Check result false, status: 0x%X %s", _status, GET_ERRORNO_STR(_status).c_str())); \
  94. GELOGI("%s", msg.c_str()); \
  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. GE_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. GE_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. GE_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. GE_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. GE_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. GE_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. GE_LOGE("Call rt api failed, ret: 0x%X", _rt_ret); \
  212. return ge::RT_FAILED; \
  213. } \
  214. } while (0);
  215. // ------------------------cce related macro definitions----------------------------
  216. // If expr is not CC_STATUS_SUCCESS, print the log
  217. #define GE_CHK_CCE(expr) \
  218. do { \
  219. ccStatus_t _cc_ret = (expr); \
  220. if (_cc_ret != CC_STATUS_SUCCESS) { \
  221. GE_LOGE("Call cce api failed, ret: 0x%X", _cc_ret); \
  222. } \
  223. } while (0);
  224. // If expr is not CC_STATUS_SUCCESS, print the log and execute the exec_expr expression
  225. #define GE_CHK_CCE_EXEC(expr, exec_expr) \
  226. do { \
  227. ccStatus_t _cc_ret = (expr); \
  228. if (_cc_ret != CC_STATUS_SUCCESS) { \
  229. GE_LOGE("Call cce api failed, ret: 0x%X", _cc_ret); \
  230. exec_expr; \
  231. } \
  232. } while (0);
  233. // If expr is not CC_STATUS_SUCCESS, print the log and return
  234. #define GE_CHK_CCE_RET(expr) \
  235. do { \
  236. ccStatus_t _cc_ret = (expr); \
  237. if (_cc_ret != CC_STATUS_SUCCESS) { \
  238. GE_LOGE("Call cce api failed, ret: 0x%X", _cc_ret); \
  239. return ge::CCE_FAILED; \
  240. } \
  241. } while (0);
  242. // If expr is true, execute exec_expr without printing logs
  243. #define GE_IF_BOOL_EXEC(expr, exec_expr) \
  244. { \
  245. if (expr) { \
  246. exec_expr; \
  247. } \
  248. }
  249. // If make_shared is abnormal, print the log and execute the statement
  250. #define GE_MAKE_SHARED(exec_expr0, exec_expr1) \
  251. try { \
  252. exec_expr0; \
  253. } catch (const std::bad_alloc &) { \
  254. GE_LOGE("Make shared failed"); \
  255. exec_expr1; \
  256. }
  257. #define GE_CHECK_INT32_MUL_OVERFLOW(a, b, ...) \
  258. do { \
  259. if ((a) > 0) { \
  260. if ((b) > 0) { \
  261. if ((a) > (INT32_MAX / (b))) { \
  262. GE_LOGE(__VA_ARGS__); \
  263. return ge::FAILED; \
  264. } \
  265. } else { \
  266. if ((b) < (INT32_MIN / (a))) { \
  267. GE_LOGE(__VA_ARGS__); \
  268. return ge::FAILED; \
  269. } \
  270. } \
  271. } else { \
  272. if ((b) > 0) { \
  273. if ((a) < (INT32_MAX / (b))) { \
  274. GE_LOGE(__VA_ARGS__); \
  275. return ge::FAILED; \
  276. } \
  277. } else { \
  278. if (((a) != 0) && ((b) < (INT32_MAX / (a)))) { \
  279. GE_LOGE(__VA_ARGS__); \
  280. return ge::FAILED; \
  281. } \
  282. } \
  283. } \
  284. } while (0);
  285. #endif // INC_FRAMEWORK_COMMON_DEBUG_LOG_H_

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