Исходный код СУБД 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
 
namespace Microsoft.ML.OnnxRuntime
{
    /// <summary>
    /// Represents a synchronization primitive for stream operations.
    /// </summary>
    public class OrtSyncStream : SafeHandle
    {
        internal OrtSyncStream(IntPtr streamHandle)
            : base(IntPtr.Zero, true) // Provide required arguments to SafeHandle constructor
        {
            handle = streamHandle;
        }
 
        /// <summary>
        /// Fetch sync stream handle for possible use
        /// in session options.
        /// </summary>
        /// <returns>Opaque stream handle</returns>
        public IntPtr GetHandle()
        {
            return NativeMethods.OrtSyncStream_GetHandle(handle);
        }
 
        internal IntPtr Handle => handle;
 
        /// <summary>
        /// Implements SafeHandle interface
        /// </summary>
        public override bool IsInvalid => handle == IntPtr.Zero;
 
        /// <summary>
        /// Implements SafeHandle interface to release native handle
        /// </summary>
        /// <returns>always true</returns>
        protected override bool ReleaseHandle()
        {
            NativeMethods.OrtReleaseSyncStream(handle);
            handle = IntPtr.Zero;
            return true;
        }
    }
 
    /// <summary>
    /// Represents the combination of an execution provider and a hardware device 
    /// that the execution provider can utilize.
    /// </summary>
    public class OrtEpDevice
    {
        /// <summary>
        /// Construct an OrtEpDevice from an existing native OrtEpDevice instance.
        /// </summary>
        /// <param name="epDeviceHandle">Native OrtEpDevice handle.</param>
        internal OrtEpDevice(IntPtr epDeviceHandle)
        {
            _handle = epDeviceHandle;
        }
 
        internal IntPtr Handle => _handle;
 
        /// <summary>
        /// The name of the execution provider.
        /// </summary>
        public string EpName
        {
            get
            {
                IntPtr namePtr = NativeMethods.OrtEpDevice_EpName(_handle);
                return NativeOnnxValueHelper.StringFromNativeUtf8(namePtr);
            }
        }
 
        /// <summary>
        /// The vendor who owns the execution provider.
        /// </summary>
        public string EpVendor
        {
            get
            {
                IntPtr vendorPtr = NativeMethods.OrtEpDevice_EpVendor(_handle);
                return NativeOnnxValueHelper.StringFromNativeUtf8(vendorPtr);
            }
        }
 
        /// <summary>
        /// Execution provider metadata.
        /// </summary>
        public OrtKeyValuePairs EpMetadata
        {
            get
            {
                return new OrtKeyValuePairs(NativeMethods.OrtEpDevice_EpMetadata(_handle));
            }
        }
 
        /// <summary>
        /// Execution provider options.
        /// </summary>
        public OrtKeyValuePairs EpOptions
        {
            get
            {
                return new OrtKeyValuePairs(NativeMethods.OrtEpDevice_EpOptions(_handle));
            }
        }
 
        /// <summary>
        /// The hardware device that the execution provider can utilize.
        /// </summary>
        public OrtHardwareDevice HardwareDevice
        {
            get
            {
                IntPtr devicePtr = NativeMethods.OrtEpDevice_Device(_handle);
                return new OrtHardwareDevice(devicePtr);
            }
        }
 
        /// <summary>
        /// The OrtMemoryInfo instance describing the memory characteristics of the device.
        /// </summary>
        /// <param name="deviceMemoryType">memory type requested</param>
        /// <returns></returns>
        public OrtMemoryInfo GetMemoryInfo(OrtDeviceMemoryType deviceMemoryType)
        {
            IntPtr memoryInfoPtr = NativeMethods.OrtEpDevice_MemoryInfo(_handle, deviceMemoryType);
            return new OrtMemoryInfo(memoryInfoPtr, /* owned= */ false);
        }
 
        /// <summary>
        /// Creates a synchronization stream for operations on this device.
        /// Can be used to implement async operations on the device such as
        /// CopyTensors.
        /// </summary>
        /// <param name="streamOptions">stream options can be null</param>
        /// <returns></returns>
        public OrtSyncStream CreateSyncStream(IReadOnlyDictionary<string, string> streamOptions)
        {
            OrtKeyValuePairs options = null;
            IntPtr optionsHandle = IntPtr.Zero;
            try
            {
                if (streamOptions != null)
                {
                    options = new OrtKeyValuePairs(streamOptions);
                    optionsHandle = options.Handle;
                }
 
                NativeApiStatus.VerifySuccess(NativeMethods.OrtCreateSyncStreamForEpDevice(_handle,
                    optionsHandle, out IntPtr syncStream));
                return new OrtSyncStream(syncStream);
            }
            finally
            {
                options?.Dispose();
            }
        }
 
        private readonly IntPtr _handle;
    }
}