Исходный код СУБД 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
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include "core/common/inlined_containers.h"
#include "core/common/logging/logging.h"
#include "core/common/common.h"
#include "core/optimizer/graph_transformer.h"
#include "core/framework/execution_providers.h"
#include "core/framework/compute_capability.h"
 
namespace onnxruntime {
/**
 * Optimizer's selection function: Selects a set of nodes from a given graph for optimization. Additional key/value strings can be provided to configure the optimizer.
 *                                 If needed, use graph_optimizer_registry to access the session options, the CPU EP and the logger.
 *
 * Optimizer's optimization function: Gets the nodes in ComputeCapability from nodes_to_optimize. Use graph_optimizer_registry to access the session options, the CPU EP
 *                                    and the logger if needed to create the optimizer. Run optimization on the nodes/subgraph, and finally, update the ComputeCapability.
 *
 */
using KeyValueConfig = std::unordered_map<std::string, std::string>;
using SelectionFunc = std::function<std::vector<std::unique_ptr<ComputeCapability>>(const GraphViewer&,
                                                                                    const KeyValueConfig&,
                                                                                    const GraphOptimizerRegistry& graph_optimizer_registry)>;
using OptimizationFunc = std::function<Status(Graph& graph,
                                              const ComputeCapability& optimization_cc,
                                              ComputeCapability& cc_to_update,
                                              const GraphOptimizerRegistry& graph_optimizer_registry)>;
 
/**
 * A registration/lookup class for re-usable optimizers for EPs.
 */
class GraphOptimizerRegistry {
 public:
  /**
   * The constructor takes in session options, the CPU EP and a logger as these are required by some optimizers.
   */
  GraphOptimizerRegistry(const onnxruntime::SessionOptions* sess_options,
                         const onnxruntime::IExecutionProvider* cpu_ep,
                         const logging::Logger* logger);
 
  /**
   * Get optimizer selection function. If the optimizer name can't be found, return nullopt.
   */
  std::optional<SelectionFunc> GetSelectionFunc(std::string& name) const;
 
  /**
   * Get CPU EP.
   */
  const onnxruntime::IExecutionProvider& GetCpuEp() const { return *cpu_ep_; }
 
  /**
   * Get Session Options.
   */
  const onnxruntime::SessionOptions& GetSessionOptions() const { return *session_options_; }
 
  /**
   * Get Logger.
   */
  const logging::Logger* GetLogger() const { return logger_; }
 
 private:
  const onnxruntime::SessionOptions* session_options_;
  const onnxruntime::IExecutionProvider* cpu_ep_;
  const logging::Logger* logger_;
 
#if !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD)
  InlinedHashMap<std::string, SelectionFunc> transformer_name_to_selection_func_;
 
  /**
   * Create pre-defined selection functions.
   */
  Status CreatePredefinedSelectionFuncs();
#endif
};
}  // namespace onnxruntime