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.2 kB

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

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