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.

multi_batch_clone_pass.h 6.9 kB

4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 GE_GRAPH_PASSES_MULTI_BATCH_CLONE_PASS_H_
  17. #define GE_GRAPH_PASSES_MULTI_BATCH_CLONE_PASS_H_
  18. #include <map>
  19. #include <string>
  20. #include <vector>
  21. #include "inc/graph_pass.h"
  22. namespace ge {
  23. class MultiBatchClonePass : public GraphPass {
  24. public:
  25. Status Run(ComputeGraphPtr graph);
  26. private:
  27. ///
  28. /// @ingroup ge
  29. /// @brief Collect input output node from original graph.
  30. /// @param [in] const ComputeGraphPtr &graph: original graph.
  31. /// @return 0: SUCCESS / others: FAILED
  32. ///
  33. Status CollectIoNodes(const ComputeGraphPtr &graph);
  34. Status InitParamsOfGetNext(const NodePtr &node);
  35. ///
  36. /// @ingroup ge
  37. /// @brief Create nodes for root graph.
  38. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  39. /// @return 0: SUCCESS / others: FAILED
  40. ///
  41. Status CreateRootGraph(const ComputeGraphPtr &graph);
  42. ///
  43. /// @ingroup ge
  44. /// @brief Create index data node for root graph.
  45. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  46. /// @param [in] NodePtr shape_node: index data node, DATA or GETDYNAMICDIMS type.
  47. /// @return 0: SUCCESS / others: FAILED
  48. ///
  49. Status CreateIndexDataNode(const ComputeGraphPtr &graph, NodePtr &shape_node);
  50. Status CreateGetDynamicDimsNode(const ComputeGraphPtr &graph, NodePtr &shape_node);
  51. ///
  52. /// @ingroup ge
  53. /// @brief Create index const node for root graph.
  54. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  55. /// @param [in] NodePtr node: index const node.
  56. /// @return 0: SUCCESS / others: FAILED
  57. ///
  58. Status CreateIndexConstNode(const ComputeGraphPtr &graph, NodePtr &node);
  59. ///
  60. /// @ingroup ge
  61. /// @brief Create index node for root graph.
  62. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  63. /// @return 0: SUCCESS / others: FAILED
  64. ///
  65. Status CreateIndexNode(const ComputeGraphPtr &graph);
  66. Status AddAttrForGetDynamicDims(const NodePtr &shape_node);
  67. Status LinkGetNextToGetDynamicDims(const NodePtr &getnext_node, const NodePtr &shape_node);
  68. Status LinkGetDynamicDimsToNetOutput(const NodePtr &output_node);
  69. ///
  70. /// @ingroup ge
  71. /// @brief Create input node for root graph.
  72. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  73. /// @return 0: SUCCESS / others: FAILED
  74. ///
  75. Status CreateInputNode(const ComputeGraphPtr &graph);
  76. Status LinkEdgeForGetNext(const NodePtr &getnext_node, size_t &case_input_index);
  77. ///
  78. /// @ingroup ge
  79. /// @brief Set max shape to Data node in root graph.
  80. /// @param [in] const NodePtr &data: data in Root/Case graph.
  81. /// @return 0: SUCCESS / others: FAILED
  82. ///
  83. Status SetMaxShape(const NodePtr &data);
  84. Status SetMaxShapeToData(const NodePtr &node, size_t out_anchor_index);
  85. ///
  86. /// @ingroup ge
  87. /// @brief Set max shape to Data/GetNext node in root graph.
  88. /// @param [in] const std::vector<int64_t> &shapes: dims of shape.
  89. /// @param [in] const NodePtr &data: data in Root/Case graph.
  90. /// @param [in] GeShape &data_shape: dims of data node.
  91. /// @param [in] size_t out_anchor_index: out anchor index of data node.
  92. /// @return 0: SUCCESS / others: FAILED
  93. ///
  94. Status SetShapeToData(const std::vector<int64_t> &shapes, const NodePtr &data, GeShape &data_shape,
  95. size_t out_anchor_index);
  96. Status UpdateShapeOfShapeNode(const NodePtr &node, size_t out_anchor_index);
  97. ///
  98. /// @ingroup ge
  99. /// @brief Create Const node for root graph.
  100. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  101. /// @return 0: SUCCESS / others: FAILED
  102. ///
  103. Status CreateConstNode(const ComputeGraphPtr &graph);
  104. void ChangeConstToData();
  105. ///
  106. /// @ingroup ge
  107. /// @brief Create output node for root graph.
  108. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  109. /// @return 0: SUCCESS / others: FAILED
  110. ///
  111. Status CreateOutputNode(const ComputeGraphPtr &graph);
  112. ///
  113. /// @ingroup ge
  114. /// @brief Update Data node in Subgraph.
  115. /// @param [in] const NodePtr &data: data in Subgraph.
  116. /// @param [in] size_t batch_index: The batch index.
  117. /// @return 0: SUCCESS / others: FAILED
  118. ///
  119. Status UpdateSubgraphData(const NodePtr &data, size_t batch_index);
  120. ///
  121. /// @ingroup ge
  122. /// @brief Update output_node in Subgraph.
  123. /// @param [in] const NodePtr &output_node: output_node in Subgraph.
  124. /// @return 0: SUCCESS / others: FAILED
  125. ///
  126. Status UpdateSubgraphOutput(const NodePtr &output_node);
  127. ///
  128. /// @ingroup ge
  129. /// @brief Create nodes for root graph.
  130. /// @param [in] const ComputeGraphPtr &graph: Original graph.
  131. /// @return 0: SUCCESS / others: FAILED
  132. ///
  133. Status CreateOriGraph(const ComputeGraphPtr &graph);
  134. NodePtr CreateDataNode(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_data_anchor, size_t data_index);
  135. ///
  136. /// @ingroup ge
  137. /// @brief Create nodes for root graph.
  138. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  139. /// @param [in] const ComputeGraphPtr &branch: original graph.
  140. /// @return 0: SUCCESS / others: FAILED
  141. ///
  142. Status CreateSubgraphs(const ComputeGraphPtr &graph, const ComputeGraphPtr &branch);
  143. ///
  144. /// @ingroup ge
  145. /// @brief Remove subgraph supend output anchor.
  146. /// @param [in] ComputeGraphPtr &graph: Parent compute graph.
  147. /// @return 0: SUCCESS / others: FAILED
  148. ///
  149. Status PruneDirectOutput(const ComputeGraphPtr &graph);
  150. ///
  151. /// @ingroup ge
  152. /// @brief Update subgraph suspend output tensor.
  153. /// @param [in] parent_index: parent index for check.
  154. /// @param [in] unused_num: total unused tensor.
  155. /// @return 0: SUCCESS / others: FAILED
  156. ///
  157. Status UpdateOutputTensor(uint32_t parent_index, uint32_t unused_num);
  158. Status CheckAndParseDynamicData();
  159. std::string session_graph_id_;
  160. std::vector<std::vector<int64_t>> batch_shapes_;
  161. std::vector<NodePtr> all_data_nodes_;
  162. std::vector<NodePtr> all_const_nodes_;
  163. std::vector<NodePtr> all_output_nodes_;
  164. std::map<uint32_t, std::string> direct_output_;
  165. std::map<ComputeGraphPtr, NodePtr> all_branch_output_;
  166. std::map<string, vector<vector<int64_t>>> data_to_dynamic_info_;
  167. NodePtr case_node_;
  168. size_t data_count_from_getnext_ = 0;
  169. bool getnext_sink_dynamic_dims_ = false;
  170. NodePtr shape_node_;
  171. std::set<NodePtr> out_control_nodes_;
  172. };
  173. } // namespace ge
  174. #endif // GE_GRAPH_PASSES_MULTI_BATCH_CLONE_PASS_H_

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