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.

model_builder.h 3.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
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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_BUILD_MODEL_BUILDER_H_
  17. #define GE_GRAPH_BUILD_MODEL_BUILDER_H_
  18. #include <algorithm>
  19. #include <map>
  20. #include <memory>
  21. #include <string>
  22. #include <utility>
  23. #include <vector>
  24. #include "common/op/ge_op_utils.h"
  25. #include "common/tbe_kernel_store.h"
  26. #include "common/cust_aicpu_kernel_store.h"
  27. #include "common/types.h"
  28. #include "common/util.h"
  29. #include "graph/compute_graph.h"
  30. #include "graph/manager/graph_manager_utils.h"
  31. #include "graph/model.h"
  32. #include "graph/node.h"
  33. #include "model/ge_model.h"
  34. #include "omg/omg_inner_types.h"
  35. namespace ge {
  36. class ModelBuilder {
  37. public:
  38. ModelBuilder(uint64_t session_id, ge::ComputeGraphPtr whole_graph, const Graph2SubGraphInfoList &subgraphs,
  39. const std::map<std::string, int> &stream_max_parallel_num, bool hcom_parallel,
  40. int mode = static_cast<int>(domi::BuildMode::GEN_TASK_WITHOUT_FUSION));
  41. ModelBuilder(const ModelBuilder &) = delete;
  42. ModelBuilder &operator=(const ModelBuilder &op) = delete;
  43. ~ModelBuilder();
  44. Status SaveDataToModel(ge::Model &model, ge::GeModel &ge_model);
  45. Status PreBuildModel();
  46. Status BuildModelForGetTask(ge::Model &model_def);
  47. ge::Status BuildModelForGetDynShapeTask(ge::Model &model_def);
  48. ge::Buffer GetWeightBuffer() const;
  49. protected:
  50. void AddNodeInputProperty();
  51. void ClearOriginalFormat();
  52. Status MergeWeights();
  53. private:
  54. bool SetInputConst(const OpDescPtr &op_desc, const NodePtr &src_node, size_t index, vector<bool> &is_input_const);
  55. void SetInputIsConst(const ge::NodePtr &n);
  56. void SetModelVersion(ge::Model &model);
  57. Status CalcOutputSize(const ge::NodePtr &n);
  58. Status AdjustConstWeightSize(const ge::NodePtr &node, size_t &mem_offset);
  59. Status SetInputOutputDesc();
  60. Status AdjustInputTensorFlag();
  61. Status BuildModelDef(ge::Model &model_def);
  62. void InitL1FusionOption();
  63. Status CompileSingleOp();
  64. void CollectCheckAicpuAttr(const OpDescPtr &op_desc, std::set<std::string> &aicpu_op_types,
  65. std::set<std::string> &aicpu_tf_op_types);
  66. void SetModelCheckAicpuAttr(ge::Model &model, std::set<std::string> &aicpu_op_types,
  67. std::set<std::string> &aicpu_tf_op_types);
  68. uint64_t session_id_;
  69. map<int64_t, size_t> mem_type_to_mem_offset_;
  70. size_t weight_offset_;
  71. ge::ComputeGraphPtr compute_graph_;
  72. const Graph2SubGraphInfoList &subgraphs_;
  73. int64_t stream_num_;
  74. int64_t event_num_;
  75. vector<int64_t> huge_streams_;
  76. uint32_t label_num_;
  77. ge::Buffer weight_buffer_;
  78. std::map<std::string, int> stream_max_parallel_num_;
  79. bool hcom_parallel_;
  80. int build_mode_;
  81. size_t max_mem_offset_;
  82. size_t p2p_mem_offset_;
  83. size_t zero_copy_mem_size_;
  84. TBEKernelStore tbe_kernel_store_;
  85. CustAICPUKernelStore cust_aicpu_kernel_store_;
  86. uint8_t platform_type_;
  87. bool is_loop_graph_;
  88. bool is_l1_fusion_enable_;
  89. };
  90. } // namespace ge
  91. #endif // GE_GRAPH_BUILD_MODEL_BUILDER_H_

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