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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. #if !defined(__ANDROID__) && !defined(ANDROID)
  28. #define DOMI_LOGE(...) DAV_LOGE("DOMI", __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. std::string msg; \
  97. (void)msg.append(domi::StringUtils::FormatString(__VA_ARGS__)); \
  98. (void)msg.append( \
  99. domi::StringUtils::FormatString(" Error Code:0x%X(%s)", _status, GET_ERRORNO_STR(_status).c_str())); \
  100. DOMI_LOGE("%s", msg.c_str()); \
  101. return _status; \
  102. } \
  103. } while (0);
  104. // If expr is not true, print the log and return the specified status
  105. #define GE_CHK_BOOL_RET_STATUS_NOLOG(expr, _status, ...) \
  106. do { \
  107. bool b = (expr); \
  108. if (!b) { \
  109. return _status; \
  110. } \
  111. } while (0);
  112. // If expr is not true, print the log and execute a custom statement
  113. #define GE_CHK_BOOL_EXEC(expr, exec_expr, ...) \
  114. { \
  115. bool b = (expr); \
  116. if (!b) { \
  117. DOMI_LOGE(__VA_ARGS__); \
  118. exec_expr; \
  119. } \
  120. };
  121. // If expr is not true, print the log and execute a custom statement
  122. #define GE_CHK_BOOL_EXEC_WARN(expr, exec_expr, ...) \
  123. { \
  124. bool b = (expr); \
  125. if (!b) { \
  126. GELOGW(__VA_ARGS__); \
  127. exec_expr; \
  128. } \
  129. };
  130. // If expr is not true, print the log and execute a custom statement
  131. #define GE_CHK_BOOL_EXEC_INFO(expr, exec_expr, ...) \
  132. { \
  133. bool b = (expr); \
  134. if (!b) { \
  135. GELOGI(__VA_ARGS__); \
  136. exec_expr; \
  137. } \
  138. };
  139. // If expr is not true, print the log and execute a custom statement
  140. #define GE_CHK_BOOL_TRUE_EXEC_INFO(expr, exec_expr, ...) \
  141. { \
  142. bool b = (expr); \
  143. if (b) { \
  144. GELOGI(__VA_ARGS__); \
  145. exec_expr; \
  146. } \
  147. };
  148. // If expr is true, print logs and execute custom statements
  149. #define GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(expr, exec_expr, ...) \
  150. { \
  151. bool b = (expr); \
  152. if (b) { \
  153. DOMI_LOGE(__VA_ARGS__); \
  154. exec_expr; \
  155. } \
  156. };
  157. // If expr is true, print the Information log and execute a custom statement
  158. #define GE_CHK_TRUE_EXEC_INFO(expr, exec_expr, ...) \
  159. { \
  160. bool b = (expr); \
  161. if (b) { \
  162. GELOGI(__VA_ARGS__); \
  163. exec_expr; \
  164. } \
  165. };
  166. // If expr is not SUCCESS, print the log and execute the expression + return
  167. #define GE_CHK_BOOL_TRUE_RET_VOID(expr, exec_expr, ...) \
  168. { \
  169. bool b = (expr); \
  170. if (b) { \
  171. DOMI_LOGE(__VA_ARGS__); \
  172. exec_expr; \
  173. return; \
  174. } \
  175. };
  176. // If expr is not SUCCESS, print the log and execute the expression + return _status
  177. #define GE_CHK_BOOL_TRUE_EXEC_RET_STATUS(expr, _status, exec_expr, ...) \
  178. { \
  179. bool b = (expr); \
  180. if (b) { \
  181. DOMI_LOGE(__VA_ARGS__); \
  182. exec_expr; \
  183. return _status; \
  184. } \
  185. };
  186. // If expr is not true, execute a custom statement
  187. #define GE_CHK_BOOL_EXEC_NOLOG(expr, exec_expr) \
  188. { \
  189. bool b = (expr); \
  190. if (!b) { \
  191. exec_expr; \
  192. } \
  193. };
  194. // -----------------runtime related macro definitions-------------------------------
  195. // If expr is not RT_ERROR_NONE, print the log
  196. #define GE_CHK_RT(expr) \
  197. do { \
  198. rtError_t _rt_ret = (expr); \
  199. if (_rt_ret != RT_ERROR_NONE) { \
  200. DOMI_LOGE("Call rt api failed, ret: 0x%X", _rt_ret); \
  201. } \
  202. } while (0);
  203. // If expr is not RT_ERROR_NONE, print the log and execute the exec_expr expression
  204. #define GE_CHK_RT_EXEC(expr, exec_expr) \
  205. { \
  206. rtError_t _rt_ret = (expr); \
  207. if (_rt_ret != RT_ERROR_NONE) { \
  208. DOMI_LOGE("Call rt api failed, ret: 0x%X", _rt_ret); \
  209. exec_expr; \
  210. } \
  211. }
  212. // If expr is not RT_ERROR_NONE, print the log and return
  213. #define GE_CHK_RT_RET(expr) \
  214. do { \
  215. rtError_t _rt_ret = (expr); \
  216. if (_rt_ret != RT_ERROR_NONE) { \
  217. DOMI_LOGE("Call rt api failed, ret: 0x%X", _rt_ret); \
  218. return ge::RT_FAILED; \
  219. } \
  220. } while (0);
  221. // ------------------------cce related macro definitions----------------------------
  222. // If expr is not CC_STATUS_SUCCESS, print the log
  223. #define GE_CHK_CCE(expr) \
  224. do { \
  225. ccStatus_t _cc_ret = (expr); \
  226. if (_cc_ret != CC_STATUS_SUCCESS) { \
  227. DOMI_LOGE("Call cce api failed, ret: 0x%X", _cc_ret); \
  228. } \
  229. } while (0);
  230. // If expr is true, execute exec_expr without printing logs
  231. #define GE_IF_BOOL_EXEC(expr, exec_expr) \
  232. { \
  233. if (expr) { \
  234. exec_expr; \
  235. } \
  236. }
  237. // If make_shared is abnormal, print the log and execute the statement
  238. #define GE_MAKE_SHARED(exec_expr0, exec_expr1) \
  239. try { \
  240. exec_expr0; \
  241. } catch (const std::bad_alloc &) { \
  242. DOMI_LOGE("Make shared failed"); \
  243. exec_expr1; \
  244. }
  245. #endif // INC_FRAMEWORK_COMMON_DEBUG_LOG_H_

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