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.

ge_log.h 6.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * Copyright 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 COMMON_GRAPH_DEBUG_GE_LOG_H_
  17. #define COMMON_GRAPH_DEBUG_GE_LOG_H_
  18. #include "graph/ge_error_codes.h"
  19. #include "framework/common/debug/ge_log.h"
  20. #define GE_LOGE(fmt, ...) GE_LOG_ERROR(GE_MODULE_NAME, ge::FAILED, fmt, ##__VA_ARGS__)
  21. #define GE_LOGI_IF(condition, ...) \
  22. if ((condition)) { \
  23. GELOGI(__VA_ARGS__); \
  24. }
  25. #define GE_LOGW_IF(condition, ...) \
  26. if ((condition)) { \
  27. GELOGW(__VA_ARGS__); \
  28. }
  29. #define GE_LOGE_IF(condition, ...) \
  30. if ((condition)) { \
  31. GELOGE(ge::FAILED, __VA_ARGS__); \
  32. }
  33. #define GE_CHK_STATUS_RET_NOLOG(expr) \
  34. do { \
  35. const ge::graphStatus _status = (expr); \
  36. if (ge::SUCCESS != _status) { \
  37. return _status; \
  38. } \
  39. } while (0)
  40. #define GE_CHK_BOOL_RET_STATUS(expr, _status, ...) \
  41. do { \
  42. bool b = (expr); \
  43. if (!b) { \
  44. GELOGE(ge::FAILED, __VA_ARGS__); \
  45. return _status; \
  46. } \
  47. } while (0)
  48. #define GE_CHK_BOOL_EXEC_NOLOG(expr, exec_expr) \
  49. { \
  50. bool b = (expr); \
  51. if (!b) { \
  52. exec_expr; \
  53. } \
  54. }
  55. #define GE_IF_BOOL_EXEC(expr, exec_expr) \
  56. { \
  57. if (expr) { \
  58. exec_expr; \
  59. } \
  60. }
  61. #define GE_RETURN_WITH_LOG_IF_ERROR(expr, ...) \
  62. do { \
  63. const ge::graphStatus _status = (expr); \
  64. if (_status) { \
  65. GELOGE(ge::FAILED, __VA_ARGS__); \
  66. return _status; \
  67. } \
  68. } while (0)
  69. // If expr is true, the log is printed and a custom statement is executed
  70. #define GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(expr, exec_expr, ...) \
  71. { \
  72. bool b = (expr); \
  73. if (b) { \
  74. GELOGE(ge::FAILED, __VA_ARGS__); \
  75. exec_expr; \
  76. } \
  77. }
  78. // Only check error log
  79. #define GE_CHK_BOOL_ONLY_LOG(expr, ...) \
  80. do { \
  81. bool b = (expr); \
  82. if (!b) { \
  83. GELOGI(__VA_ARGS__); \
  84. } \
  85. } while (0)
  86. // If expr is not true, do not print the log and return the specified status
  87. #define GE_CHK_BOOL_RET_STATUS_NOLOG(expr, _status, ...) \
  88. do { \
  89. bool b = (expr); \
  90. if (!b) { \
  91. return _status; \
  92. } \
  93. } while (0)
  94. // If expr is not true, the log is printed and a custom statement is executed
  95. #define GE_CHK_BOOL_EXEC(expr, exec_expr, ...) \
  96. { \
  97. bool b = (expr); \
  98. if (!b) { \
  99. GELOGE(ge::FAILED, __VA_ARGS__); \
  100. exec_expr; \
  101. } \
  102. }
  103. // If expr is not true, the log is printed and a custom statement is executed
  104. #define GE_CHK_BOOL_EXEC_INFO(expr, exec_expr, ...) \
  105. { \
  106. bool b = (expr); \
  107. if (!b) { \
  108. GELOGI(__VA_ARGS__); \
  109. exec_expr; \
  110. } \
  111. }
  112. // If expr is not GRAPH_SUCCESS, print the log and return the same value
  113. #define GE_CHK_STATUS_RET(expr, ...) \
  114. do { \
  115. const ge::graphStatus _status = (expr); \
  116. if (ge::SUCCESS != _status) { \
  117. GELOGE(ge::FAILED, __VA_ARGS__); \
  118. return _status; \
  119. } \
  120. } while (0)
  121. #define GE_MAKE_SHARED(exec_expr0, exec_expr1) \
  122. try { \
  123. exec_expr0; \
  124. } catch (...) { \
  125. GELOGE(ge::FAILED, "Make shared failed"); \
  126. exec_expr1; \
  127. }
  128. #endif // COMMON_GRAPH_DEBUG_GE_LOG_H_

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