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.9 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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_GE_LOG_H_
  17. #define INC_FRAMEWORK_COMMON_DEBUG_GE_LOG_H_
  18. #include <cstdint>
  19. #include "framework/common/ge_inner_error_codes.h"
  20. #include "toolchain/slog.h"
  21. #ifdef __GNUC__
  22. #include <unistd.h>
  23. #include <sys/syscall.h>
  24. #else
  25. #include "mmpa/mmpa_api.h"
  26. #endif
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #define GE_MODULE_NAME static_cast<int>(GE)
  31. // trace status of log
  32. enum TraceStatus { TRACE_INIT = 0, TRACE_RUNNING, TRACE_WAITING, TRACE_STOP };
  33. #define GELOGE(ERROR_CODE, ...) GE_LOG_ERROR(GE_MODULE_NAME, ERROR_CODE, __VA_ARGS__)
  34. #define GELOGW(...) GE_LOG_WARN(GE_MODULE_NAME, __VA_ARGS__)
  35. #define GELOGI(...) GE_LOG_INFO(GE_MODULE_NAME, __VA_ARGS__)
  36. #define GELOGD(...) GE_LOG_DEBUG(GE_MODULE_NAME, __VA_ARGS__)
  37. #define GEEVENT(...) GE_LOG_EVENT(GE_MODULE_NAME, __VA_ARGS__)
  38. #define GELOGO(...) GE_LOG_OPLOG(GE_MODULE_NAME, __VA_ARGS__)
  39. #define GELOGT(VALUE, ...) GE_LOG_TRACE(GE_MODULE_NAME, VALUE, __VA_ARGS__)
  40. class GeLog {
  41. public:
  42. #ifdef __GNUC__
  43. static pid_t GetTid() {
  44. thread_local static pid_t tid = syscall(__NR_gettid);
  45. return tid;
  46. }
  47. #else
  48. static int GetTid() {
  49. thread_local static int tid = static_cast<int>(GetCurrentThreadId());
  50. return tid;
  51. }
  52. #endif
  53. };
  54. inline bool IsLogEnable(int module_name, int log_level) {
  55. int32_t enable = CheckLogLevel(module_name, log_level);
  56. // 1:enable, 0:disable
  57. if (enable == 1) {
  58. return true;
  59. }
  60. return false;
  61. }
  62. #define GELOGE(ERROR_CODE, fmt, ...) \
  63. dlog_error(GE_MODULE_NAME, "%lu %s: ErrorNo: %d(%s) " fmt, GeLog::GetTid(), __FUNCTION__, ERROR_CODE, \
  64. ((GE_GET_ERRORNO_STR(ERROR_CODE)).c_str()), ##__VA_ARGS__)
  65. #define GELOGW(fmt, ...) \
  66. if (IsLogEnable(GE_MODULE_NAME, DLOG_WARN)) dlog_warn(GE_MODULE_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__)
  67. #define GELOGI(fmt, ...) \
  68. if (IsLogEnable(GE_MODULE_NAME, DLOG_INFO)) dlog_info(GE_MODULE_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__)
  69. #define GELOGD(fmt, ...) \
  70. if (IsLogEnable(GE_MODULE_NAME, DLOG_DEBUG)) dlog_debug(GE_MODULE_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__)
  71. #define GEEVENT(fmt, ...) dlog_event(GE_MODULE_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__)
  72. #define GELOGO(fmt, ...) \
  73. Dlog(GE_MODULE_NAME, DLOG_OPLOG, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__)
  74. #define GELOGT(VALUE, fmt, ...) \
  75. do { \
  76. TraceStatus stat = VALUE; \
  77. const char *const TraceStatStr[] = {"INIT", "RUNNING", "WAITING", "STOP"}; \
  78. int idx = static_cast<int>(stat); \
  79. char *k = const_cast<char *>("status"); \
  80. char *v = const_cast<char *>(TraceStatStr[idx]); \
  81. KeyValue kv = {k, v}; \
  82. DlogWithKV(static_cast<int>(GE_MODULE_NAME), DLOG_TRACE, &kv, 1, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__); \
  83. } while (0)
  84. #define GE_LOG_ERROR(MOD_NAME, ERROR_CODE, fmt, ...) \
  85. dlog_error(MOD_NAME, "%lu %s: ErrorNo: %d(%s) " fmt, GeLog::GetTid(), __FUNCTION__, ERROR_CODE, \
  86. ((GE_GET_ERRORNO_STR(ERROR_CODE)).c_str()), ##__VA_ARGS__)
  87. #define GE_LOG_WARN(MOD_NAME, fmt, ...) \
  88. if (IsLogEnable(MOD_NAME, DLOG_WARN)) dlog_warn(MOD_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__)
  89. #define GE_LOG_INFO(MOD_NAME, fmt, ...) \
  90. if (IsLogEnable(MOD_NAME, DLOG_INFO)) dlog_info(MOD_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__)
  91. #define GE_LOG_DEBUG(MOD_NAME, fmt, ...) \
  92. if (IsLogEnable(MOD_NAME, DLOG_DEBUG)) dlog_debug(MOD_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__)
  93. #define GE_LOG_EVENT(MOD_NAME, fmt, ...) dlog_event(MOD_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__)
  94. #define GE_LOG_OPLOG(MOD_NAME, fmt, ...) \
  95. Dlog(MOD_NAME, DLOG_OPLOG, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__)
  96. #define GE_LOG_TRACE(MOD_NAME, value, fmt, ...) \
  97. do { \
  98. TraceStatus stat = value; \
  99. const char *const TraceStatStr[] = {"INIT", "RUNNING", "WAITING", "STOP"}; \
  100. int idx = static_cast<int>(stat); \
  101. char *k = const_cast<char *>("status"); \
  102. char *v = const_cast<char *>(TraceStatStr[idx]); \
  103. KeyValue kv = {k, v}; \
  104. DlogWithKV(static_cast<int>(MOD_NAME), DLOG_TRACE, &kv, 1, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__); \
  105. } while (0)
  106. // print memory when it is greater than 1KB.
  107. #define GE_PRINT_DYNAMIC_MEMORY(FUNC, PURPOSE, SIZE) \
  108. do { \
  109. if ((SIZE) > 1024) { \
  110. GELOGI("MallocMemory, func=%s, size=%zu, purpose=%s", (#FUNC), static_cast<size_t>(SIZE), (PURPOSE)); \
  111. } \
  112. } while (0);
  113. #ifdef __cplusplus
  114. }
  115. #endif
  116. #endif // INC_FRAMEWORK_COMMON_DEBUG_GE_LOG_H_

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