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.

attr_value_util.h 9.5 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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_OP_ATTR_VALUE_UTIL_H_
  17. #define INC_FRAMEWORK_COMMON_OP_ATTR_VALUE_UTIL_H_
  18. #include <google/protobuf/map.h>
  19. #include <unordered_map>
  20. #include <string>
  21. #include "graph/debug/ge_attr_define.h"
  22. #include "proto/om.pb.h"
  23. using domi::AttrDef;
  24. using domi::AttrDef_ListValue;
  25. using domi::ModelDef;
  26. using domi::NamedAttrs;
  27. using domi::OpDef;
  28. namespace ge {
  29. using AttrDefMap = ::google::protobuf::Map<::std::string, ::domi::AttrDef>;
  30. using AttrDefPair = ::google::protobuf::MapPair<std::string, domi::AttrDef>;
  31. void AddOpAttr(const std::string &key, AttrDef &attr, OpDef *opdef);
  32. // DEFINE_ADD_ATTR_VALUE
  33. void AddOpAttr(const std::string &key, const std::string &value, AttrDefMap *attrs);
  34. void AddOpAttr(const std::string &key, const char *value, AttrDefMap *attrs);
  35. void AddOpAttr(const char *key, const char *value, AttrDefMap *attrs);
  36. void AddOpAttr(const std::string &key, const uint32_t value, AttrDefMap *attrs);
  37. void AddOpAttr(const std::string &key, const int32_t value, AttrDefMap *attrs);
  38. void AddOpAttr(const std::string &key, const int64_t value, AttrDefMap *attrs);
  39. void AddOpAttr(const std::string &key, const float value, AttrDefMap *attrs);
  40. void AddOpAttr(const std::string &key, const double value, AttrDefMap *attrs);
  41. void AddOpAttr(const std::string &key, const bool value, AttrDefMap *attrs);
  42. void AddOpAttr(const std::string &key, const AttrDef_ListValue &value, AttrDefMap *attrs);
  43. // DEFINE_ADD_ATTR_VALUE
  44. void AddOpAttr(const std::string &key, const std::string &value, OpDef *opdef);
  45. void AddOpAttr(const std::string &key, const char *value, OpDef *opdef);
  46. void AddOpAttr(const char *key, const char *value, OpDef *opdef);
  47. void AddOpAttr(const std::string &key, const uint32_t value, OpDef *opdef);
  48. void AddOpAttr(const std::string &key, const int32_t value, OpDef *opdef);
  49. void AddOpAttr(const std::string &key, const int64_t value, OpDef *opdef);
  50. void AddOpAttr(const std::string &key, const float value, OpDef *opdef);
  51. void AddOpAttr(const std::string &key, const double value, OpDef *opdef);
  52. void AddOpAttr(const std::string &key, const bool value, OpDef *opdef);
  53. void AddOpAttr(const std::string &key, const AttrDef_ListValue &value, OpDef *opdef);
  54. void AddOpBytesAttr(const std::string &key, const void *value, size_t size, OpDef *opdef);
  55. // DEFINE_ADD_ATTR_VALUE_LIST
  56. void AddOpAttrList(const std::string &key, const double value, AttrDefMap *attrs);
  57. void AddOpAttrList(const std::string &key, const float value, AttrDefMap *attrs);
  58. void AddOpAttrList(const std::string &key, const uint32_t value, AttrDefMap *attrs);
  59. void AddOpAttrList(const std::string &key, const int32_t value, AttrDefMap *attrs);
  60. void AddOpAttrList(const std::string &key, const std::string value, AttrDefMap *attrs);
  61. void AddOpAttrList(const std::string &key, const double value, OpDef *opdef);
  62. void AddOpAttrList(const std::string &key, const float value, OpDef *opdef);
  63. void AddOpAttrList(const std::string &key, const uint32_t value, OpDef *opdef);
  64. void AddOpAttrList(const std::string &key, const int32_t value, OpDef *opdef);
  65. void AddOpAttrList(const std::string &key, const bool value, OpDef *opdef);
  66. void AddOpAttrList(const std::string &key, const int64_t value, OpDef *opdef);
  67. void AddOpAttrList(const std::string &key, const std::string &value, OpDef *opdef);
  68. bool GetOpAttr(const std::string &key, std::string *value, const OpDef *opdef);
  69. bool GetOpAttr(const std::string &key, int32_t *value, const OpDef *opdef);
  70. bool GetOpAttr(const std::string &key, int64_t *value, const OpDef *opdef);
  71. bool GetOpAttr(const std::string &key, uint32_t *value, const OpDef *opdef);
  72. bool GetOpAttr(const std::string &key, float *value, const OpDef *opdef);
  73. bool GetOpAttr(const std::string &key, double *value, const OpDef *opdef);
  74. bool GetOpAttr(const std::string &key, bool *value, const OpDef *opdef);
  75. bool GetOpAttr(const std::string &key, AttrDef_ListValue *value, const OpDef *opdef);
  76. uint32_t GetOpAttrListSize(const std::string &key, std::string value, const OpDef *opdef);
  77. uint32_t GetOpAttrListSize(const std::string &key, int32_t value, const OpDef *opdef);
  78. uint32_t GetOpAttrListSize(const std::string &key, int64_t value, const OpDef *opdef);
  79. uint32_t GetOpAttrListSize(const std::string &key, uint32_t value, const OpDef *opdef);
  80. uint32_t GetOpAttrListSize(const std::string &key, float value, const OpDef *opdef);
  81. uint32_t GetOpAttrListSize(const std::string &key, double value, const OpDef *opdef);
  82. uint32_t GetOpAttrListSize(const std::string &key, bool value, const OpDef *opdef);
  83. bool GetBytesAttr(const std::string &key, std::string *value, const OpDef *opdef);
  84. bool GetBytesAttr(const std::string &key, std::string *value, const ModelDef *model_def);
  85. void AddModelAttr(const std::string &key, const std::string &value, ModelDef *model_def);
  86. void AddModelAttr(const std::string &key, const char *value, ModelDef *model_def);
  87. void AddModelAttr(const char *key, const char *value, ModelDef *model_def);
  88. void AddModelAttr(const std::string &key, const uint32_t value, ModelDef *model_def);
  89. void AddModelAttr(const std::string &key, const int32_t value, ModelDef *model_def);
  90. void AddModelAttr(const std::string &key, const int64_t value, ModelDef *model_def);
  91. void AddModelAttr(const std::string &key, const float value, ModelDef *model_def);
  92. void AddModelAttr(const std::string &key, const double value, ModelDef *model_def);
  93. void AddModelAttr(const std::string &key, const bool value, ModelDef *model_def);
  94. void AddModelAttr(const std::string &key, const void *value, size_t size, ModelDef *model_def);
  95. void AddModelAttr(const std::string &key, const AttrDef_ListValue &value, ModelDef *model_def);
  96. void AddModelAttrList(const std::string &key, const double value, ModelDef *model_def);
  97. void AddModelAttrList(const std::string &key, const float value, ModelDef *model_def);
  98. void AddModelAttrList(const std::string &key, const uint32_t value, ModelDef *model_def);
  99. void AddModelAttrList(const std::string &key, const int32_t value, ModelDef *model_def);
  100. void AddModelAttrList(const std::string &key, const std::string &value, ModelDef *model_def);
  101. bool GetModelAttr(const std::string &key, std::string *value, const ModelDef *model_def);
  102. bool GetModelAttr(const std::string &key, int32_t *value, const ModelDef *model_def);
  103. bool GetModelAttr(const std::string &key, int64_t *value, const ModelDef *model_def);
  104. bool GetModelAttr(const std::string &key, uint32_t *value, const ModelDef *model_def);
  105. bool GetModelAttr(const std::string &key, float *value, const ModelDef *model_def);
  106. bool GetModelAttr(const std::string &key, double *value, const ModelDef *model_def);
  107. bool GetModelAttr(const std::string &key, bool *value, const ModelDef *model_def);
  108. bool GetModelAttr(const std::string &key, AttrDef_ListValue *value, const ModelDef *model_def);
  109. bool HasOpAttr(const OpDef *opdef, const std::string &attr_name);
  110. void SetAttrDef(const std::string &value, AttrDef *out);
  111. void SetAttrDef(const char *value, AttrDef *out);
  112. void SetAttrDef(const uint32_t value, AttrDef *out);
  113. void SetAttrDef(const int32_t value, AttrDef *out);
  114. void SetAttrDef(const float value, AttrDef *out);
  115. void SetAttrDef(const double value, AttrDef *out);
  116. void SetAttrDef(const bool value, AttrDef *out);
  117. void SetAttrList(const std::string &value, AttrDef *out);
  118. void SetAttrList(const bool value, AttrDef *out);
  119. void SetAttrList(const float value, AttrDef *out);
  120. void SetAttrList(const double value, AttrDef *out);
  121. void SetAttrList(const uint32_t value, AttrDef *out);
  122. bool GetAttrDefValue(const std::string &key, std::string *value, const AttrDefMap &attr);
  123. bool GetAttrDefValue(const std::string &key, int32_t *value, const AttrDefMap &attr);
  124. bool GetAttrDefValue(const std::string &key, int64_t *value, const AttrDefMap &attr);
  125. bool GetAttrDefValue(const std::string &key, uint32_t *value, const AttrDefMap &attr);
  126. bool GetAttrDefValue(const std::string &key, float *value, const AttrDefMap &attr);
  127. bool GetAttrDefValue(const std::string &key, double *value, const AttrDefMap &attr);
  128. bool GetAttrDefValue(const std::string &key, bool *value, const AttrDefMap &attr);
  129. bool GetAttrDefValue(const std::string &key, AttrDef_ListValue *value, const AttrDefMap &attr);
  130. bool GetAttrDefValue(const std::string &key, NamedAttrs *&value, AttrDefMap *attr);
  131. bool GetAttrDefValue(const std::string &key, const NamedAttrs *&value, const AttrDefMap &attr);
  132. bool GetAttrDefListValue(const std::string &key, int idx, int32_t *value, const AttrDefMap &attr);
  133. bool GetAttrDefListValue(const std::string &key, int idx, uint32_t *value, const AttrDefMap &attr);
  134. bool GetAttrDefListValue(const std::string &key, int idx, float *value, const AttrDefMap &attr);
  135. bool GetAttrDefListValue(const std::string &key, int idx, double *value, const AttrDefMap &attr);
  136. } // namespace ge
  137. #endif // INC_FRAMEWORK_COMMON_OP_ATTR_VALUE_UTIL_H_

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