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.

gnode.h 5.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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_EXTERNAL_GRAPH_NODE_H_
  17. #define INC_EXTERNAL_GRAPH_NODE_H_
  18. #include <vector>
  19. #include <cstdint>
  20. #include "./ge_error_codes.h"
  21. #include "./types.h"
  22. #include "./tensor.h"
  23. #include "./ascend_string.h"
  24. namespace ge {
  25. class AttrValue;
  26. class GNode;
  27. class OpDesc;
  28. class Graph;
  29. class ComputeGraph;
  30. using GNodePtr = std::shared_ptr<GNode>;
  31. using GraphPtr = std::shared_ptr<Graph>;
  32. using OpBytes = std::vector<uint8_t>;
  33. using OpDescPtr = std::shared_ptr<OpDesc>;
  34. using ComputeGraphPtr = std::shared_ptr<ComputeGraph>;
  35. class NodeImpl;
  36. class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY GNode {
  37. public:
  38. GNode();
  39. ~GNode() = default;
  40. graphStatus GetType(AscendString &type) const;
  41. graphStatus GetName(AscendString &name) const;
  42. std::pair<GNodePtr, int32_t> GetInDataNodesAndPortIndexs(const int32_t index) const;
  43. std::vector<GNodePtr> GetInControlNodes() const;
  44. std::vector<std::pair<GNodePtr, int32_t>> GetOutDataNodesAndPortIndexs(const int32_t index) const;
  45. std::vector<GNodePtr> GetOutControlNodes() const;
  46. graphStatus GetInputConstData(const int32_t index, Tensor &data) const;
  47. graphStatus GetInputIndexByName(const AscendString &name, int32_t &index);
  48. graphStatus GetOutputIndexByName(const AscendString &name, int32_t &index);
  49. size_t GetInputsSize() const;
  50. size_t GetOutputsSize() const;
  51. graphStatus GetInputDesc(const int32_t index, TensorDesc &tensor_desc) const;
  52. graphStatus UpdateInputDesc(const int32_t index, const TensorDesc &tensor_desc);
  53. graphStatus GetOutputDesc(const int32_t index, TensorDesc &tensor_desc) const;
  54. graphStatus UpdateOutputDesc(const int32_t index, const TensorDesc &tensor_desc);
  55. graphStatus GetAttr(const AscendString &name, int64_t &attr_value) const;
  56. graphStatus GetAttr(const AscendString &name, int32_t &attr_value) const;
  57. graphStatus GetAttr(const AscendString &name, uint32_t &attr_value) const;
  58. graphStatus GetAttr(const AscendString &name, float &attr_value) const;
  59. graphStatus GetAttr(const AscendString &name, AscendString &attr_value) const;
  60. graphStatus GetAttr(const AscendString &name, bool &attr_value) const;
  61. graphStatus GetAttr(const AscendString &name, Tensor &attr_value) const;
  62. graphStatus GetAttr(const AscendString &name, std::vector<int64_t> &attr_value) const;
  63. graphStatus GetAttr(const AscendString &name, std::vector<int32_t> &attr_value) const;
  64. graphStatus GetAttr(const AscendString &name, std::vector<uint32_t> &attr_value) const;
  65. graphStatus GetAttr(const AscendString &name, std::vector<float> &attr_value) const;
  66. graphStatus GetAttr(const AscendString &name, std::vector<AscendString> &attr_values) const;
  67. graphStatus GetAttr(const AscendString &name, std::vector<bool> &attr_value) const;
  68. graphStatus GetAttr(const AscendString &name, std::vector<Tensor> &attr_value) const;
  69. graphStatus GetAttr(const AscendString &name, OpBytes &attr_value) const;
  70. graphStatus GetAttr(const AscendString &name, std::vector<std::vector<int64_t>> &attr_value) const;
  71. graphStatus GetAttr(const AscendString &name, std::vector<ge::DataType> &attr_value) const;
  72. graphStatus GetAttr(const AscendString &name, ge::DataType &attr_value) const;
  73. graphStatus GetAttr(const AscendString &name, AttrValue &attr_value) const;
  74. graphStatus SetAttr(const AscendString &name, int64_t &attr_value) const;
  75. graphStatus SetAttr(const AscendString &name, int32_t &attr_value) const;
  76. graphStatus SetAttr(const AscendString &name, uint32_t &attr_value) const;
  77. graphStatus SetAttr(const AscendString &name, float &attr_value) const;
  78. graphStatus SetAttr(const AscendString &name, AscendString &attr_value) const;
  79. graphStatus SetAttr(const AscendString &name, bool &attr_value) const;
  80. graphStatus SetAttr(const AscendString &name, Tensor &attr_value) const;
  81. graphStatus SetAttr(const AscendString &name, std::vector<int64_t> &attr_value) const;
  82. graphStatus SetAttr(const AscendString &name, std::vector<int32_t> &attr_value) const;
  83. graphStatus SetAttr(const AscendString &name, std::vector<uint32_t> &attr_value) const;
  84. graphStatus SetAttr(const AscendString &name, std::vector<float> &attr_value) const;
  85. graphStatus SetAttr(const AscendString &name, std::vector<AscendString> &attr_values) const;
  86. graphStatus SetAttr(const AscendString &name, std::vector<bool> &attr_value) const;
  87. graphStatus SetAttr(const AscendString &name, std::vector<Tensor> &attr_value) const;
  88. graphStatus SetAttr(const AscendString &name, OpBytes &attr_value) const;
  89. graphStatus SetAttr(const AscendString &name, std::vector<std::vector<int64_t>> &attr_value) const;
  90. graphStatus SetAttr(const AscendString &name, std::vector<ge::DataType> &attr_value) const;
  91. graphStatus SetAttr(const AscendString &name, ge::DataType &attr_value) const;
  92. graphStatus SetAttr(const AscendString &name, AttrValue &attr_value) const;
  93. bool HasAttr(const AscendString &name);
  94. graphStatus GetSubgraph(uint32_t index, GraphPtr &graph) const;
  95. graphStatus GetALLSubgraphs(std::vector<GraphPtr> &graph_list) const;
  96. private:
  97. std::shared_ptr<NodeImpl> impl_;
  98. friend class NodeAdapter;
  99. };
  100. } // namespace ge
  101. #endif // INC_EXTERNAL_GRAPH_NODE_H_

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