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.8 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. // trace status of log
  34. enum TraceStatus { TRACE_INIT = 0, TRACE_RUNNING, TRACE_WAITING, TRACE_STOP };
  35. class GE_FUNC_VISIBILITY GeLog {
  36. public:
  37. static uint64_t GetTid() {
  38. #ifdef __GNUC__
  39. const uint64_t tid = static_cast<uint64_t>(syscall(__NR_gettid));
  40. #else
  41. const uint64_t tid = static_cast<uint64_t>(GetCurrentThreadId());
  42. #endif
  43. return tid;
  44. }
  45. };
  46. inline bool IsLogEnable(const int32_t module_name, const int32_t log_level) {
  47. const int32_t enable = CheckLogLevel(module_name, log_level);
  48. // 1:enable, 0:disable
  49. return (enable == 1);
  50. }
  51. #define GELOGE(ERROR_CODE, fmt, ...) \
  52. do { \
  53. dlog_error(GE_MODULE_NAME, "%" PRIu64 " %s: ErrorNo: %" PRIuLEAST8 "(%s) %s" fmt, GeLog::GetTid(), \
  54. &__FUNCTION__[0], (ERROR_CODE), ((GE_GET_ERRORNO_STR(ERROR_CODE)).c_str()), \
  55. ErrorManager::GetInstance().GetLogHeader().c_str(), ##__VA_ARGS__); \
  56. } while (false)
  57. #define GELOGW(fmt, ...) \
  58. do { \
  59. if (IsLogEnable(GE_MODULE_NAME, DLOG_WARN)) { \
  60. dlog_warn(GE_MODULE_NAME, "%" PRIu64 " %s:" fmt, GeLog::GetTid(), &__FUNCTION__[0], ##__VA_ARGS__); \
  61. } \
  62. } while (false)
  63. #define GELOGI(fmt, ...) \
  64. do { \
  65. if (IsLogEnable(GE_MODULE_NAME, DLOG_INFO)) { \
  66. dlog_info(GE_MODULE_NAME, "%" PRIu64 " %s:" fmt, GeLog::GetTid(), &__FUNCTION__[0], ##__VA_ARGS__); \
  67. } \
  68. } while (false)
  69. #define GELOGD(fmt, ...) \
  70. do { \
  71. if (IsLogEnable(GE_MODULE_NAME, DLOG_DEBUG)) { \
  72. dlog_debug(GE_MODULE_NAME, "%" PRIu64 " %s:" fmt, GeLog::GetTid(), &__FUNCTION__[0], ##__VA_ARGS__); \
  73. } \
  74. } while (false)
  75. #define GEEVENT(fmt, ...) \
  76. do { \
  77. dlog_event((RUN_LOG_MASK | GE_MODULE_NAME), "%" PRIu64 " %s:" fmt, GeLog::GetTid(), &__FUNCTION__[0], \
  78. ##__VA_ARGS__); \
  79. } while (false)
  80. #define GELOGT(VALUE, fmt, ...) \
  81. do { \
  82. TraceStatus stat = (VALUE); \
  83. const char_t *const TraceStatStr[] = {"INIT", "RUNNING", "WAITING", "STOP"}; \
  84. const int32_t idx = static_cast<int32_t>(stat); \
  85. char_t *k = const_cast<char_t *>("status"); \
  86. char_t *v = const_cast<char_t *>(TraceStatStr[idx]); \
  87. KeyValue kv = {k, v}; \
  88. DlogWithKV(GE_MODULE_NAME, DLOG_TRACE, &kv, 1, "%" PRIu64 " %s:" fmt, GeLog::GetTid(), &__FUNCTION__[0], \
  89. ##__VA_ARGS__); \
  90. } while (false)
  91. #define GE_LOG_ERROR(MOD_NAME, ERROR_CODE, fmt, ...) \
  92. do { \
  93. dlog_error((MOD_NAME), "%" PRIu64 " %s: ErrorNo: %" PRIuLEAST8 "(%s) %s" fmt, GeLog::GetTid(), &__FUNCTION__[0], \
  94. (ERROR_CODE), ((GE_GET_ERRORNO_STR(ERROR_CODE)).c_str()), \
  95. ErrorManager::GetInstance().GetLogHeader().c_str(), ##__VA_ARGS__); \
  96. } while (false)
  97. // print memory when it is greater than 1KB.
  98. #define GE_PRINT_DYNAMIC_MEMORY(FUNC, PURPOSE, SIZE) \
  99. do { \
  100. if (static_cast<size_t>(SIZE) > 1024UL) { \
  101. GELOGI("MallocMemory, func=%s, size=%" PRIu64 ", purpose=%s", (#FUNC), static_cast<size_t>(SIZE), (PURPOSE)); \
  102. } \
  103. } while (false)
  104. #ifdef __cplusplus
  105. }
  106. #endif
  107. #endif // INC_FRAMEWORK_COMMON_DEBUG_GE_LOG_H_

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