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 6.6 kB

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

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