Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include "core/optimizer/graph_transformer.h"
 
namespace onnxruntime {
 
/**
@Class ReshapeFusion
Rewrite graph fusing reshape subgraph to a single Reshape node.
*/
class ReshapeFusion : public GraphTransformer {
 public:
  ReshapeFusion(const InlinedHashSet<std::string_view>& compatible_execution_providers = {}) noexcept
      : GraphTransformer("ReshapeFusion", compatible_execution_providers) {}
 
  Status ApplyImpl(Graph& graph, bool& modified, int graph_level, const logging::Logger& logger) const override;
 
 private:
  static bool Fuse_Subgraph(Node& reshape, Graph& graph, const logging::Logger& logger);
  static bool Match_One_Element_Output_Subgraph_1(Graph& graph, const NodeArg& root_input, const Node& concat,
                                                  int index, gsl::span<const int64_t> shape_value, bool checkOneElementOnly, const logging::Logger& looger);
  static bool Match_One_Element_Output_Subgraph_2(Graph& graph, const NodeArg& root_input, const Node& concat,
                                                  int index, const logging::Logger& looger);
  static bool Is_One_Element_Input(const Node& cur_node, int index);
  static bool Is_One_Element_Output_Subgraph(Graph& graph, const NodeArg& root_input, const Node& concat,
                                             int index, gsl::span<const int64_t> shape_value, const logging::Logger& logger);
 
  // Remove contiguous Reshape/Squeeze/Unsqueeze if the shape info is concrete.
  // For some EP, such reshape Ops are not no-op, such as QNN EP, memory is allocated for each output,
  // so this fusion can help to reduce memory usage on such devices.
  static bool FuseContiguousReshapes(Node& reshape, Graph& graph);
};
 
}  // namespace onnxruntime