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

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