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 4.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * Copyright 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_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. class ModelParser {
  37. public:
  38. ModelParser() {}
  39. virtual ~ModelParser() {}
  40. /**
  41. * @ingroup domi_omg
  42. * @brief Analyze network model data
  43. * @param [in] file Network model file path
  44. * @param [in|out] graph Save the network information after analysis
  45. * @return SUCCESS
  46. * @return Others failed
  47. */
  48. virtual Status Parse(const char *file, ge::Graph &graph) = 0;
  49. /**
  50. * @ingroup domi_omg
  51. * @brief Parse relevant data from memory and save it to graph
  52. * @param [in] input Model file memory data
  53. * @param [in] input Model file memory size
  54. * @param [in|out] graph A graph for saving the model information after analysis
  55. * @return SUCCESS
  56. * @return FAILED
  57. * @author
  58. */
  59. virtual Status ParseFromMemory(const char *data, uint32_t size, ge::ComputeGraphPtr &graph) = 0;
  60. #ifndef ONLY_COMPILE_OPEN_SRC
  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. #endif
  73. /**
  74. * @ingroup domi_omg
  75. * @brief Analyze network model data
  76. * @param [in] proto network model
  77. * @param [in|out] graph Save the network information after analysis
  78. * @return SUCCESS
  79. * @return Others failed
  80. */
  81. virtual Status ParseProto(const google::protobuf::Message *proto, ge::ComputeGraphPtr &graph) = 0;
  82. /**
  83. * @ingroup domi_omg
  84. * @brief Analyze callback model data in subgraph
  85. * @param [in] proto network model
  86. * @param [in] callback callback of subgraph
  87. * @param [in|out] graph Save the network information after analysis
  88. * @return SUCCESS
  89. * @return Others failed
  90. */
  91. virtual Status ParseProtoWithSubgraph(const google::protobuf::Message *proto, GetGraphCallback callback,
  92. ge::ComputeGraphPtr &graph) = 0;
  93. /**
  94. * @ingroup domi_omg
  95. * @brief Convert model files to JSON format
  96. * @param [in] model_file Model file path to be converted
  97. * @param [out] json_file Converted JSON file path
  98. * @return SUCCESS
  99. * @return Others failed
  100. */
  101. virtual Status ToJson(const char *model_file, const char *json_file) { return domi::SUCCESS; }
  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. } // namespace domi
  112. #endif // INC_FRAMEWORK_OMG_PARSER_MODEL_PARSER_H_

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