Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include "core/common/status.h"
#include "core/platform/path_lib.h"
#include "core/framework/alloc_kind.h"
#include "core/framework/allocator.h"
#include "core/framework/sequential_execution_plan.h"
#include "core/graph/graph_viewer.h"
#include "core/framework/session_options.h"
 
namespace ONNX_NAMESPACE {
class TensorShapeProto;
}
namespace onnxruntime {
 
namespace NestedSubgraphInfoDetails {
 
// Used to compose a unique key to identify a nested subgraph
// relative to a current graph level (which in turn is identified using a "base")
std::string ComposeNestedSubgraphInfoKeyHelper(const std::string& base, size_t graph_depth,
                                               NodeIndex node_index, const std::string& attr_name);
 
}  // namespace NestedSubgraphInfoDetails
 
class ExecutionProviders;
struct KernelCreateInfo;
class KernelRegistryManager;
class OrtValueNameIdxMap;
class IStreamCommandHandleRegistry;
 
using KernelCreateInfoMap = std::unordered_map<onnxruntime::NodeIndex, gsl::not_null<const KernelCreateInfo*>>;
using SubgraphsKernelCreateInfoMaps = std::unordered_map<std::string, KernelCreateInfoMap>;
 
// ISequentialPlannerContext abstracts how the planner accesses information (such as inferred shape)
// to do the planning.
class ISequentialPlannerContext {
 public:
  virtual const ONNX_NAMESPACE::TensorShapeProto* GetShape(const onnxruntime::NodeArg& arg) const = 0;
  // If it returns true, planner won't reuse output tensors
  // see PlannerImpl::ComputeReusePlan
  virtual bool IsParallelExecutionEnabled() const { return false; }
 
  virtual ExecutionOrder GetExecutionOrder() const { return ExecutionOrder::DEFAULT; }
 
  virtual bool GetEnableMemoryReuse() const { return true; }
  virtual ~ISequentialPlannerContext() = default;
};
 
class SequentialPlannerContext : public ISequentialPlannerContext {
 public:
  SequentialPlannerContext(ExecutionMode execution_mode, ExecutionOrder execution_order, bool enable_memory_reuse)
      : execution_mode_(execution_mode),
        execution_order_(execution_order),
        enable_memory_reuse_(enable_memory_reuse) {
  }
 
  const ONNX_NAMESPACE::TensorShapeProto* GetShape(const onnxruntime::NodeArg& arg) const override {
    return arg.Shape();
  }
 
  bool IsParallelExecutionEnabled() const override { return execution_mode_ == ExecutionMode::ORT_PARALLEL; }
 
  ExecutionOrder GetExecutionOrder() const override { return execution_order_; }
 
  bool GetEnableMemoryReuse() const override { return enable_memory_reuse_; }
 
 private:
  ExecutionMode execution_mode_ = ExecutionMode::ORT_SEQUENTIAL;
  ExecutionOrder execution_order_ = ExecutionOrder::DEFAULT;
  bool enable_memory_reuse_ = true;
};
 
#ifdef ORT_ENABLE_STREAM
// Given a graph with node placement information, partition the nodes into multiple sequence.
// Each sequence can be executed in-dependently. The nodes in each sequence are executed in order,
// but we can't assume any execution order between sequences, unless there is a data dependency.
class IGraphPartitioner {
 public:
  // DeviceBasedPartitioner is the default, who partitions a graph based off device information.
  // i.e., given a graph which has CPU EP nodes, Cuda EP nodes and TRT EP nodes,
  // it will be partitioned as two sequences, one is for CPU EP nodes, another is for TRT and Cuda nodes.
  // We will add more optimized partitioner later.
  enum GraphPartitioningStrategy {
    DeviceBasedPartition = 0,
    Unknown,
  };
  virtual ~IGraphPartitioner() = default;
  // create the partition based on the partition type.
  // perform partition based on the user input when provided.
  static std::unique_ptr<IGraphPartitioner> CreateGraphPartitioner(const logging::Logger& logger,
                                                                   const PathString& config_file);
  virtual Status PartitionGraph(const onnxruntime::GraphViewer& graph_viewer,
                                const ExecutionProviders& execution_providers,
                                std::vector<InlinedVector<NodeIndex>>& stream_nodes,
                                ExecutionOrder execution_order) = 0;
  virtual const char* Type() const = 0;
  // return total number of streams
  virtual size_t Streams() const = 0;
 
 protected:
  IGraphPartitioner(const logging::Logger& logger,
                    const PathString& config_file) : logger_(logger),
                                                     config_file_(config_file) {}
  const logging::Logger& logger_;
  PathString config_file_;
};
#endif
 
class SequentialPlanner {
 public:
  // This API allows user to provide a custom planner context.
  // TODO - remove duplicated ExecutionProvider argument
  static Status CreatePlan(
      const Node* parent_node, const onnxruntime::GraphViewer& graph,
      gsl::span<const NodeArg* const> outer_scope_node_args,
      const ExecutionProviders& providers,
      const KernelCreateInfoMap& kernel_create_info_map,
      const SubgraphsKernelCreateInfoMaps& subgraphs_kernel_create_info_maps,
      const InlinedHashMap<OrtValueName, OrtDevice>& outer_scope_arg_to_location_map,
      const OrtValueNameIdxMap& ort_value_name_idx_map,
      const ISequentialPlannerContext& context,
#ifdef ORT_ENABLE_STREAM
      const IStreamCommandHandleRegistry& stream_handle_registry,
#endif
      const std::basic_string<PATH_CHAR_TYPE>& partition_config_file,
      const logging::Logger& logger,
      std::optional<SequentialExecutionPlan>& plan);
};
 
}  // namespace onnxruntime