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.

single_op_model.h 3.5 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_SINGLE_OP_SINGLE_OP_MODEL_H_
  17. #define GE_SINGLE_OP_SINGLE_OP_MODEL_H_
  18. #include <cstdint>
  19. #include <map>
  20. #include <memory>
  21. #include <string>
  22. #include <vector>
  23. #include "framework/common/helper/model_helper.h"
  24. #include "single_op/single_op.h"
  25. #include "single_op/stream_resource.h"
  26. #include "single_op/task/op_task.h"
  27. namespace ge {
  28. struct SingleOpModelParam {
  29. uint64_t base_addr = 0;
  30. uint64_t memory_size = 0;
  31. uint64_t weight_addr = 0;
  32. uint64_t weight_size = 0;
  33. uint64_t zero_copy_mem_size = 0;
  34. uint8_t *mem_base = nullptr;
  35. uint8_t *weight_base = nullptr;
  36. std::map<uintptr_t, int> addr_mapping_;
  37. int64_t core_type = 0;
  38. bool graph_is_dynamic = false;
  39. };
  40. class SingleOpModel {
  41. public:
  42. SingleOpModel(const std::string &model_name,
  43. const void *model_data,
  44. uint32_t model_size);
  45. ~SingleOpModel() = default;
  46. Status Init();
  47. Status BuildOp(StreamResource &resource, SingleOp &single_op);
  48. Status BuildDynamicOp(StreamResource &resource, DynamicSingleOp &single_op);
  49. private:
  50. Status InitModel();
  51. Status LoadAllNodes();
  52. Status ParseInputsAndOutputs();
  53. Status SetInputsAndOutputs(SingleOp &single_op);
  54. Status InitModelMem(StreamResource &resource);
  55. Status ParseInputNode(const OpDescPtr &op_desc);
  56. void ParseOutputNode(const OpDescPtr &op_desc);
  57. Status BuildTaskList(StreamResource *stream_resource, SingleOp &single_op);
  58. Status BuildTaskListForDynamicOp(StreamResource *stream_resource, DynamicSingleOp &dynamic_single_op);
  59. Status BuildKernelTask(const domi::TaskDef &task_def, TbeOpTask **task);
  60. Status BuildAtomicTask(const domi::TaskDef &task_def, AtomicAddrCleanOpTask **task);
  61. Status BuildKernelExTask(const domi::KernelExDef &kernel_def, AiCpuTask **task, uint64_t kernel_id);
  62. Status BuildCpuKernelTask(const domi::KernelDef &kernel_def, OpTask **task, uint64_t kernel_id);
  63. static void ParseOpModelParams(ModelHelper &model_helper, SingleOpModelParam &param);
  64. void ParseArgTable(OpTask *task, SingleOp &op);
  65. Status InitHybridModelExecutor(const StreamResource &resource, const GeModelPtr &ge_model, SingleOp &single_op);
  66. Status SetHostMemTensor(DynamicSingleOp &single_op);
  67. Status NeedHybridModel(GeModelPtr &ge_model, bool &flag);
  68. Status ParseTasks();
  69. std::map<NodePtr, std::vector<domi::TaskDef>> node_tasks_;
  70. std::string model_name_;
  71. uint32_t model_id_ = 0;
  72. const void *ori_model_data_;
  73. uint32_t ori_model_size_;
  74. ModelHelper model_helper_;
  75. map<uint32_t, NodePtr> op_list_;
  76. map<int32_t, NodePtr> op_with_hostmem_;
  77. SingleOpModelParam model_params_;
  78. std::vector<ptrdiff_t> input_offset_list_;
  79. std::vector<size_t> input_sizes_;
  80. std::vector<ptrdiff_t> output_offset_list_;
  81. std::vector<size_t> output_sizes_;
  82. std::vector<OpDescPtr> data_ops_;
  83. OpDescPtr netoutput_op_;
  84. bool has_weight_ = false;
  85. };
  86. } // namespace ge
  87. #endif // GE_SINGLE_OP_SINGLE_OP_MODEL_H_

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