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 7.2 kB

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

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