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.

op_desc_utils.h 4.3 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_OP_DESC_UTILS_H_
  17. #define INC_GRAPH_UTILS_OP_DESC_UTILS_H_
  18. #include <memory>
  19. #include <string>
  20. #include <vector>
  21. #include "graph/def_types.h"
  22. #include "graph/node.h"
  23. #include "graph/op_desc.h"
  24. #include "graph/operator.h"
  25. #include "graph/range_vistor.h"
  26. namespace ge {
  27. class OpDesc;
  28. using OpDescPtr = std::shared_ptr<OpDesc>;
  29. class OpDescUtils {
  30. public:
  31. template <class T>
  32. using Vistor = RangeVistor<T, std::shared_ptr<OpDesc>>;
  33. OpDescUtils() = default;
  34. ~OpDescUtils() = default;
  35. static bool HasQuantizeFactorParams(const OpDescPtr& op_desc);
  36. static bool HasQuantizeFactorParams(const OpDesc& op_desc);
  37. static graphStatus GetQuantizeFactorParams(const OpDescPtr& op_desc, QuantizeFactorParams& quant);
  38. static graphStatus GetQuantizeFactorParams(const OpDesc& op_desc, QuantizeFactorParams& quant);
  39. static graphStatus SetQuantizeFactorParams(const OpDescPtr &op_desc, const QuantizeFactorParams& quant);
  40. static graphStatus SetQuantizeFactorParams(OpDesc& op_desc, const QuantizeFactorParams& quant);
  41. static vector<ge::NodePtr> GetConstInputNode(const ge::Node& node);
  42. static vector<ConstGeTensorPtr> GetInputData(const vector<ge::NodePtr>& input_nodes);
  43. static vector<ConstGeTensorPtr> GetWeights(const ge::Node& node);
  44. static vector<ConstGeTensorPtr> GetWeights(const ge::ConstNodePtr& node);
  45. static vector<GeTensorPtr> MutableWeights(const ge::Node& node);
  46. static vector<GeTensorPtr> MutableWeights(const ge::NodePtr node);
  47. static graphStatus SetWeights(ge::Node& node, const vector<ge::GeTensorPtr>& weights);
  48. static graphStatus SetWeights(ge::NodePtr node, const vector<ge::GeTensorPtr>& weights);
  49. static graphStatus ClearWeights(ge::NodePtr node);
  50. static bool ClearInputDesc(ge::OpDescPtr op_desc, uint32_t index);
  51. static bool ClearInputDesc(const ge::NodePtr& node);
  52. static bool ClearOutputDesc(const ge::OpDescPtr& op_desc, uint32_t index);
  53. static bool ClearOutputDesc(const ge::NodePtr& node);
  54. static vector<ge::NodePtr> GetConstInputs(const ge::Node& node);
  55. static vector<ge::NodePtr> GetConstInputs(const ge::ConstNodePtr& node);
  56. static size_t GetNonConstInputsSize(const ge::Node& node);
  57. static size_t GetNonConstInputsSize(ge::ConstNodePtr node);
  58. // Index: Indicates the index of all non const inputs
  59. static GeTensorDesc GetNonConstInputTensorDesc(const ge::Node& node, size_t index_non_const = 0);
  60. static GeTensorDesc GetNonConstInputTensorDesc(const ge::ConstNodePtr& node, size_t index_non_const = 0);
  61. static bool GetNonConstInputIndex(const ge::Node& node, size_t index_non_const, size_t& index);
  62. static bool GetNonConstInputIndex(const ge::ConstNodePtr& node, size_t index_non_const, size_t& index);
  63. // Index: Indicates the index of all inputs
  64. static bool IsNonConstInput(const ge::Node& node, size_t index = 0);
  65. static bool IsNonConstInput(const ge::ConstNodePtr& node, size_t index = 0);
  66. static vector<ge::GeTensorDesc> GetNonConstTensorDesc(const ge::ConstNodePtr& node);
  67. static graphStatus AddConstOpToAnchor(InDataAnchorPtr in_anchor, const GeTensorPtr& tensor_ptr);
  68. static Operator CreateOperatorFromOpDesc(OpDescPtr op_desc);
  69. static Operator CreateOperatorFromNode(ge::ConstNodePtr node_ptr);
  70. static OpDescPtr GetOpDescFromOperator(const Operator& oprt);
  71. static OpDescPtr CreateConstOp(const GeTensorPtr& tensor_ptr);
  72. private:
  73. static GeTensorPtr MutableWeights(ge::OpDesc& op_desc);
  74. static GeTensorPtr MutableWeights(ge::OpDescPtr op_desc);
  75. static graphStatus SetWeights(ge::OpDesc& op_desc, const GeTensorPtr weight);
  76. static graphStatus SetWeights(ge::OpDescPtr op_desc, const GeTensorPtr weight);
  77. };
  78. } // namespace ge
  79. #endif // INC_GRAPH_UTILS_OP_DESC_UTILS_H_

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

Contributors (1)