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.

subexpression_migration_pass.h 5.3 kB

4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_COMMON_SUBEXPRESSION_MIGRATION_H_
  17. #define GE_COMMON_SUBEXPRESSION_MIGRATION_H_
  18. #include "graph/types.h"
  19. #include "inc/graph_pass.h"
  20. #include <map>
  21. #include <set>
  22. #include <vector>
  23. #include <string>
  24. using std::set;
  25. using std::map;
  26. namespace ge {
  27. class SubexpressionMigrationPass : public GraphPass {
  28. public:
  29. Status Run(ComputeGraphPtr graph) override;
  30. private:
  31. ///
  32. /// @ingroup ge
  33. /// @brief Get all Data nodes for all subgraph.
  34. /// @param [in] graph: Root compute graph.
  35. /// @param [in] func_desc: functional OpDesc of Case.
  36. /// @param [out] graph_nodes: Data groups of subgraph.
  37. /// @return 0: SUCCESS / others: FAILED
  38. ///
  39. Status ClassifyDataNodes(const ComputeGraphPtr &graph, const OpDescPtr &func_desc,
  40. map<ComputeGraphPtr, map<uint32_t, NodePtr>> &graph_nodes);
  41. ///
  42. /// @ingroup ge
  43. /// @brief Get all Data nodes for all subgraph.
  44. /// @param [in] node: Node Directly to Data.
  45. /// @param [out] inputs: parent index of Input.
  46. /// @param [out] outputs: parent index of Output.
  47. /// @return true: SUCCESS / false: FAILED
  48. ///
  49. bool GetAssociatedNodes(const NodePtr &node, map<uint32_t, uint32_t> &inputs, map<uint32_t, uint32_t> &outputs);
  50. ///
  51. /// @ingroup ge
  52. /// @brief Get all Data nodes for all subgraph.
  53. /// @param [in] graph_nodes: Data groups of subgraph.
  54. /// @param [in] base_node: Data Node for migration.
  55. /// @param [in] node_idx: Parent index of Data node.
  56. /// @param [in] anchor_idx: Anchor index of node.
  57. /// @return true: Same / false: not same
  58. ///
  59. bool IsParallelNodeSame(const map<ComputeGraphPtr, map<uint32_t, NodePtr>> &graph_nodes,
  60. const NodePtr &base_node, uint32_t node_idx, uint32_t anchor_idx);
  61. ///
  62. /// @ingroup ge
  63. /// @brief Migration subgraph Node to Root
  64. /// @param [in] graph: Root compute graph.
  65. /// @param [in] func_node: functional Node of Case.
  66. /// @param [in] graph_nodes: Data groups of subgraph.
  67. /// @param [in] data_base: Data Node for migration.
  68. /// @param [in] data_idx: Data groups of subgraph.
  69. /// @return 0: SUCCESS / others: FAILED
  70. ///
  71. Status GraphNodeMigration(const ComputeGraphPtr &graph, const NodePtr &func_node,
  72. map<ComputeGraphPtr, map<uint32_t, NodePtr>> &graph_nodes,
  73. const NodePtr &data_base, uint32_t data_idx);
  74. ///
  75. /// @ingroup ge
  76. /// @brief Move node to Parent graph.
  77. /// @param [in] graph: Root compute graph.
  78. /// @param [in] func_node: functional Node of Case.
  79. /// @param [in] graph_nodes: Data groups of subgraph.
  80. /// @param [in] anchor_idx: anchor index of move Node.
  81. /// @param [in] inputs: Parent index of Node input.
  82. /// @param [in] outputs: Parent index of Node output.
  83. /// @return 0: SUCCESS / others: FAILED
  84. ///
  85. Status MoveNodeToParent(const ComputeGraphPtr &graph, const NodePtr &func_node,
  86. const map<ComputeGraphPtr, map<uint32_t, NodePtr>> &graph_nodes, uint32_t anchor_idx,
  87. const map<uint32_t, uint32_t> &inputs, const map<uint32_t, uint32_t> &outputs);
  88. ///
  89. /// @ingroup ge
  90. /// @brief Append Input Tensor for functional node.
  91. /// @param [in] graph_nodes: Data groups of subgraph.
  92. /// @param [in] func_node: functional Node of Case.
  93. /// @param [in] outputs: Parent index of Node output.
  94. /// @return 0: SUCCESS / others: FAILED
  95. ///
  96. Status AppendParallelNode(map<ComputeGraphPtr, map<uint32_t, NodePtr>> &graph_nodes,
  97. const NodePtr &func_node, map<uint32_t, uint32_t> &outputs);
  98. ///
  99. /// @ingroup ge
  100. /// @brief Delete Node from all subgraph.
  101. /// @param [in] graph_nodes: Data groups of subgraph.
  102. /// @param [in] detach: Node will move to parent.
  103. /// @param [in] outputs: Parent index of Node output.
  104. /// @return 0: SUCCESS / others: FAILED
  105. ///
  106. Status DetachParallelNode(const map<uint32_t, NodePtr> &graph_datas, const NodePtr &detach,
  107. const map<uint32_t, uint32_t> &outputs);
  108. ///
  109. /// @ingroup ge
  110. /// @brief Move Node to Parent Graph.
  111. /// @param [in] graph: Parent compute graph.
  112. /// @param [in] func_node: functional Node of Case.
  113. /// @param [in] attach: Node will move to parent.
  114. /// @param [in] inputs: Parent index of Node input.
  115. /// @param [in] outputs: Parent index of Node output.
  116. /// @return 0: SUCCESS / others: FAILED
  117. ///
  118. Status AttachParallelNode(const ComputeGraphPtr &graph, const NodePtr &func_node, const NodePtr &attach,
  119. const map<uint32_t, uint32_t> &inputs, const map<uint32_t, uint32_t> &outputs);
  120. bool migration_append_{false};
  121. };
  122. } // namespace ge
  123. #endif // GE_COMMON_SUBEXPRESSION_MIGRATION_H_

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