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

5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #define GE_MODULE_NAME GE
  22. // trace status of log
  23. enum TraceStatus { TRACE_INIT = 0, TRACE_RUNNING, TRACE_WAITING, TRACE_STOP };
  24. #define GELOGE(ERROR_CODE, ...) GE_LOG_ERROR(GE_MODULE_NAME, ERROR_CODE, __VA_ARGS__)
  25. #define GELOGW(...) GE_LOG_WARN(GE_MODULE_NAME, __VA_ARGS__)
  26. #define GELOGI(...) GE_LOG_INFO(GE_MODULE_NAME, __VA_ARGS__)
  27. #define GELOGD(...) GE_LOG_DEBUG(GE_MODULE_NAME, __VA_ARGS__)
  28. #define GEEVENT(...) GE_LOG_EVENT(GE_MODULE_NAME, __VA_ARGS__)
  29. #define GELOGO(...) GE_LOG_OPLOG(GE_MODULE_NAME, __VA_ARGS__)
  30. #define GELOGT(VALUE, ...) GE_LOG_TRACE(GE_MODULE_NAME, VALUE, __VA_ARGS__)
  31. inline bool IsLogEnable(int module_name, int log_level) noexcept {
  32. int32_t enable_event = 0;
  33. int32_t dlog_level = dlog_getlevel(module_name, &enable_event);
  34. if (dlog_level <= log_level) {
  35. return true;
  36. }
  37. return false;
  38. }
  39. /*lint --emacro((773),GE_TIMESTAMP_START)*/
  40. /*lint -esym(773,GE_TIMESTAMP_START)*/
  41. #define GE_TIMESTAMP_START(stage) uint64_t startUsec_##stage = ge::GetCurrentTimestap()
  42. #define GE_TIMESTAMP_END(stage, stage_name) \
  43. do { \
  44. uint64_t endUsec_##stage = ge::GetCurrentTimestap(); \
  45. GEEVENT("[GEPERFTRACE] The time cost of %s is [%lu] micro second.", (stage_name), \
  46. (endUsec_##stage - startUsec_##stage)); \
  47. } while (0);
  48. #define GE_TIMESTAMP_CALLNUM_START(stage) \
  49. uint64_t startUsec_##stage = ge::GetCurrentTimestap(); \
  50. uint64_t call_num_of##stage = 0; \
  51. uint64_t time_of##stage = 0
  52. #define GE_TIMESTAMP_RESTART(stage) (startUsec_##stage = ge::GetCurrentTimestap())
  53. #define GE_TIMESTAMP_ADD(stage) \
  54. time_of##stage += ge::GetCurrentTimestap() - startUsec_##stage; \
  55. call_num_of##stage++
  56. #define GE_TIMESTAMP_CALLNUM_END(stage, stage_name) \
  57. GEEVENT("[GEPERFTRACE] The time cost of %s is [%lu] micro second, call num is %lu", (stage_name), time_of##stage, \
  58. call_num_of##stage)
  59. #define GE_LOG_ERROR(MOD_NAME, ERROR_CODE, fmt, ...) \
  60. dlog_error(static_cast<int>(MOD_NAME), "%s: ErrorNo: %d(%s) " fmt, __FUNCTION__, ERROR_CODE, \
  61. ((GE_GET_ERRORNO_STR(ERROR_CODE)).c_str()), ##__VA_ARGS__)
  62. #define GE_LOG_WARN(MOD_NAME, fmt, ...) \
  63. if (IsLogEnable(static_cast<int>(MOD_NAME), DLOG_WARN)) \
  64. dlog_warn(static_cast<int>(MOD_NAME), "%s:" fmt, __FUNCTION__, ##__VA_ARGS__)
  65. #define GE_LOG_INFO(MOD_NAME, fmt, ...) \
  66. if (IsLogEnable(static_cast<int>(MOD_NAME), DLOG_INFO)) \
  67. dlog_info(static_cast<int>(MOD_NAME), "%s:" fmt, __FUNCTION__, ##__VA_ARGS__)
  68. #define GE_LOG_DEBUG(MOD_NAME, fmt, ...) \
  69. if (IsLogEnable(static_cast<int>(MOD_NAME), DLOG_DEBUG)) \
  70. dlog_debug(static_cast<int>(MOD_NAME), "%s:" fmt, __FUNCTION__, ##__VA_ARGS__)
  71. #define GE_LOG_EVENT(MOD_NAME, fmt, ...) dlog_event(static_cast<int>(MOD_NAME), "%s:" fmt, __FUNCTION__, ##__VA_ARGS__)
  72. #define GE_LOG_OPLOG(MOD_NAME, fmt, ...) \
  73. Dlog(static_cast<int>(MOD_NAME), DLOG_OPLOG, "%s:" fmt, __FUNCTION__, ##__VA_ARGS__)
  74. #define GE_LOG_TRACE(MOD_NAME, 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>(MOD_NAME), DLOG_TRACE, &kv, 1, "%s:" fmt, __FUNCTION__, ##__VA_ARGS__); \
  83. } while (0)
  84. #endif // INC_FRAMEWORK_COMMON_DEBUG_GE_LOG_H_

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