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_optimizer.h 3.4 kB

5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #ifndef GE_GRAPH_OPTIMIZE_GRAPH_OPTIMIZER_H_
  17. #define GE_GRAPH_OPTIMIZE_GRAPH_OPTIMIZER_H_
  18. #include <map>
  19. #include <string>
  20. #include <unordered_map>
  21. #include <vector>
  22. #include "graph/anchor.h"
  23. #include "graph/compute_graph.h"
  24. #include "graph/node.h"
  25. #include "omg/omg_inner_types.h"
  26. namespace ge {
  27. class ParserGraphOptimizer {
  28. public:
  29. explicit ParserGraphOptimizer(ge::ComputeGraphPtr graph, domi::FrameworkType type = domi::TENSORFLOW)
  30. : graph_(graph), fmktype_(type) {}
  31. ~ParserGraphOptimizer() {}
  32. domi::Status FusionFmkop();
  33. private:
  34. ge::ComputeGraphPtr graph_;
  35. domi::FrameworkType fmktype_;
  36. domi::Status FindFmkNodeCluser(std::unordered_map<std::string, std::vector<ge::NodePtr>> &node_cluser_Map) const;
  37. domi::Status MarkForFusion(std::unordered_map<std::string, std::vector<ge::NodePtr>> &node_cluster_map);
  38. domi::Status GetFusionCluster(const bool has_get_next, const bool has_dyn_get_next,
  39. unordered_map<string, vector<NodePtr>> &node_cluster_map);
  40. domi::Status UpdateGraph(std::vector<ge::NodePtr> &nodes);
  41. static domi::Status InsertNode(ge::ComputeGraphPtr sub_graph, std::vector<ge::NodePtr> &nodes,
  42. std::vector<ge::InDataAnchorPtr> &input_anchors,
  43. std::vector<ge::OutDataAnchorPtr> &output_anchors,
  44. std::map<ge::OutDataAnchorPtr, std::vector<ge::InDataAnchorPtr>> &output_in_map,
  45. std::vector<ge::InControlAnchorPtr> &input_control_anchors,
  46. std::vector<ge::OutControlAnchorPtr> &output_control_anchors,
  47. std::unordered_map<std::string, ge::NodePtr> &node_map);
  48. domi::Status LinkInnerAnchor(std::unordered_map<std::string, ge::NodePtr> &node_map) const;
  49. static domi::Status RebuildOutputAnchors(std::vector<ge::OutDataAnchorPtr> &output_anchors,
  50. ge::OpDescPtr fusion_op_desc);
  51. static domi::Status RebuildInputAnchors(std::vector<ge::InDataAnchorPtr> &input_anchors,
  52. ge::OpDescPtr fusion_op_desc);
  53. static domi::Status RebuildFusionNode(std::vector<ge::InDataAnchorPtr> &input_anchors,
  54. std::vector<ge::OutDataAnchorPtr> &output_anchors,
  55. std::map<ge::OutDataAnchorPtr, std::vector<ge::InDataAnchorPtr>> &output_in_map,
  56. std::vector<ge::InControlAnchorPtr> &input_control_anchors,
  57. std::vector<ge::OutControlAnchorPtr> &output_control_anchors,
  58. ge::NodePtr fusion_node);
  59. };
  60. } // namespace ge
  61. #endif // GE_GRAPH_OPTIMIZE_GRAPH_OPTIMIZER_H_