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.6 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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. attrs_.InitDefault();
  35. Init();
  36. }
  37. const Graph &GeModel::GetGraph() const { return this->graph_; }
  38. std::shared_ptr<domi::ModelTaskDef> GeModel::GetModelTaskDefPtr() const { return this->task_; }
  39. const TBEKernelStore &GeModel::GetTBEKernelStore() const { return this->tbe_kernal_store_; }
  40. const CustAICPUKernelStore &GeModel::GetCustAICPUKernelStore() const { return this->cust_aicpu_kernal_store_; }
  41. Buffer GeModel::GetWeight() const { return this->weights_buffer_; }
  42. std::string GeModel::GetName() const { return this->name_; }
  43. uint32_t GeModel::GetVersion() const { return this->version_; }
  44. std::string GeModel::GetPlatformVersion() const { return this->platform_version_; }
  45. uint8_t GeModel::GetPlatformType() const { return this->platform_type_; }
  46. void GeModel::SetGraph(const Graph &graph) { this->graph_ = graph; }
  47. void GeModel::SetModelTaskDef(const std::shared_ptr<domi::ModelTaskDef> &task) { this->task_ = task; }
  48. void GeModel::SetTBEKernelStore(const TBEKernelStore &tbe_kernal_store) {
  49. this->tbe_kernal_store_ = tbe_kernal_store;
  50. }
  51. void GeModel::SetCustAICPUKernelStore(const CustAICPUKernelStore &cust_aicpu_kernal_store) {
  52. this->cust_aicpu_kernal_store_ = cust_aicpu_kernal_store;
  53. }
  54. void GeModel::SetWeight(const Buffer &weights_buffer) { this->weights_buffer_ = weights_buffer; }
  55. void GeModel::SetName(const std::string &name) { this->name_ = name; }
  56. void GeModel::SetVersion(uint32_t version) { this->version_ = version; }
  57. void GeModel::SetPlatformVersion(const std::string &platform_version) { this->platform_version_ = platform_version; }
  58. void GeModel::SetPlatformType(uint8_t platform_type) { this->platform_type_ = platform_type; }
  59. void GeModel::SetAttr(const ProtoAttrMapHelper &attrs) { attrs_ = attrs; }
  60. ProtoAttrMapHelper GeModel::MutableAttrMap() { return attrs_; }
  61. ConstProtoAttrMapHelper GeModel::GetAttrMap() const {
  62. return ConstProtoAttrMapHelper(attrs_.GetProtoOwner(), attrs_.GetProtoMsg());
  63. }
  64. Status GeModel::GetSessionId(uint32_t model_id, uint64_t &session_id) const {
  65. auto it = model_id_to_session_id_map_.find(model_id);
  66. if (it != model_id_to_session_id_map_.end()) {
  67. session_id = it->second;
  68. return SUCCESS;
  69. }
  70. GELOGW("No session id were found with model id [%u].", model_id);
  71. return INTERNAL_ERROR;
  72. }
  73. } // namespace ge

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