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.

graph_util.h 6.3 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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_GRAPH_GRAPH_UTIL_H_
  17. #define INC_GRAPH_GRAPH_UTIL_H_
  18. #include <string>
  19. #include "proto/om.pb.h"
  20. namespace ge {
  21. using AttrDefMap = ::google::protobuf::Map<::std::string, ::domi::AttrDef>;
  22. bool HasOpAttr(const OpDef *opdef, std::string attr_name);
  23. bool GetOpAttr(const std::string &key, int32_t *value, const OpDef *opdef);
  24. static const char OP_TYPE_DATA[] = "Data";
  25. static const char OP_TYPE_INPUT[] = "Input";
  26. static const char ATTR_KEY_INPUT_FORMAT[] = "input_format";
  27. static const char ATTR_KEY_OUTPUT_FORMAT[] = "output_format";
  28. static const char OP_TYPE_ANN_DATA[] = "AnnData";
  29. } // namespace ge
  30. #if !defined(__ANDROID__) && !defined(ANDROID)
  31. #include "toolchain/slog.h"
  32. const char levelStr[4][8] = {"ERROR", "WARN", "INFO", "DEBUG"};
  33. #else
  34. #include <syslog.h>
  35. #include <utils/Log.h>
  36. const char levelStr[8][8] = {"EMERG", "ALERT", "CRIT", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG"};
  37. #endif
  38. #ifdef _MSC_VER
  39. #define FUNC_NAME __FUNCTION__
  40. #else
  41. #define FUNC_NAME __PRETTY_FUNCTION__
  42. #endif
  43. #if !defined(__ANDROID__) && !defined(ANDROID)
  44. #define D_GRAPH_LOGI(MOD_NAME, fmt, ...) \
  45. dlog_info(FMK, "%s:%s:%d:" #fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
  46. #define D_GRAPH_LOGW(MOD_NAME, fmt, ...) \
  47. dlog_warn(FMK, "%s:%s:%d:" #fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
  48. #define D_GRAPH_LOGE(MOD_NAME, fmt, ...) \
  49. dlog_error(FMK, "%s:%s:%d:" #fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
  50. #else
  51. #define D_GRAPH_LOG(level, format, ...) \
  52. do { \
  53. { \
  54. fprintf(stdout, "[%s] [%s] [%s] [%s] [%s:%d] " format "\n", "", "GRAPH", levelStr[level], __FUNCTION__, \
  55. __FILE__, __LINE__, ##__VA_ARGS__); \
  56. syslog(level, "%s %s:%d] [%s] %s " format "\n", "", __FILE__, __LINE__, "OPTIMIZER", __FUNCTION__, \
  57. ##__VA_ARGS__); \
  58. } \
  59. } while (0)
  60. #define D_GRAPH_LOGI(MOD_NAME, fmt, ...) D_GRAPH_LOG(ANDROID_LOG_INFO, #fmt, ##__VA_ARGS__)
  61. #define D_GRAPH_LOGW(MOD_NAME, fmt, ...) D_GRAPH_LOG(ANDROID_LOG_INFO, #fmt, ##__VA_ARGS__)
  62. #define D_GRAPH_LOGE(MOD_NAME, fmt, ...) D_GRAPH_LOG(ANDROID_LOG_INFO, #fmt, ##__VA_ARGS__)
  63. #endif
  64. #if !defined(__ANDROID__) && !defined(ANDROID)
  65. #define GRAPH_LOGI(...) D_GRAPH_LOGI(GRAPH_MOD_NAME, __VA_ARGS__)
  66. #define GRAPH_LOGW(...) D_GRAPH_LOGW(GRAPH_MOD_NAME, __VA_ARGS__)
  67. #define GRAPH_LOGE(...) D_GRAPH_LOGE(GRAPH_MOD_NAME, __VA_ARGS__)
  68. #else
  69. #define GRAPH_LOG(level, format, ...) \
  70. do { \
  71. { \
  72. fprintf(stdout, "[%s] [%s] [%s] [%s] [%s:%d] " format "\n", "", "GRAPH", levelStr[level], __FUNCTION__, \
  73. __FILE__, __LINE__, ##__VA_ARGS__); \
  74. syslog(level, "%s %s:%d] [%s] %s " format "\n", "", __FILE__, __LINE__, "OPTIMIZER", __FUNCTION__, \
  75. ##__VA_ARGS__); \
  76. } \
  77. } while (0)
  78. #define GRAPH_LOGI(fmt, ...) GRAPH_LOG(ANDROID_LOG_INFO, #fmt, ##__VA_ARGS__)
  79. #define GRAPH_LOGW(fmt, ...) GRAPH_LOG(ANDROID_LOG_INFO, #fmt, ##__VA_ARGS__)
  80. #define GRAPH_LOGE(fmt, ...) GRAPH_LOG(ANDROID_LOG_INFO, #fmt, ##__VA_ARGS__)
  81. #endif
  82. #define GRAPH_CHK_STATUS_RET_NOLOG(expr) \
  83. do { \
  84. const domi::graphStatus _status = (expr); \
  85. if (_status != domi::GRAPH_SUCCESS) { \
  86. return _status; \
  87. } \
  88. } while (0)
  89. #define GRAPH_CHK_BOOL_RET_STATUS(expr, _status, ...) \
  90. do { \
  91. bool b = (expr); \
  92. if (!b) { \
  93. GRAPH_LOGE(__VA_ARGS__); \
  94. return _status; \
  95. } \
  96. } while (0)
  97. #define GRAPH_CHK_BOOL_EXEC_NOLOG(expr, exec_expr) \
  98. { \
  99. bool b = (expr); \
  100. if (!b) { \
  101. exec_expr; \
  102. } \
  103. };
  104. #define GRAPH_IF_BOOL_EXEC(expr, exec_expr) \
  105. { \
  106. if (expr) { \
  107. exec_expr; \
  108. } \
  109. }
  110. #define GRAPH_RETURN_WITH_LOG_IF_ERROR(expr, ...) \
  111. do { \
  112. const ::domi::graphStatus _status = (expr); \
  113. if (_status) { \
  114. GRAPH_LOGE(__VA_ARGS__); \
  115. return _status; \
  116. } \
  117. } while (0)
  118. #endif // INC_GRAPH_GRAPH_UTIL_H_

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

Contributors (1)