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.

subgraph_const_migration_pass.h 5.6 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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_SUBGRAPH_CONST_MIGRATION_H_
  17. #define GE_COMMON_SUBGRAPH_CONST_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 SubgraphConstMigrationPass : public GraphPass {
  28. public:
  29. Status Run(ComputeGraphPtr graph) override;
  30. private:
  31. ///
  32. /// @ingroup ge
  33. /// @brief Get all Const/Data nodes for all subgraph.
  34. /// @param [in] graph: Root compute graph.
  35. /// @param [in] func_desc: functional OpDesc of Case.
  36. /// @param [out] all_const_nodes: Const groups of subgraph.
  37. /// @param [out] all_data_nodes: Data groups of subgraph.
  38. /// @return 0: SUCCESS / others: FAILED
  39. ///
  40. Status ClassifyGraphNodes(const ComputeGraphPtr &graph, const OpDescPtr &func_desc,
  41. map<ComputeGraphPtr, map<string, NodePtr>> &all_const_nodes,
  42. map<ComputeGraphPtr, map<uint32_t, NodePtr>> &all_data_nodes);
  43. ///
  44. /// @ingroup ge
  45. /// @brief Get parent_index for Const node migration.
  46. /// @param [in] all_data_nodes: Data groups of subgraph.
  47. /// @param [in] const_node: Const node will process.
  48. /// @param [out] parent_index: parent index for replace Data.
  49. /// @return true: SUCCESS / false: FAILED
  50. ///
  51. bool GetAssociatedNodes(const map<ComputeGraphPtr, map<uint32_t, NodePtr>> &all_data_nodes,
  52. const NodePtr &const_node, uint32_t &parent_index);
  53. ///
  54. /// @ingroup ge
  55. /// @brief Check parallel node is same for all subgraph.
  56. /// @param [in] all_const_nodes: Const groups of subgraph.
  57. /// @param [in] const_node: Const Node for migration.
  58. /// @param [in] node_key: Key of Const node.
  59. /// @return true: Same / false: not same
  60. ///
  61. bool IsParallelNodeSame(const map<ComputeGraphPtr, map<string, NodePtr>> &all_const_nodes,
  62. const NodePtr &const_node, const string &node_key);
  63. ///
  64. /// @ingroup ge
  65. /// @brief Migration subgraph Node to Root
  66. /// @param [in] graph: Root compute graph.
  67. /// @param [in] func_node: functional Node of Case.
  68. /// @param [in] all_const_nodes: Const groups of subgraph.
  69. /// @param [in] all_data_nodes: Data groups of subgraph.
  70. /// @param [in] const_node: Const Node for migration.
  71. /// @param [in] node_key: Key of Const node for migration.
  72. /// @return 0: SUCCESS / others: FAILED
  73. ///
  74. Status GraphNodeMigration(const ComputeGraphPtr &graph, const NodePtr &func_node,
  75. const map<ComputeGraphPtr, map<string, NodePtr>> &all_const_nodes,
  76. map<ComputeGraphPtr, map<uint32_t, NodePtr>> &all_data_nodes,
  77. const NodePtr &const_node, const string &node_key);
  78. ///
  79. /// @ingroup ge
  80. /// @brief Move node to Parent graph.
  81. /// @param [in] graph: Root compute graph.
  82. /// @param [in] func_node: functional Node of Case.
  83. /// @param [in] graph_nodes: Data groups of subgraph.
  84. /// @param [in] anchor_idx: anchor index of move Node.
  85. /// @param [in] inputs: Parent index of Node input.
  86. /// @param [in] outputs: Parent index of Node output.
  87. /// @return 0: SUCCESS / others: FAILED
  88. ///
  89. Status MoveNodeToParent(const ComputeGraphPtr &graph, const NodePtr &func_node,
  90. const map<ComputeGraphPtr, map<string, NodePtr>> &all_const_nodes,
  91. const map<ComputeGraphPtr, map<uint32_t, NodePtr>> &all_data_nodes,
  92. const string &node_key, uint32_t parent_index);
  93. ///
  94. /// @ingroup ge
  95. /// @brief Append Input Tensor for functional node.
  96. /// @param [in] graph_nodes: Const groups of subgraph.
  97. /// @param [in/out] parent_index: Parent index for migration.
  98. /// @param [in/out] all_data_nodes: Data groups of subgraph.
  99. /// @return 0: SUCCESS / others: FAILED
  100. ///
  101. Status AppendParallelNode(const NodePtr &func_node, uint32_t &parent_index,
  102. map<ComputeGraphPtr, map<uint32_t, NodePtr>> &all_data_nodes);
  103. ///
  104. /// @ingroup ge
  105. /// @brief Delete Node from subgraph.
  106. /// @param [in] graph: subgraph for process.
  107. /// @param [in] const_node: Node will move to parent.
  108. /// @param [in] data_node: Place holder for Const.
  109. /// @return 0: SUCCESS / others: FAILED
  110. ///
  111. Status DetachParallelNode(const ComputeGraphPtr &graph, const NodePtr &const_node, const NodePtr &data_node);
  112. ///
  113. /// @ingroup ge
  114. /// @brief Move Node to Parent Graph.
  115. /// @param [in] graph: Parent compute graph.
  116. /// @param [in] func_node: functional Node of Case.
  117. /// @param [in] const_node: Node will move to parent.
  118. /// @param [in] parent_index: Parent index of Node input.
  119. /// @return 0: SUCCESS / others: FAILED
  120. ///
  121. Status AttachParallelNode(const ComputeGraphPtr &graph, const NodePtr &func_node,
  122. const NodePtr &const_node, uint32_t parent_index);
  123. };
  124. } // namespace ge
  125. #endif // GE_COMMON_SUBGRAPH_CONST_MIGRATION_H_

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