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

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