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

4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. ///
  35. /// @ingroup ge
  36. /// @brief Create nodes for root graph.
  37. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  38. /// @return 0: SUCCESS / others: FAILED
  39. ///
  40. Status CreateRootGraph(const ComputeGraphPtr &graph);
  41. ///
  42. /// @ingroup ge
  43. /// @brief Create index data node for root graph.
  44. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  45. /// @param [in] NodePtr node: index data node.
  46. /// @return 0: SUCCESS / others: FAILED
  47. ///
  48. Status CreateIndexDataNode(const ComputeGraphPtr &graph, NodePtr &node);
  49. ///
  50. /// @ingroup ge
  51. /// @brief Create index const node for root graph.
  52. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  53. /// @param [in] NodePtr node: index const node.
  54. /// @return 0: SUCCESS / others: FAILED
  55. ///
  56. Status CreateIndexConstNode(const ComputeGraphPtr &graph, NodePtr &node);
  57. ///
  58. /// @ingroup ge
  59. /// @brief Create index node for root graph.
  60. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  61. /// @return 0: SUCCESS / others: FAILED
  62. ///
  63. Status CreateIndexNode(const ComputeGraphPtr &graph);
  64. ///
  65. /// @ingroup ge
  66. /// @brief Create input node for root graph.
  67. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  68. /// @return 0: SUCCESS / others: FAILED
  69. ///
  70. Status CreateInputNode(const ComputeGraphPtr &graph);
  71. ///
  72. /// @ingroup ge
  73. /// @brief Create Const node for root graph.
  74. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  75. /// @return 0: SUCCESS / others: FAILED
  76. ///
  77. Status CreateConstNode(const ComputeGraphPtr &graph);
  78. ///
  79. /// @ingroup ge
  80. /// @brief Create output node for root graph.
  81. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  82. /// @return 0: SUCCESS / others: FAILED
  83. ///
  84. Status CreateOutputNode(const ComputeGraphPtr &graph);
  85. ///
  86. /// @ingroup ge
  87. /// @brief Set max shape to Data node in root graph.
  88. /// @param [in] const NodePtr &data: data in Root/Case graph.
  89. /// @return 0: SUCCESS / others: FAILED
  90. ///
  91. Status SetMaxShapeToData(const NodePtr &data);
  92. ///
  93. /// @ingroup ge
  94. /// @brief Set shape to Data node in branch.
  95. /// @param [in] const NodePtr &data: data in branch.
  96. /// @param [in] size_t index: The batch index.
  97. /// @return 0: SUCCESS / others: FAILED
  98. ///
  99. Status UpdateShapeToData(const NodePtr &data, size_t index);
  100. ///
  101. /// @ingroup ge
  102. /// @brief Set max shape to Data node in root graph.
  103. /// @param [in] const std::vector<int64_t> &shapes: dims of shape.
  104. /// @param [in] const NodePtr &data: data in Root/Case graph.
  105. /// @param [in] GeShape &data_shape: dims of data node.
  106. /// @return 0: SUCCESS / others: FAILED
  107. ///
  108. Status SetShapeToData(const std::vector<int64_t> &shapes, const NodePtr &data, GeShape &data_shape);
  109. ///
  110. /// @ingroup ge
  111. /// @brief Create nodes for root graph.
  112. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  113. /// @param [in] const ComputeGraphPtr &branch: original graph.
  114. /// @return 0: SUCCESS / others: FAILED
  115. ///
  116. Status CreateSubgraphs(const ComputeGraphPtr &graph, const ComputeGraphPtr &branch);
  117. ///
  118. /// @ingroup ge
  119. /// @brief Assign parent index for branches.
  120. /// @param [in] const ComputeGraphPtr &graph: Root/Case graph.
  121. /// @return 0: SUCCESS / others: FAILED
  122. ///
  123. Status PostProcSubgraph(const ComputeGraphPtr &graph);
  124. ///
  125. /// @ingroup ge
  126. /// @brief Remove subgraph supend output anchor.
  127. /// @param [in] ComputeGraphPtr &graph: Parent compute graph.
  128. /// @return 0: SUCCESS / others: FAILED
  129. ///
  130. Status PruneDirectOutput(const ComputeGraphPtr &graph);
  131. ///
  132. /// @ingroup ge
  133. /// @brief Update subgraph suspend output tensor.
  134. /// @param [in] parent_index: parent index for check.
  135. /// @param [in] unused_num: total unused tensor.
  136. /// @return 0: SUCCESS / others: FAILED
  137. ///
  138. Status UpdateOutputTensor(uint32_t parent_index, uint32_t unused_num);
  139. std::string session_graph_id_;
  140. std::vector<std::vector<int64_t>> batch_shapes_;
  141. std::vector<NodePtr> all_data_nodes_;
  142. std::vector<NodePtr> all_const_nodes_;
  143. std::vector<NodePtr> all_output_nodes_;
  144. std::map<uint32_t, std::string> direct_output_;
  145. std::map<ComputeGraphPtr, NodePtr> all_branch_output_;
  146. std::map<string, vector<vector<int64_t>>> data_to_dynamic_info_;
  147. NodePtr case_node_;
  148. };
  149. } // namespace ge
  150. #endif // GE_GRAPH_PASSES_MULTI_BATCH_CLONE_PASS_H_

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