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.

graph_preprocess.h 3.8 kB

5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * Copyright 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 GE_GRAPH_PREPROCESS_GRAPH_PREPROCESS_H_
  17. #define GE_GRAPH_PREPROCESS_GRAPH_PREPROCESS_H_
  18. #include <fstream>
  19. #include <iostream>
  20. #include <memory>
  21. #include <string>
  22. #include <vector>
  23. #include "common/debug/log.h"
  24. #include "common/debug/memory_dumper.h"
  25. #include "common/model_parser/model_parser.h"
  26. #include "common/properties_manager.h"
  27. #include "common/string_util.h"
  28. #include "common/types.h"
  29. #include "common/util.h"
  30. #include "graph/compute_graph.h"
  31. #include "graph/manager/graph_manager_utils.h"
  32. #include "graph/manager/util/variable_accelerate_ctrl.h"
  33. #include "graph/model.h"
  34. #include "graph/node.h"
  35. #include "graph/utils/graph_utils.h"
  36. #include "graph/utils/tensor_utils.h"
  37. #include "omg/omg_inner_types.h"
  38. #include "runtime/context.h"
  39. namespace ge {
  40. class GraphPrepare {
  41. public:
  42. GraphPrepare();
  43. virtual ~GraphPrepare();
  44. GraphPrepare(const GraphPrepare &in) = delete;
  45. GraphPrepare &operator=(const GraphPrepare &in) = delete;
  46. Status PrepareDynShape(const GraphNodePtr &graph_node,
  47. const std::vector<GeTensor> &user_input,
  48. ge::ComputeGraphPtr &compute_graph,
  49. uint64_t session_id = 0);
  50. Status RecordAIPPInfo(ge::ComputeGraphPtr &compute_graph);
  51. Status PrepareRunningFormatRefiner();
  52. void SetOptions(const GraphManagerOptions &options);
  53. Status GenerateInfershapeGraph(ConstGraphPtr graph);
  54. Status SwitchOpOptimize(ComputeGraphPtr &compute_graph);
  55. private:
  56. Status Init(const ge::Graph &graph, uint64_t session_id = 0);
  57. Status CheckGraph();
  58. Status CheckRefInputNode(const NodePtr &node, const std::string &input_name,
  59. const std::set<NodePtr> &ref_nodes);
  60. Status CheckRefOp();
  61. Status SetRtContext(rtContext_t rt_context, rtCtxMode_t mode);
  62. Status AdjustDataOpOutput(const NodePtr &node);
  63. Status CheckInternalFormat(const NodePtr &input_node, const GeTensorDesc &desc);
  64. Status UpdateDataInputOutputDesc(GeAttrValue::INT index, OpDescPtr &op, GeTensorDesc &desc);
  65. Status UpdateInput(const std::vector<GeTensor> &user_input, const std::map<string, string> &graph_option);
  66. Status CheckAndUpdateInput(const std::vector<GeTensor> &user_input, const std::map<string, string> &graph_option);
  67. Status CheckConstOp();
  68. Status VerifyConstOp(const NodePtr &node);
  69. Status CheckUserInput(const std::vector<GeTensor> &user_input);
  70. Status UpdateDataNetOutputByStorageFormat();
  71. Status PrepareOptimize();
  72. Status InferShapeForPreprocess();
  73. Status TryDoAipp();
  74. Status UpdateVariableFormats(ComputeGraphPtr &graph);
  75. Status FormatAndShapeProcess();
  76. Status ResourcePairProcess(const std::string &action);
  77. Status SaveOriginalGraphToOmModel();
  78. Status ProcessNetOutput();
  79. Status ProcessBeforeInfershape();
  80. Status UpdateInputOutputByOptions();
  81. Status CtrlFlowPreProcess();
  82. bool IsTansDataOpData(const ge::NodePtr &var_node);
  83. Status GraphEquivalentTransformation();
  84. void TypeConversionOfConstant();
  85. bool IsDynamicDims(const NodePtr &input_node);
  86. ge::ComputeGraphPtr compute_graph_;
  87. GraphManagerOptions options_;
  88. uint64_t session_id_ = 0;
  89. };
  90. } // namespace ge
  91. #endif // GE_GRAPH_PREPROCESS_GRAPH_PREPROCESS_H_

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