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

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