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.

flow_ctrl_pass.h 5.2 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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_FLOW_CTRL_PASS_H_
  17. #define GE_GRAPH_PASSES_FLOW_CTRL_PASS_H_
  18. #include <string>
  19. #include <vector>
  20. #include "common/ge_inner_error_codes.h"
  21. #include "inc/graph_pass.h"
  22. namespace ge {
  23. ///
  24. /// Add flow control to the computeGraph
  25. ///
  26. class FlowCtrlPass : public GraphPass {
  27. public:
  28. ///
  29. /// Add flow control to the computeGraph.
  30. /// @param compute_graph graph
  31. /// @return SUCCESS: do success
  32. /// NOT_CHANGED : do nothing
  33. /// Other: failed
  34. ///
  35. Status Run(ComputeGraphPtr compute_graph) override;
  36. private:
  37. ///
  38. /// Universal insert node to graph.
  39. /// @param compute_graph graph
  40. /// @param node_type inserted node type
  41. /// @param node_name inserted node name
  42. /// @param input_list input desc list
  43. /// @param output_list output desc list
  44. /// @return the inserted node. if insert failed return nullptr.
  45. ///
  46. NodePtr InsertOp(ComputeGraphPtr &compute_graph, const string &node_type, const string &node_name,
  47. const std::vector<GeTensorDesc> &input_list, const std::vector<GeTensorDesc> &output_list);
  48. ///
  49. /// used for insert assign and assign add node.
  50. /// include add input desc info.
  51. /// @param compute_graph graph
  52. /// @param node_type node type(assign/assignAdd)
  53. /// @param node_name node name
  54. /// @param ref_node assign input0
  55. /// @param value_node assign input1
  56. /// @return the inserted node. if insert failed return nullptr.
  57. ///
  58. NodePtr InsertAssignOp(ComputeGraphPtr &compute_graph, const string &node_type, const string &node_name,
  59. const NodePtr &ref_node, const NodePtr &value_node);
  60. ///
  61. /// insert StreamSwitch to graph.
  62. /// @param compute_graph graph
  63. /// @param switch_name inserted StreamSwitch node name
  64. /// @param loop_cond loop condition
  65. /// @param iter_per_loop iter per loop
  66. /// @return the inserted node. if insert failed return nullptr.
  67. ///
  68. NodePtr InsertStreamSwitchOp(ComputeGraphPtr &compute_graph, const string &switch_name, const NodePtr &loop_cond,
  69. const NodePtr &iter_per_loop);
  70. ///
  71. /// check and add variable node to graph.
  72. /// if the variable is exists, do nothing.
  73. /// @param compute_graph graph
  74. /// @param name inserted variable node name
  75. /// @return the variable node. if insert failed return nullptr.
  76. ///
  77. NodePtr AddVariableNode(ComputeGraphPtr &compute_graph, const string &name);
  78. ///
  79. /// add global step variable node to graph.
  80. /// if the variable is exists, do nothing.
  81. /// @param compute_graph graph
  82. /// @return SUCCESS: do success
  83. /// Other: failed
  84. ///
  85. Status AddGlobalStepVariableNode(ComputeGraphPtr &compute_graph);
  86. ///
  87. /// create switch true branch for big cycle.
  88. /// @param compute_graph graph
  89. /// @param loop_cond_node loop condition node
  90. /// @param loop_increment_node loop increment node
  91. /// @param switch_node switch node
  92. /// @return SUCCESS: do success
  93. /// Other: failed
  94. ///
  95. Status CreateIterCtrlTrueBranch(ComputeGraphPtr &compute_graph, const NodePtr &loop_cond_node,
  96. const NodePtr &loop_increment_node, NodePtr &switch_node);
  97. ///
  98. /// create switch false branch for big cycle.
  99. /// @param compute_graph graph
  100. /// @param loop_cond_node loop condition node
  101. /// @param loop_reset_node loop reset node
  102. /// @param switch_node switch node
  103. /// @return SUCCESS: do success
  104. /// Other: failed
  105. ///
  106. Status CreateIterCtrlFalseBranch(ComputeGraphPtr &compute_graph, const NodePtr &loop_cond_node,
  107. const NodePtr &loop_reset_node, NodePtr &switch_node);
  108. ///
  109. /// add Fp/Bp iterator ctrl nodes(big cycle).
  110. /// @param compute_graph graph
  111. /// @param pre_node pre node(netoutput node)
  112. /// @return SUCCESS: do success
  113. /// Other: failed
  114. ///
  115. Status AddFpBpIteratorCtrl(ComputeGraphPtr &compute_graph, NodePtr &pre_node);
  116. ///
  117. /// add special iterator ctrl nodes(small cycle).
  118. /// @param compute_graph graph
  119. /// @param loop_after_node pre node(iterate node)
  120. /// @return SUCCESS: do success
  121. /// Other: failed
  122. ///
  123. Status AddSpecialNodeIteratorCtrl(ComputeGraphPtr &compute_graph, NodePtr &loop_after_node);
  124. ///
  125. /// add special iterator ctrl nodes(small cycle).
  126. /// @param compute_graph graph
  127. /// @return true: two or more dataSet exist
  128. /// false: only one dataSet exist
  129. ///
  130. bool CheckMultiDataSet(ComputeGraphPtr &compute_graph);
  131. };
  132. } // namespace ge
  133. #endif // GE_GRAPH_PASSES_FLOW_CTRL_PASS_H_

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