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.

graph_pass.h 3.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #ifndef GE_INC_GRAPH_PASS_H_
  17. #define GE_INC_GRAPH_PASS_H_
  18. #include <string>
  19. #include <vector>
  20. #include "framework/common/op/attr_value_util.h"
  21. #include "framework/common/op/ge_op_utils.h"
  22. #include "framework/common/types.h"
  23. #include "framework/common/debug/ge_log.h"
  24. #include "graph/compute_graph.h"
  25. #include "graph/utils/attr_utils.h"
  26. #include "graph/utils/graph_utils.h"
  27. #include "inc/pass.h"
  28. namespace ge {
  29. ///
  30. /// @ingroup domi_omg
  31. /// @brief graph pass
  32. /// @author
  33. ///
  34. class GraphPass : public Pass<ge::ComputeGraph> {
  35. public:
  36. ///
  37. /// run graph pass
  38. /// @param [in] graph graph to be optimized
  39. /// @return SUCCESS optimize successfully
  40. /// @return NOT_CHANGED not optimized
  41. /// @return others optimized failed
  42. /// @author
  43. ///
  44. virtual Status Run(ge::ComputeGraphPtr graph) = 0;
  45. virtual Status ClearStatus() { return SUCCESS; };
  46. static void RecordOriginalNames(std::vector<ge::NodePtr> original_nodes, const ge::NodePtr &node) {
  47. GE_CHECK_NOTNULL_JUST_RETURN(node);
  48. std::vector<std::string> original_names;
  49. for (ge::NodePtr &node_tmp : original_nodes) {
  50. std::vector<std::string> names_tmp;
  51. ge::OpDescPtr opdesc_tmp = node_tmp->GetOpDesc();
  52. GE_CHECK_NOTNULL_JUST_RETURN(opdesc_tmp);
  53. Status ret = ge::AttrUtils::GetListStr(opdesc_tmp, "_datadump_original_op_names", names_tmp);
  54. if (ret != domi::SUCCESS) {
  55. GELOGW("get the original_op_names fail.");
  56. }
  57. if (names_tmp.size() != 0) {
  58. original_names.insert(original_names.end(), names_tmp.begin(), names_tmp.end());
  59. } else {
  60. original_names.push_back(opdesc_tmp->GetName());
  61. }
  62. }
  63. if (original_names.size() == 0) {
  64. std::string tmp;
  65. original_names.push_back(tmp);
  66. }
  67. GE_CHK_BOOL_EXEC(ge::AttrUtils::SetListStr(node->GetOpDesc(), "_datadump_original_op_names", original_names),
  68. return, "Set original_op_names fail.");
  69. }
  70. static bool IsConstNode(const ge::NodePtr &node) {
  71. GE_IF_BOOL_EXEC(node->GetOpDesc() == nullptr, GELOGE(FAILED, "Node GetOpDesc is nullptr"); return false);
  72. if (node->GetOpDesc()->GetType() == CONSTANTOP) {
  73. return true;
  74. } else if (node->GetOpDesc()->GetType() == FRAMEWORKOP) {
  75. string type;
  76. GE_CHK_BOOL_EXEC(ge::AttrUtils::GetStr(node->GetOpDesc(), ATTR_NAME_FRAMEWORK_ORIGINAL_TYPE, type),
  77. return false, "Get original_type for op %s fail!", node->GetName().c_str());
  78. GE_IF_BOOL_EXEC(type == CONSTANT, GELOGI("Is const op"); return true);
  79. return false;
  80. } else {
  81. return false;
  82. }
  83. }
  84. };
  85. } // namespace ge
  86. #endif // GE_INC_GRAPH_PASS_H_

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