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.

net_output_pass.h 7.9 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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_NET_OUTPUT_PASS_H_
  17. #define GE_GRAPH_PASSES_NET_OUTPUT_PASS_H_
  18. #include <map>
  19. #include <set>
  20. #include <utility>
  21. #include <vector>
  22. #include "external/graph/types.h"
  23. #include "inc/graph_pass.h"
  24. namespace ge {
  25. struct RetvalInfo {
  26. NodePtr output_node;
  27. int32_t node_output_index;
  28. int parent_node_index;
  29. };
  30. class NetOutputPass : public GraphPass {
  31. public:
  32. ///
  33. /// Entry of the NetOutputPass optimizer
  34. /// @param [in] graph: Input ComputeGraph
  35. /// @return SUCCESS: Execution succeed
  36. /// @return OTHERS: Execution failed
  37. /// @author
  38. ///
  39. Status Run(ge::ComputeGraphPtr graph) override;
  40. private:
  41. ///
  42. /// The graph of identifies the network output with
  43. /// the _Retval node, we determine if the input node is a network output here.
  44. /// @param [in] node: Input node
  45. /// @param [in/out] retval_node_index_map: Obtained output node <NodePtr, index> pair
  46. /// @return SUCCESS: Execution succeed
  47. /// @return OTHERS: Execution failed
  48. /// @author
  49. ///
  50. Status GetRetvalOutputInfo(const ge::NodePtr &node, std::map<int32_t, RetvalInfo> &retval_node_index_map);
  51. ///
  52. /// Get the output node of the graph
  53. /// @param [in] graph: Input ComputeGraph
  54. /// @param [in/out] output_nodes_info: Obtained output node <NodePtr, index> pair
  55. /// @return SUCCESS: Execution succeed
  56. /// @return OTHERS: Execution failed
  57. /// @author
  58. ///
  59. Status GetOutputNode(const ge::ComputeGraphPtr &graph, std::vector<RetvalInfo> &output_nodes_info);
  60. ///
  61. /// Get the output node of the graph
  62. /// @param [in] graph: Input ComputeGraph
  63. /// @param [in/out] net_output_desc: output netoutput node <NodePtr, index> pair
  64. /// @return SUCCESS: Execution succeed
  65. /// @return OTHERS: Execution failed
  66. /// @author
  67. ///
  68. Status CreateNetOutputNode(OpDescPtr &net_output_desc, const ge::ComputeGraphPtr &graph);
  69. ///
  70. /// Check if the network output node is legal
  71. /// @param [in] graph: Input ComputeGraph
  72. /// @param [in] outputs: Output node information of graph
  73. /// @return SUCCESS: Execution succeed
  74. /// @return OTHERS: Execution failed
  75. /// @author
  76. ///
  77. Status CheckOutputNodeInfo(const ComputeGraphPtr &graph, const std::vector<RetvalInfo> &outputs);
  78. ///
  79. /// Set input and output for the NetOutput node
  80. /// @param [in] graph: Input ComputeGraph
  81. /// @param [in] net_output_desc: OpDesc of the NetOutput node
  82. /// @param [in] output_nodes_info: RetvalInfos of the NetOutput
  83. /// @return void
  84. /// @author
  85. ///
  86. void AddInOutForNetOutputOp(const ComputeGraphPtr &graph, OpDescPtr &net_output_desc,
  87. vector<RetvalInfo> &output_nodes_info);
  88. ///
  89. /// Delete unwanted _Retval/Save/Summary nodes
  90. /// @param [in] graph: Input ComputeGraph
  91. /// @return SUCCESS: Execution succeed
  92. /// @return OTHERS: Execution failed
  93. /// @author
  94. ///
  95. Status RemoveUnusedNode(const ge::ComputeGraphPtr &graph);
  96. ///
  97. /// Update the output/input tensor description of the NetOutput node
  98. /// @param [in] net_output: The netOutput node
  99. /// @return SUCCESS: Execution succeed
  100. /// @return OTHERS: Execution failed
  101. /// @author
  102. ///
  103. Status UpdateNetOutputDesc(const ge::NodePtr &net_output);
  104. ///
  105. /// Add ctrl edge from target node to netoutput node
  106. /// @param [in] net_output: The netOutput node
  107. /// @return SUCCESS: Execution succeed
  108. /// @return OTHERS: Execution failed
  109. /// @author
  110. ///
  111. Status AddCtrlEdgeForTargets(const ge::NodePtr &net_out_node);
  112. ///
  113. /// Remove invalid node and duplicated node of user set targets
  114. /// @param [in] : compute graph
  115. /// @return SUCCESS: Execution succeed
  116. /// @return OTHERS: Execution failed
  117. /// @author
  118. ///
  119. void SaveAndRemoveTargets(const ge::ComputeGraphPtr &graph);
  120. ///
  121. /// Add edges for the NetOutput node
  122. /// @param [in] graph: Input ComputeGraph
  123. /// @param [in] net_out_node: The netOutput node
  124. /// @param [in] output_nodes_info: Output node <NodePtr, index> pair
  125. /// @return SUCCESS: Execution succeed
  126. /// @return OTHERS: Execution failed
  127. /// @author
  128. ///
  129. Status AddEdgesForNetOutput(const ge::ComputeGraphPtr &graph, const ge::NodePtr &net_out_node,
  130. const std::vector<RetvalInfo> &output_nodes_info);
  131. ///
  132. /// Add ctrl edges for leaf node
  133. /// @param [in] graph: Input ComputeGraph
  134. /// @param [in] net_out_node: The netOutput node
  135. /// @return SUCCESS: Execution succeed
  136. /// @return OTHERS: Execution failed
  137. /// @author
  138. ///
  139. Status AddCtrlEdgesBetweenLeafAndNetOutput(const ge::ComputeGraphPtr &graph, const ge::NodePtr &net_out_node);
  140. ///
  141. /// Unlink all connections between target nodes and netoutput node
  142. /// @param [in] graph: ComputeGraph
  143. /// @param [in] net_out_node: The netOutput node
  144. /// @return SUCCESS: Execution succeed
  145. /// @return OTHERS: Execution failed
  146. /// @author
  147. ///
  148. Status UnLink(const ge::ComputeGraphPtr &graph, const ge::NodePtr &net_out_node);
  149. ///
  150. /// Unlink data connections between target nodes and netoutput node
  151. /// @param [in] graph: ComputeGraph
  152. /// @param [in] net_out_node: The netOutput node
  153. /// @return SUCCESS: Execution succeed
  154. /// @return OTHERS: Execution failed
  155. /// @author
  156. ///
  157. Status UnLinkDataAnchorOfNetoutput(const ge::ComputeGraphPtr &graph, const ge::NodePtr &net_out_node);
  158. ///
  159. /// Unlink control connections between target nodes and netoutput node
  160. /// @param [in] graph: ComputeGraph
  161. /// @param [in] net_out_node: The netOutput node
  162. /// @return SUCCESS: Execution succeed
  163. /// @return OTHERS: Execution failed
  164. /// @author
  165. ///
  166. Status UnLinkControlAnchorOfNetoutput(const ge::ComputeGraphPtr &graph, const ge::NodePtr &net_out_node);
  167. ///
  168. /// if user have set netoutput node , do relative process
  169. /// @param [in] graph: ComputeGraph
  170. /// @param [in] net_out_node: The netOutput node
  171. /// @return SUCCESS: Execution succeed
  172. /// @return OTHERS: Execution failed
  173. /// @author
  174. ///
  175. Status ProcessWithNetoutput(const ge::ComputeGraphPtr &graph, const ge::NodePtr &output_node);
  176. ///
  177. /// check node wether exist in user-set output nodes
  178. /// @param [in] graph: ComputeGraph
  179. /// @param [in] net_out_node: The netOutput node
  180. /// @return SUCCESS: Execution succeed
  181. /// @return OTHERS: Execution failed
  182. /// @author
  183. ///
  184. bool CheckNodeIsInOutputNodes(const ge::ComputeGraphPtr &graph, const ge::NodePtr &node);
  185. ///
  186. /// Add netoutput node to graph with output node infos
  187. /// @param [in] graph: ComputeGraph
  188. /// @param [in] output_node: shared_ptr to netoutput node
  189. /// @return SUCCESS: Execution succeed
  190. /// @return OTHERS: Execution failed
  191. /// @author
  192. ///
  193. Status AddNetOutputNodeToGraph(const ge::ComputeGraphPtr &graph, NodePtr &output_node);
  194. ///
  195. /// Add user_def_dtype & format for netoutput node
  196. /// @param [in] output_node: The netOutput node
  197. /// @return SUCCESS: Execution succeed
  198. /// @return OTHERS: Execution failed
  199. /// @author
  200. ///
  201. Status SetUserDefDTypeAndFormatFromAtcParams(const ge::NodePtr &output_node);
  202. bool is_include_special_node_ = false;
  203. std::set<NodePtr> targets_;
  204. friend class ReUpdateNetOutputPass;
  205. bool is_user_define_ouput_nodes = false;
  206. };
  207. } // namespace ge
  208. #endif // GE_GRAPH_PASSES_NET_OUTPUT_PASS_H_

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