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

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

Contributors (1)