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.4 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 bool IsInNodesEmpty(const Node &node);
  56. static GeTensorDesc GetOutputDesc(const Node &node, uint32_t index);
  57. static GeTensorDesc GetInputDesc(const Node &node, uint32_t index);
  58. static graphStatus UpdateOutputShape(const Node &node, uint32_t index, const GeShape &shape);
  59. static graphStatus UpdateInputShape(const Node &node, uint32_t index, const GeShape &shape);
  60. // check node whether unknown shape.If node shape contain -1 or -2,out param "is_unknow" will be true;
  61. // for func op, it will check subgraph yet, if some node shape of subgraph contain -1 or -2,
  62. // the out param "is_unknow" will be true too
  63. static graphStatus GetNodeUnknownShapeStatus(const Node &node, bool &is_unknow);
  64. static std::string GetNodeType(const Node &node);
  65. static ComputeGraphPtr GetSubgraph(const Node &node, uint32_t index);
  66. static graphStatus SetSubgraph(Node &node, uint32_t index, const ComputeGraphPtr &subgraph);
  67. ///
  68. /// Check if node is input of subgraph
  69. /// @param [in] node
  70. /// @return bool
  71. ///
  72. static bool IsSubgraphInput(const NodePtr &node);
  73. ///
  74. /// Check if node is output of subgraph
  75. /// @param [in] node
  76. /// @return bool
  77. ///
  78. static bool IsSubgraphOutput(const NodePtr &node);
  79. ///
  80. /// @brief Get subgraph original input node.
  81. /// @param [in] node
  82. /// @return Node
  83. ///
  84. static NodePtr GetParentInput(const NodePtr &node);
  85. ///
  86. /// @brief Check is varying_input for while node
  87. /// @param [in] node: Data node for subgraph
  88. /// @return bool
  89. ///
  90. static bool IsWhileVaryingInput(const ge::NodePtr &node);
  91. ///
  92. /// @brief Get subgraph input is constant.
  93. /// @param [in] node
  94. /// @param [out] string
  95. /// @return bool
  96. ///
  97. static bool GetConstOpType(const NodePtr &in_node, std::string &op_type);
  98. ///
  99. /// @brief Remove node-related subgraphs, including subgraphs of nodes in the subgraph.
  100. /// @param [in] node
  101. /// @return return GRAPH_SUCCESS if remove successfully, other for failed.
  102. ///
  103. static graphStatus RemoveSubgraphsOnNode(const NodePtr &node);
  104. ///
  105. /// @brief Get subgraph input data node by index.
  106. /// @param [in] node
  107. /// @return Node
  108. ///
  109. static vector<NodePtr> GetSubgraphDataNodesByIndex(const Node &node, int index);
  110. ///
  111. /// @brief Get subgraph input data node by index.
  112. /// @param [in] node
  113. /// @return Node
  114. ///
  115. static vector<NodePtr> GetSubgraphOutputNodes(const Node &node);
  116. static NodePtr GetInDataNodeByIndex(const Node &node, int index);
  117. static vector<NodePtr> GetOutDataNodesByIndex(const Node &node, int index);
  118. private:
  119. static std::map<NodePtr, std::vector<uint32_t>> map_send_info_;
  120. static std::map<NodePtr, std::vector<uint32_t>> map_recv_info_;
  121. };
  122. } // namespace ge
  123. #endif // INC_GRAPH_UTILS_NODE_UTILS_H_

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