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

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

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