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.

transop_depth_fusion_pass.h 3.5 kB

5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_TRANSOP_DEPTH_FUSION_PASS_H_
  17. #define GE_GRAPH_PASSES_TRANSOP_DEPTH_FUSION_PASS_H_
  18. #include <stack>
  19. #include <string>
  20. #include <vector>
  21. #include "inc/graph_pass.h"
  22. namespace ge {
  23. ///
  24. /// Transform operators depth fusion
  25. ///
  26. class TransOpDepthFusionPass : public GraphPass {
  27. public:
  28. TransOpDepthFusionPass() = default;
  29. ~TransOpDepthFusionPass() = default;
  30. graphStatus Run(ge::ComputeGraphPtr graph) override;
  31. private:
  32. ///
  33. /// Judge whether the node can be deleted in depth fusion
  34. /// @param node
  35. /// @return True or False
  36. ///
  37. static bool CheckNodeCanBeDeleted(const NodePtr &node);
  38. ///
  39. /// two transform nodes can be offset only when the front node's input is
  40. /// consistent with the back one's output
  41. /// @param src_node: the front node
  42. /// @param dst_node: the back node
  43. /// @return True or False, whether can be offset or not
  44. ///
  45. static bool DescAreSymmetry(const NodePtr &src_node, const NodePtr &dst_node);
  46. ///
  47. /// update the input_name and src_name info when the relationship was changed
  48. /// @param src_out_anchor: the new peer in data anchor of dst_in_anchor
  49. /// @param old_src_anchor: the original peer in data anchor of dst_in_anchor
  50. /// @param dst_in_anchor: the target anchor
  51. /// @return Status
  52. ///
  53. static graphStatus UpdateSrcAttr(const OutDataAnchorPtr &src_out_anchor, const OutDataAnchorPtr &old_src_anchor,
  54. const InDataAnchorPtr &dst_in_anchor);
  55. ///
  56. /// Depth-first recursive to traverse all the transops
  57. /// @param dst_in_anchor: each in_data_anchor is set as the root in the recursive
  58. /// @return Status
  59. ///
  60. graphStatus RecursiveInDepth(const InDataAnchorPtr &dst_in_anchor, const ge::ComputeGraphPtr &graph);
  61. ///
  62. /// Remove transop by using interface: IsolateNode & RemoveNodeWithoutRelink
  63. /// @param node: the trans op which will be removed
  64. /// @return Status
  65. ///
  66. static graphStatus RemoveNode(const NodePtr &node, const ge::ComputeGraphPtr &graph);
  67. ///
  68. /// Relink the offset trans op with it's former's father node.
  69. /// Note: control edge will be added to link the two offset ops, if the former
  70. /// trans op have in control nodes
  71. /// @param new_out_anchor: out_data_anchor of father node of the former trans op
  72. /// @param old_out_anchor: out_data_anchor of the former trans op
  73. /// @param in_data_anchor: in_data_anchor of the after trans op
  74. /// @return Status
  75. ///
  76. static graphStatus RelinkEdges(const OutDataAnchorPtr &new_out_anchor, const OutDataAnchorPtr &old_out_anchor,
  77. const InDataAnchorPtr &in_data_anchor);
  78. ///
  79. /// @param trans_op_ : the trans op which can't be offset at the moment
  80. /// @param offset_op_ : the former one of the offset pair nodes
  81. ///
  82. std::stack<NodePtr> trans_op_;
  83. std::stack<NodePtr> offset_op_;
  84. };
  85. } // namespace ge
  86. #endif // GE_GRAPH_PASSES_TRANSOP_DEPTH_FUSION_PASS_H_

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