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.

label_allocator.cc 4.3 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #include "label_allocator.h"
  17. #include "framework/common/types.h"
  18. #include "common/util.h"
  19. #include "common/ge_inner_error_codes.h"
  20. #include "graph/debug/ge_attr_define.h"
  21. #include "graph/utils/graph_utils.h"
  22. #include "graph/label/label_maker.h"
  23. namespace ge {
  24. LabelAllocator::LabelAllocator(const ComputeGraphPtr &graph) : compute_graph_(graph) {}
  25. Status LabelAllocator::AssignFunctionalLabels() {
  26. if (compute_graph_ == nullptr) {
  27. REPORT_INNER_ERROR("E19999", "check param compute_graph nullptr");
  28. GELOGE(INTERNAL_ERROR, "[Check][Param] ComputeGraph not set, Assign labels failed.");
  29. return INTERNAL_ERROR;
  30. }
  31. // Add label task for sub graph.
  32. GELOGD("AssignFunctionalLabels start: %s.", compute_graph_->GetName().c_str());
  33. std::set<NodePtr> functional_nodes;
  34. for (auto graph : compute_graph_->GetAllSubgraphs()) {
  35. if (!CollectFunctionalNode(graph, functional_nodes)) {
  36. return INTERNAL_ERROR;
  37. }
  38. }
  39. // Add label for functional op.
  40. uint32_t label_index = 0;
  41. for (auto node : functional_nodes) {
  42. LabelMakerPtr maker = LabelMakerFactory::Instance().Create(node->GetType(), compute_graph_, node);
  43. if (maker == nullptr) {
  44. REPORT_CALL_ERROR("E19999", "Check Node:%s(%s) label maker not registed",
  45. node->GetName().c_str(), node->GetType().c_str());
  46. GELOGE(INTERNAL_ERROR, "[Create][LabelMaker] Node: %s label maker not registed.", node->GetType().c_str());
  47. return INTERNAL_ERROR;
  48. }
  49. if (maker->Run(label_index) != SUCCESS) {
  50. REPORT_CALL_ERROR("E19999", "Node:%s(%s) run label maker failed",
  51. node->GetName().c_str(), node->GetType().c_str());
  52. GELOGE(INTERNAL_ERROR, "[Call][Run] Node: %s run label maker failed.", node->GetType().c_str());
  53. return INTERNAL_ERROR;
  54. }
  55. }
  56. (void)AttrUtils::SetInt(*compute_graph_, ATTR_MODEL_LABEL_NUM, label_index);
  57. GELOGI("AssignFunctionalLabels success, Num: %u.", label_index);
  58. return SUCCESS;
  59. }
  60. bool LabelAllocator::CollectFunctionalNode(ComputeGraphPtr &graph, std::set<NodePtr> &functional_nodes) {
  61. if (graph == nullptr) {
  62. REPORT_INNER_ERROR("E19999", "check param compute_graph nullptr");
  63. GELOGE(INTERNAL_ERROR, "[Check][Param] Sub ComputeGraph is null.");
  64. return false;
  65. }
  66. if (graph->GetGraphUnknownFlag()) {
  67. GELOGD("Graph[%s] is unknown graph, skip label allocator.", graph->GetName().c_str());
  68. return true;
  69. }
  70. NodePtr func_node = graph->GetParentNode();
  71. if (func_node == nullptr) {
  72. REPORT_INNER_ERROR("E19999", "Parent node not set in node:%s(%s), graph:%s",
  73. func_node->GetName().c_str(), func_node->GetType().c_str(), graph->GetName().c_str());
  74. GELOGE(INTERNAL_ERROR, "[Get][Node] Parent functional node not set: %s.", graph->GetName().c_str());
  75. return false;
  76. }
  77. if (func_node->GetOpDesc() != nullptr && func_node->GetOpDesc()->HasAttr(ATTR_NAME_FFTS_SUB_GRAPH)) {
  78. GELOGD("Graph[%s] is ffts subgraph, skip label allocator.", graph->GetName().c_str());
  79. return true;
  80. }
  81. ComputeGraphPtr owner_graph = func_node->GetOwnerComputeGraph();
  82. if (owner_graph == nullptr) {
  83. REPORT_INNER_ERROR("E19999", "ComputeGraph owner not set in node:%s(%s), graph:%s",
  84. func_node->GetName().c_str(), func_node->GetType().c_str(), graph->GetName().c_str());
  85. GELOGE(INTERNAL_ERROR, "[Get][Graph] ComputeGraph owner not set: %s.", func_node->GetName().c_str());
  86. return false;
  87. }
  88. if (owner_graph->GetGraphUnknownFlag()) {
  89. GELOGD("Graph[%s] is unknown graph, skip label allocator.", owner_graph->GetName().c_str());
  90. return true;
  91. }
  92. (void)functional_nodes.insert(func_node); // unique functional node.
  93. return true;
  94. }
  95. } // namespace ge

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