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.

node_utils.h 5.5 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /**
  2. * Copyright 2019-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 INC_GRAPH_UTILS_NODE_UTILS_H_
  17. #define INC_GRAPH_UTILS_NODE_UTILS_H_
  18. #include <set>
  19. #include <map>
  20. #include <vector>
  21. #include "graph/node.h"
  22. namespace ge {
  23. // Op types of Const like Opps.
  24. extern const std::set<std::string> kConstOpTypes;
  25. // Op types of If like Opps.
  26. extern const std::set<std::string> kIfOpTypes;
  27. // Op types of While like Opps.
  28. extern const std::set<std::string> kWhileOpTypes;
  29. // Op types of Case like Opps.
  30. extern const std::set<std::string> kCaseOpTypes;
  31. // Op types of For like Opps.
  32. extern const std::set<std::string> kForOpTypes;
  33. class NodeUtils {
  34. public:
  35. static graphStatus AddSendEventId(const NodePtr &node, const uint32_t &event_id);
  36. static graphStatus AddRecvEventId(const NodePtr &node, const uint32_t &event_id);
  37. static graphStatus GetSendEventIdList(const NodePtr &node, std::vector<uint32_t> &vec_send);
  38. static graphStatus GetRecvEventIdList(const NodePtr &node, std::vector<uint32_t> &vec_recv);
  39. static graphStatus ClearSendInfo();
  40. static graphStatus ClearRecvInfo();
  41. static graphStatus GetSingleOutputNodeOfNthLayer(const NodePtr &src, int depth, NodePtr &dst);
  42. static graphStatus GetDataOutAnchorAndControlInAnchor(const NodePtr &node_ptr, OutDataAnchorPtr &out_data,
  43. InControlAnchorPtr &in_control);
  44. static graphStatus ClearInDataAnchor(const NodePtr &node_ptr, const InDataAnchorPtr &in_data_anchor);
  45. static graphStatus SetAllAnchorStatus(const NodePtr &nodePtr);
  46. static graphStatus SetAllAnchorStatus(Node &node);
  47. static bool IsAnchorStatusSet(const NodePtr &nodePtr);
  48. static bool IsAnchorStatusSet(const Node &node);
  49. static graphStatus MoveOutputEdges(const NodePtr &origin_node, const NodePtr &new_node);
  50. static void UpdateIsInputConst(const NodePtr &nodePtr);
  51. static void UpdateIsInputConst(Node &node);
  52. static bool IsConst(const Node &node);
  53. static void UnlinkAll(const Node &node);
  54. static graphStatus UpdatePeerNodeInputDesc(const NodePtr &node_ptr);
  55. static graphStatus AppendInputAnchor(const NodePtr &node, uint32_t index);
  56. static graphStatus RemoveInputAnchor(const NodePtr &node, uint32_t index);
  57. static bool IsInNodesEmpty(const Node &node);
  58. static GeTensorDesc GetOutputDesc(const Node &node, uint32_t index);
  59. static GeTensorDesc GetInputDesc(const Node &node, uint32_t index);
  60. static graphStatus UpdateOutputShape(const Node &node, uint32_t index, const GeShape &shape);
  61. static graphStatus UpdateInputShape(const Node &node, uint32_t index, const GeShape &shape);
  62. // check node whether unknown shape.If node shape contain -1 or -2,out param "is_unknow" will be true;
  63. // for func op, it will check subgraph yet, if some node shape of subgraph contain -1 or -2,
  64. // the out param "is_unknow" will be true too
  65. static graphStatus GetNodeUnknownShapeStatus(const Node &node, bool &is_unknow);
  66. static std::string GetNodeType(const Node &node);
  67. static ComputeGraphPtr GetSubgraph(const Node &node, uint32_t index);
  68. static graphStatus SetSubgraph(Node &node, uint32_t index, const ComputeGraphPtr &subgraph);
  69. ///
  70. /// Check if node is input of subgraph
  71. /// @param [in] node
  72. /// @return bool
  73. ///
  74. static bool IsSubgraphInput(const NodePtr &node);
  75. ///
  76. /// Check if node is output of subgraph
  77. /// @param [in] node
  78. /// @return bool
  79. ///
  80. static bool IsSubgraphOutput(const NodePtr &node);
  81. ///
  82. /// @brief Get subgraph original input node.
  83. /// @param [in] node
  84. /// @return Node
  85. ///
  86. static NodePtr GetParentInput(const NodePtr &node);
  87. ///
  88. /// @brief Check is varying_input for while node
  89. /// @param [in] node: Data node for subgraph
  90. /// @return bool
  91. ///
  92. static bool IsWhileVaryingInput(const ge::NodePtr &node);
  93. ///
  94. /// @brief Get subgraph input is constant.
  95. /// @param [in] node
  96. /// @param [out] string
  97. /// @return bool
  98. ///
  99. static bool GetConstOpType(const NodePtr &in_node, std::string &op_type);
  100. ///
  101. /// @brief Remove node-related subgraphs, including subgraphs of nodes in the subgraph.
  102. /// @param [in] node
  103. /// @return return GRAPH_SUCCESS if remove successfully, other for failed.
  104. ///
  105. static graphStatus RemoveSubgraphsOnNode(const NodePtr &node);
  106. ///
  107. /// @brief Get subgraph input data node by index.
  108. /// @param [in] node
  109. /// @return Node
  110. ///
  111. static vector<NodePtr> GetSubgraphDataNodesByIndex(const Node &node, int index);
  112. ///
  113. /// @brief Get subgraph input data node by index.
  114. /// @param [in] node
  115. /// @return Node
  116. ///
  117. static vector<NodePtr> GetSubgraphOutputNodes(const Node &node);
  118. static NodePtr GetInDataNodeByIndex(const Node &node, int index);
  119. static vector<NodePtr> GetOutDataNodesByIndex(const Node &node, int index);
  120. private:
  121. static std::map<NodePtr, std::vector<uint32_t>> map_send_info_;
  122. static std::map<NodePtr, std::vector<uint32_t>> map_recv_info_;
  123. };
  124. } // namespace ge
  125. #endif // INC_GRAPH_UTILS_NODE_UTILS_H_

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