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.

cond_pass.h 4.0 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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_COND_PASS_H
  17. #define GE_GRAPH_PASSES_COND_PASS_H
  18. #include "graph/passes/base_pass.h"
  19. namespace ge {
  20. class CondPass : public BaseNodePass {
  21. public:
  22. Status Run(NodePtr &node) override;
  23. private:
  24. ///
  25. /// @brief Get cond info for if / while
  26. /// @param [in] node: If / While op
  27. /// @param [out] graph: owner_graph of if node / while_cond subgraph
  28. /// @param [out] cond_out_anchor: peer_cond_anchor
  29. /// @param [out] cond_in_anchor: cond_input
  30. /// @return Status
  31. ///
  32. static Status GetCondInfo(const NodePtr &node, ComputeGraphPtr &graph, OutDataAnchorPtr &cond_out_anchor,
  33. InDataAnchorPtr &cond_in_anchor);
  34. ///
  35. /// @brief Get cond info for if node
  36. /// @param [in] node: If op
  37. /// @param [out] graph: owner_graph of if node
  38. /// @param [out] cond_out_anchor: peer_cond_anchor
  39. /// @param [out] cond_in_anchor: cond_input of if
  40. /// @return Status
  41. ///
  42. static Status GetCondInfoForIf(const NodePtr &node, ComputeGraphPtr &graph, OutDataAnchorPtr &cond_out_anchor,
  43. InDataAnchorPtr &cond_in_anchor);
  44. ///
  45. /// @brief Get cond info for while node
  46. /// @param [in] node: While op
  47. /// @param [out] graph: while_cond subgraph
  48. /// @param [out] cond_out_anchor: peer_cond_anchor
  49. /// @param [out] cond_in_anchor: input of NetOutput in cond_graph
  50. /// @return Status
  51. ///
  52. static Status GetCondInfoForWhile(const NodePtr &node, ComputeGraphPtr &graph, OutDataAnchorPtr &cond_out_anchor,
  53. InDataAnchorPtr &cond_in_anchor);
  54. ///
  55. /// @brief Process Cond Op with non-scalar cond_input
  56. /// @param [in] graph
  57. /// @param [in] out_anchor: peer_cond_anchor
  58. /// @param [in] in_anchor: cond_input
  59. /// @return Status
  60. ///
  61. Status HandleNonScalarCond(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_anchor,
  62. const InDataAnchorPtr &in_anchor);
  63. ///
  64. /// @brief Process Cond Op with scalar-string cond_input
  65. /// @param [in] graph
  66. /// @param [in] out_anchor: peer_cond_anchor
  67. /// @param [in] in_anchor: cond_input
  68. /// @return Status
  69. ///
  70. Status HandleStringCond(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_anchor,
  71. const InDataAnchorPtr &in_anchor);
  72. ///
  73. /// @brief Process Cond Op with scalar cond_input
  74. /// @param [in] graph
  75. /// @param [in] out_anchor: peer_cond_anchor
  76. /// @param [in] in_anchor: cond_input
  77. /// @param [in] src_type
  78. /// @return Status
  79. ///
  80. Status HandleScalarCond(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_anchor,
  81. const InDataAnchorPtr &in_anchor, DataType src_type);
  82. ///
  83. /// @brief Insert node
  84. /// @param [in] graph
  85. /// @param [in] out_anchor
  86. /// @param [in] in_anchor
  87. /// @param [in] type
  88. /// @return Status
  89. ///
  90. Status InsertNode(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_anchor,
  91. const InDataAnchorPtr &in_anchor, const std::string &type);
  92. ///
  93. /// @brief Add cast node
  94. /// @param [in] graph
  95. /// @param [in] name
  96. /// @param [in] tensor
  97. /// @param [in] src
  98. /// @param [in] dst
  99. /// @return NodePtr
  100. ///
  101. NodePtr AddCastNode(const ComputeGraphPtr &graph, const std::string &name, const GeTensorDesc &tensor,
  102. DataType src, DataType dst);
  103. };
  104. } // namespace ge
  105. #endif //GE_GRAPH_PASSES_COND_PASS_H

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