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.5 kB

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

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