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.

hccl_group_pass.cc 2.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 "hccl_group_pass.h"
  17. #include <deque>
  18. #include "framework/common/debug/ge_log.h"
  19. #include "graph/debug/ge_attr_define.h"
  20. #include "framework/common/util.h"
  21. namespace ge {
  22. Status HcclGroupPass::Run(NodePtr &node) {
  23. GE_CHECK_NOTNULL(node);
  24. OpDescPtr op_desc = node->GetOpDesc();
  25. GE_CHECK_NOTNULL(op_desc);
  26. bool is_fused_node = false;
  27. if (!AttrUtils::GetBool(op_desc, ATTR_NAME_HCCL_FUSED_FLAG, is_fused_node)) {
  28. GELOGW("Get attr ATTR_NAME_GRADIENT_FUSED_GROUP failed.");
  29. return SUCCESS;
  30. }
  31. GELOGI("Recoginzed fused node %s", node->GetName().c_str());
  32. if (op_desc->HasAttr(ATTR_NAME_HCCL_FUSED_GROUP)) {
  33. GELOGD("Current node %s already marked group id, ignore it.", node->GetName().c_str());
  34. return SUCCESS;
  35. }
  36. if (!is_fused_node) {
  37. GELOGD("Current node %s is not gradient fused node , ignore it.", node->GetName().c_str());
  38. return SUCCESS;
  39. }
  40. Status ret = MarkGroupForFusedNode(node);
  41. if (ret != SUCCESS) {
  42. GELOGW("Mark group for fused node %s failed. It might cause performance problem.", node->GetName().c_str());
  43. }
  44. return SUCCESS;
  45. }
  46. Status HcclGroupPass::MarkGroupForFusedNode(NodePtr &fused_node) {
  47. std::deque<NodePtr> queue;
  48. queue.push_back(fused_node);
  49. string group_id = fused_node->GetName();
  50. while (!queue.empty()) {
  51. NodePtr node = queue.front();
  52. queue.pop_front();
  53. for (auto out_data_node : node->GetOutDataNodes()) {
  54. if (out_data_node->GetType() == fused_node->GetType()) {
  55. // if meet fused node, it is the end of current group
  56. break;
  57. }
  58. if (!AttrUtils::SetStr(out_data_node->GetOpDesc(), ATTR_NAME_HCCL_FUSED_GROUP, group_id)) {
  59. GELOGW("Set attr ATTR_NAME_GRADIENT_FUSED_GROUP failed.");
  60. return FAILED;
  61. }
  62. GELOGI("Set group_id %s for node %s", group_id.c_str(), out_data_node->GetName().c_str());
  63. queue.emplace_back(out_data_node);
  64. }
  65. }
  66. return SUCCESS;
  67. }
  68. } // namespace ge

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