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.

inplace_support_check_pass.cc 3.9 kB

4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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/passes/inplace_support_check_pass.h"
  17. #include "framework/common/debug/log.h"
  18. #include "graph/utils/graph_utils.h"
  19. #include "graph/debug/ge_attr_define.h"
  20. namespace ge {
  21. namespace {
  22. constexpr uint32_t kInplaceSupportOutputIndex = 0;
  23. constexpr uint32_t kInplaceSupportOutputNum = 1;
  24. const std::set<std::string> kSrcNodeTypes = { ge::DATA, ge::ANN_DATA, ge::AIPPDATA,
  25. ge::CONSTANT, ge::CONSTANTOP,
  26. ge::VARIABLE, ge::VARIABLEV2 };
  27. }
  28. Status InplaceSupportCheckPass::Run(NodePtr &node) {
  29. GELOGD("InplaceSupportCheckPass running");
  30. if (node->GetAllOutDataAnchorsSize() != kInplaceSupportOutputNum) {
  31. GELOGD("output num of node %s is not %u, skip InplaceSupportCheckPass",
  32. node->GetName().c_str(), kInplaceSupportOutputNum);
  33. return SUCCESS;
  34. }
  35. GE_CHECK_NOTNULL(node->GetOpDesc());
  36. const DataType &output_type = node->GetOpDesc()->GetOutputDesc(kInplaceSupportOutputIndex).GetDataType();
  37. const GeShape &output_shape = node->GetOpDesc()->GetOutputDesc(kInplaceSupportOutputIndex).GetShape();
  38. GELOGD("process InplaceSupportCheckPass on node %s", node->GetName().c_str());
  39. for (const auto &in_data_anchor : node->GetAllInDataAnchors()) {
  40. const auto &peer_data_anchor = in_data_anchor->GetPeerOutAnchor();
  41. if (peer_data_anchor == nullptr) {
  42. continue;
  43. }
  44. auto in_node = peer_data_anchor->GetOwnerNode();
  45. if (kSrcNodeTypes.count(in_node->GetType()) > 0) {
  46. GELOGD("meet src_node %s", in_node->GetName().c_str());
  47. continue;
  48. }
  49. if (peer_data_anchor->GetPeerInDataNodesSize() != kInplaceSupportOutputNum) {
  50. GELOGD("peer_data_anchor links with multi in_data_anchors");
  51. continue;
  52. }
  53. int32_t inplace_input_idx = in_data_anchor->GetIdx();
  54. const DataType &input_type = node->GetOpDesc()->GetInputDesc(inplace_input_idx).GetDataType();
  55. const GeShape &input_shape = node->GetOpDesc()->GetInputDesc(inplace_input_idx).GetShape();
  56. if (input_type != output_type) {
  57. GELOGW("DataType mismatch, in_idx=%d, input_type=%u, output_type=%u", inplace_input_idx, input_type, output_type);
  58. continue;
  59. }
  60. if (input_shape.GetDims() != output_shape.GetDims()) {
  61. GELOGW("Shape mismatch, in_idx=%d, input_shape=[%s], output_shape=[%s]",
  62. inplace_input_idx, input_shape.ToString().c_str(), output_shape.ToString().c_str());
  63. continue;
  64. }
  65. GELOGD("add attr INPLACE_SUPPORT_INPUT_INDEX on node %s, input_idx=%d", node->GetName().c_str(), inplace_input_idx);
  66. if (!AttrUtils::SetInt(node->GetOpDesc()->MutableOutputDesc(kInplaceSupportOutputIndex),
  67. INPLACE_SUPPORT_INPUT_INDEX, inplace_input_idx)) {
  68. REPORT_CALL_ERROR("E19999", "Set Attr:%s to output:%u tensor of op:%s(%s) failed",
  69. INPLACE_SUPPORT_INPUT_INDEX.c_str(), kInplaceSupportOutputIndex,
  70. node->GetName().c_str(), node->GetType().c_str());
  71. GELOGE(FAILED, "[Set][Attr] %s to output:%u tensor of op:%s(%s) failed",
  72. INPLACE_SUPPORT_INPUT_INDEX.c_str(), kInplaceSupportOutputIndex,
  73. node->GetName().c_str(), node->GetType().c_str());
  74. return FAILED;
  75. }
  76. AddRePassNode(node);
  77. break;
  78. }
  79. return SUCCESS;
  80. }
  81. } // namespace ge

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