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.

ge_model.h 3.3 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
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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_MODEL_GE_MODEL_H_
  17. #define GE_MODEL_GE_MODEL_H_
  18. #include <map>
  19. #include <memory>
  20. #include <string>
  21. #include "securec.h"
  22. #include "runtime/rt.h"
  23. #include "common/tbe_kernel_store.h"
  24. #include "common/cust_aicpu_kernel_store.h"
  25. #include "framework/common/debug/log.h"
  26. #include "framework/common/fmk_error_codes.h"
  27. #include "graph/buffer.h"
  28. #include "external/graph/graph.h"
  29. #include "proto/task.pb.h"
  30. namespace ge {
  31. const uint32_t INVALID_MODEL_ID = 0xFFFFFFFFUL;
  32. class GeModel : public AttrHolder {
  33. public:
  34. GeModel();
  35. ~GeModel() = default;
  36. GeModel(const GeModel &other) = delete;
  37. GeModel &operator=(const GeModel &other) = delete;
  38. const Graph &GetGraph() const;
  39. std::shared_ptr<domi::ModelTaskDef> GetModelTaskDefPtr() const;
  40. const TBEKernelStore &GetTBEKernelStore() const;
  41. const CustAICPUKernelStore &GetCustAICPUKernelStore() const;
  42. Buffer GetWeight() const;
  43. std::string GetName() const;
  44. uint32_t GetVersion() const;
  45. std::string GetPlatformVersion() const;
  46. uint8_t GetPlatformType() const;
  47. void SetGraph(const Graph &graph);
  48. void SetModelTaskDef(const std::shared_ptr<domi::ModelTaskDef> &task);
  49. void SetTBEKernelStore(const TBEKernelStore &tbe_kernal_store);
  50. void SetCustAICPUKernelStore(const CustAICPUKernelStore &cust_aicpu_kernal_store);
  51. void SetWeight(const Buffer &weights_buffer);
  52. void SetName(const std::string &name);
  53. void SetVersion(uint32_t version);
  54. void SetPlatformVersion(const std::string &platform_version);
  55. void SetPlatformType(uint8_t platform_type);
  56. void SetAttr(const ProtoAttrMap &attrs);
  57. ProtoAttrMap &MutableAttrMap() override;
  58. using AttrHolder::SetAttr;
  59. using AttrHolder::GetAllAttrs;
  60. using AttrHolder::GetAllAttrNames;
  61. void SetModelId(uint32_t model_id) { model_id_ = model_id; }
  62. uint32_t GetModelId() const { return model_id_; }
  63. Status GetSessionId(uint32_t model_id, uint64_t &session_id) const;
  64. void InsertSessionMap(uint32_t model_id, uint64_t session_id) {
  65. model_id_to_session_id_map_.insert({model_id, session_id});
  66. }
  67. protected:
  68. ConstProtoAttrMap &GetAttrMap() const override;
  69. private:
  70. void Init();
  71. ProtoAttrMap attrs_; /*lint !e148*/
  72. Graph graph_;
  73. std::shared_ptr<domi::ModelTaskDef> task_; /*lint !e148*/
  74. TBEKernelStore tbe_kernal_store_; /*lint !e148*/
  75. CustAICPUKernelStore cust_aicpu_kernal_store_; /*lint !e148*/
  76. Buffer weights_buffer_; /*lint !e148*/
  77. std::string name_;
  78. uint32_t version_ = {0};
  79. std::string platform_version_;
  80. uint8_t platform_type_ = {0};
  81. uint32_t model_id_ = INVALID_MODEL_ID;
  82. std::map<uint32_t, uint64_t> model_id_to_session_id_map_;
  83. };
  84. } // namespace ge
  85. using GeModelPtr = std::shared_ptr<ge::GeModel>;
  86. #endif // GE_MODEL_GE_MODEL_H_

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