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

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