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.4 kB

5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
3 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
3 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
3 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 "framework/common/ge_types.h"
  28. #include "graph/buffer.h"
  29. #include "external/graph/graph.h"
  30. #include "proto/task.pb.h"
  31. namespace ge {
  32. class GeModel : public AttrHolder {
  33. public:
  34. GeModel();
  35. ~GeModel() override = 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. bool LoadTBEKernelStore(const uint8_t *const data, const size_t len);
  53. bool loadAICPUKernelStore(const uint8_t *const data, const size_t len);
  54. void SetName(const std::string &name);
  55. void SetVersion(const uint32_t version);
  56. void SetPlatformVersion(const std::string &platform_version);
  57. void SetPlatformType(const uint8_t platform_type);
  58. void SetAttr(const ProtoAttrMap &attrs);
  59. ProtoAttrMap &MutableAttrMap() override;
  60. using AttrHolder::SetAttr;
  61. using AttrHolder::GetAllAttrs;
  62. using AttrHolder::GetAllAttrNames;
  63. void SetModelId(const uint32_t model_id) { model_id_ = model_id; }
  64. uint32_t GetModelId() const { return model_id_; }
  65. Status GetSessionId(const uint32_t model_id, uint64_t &session_id) const;
  66. protected:
  67. ConstProtoAttrMap &GetAttrMap() const override;
  68. private:
  69. void Init();
  70. ProtoAttrMap attrs_; /*lint !e148*/
  71. Graph graph_;
  72. std::shared_ptr<domi::ModelTaskDef> task_; /*lint !e148*/
  73. TBEKernelStore tbe_kernal_store_; /*lint !e148*/
  74. CustAICPUKernelStore cust_aicpu_kernal_store_; /*lint !e148*/
  75. Buffer weights_buffer_; /*lint !e148*/
  76. std::string name_;
  77. uint32_t version_ = {0U};
  78. std::string platform_version_;
  79. uint8_t platform_type_ = {0U};
  80. uint32_t model_id_ = INVALID_MODEL_ID;
  81. std::map<uint32_t, uint64_t> model_id_to_session_id_map_;
  82. };
  83. } // namespace ge
  84. using GeModelPtr = std::shared_ptr<ge::GeModel>;
  85. #endif // GE_MODEL_GE_MODEL_H_

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