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.

model_parser.h 5.4 kB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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_OMG_PARSER_MODEL_PARSER_H_
  17. #define INC_FRAMEWORK_OMG_PARSER_MODEL_PARSER_H_
  18. #include <google/protobuf/message.h>
  19. #include "framework/omg/parser/parser_types.h"
  20. #include "framework/omg/omg_inner_types.h"
  21. #include "graph/attr_value.h"
  22. #include "graph/compute_graph.h"
  23. #include "graph/ge_tensor.h"
  24. #include "graph/graph.h"
  25. #include "graph/op_desc.h"
  26. #include "graph/utils/attr_utils.h"
  27. #include "graph/utils/graph_utils.h"
  28. #include "graph/utils/op_desc_utils.h"
  29. #include "graph/utils/tensor_utils.h"
  30. namespace domi {
  31. using GetGraphCallback = std::function<std::unique_ptr<google::protobuf::Message>(
  32. const google::protobuf::Message *root_proto, const std::string &graph)>;
  33. using GetGraphCallbackV2 = std::function<std::string(const std::string &subgraph_name)>;
  34. class GE_FUNC_VISIBILITY ModelParser {
  35. public:
  36. ModelParser() {}
  37. virtual ~ModelParser() {}
  38. /**
  39. * @ingroup domi_omg
  40. * @brief Analyze network model data
  41. * @param [in] file Network model file path
  42. * @param [in|out] graph Save the network information after analysis
  43. * @return SUCCESS
  44. * @return Others failed
  45. */
  46. virtual Status Parse(const char *file, ge::Graph &graph) = 0;
  47. /**
  48. * @ingroup domi_omg
  49. * @brief Parse relevant data from memory and save it to graph
  50. * @param [in] input Model file memory data
  51. * @param [in] input Model file memory size
  52. * @param [in|out] graph A graph for saving the model information after analysis
  53. * @return SUCCESS
  54. * @return FAILED
  55. * @author
  56. */
  57. virtual Status ParseFromMemory(const char *data, uint32_t size, ge::ComputeGraphPtr &graph) = 0;
  58. /**
  59. * @ingroup domi_omg
  60. * @brief Parse relevant data from memory and save it to graph
  61. * @param [in] input Model file memory data
  62. * @param [in] input Model file memory size
  63. * @param [in|out] graph A graph for saving the model information after analysis
  64. * @return SUCCESS
  65. * @return FAILED
  66. * @author
  67. */
  68. virtual Status ParseFromMemory(const char *data, uint32_t size, ge::Graph &graph) = 0;
  69. /**
  70. * @ingroup domi_omg
  71. * @brief Analyze network model data
  72. * @param [in] proto network model
  73. * @param [in|out] graph Save the network information after analysis
  74. * @return SUCCESS
  75. * @return Others failed
  76. */
  77. virtual Status ParseProto(const google::protobuf::Message *proto, ge::ComputeGraphPtr &graph) = 0;
  78. /**
  79. * @ingroup domi_omg
  80. * @brief Analyze callback model data in subgraph
  81. * @param [in] proto network model
  82. * @param [in] callback callback of subgraph
  83. * @param [in|out] graph Save the network information after analysis
  84. * @return SUCCESS
  85. * @return Others failed
  86. */
  87. virtual Status ParseProtoWithSubgraph(const google::protobuf::Message *proto, GetGraphCallback callback,
  88. ge::ComputeGraphPtr &graph) = 0;
  89. /**
  90. * @ingroup domi_omg
  91. * @brief Convert model files to JSON format
  92. * @param [in] model_file Model file path to be converted
  93. * @param [out] json_file Converted JSON file path
  94. * @return SUCCESS
  95. * @return Others failed
  96. */
  97. virtual Status ToJson(const char *model_file, const char *json_file) {
  98. (void)model_file;
  99. (void)json_file;
  100. return SUCCESS;
  101. }
  102. /*
  103. * @ingroup domi_omg
  104. * @brief Convert network data type
  105. * @param [in] type Data type to be converted
  106. * @return ge::DataType
  107. */
  108. virtual ge::DataType ConvertToGeDataType(const uint32_t type) = 0;
  109. virtual Status ParseAllGraph(const google::protobuf::Message *root_proto, ge::ComputeGraphPtr &root_graph) = 0;
  110. /**
  111. * @ingroup domi_omg
  112. * @brief Analyze network model data
  113. * @param [in] proto serialized network model
  114. * @param [in|out] graph Save the network information after analysis
  115. * @return SUCCESS
  116. * @return Others failed
  117. */
  118. virtual Status ParseProto(const std::string &serialized_proto, ge::ComputeGraphPtr &graph) {
  119. (void)serialized_proto;
  120. (void)graph;
  121. return UNSUPPORTED;
  122. }
  123. /**
  124. * @ingroup domi_omg
  125. * @brief Analyze callback model data in subgraph
  126. * @param [in] proto serialized network model
  127. * @param [in] callback callback of subgraph
  128. * @param [in|out] graph Save the network information after analysis
  129. * @return SUCCESS
  130. * @return Others failed
  131. */
  132. virtual Status ParseProtoWithSubgraph(const std::string &serialized_proto, GetGraphCallbackV2 callback,
  133. ge::ComputeGraphPtr &graph) {
  134. (void)serialized_proto;
  135. (void)callback;
  136. (void)graph;
  137. return UNSUPPORTED;
  138. }
  139. virtual bool HasError() {
  140. return false;
  141. }
  142. virtual Status Save(const std::string &file) {
  143. (void)file;
  144. return SUCCESS;
  145. }
  146. virtual void Clear(){};
  147. };
  148. } // namespace domi
  149. #endif // INC_FRAMEWORK_OMG_PARSER_MODEL_PARSER_H_

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