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.cc 3.5 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
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include "common/model/ge_model.h"
  17. #include <utility>
  18. #include "framework/common/debug/log.h"
  19. #include "graph/debug/ge_attr_define.h"
  20. #include "graph/utils/attr_utils.h"
  21. namespace ge {
  22. void GeModel::Init() {
  23. (void)AttrUtils::SetInt(this, ATTR_MODEL_MEMORY_SIZE, 0);
  24. (void)AttrUtils::SetInt(this, ATTR_MODEL_P2P_MEMORY_SIZE, 0);
  25. (void)AttrUtils::SetInt(this, ATTR_MODEL_STREAM_NUM, 0);
  26. (void)AttrUtils::SetInt(this, ATTR_MODEL_EVENT_NUM, 0);
  27. (void)AttrUtils::SetInt(this, ATTR_MODEL_LABEL_NUM, 0);
  28. (void)AttrUtils::SetInt(this, ATTR_MODEL_WEIGHT_SIZE, 0);
  29. (void)AttrUtils::SetStr(this, ATTR_MODEL_TARGET_TYPE, TARGET_TYPE_MINI);
  30. version_ = 0;
  31. // default attrSize = 5
  32. }
  33. GeModel::GeModel() {
  34. Init();
  35. }
  36. const Graph &GeModel::GetGraph() const { return this->graph_; }
  37. std::shared_ptr<domi::ModelTaskDef> GeModel::GetModelTaskDefPtr() const { return this->task_; }
  38. const TBEKernelStore &GeModel::GetTBEKernelStore() const { return this->tbe_kernal_store_; }
  39. const CustAICPUKernelStore &GeModel::GetCustAICPUKernelStore() const { return this->cust_aicpu_kernal_store_; }
  40. Buffer GeModel::GetWeight() const { return this->weights_buffer_; }
  41. std::string GeModel::GetName() const { return this->name_; }
  42. uint32_t GeModel::GetVersion() const { return this->version_; }
  43. std::string GeModel::GetPlatformVersion() const { return this->platform_version_; }
  44. uint8_t GeModel::GetPlatformType() const { return this->platform_type_; }
  45. void GeModel::SetGraph(const Graph &graph) { this->graph_ = graph; }
  46. void GeModel::SetModelTaskDef(const std::shared_ptr<domi::ModelTaskDef> &task) { this->task_ = task; }
  47. void GeModel::SetTBEKernelStore(const TBEKernelStore &tbe_kernal_store) {
  48. this->tbe_kernal_store_ = tbe_kernal_store;
  49. }
  50. void GeModel::SetCustAICPUKernelStore(const CustAICPUKernelStore &cust_aicpu_kernal_store) {
  51. this->cust_aicpu_kernal_store_ = cust_aicpu_kernal_store;
  52. }
  53. void GeModel::SetWeight(const Buffer &weights_buffer) { this->weights_buffer_ = weights_buffer; }
  54. void GeModel::SetName(const std::string &name) { this->name_ = name; }
  55. void GeModel::SetVersion(uint32_t version) { this->version_ = version; }
  56. void GeModel::SetPlatformVersion(const std::string &platform_version) { this->platform_version_ = platform_version; }
  57. void GeModel::SetPlatformType(uint8_t platform_type) { this->platform_type_ = platform_type; }
  58. void GeModel::SetAttr(const ProtoAttrMap &attrs) { attrs_ = attrs; }
  59. ProtoAttrMap &GeModel::MutableAttrMap() { return attrs_; }
  60. ConstProtoAttrMap &GeModel::GetAttrMap() const {
  61. return attrs_;
  62. }
  63. Status GeModel::GetSessionId(uint32_t model_id, uint64_t &session_id) const {
  64. auto it = model_id_to_session_id_map_.find(model_id);
  65. if (it != model_id_to_session_id_map_.end()) {
  66. session_id = it->second;
  67. return SUCCESS;
  68. }
  69. GELOGW("No session id were found with model id [%u].", model_id);
  70. return INTERNAL_ERROR;
  71. }
  72. } // namespace ge

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