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.2 kB

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

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