Исходный код СУБД 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
78
79
80
81
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include <memory>
#include "core/common/inlined_containers_fwd.h"
#include "core/session/onnxruntime_c_api.h"
#include "core/framework/allocator.h"
#include "core/framework/data_types.h"
#include "core/framework/error_code_helper.h"
#include "core/framework/kernel_def_builder.h"
#include "core/framework/kernel_registry.h"
#include "core/framework/op_kernel.h"
#include "core/framework/prepacked_weights.h"
 
/// <summary>
/// Implementation of the public C API opaque type OrtSharedPrePackedWeightCache used by plugin EP kernels.
/// This wraps and fills out an instance of onnxruntime::PrePackedWeights via the
/// C API SharedPrePackedWeightCache_StoreWeightData.
/// </summary>
struct OrtSharedPrePackedWeightCache {
  /// <summary>
  /// Constructs an OrtSharedPrePackedWeightCache that will fill out the provided PrePackedWeights object.
  /// </summary>
  /// <param name="container">The PrePackedWeights container to fill out.</param>
  /// <param name="allocator">The allocator that will be used to free buffers set by the call to SetBuffers().</param>
  OrtSharedPrePackedWeightCache(onnxruntime::PrePackedWeights& container, onnxruntime::AllocatorPtr allocator);
 
  /// <summary>
  /// Sets data buffers for the shared weight. Ownership of the buffers is transferred to this class's contained
  /// PrePackedWeights instance, which will delete the buffers with `this->allocator_`.
  /// The buffer data is required to have been allocated with `this->allocator_`.
  /// Refer to OrtKernelImpl::PrePackWeight and OrtEpApi::SharedPrePackedWeightCache_StoreWeightData.
  /// </summary>
  /// <param name="data_ptrs"></param>
  /// <param name="data_sizes"></param>
  /// <param name="num_buffers"></param>
  void SetBuffers(void** data_ptrs, size_t* data_sizes, size_t num_buffers);
 
  /// <summary>
  /// Returns true if this instance has any weight buffer data.
  /// </summary>
  /// <returns></returns>
  bool HasData() const noexcept;
 
  /// <summary>
  /// Releases all buffer data.
  /// Used within OrtEpApi::SharedPrePackedWeightCache_StoreWeightData() if an error occurs and ORT wants to
  /// release all data to allow caller to retain ownership of data.
  /// </summary>
  void ReleaseAllData() noexcept;
 
 private:
  onnxruntime::PrePackedWeights& container_;
  onnxruntime::AllocatorPtr allocator_;
};
 
namespace onnxruntime {
 
/// <summary>
/// Make a KernelCreateInfo for a plugin EP's kernel. A KernelCreateInfo contains the function and state
/// necessary to create a kernel.
/// </summary>
/// <param name="kernel_def"></param>
/// <param name="kernel_create_func"></param>
/// <param name="kernel_create_func_state"></param>
/// <returns></returns>
KernelCreateInfo MakePluginEpKernelCreateInfo(const KernelDef* kernel_def,
                                              OrtKernelCreateFunc kernel_create_func,
                                              void* kernel_create_func_state);
 
/// <summary>
/// Gets the kernel registry for a plugin EP.
/// </summary>
/// <param name="ort_ep">The OrtEp instance.</param>
/// <param name="kernel_registry">Output parameter set to the EP's registry.</param>
/// <returns>A status indicating success or an error</returns>
Status GetPluginEpKernelRegistry(OrtEp& ort_ep, /*out*/ std::shared_ptr<KernelRegistry>& kernel_registry);
 
}  // namespace onnxruntime