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 2.8 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 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/types.h"
  27. #include "common/util.h"
  28. #include "graph/compute_graph.h"
  29. #include "graph/manager/graph_manager_utils.h"
  30. #include "graph/model.h"
  31. #include "graph/node.h"
  32. #include "model/ge_model.h"
  33. #include "omg/omg_inner_types.h"
  34. namespace ge {
  35. class ModelBuilder {
  36. public:
  37. ModelBuilder(ge::ComputeGraphPtr whole_graph, const Graph2SubGraphInfoList &subgraphs,
  38. const std::map<std::string, int> &stream_max_parallel_num, bool hcom_parallel,
  39. int mode = static_cast<int>(domi::BuildMode::GEN_TASK_WITHOUT_FUSION));
  40. ModelBuilder(const ModelBuilder &) = delete;
  41. ModelBuilder &operator=(const ModelBuilder &op) = delete;
  42. ~ModelBuilder();
  43. Status SaveDataToModel(ge::Model &model, ge::GeModel &ge_model);
  44. Status PreBuildModel();
  45. Status BuildModelForGetTask(ge::Model &model_def);
  46. ge::Buffer GetWeightBuffer() const;
  47. protected:
  48. void AddNodeInputProperty();
  49. void ClearOriginalFormat();
  50. Status MergeWeights();
  51. private:
  52. void SetInputIsConst(const ge::NodePtr &n);
  53. void SetModelVersion(ge::Model &model);
  54. Status CalcOutputSize(const ge::NodePtr &n);
  55. Status AdjustConstWeightSize(const ge::NodePtr &node, size_t &mem_offset);
  56. Status SetInputOutputDesc();
  57. Status AdjustInputTensorFlag();
  58. Status BuildModelDef(ge::Model &model_def);
  59. void InitL1FusionOption();
  60. Status CompileSingleOp();
  61. size_t mem_offset_;
  62. size_t weight_offset_;
  63. ge::ComputeGraphPtr compute_graph_;
  64. const Graph2SubGraphInfoList &subgraphs_;
  65. int64_t stream_num_;
  66. int64_t event_num_;
  67. uint32_t label_num_;
  68. ge::Buffer weight_buffer_;
  69. std::map<std::string, int> stream_max_parallel_num_;
  70. bool hcom_parallel_;
  71. int build_mode_;
  72. size_t max_mem_offset_;
  73. TBEKernelStore tbe_kernel_store_;
  74. uint8_t platform_type_;
  75. bool is_loop_graph_;
  76. bool is_l1_fusion_enable_;
  77. };
  78. } // namespace ge
  79. #endif // GE_GRAPH_BUILD_MODEL_BUILDER_H_

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