Исходный код СУБД 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#import <Foundation/Foundation.h>
 
#import "ort_custom_op_registration.h"
#import "ort_enums.h"
 
NS_ASSUME_NONNULL_BEGIN
 
@class ORTEnv;
@class ORTRunOptions;
@class ORTSessionOptions;
@class ORTValue;
 
/**
 * A block that supplies application-managed external EPContext data.
 *
 * Available since 1.31.
 *
 * The block may be called concurrently from arbitrary ONNX Runtime threads and must be thread-safe.
 *
 * @param name The logical name of the requested EPContext data.
 * @param error Error information to set when returning nil.
 * @return The requested data. Zero-length data is a successful empty payload. Return nil only on failure and set error.
 */
typedef NSData* _Nullable (^ORTEpContextDataReadBlock)(NSString* name, NSError** error);
 
/**
 * An ORT session loads and runs a model.
 */
@interface ORTSession : NSObject
 
- (instancetype)init NS_UNAVAILABLE;
 
/**
 * Creates a session.
 *
 * @param env The ORT Environment instance.
 * @param path The path to the ONNX model.
 * @param sessionOptions Optional session configuration options.
 * @param error Optional error information set if an error occurs.
 * @return The instance, or nil if an error occurs.
 */
- (nullable instancetype)initWithEnv:(ORTEnv*)env
                           modelPath:(NSString*)path
                      sessionOptions:(nullable ORTSessionOptions*)sessionOptions
                               error:(NSError**)error NS_DESIGNATED_INITIALIZER;
 
/**
 * Runs the model.
 * The inputs and outputs are pre-allocated.
 *
 * @param inputs Dictionary of input names to input ORT values.
 * @param outputs Dictionary of output names to output ORT values.
 * @param runOptions Optional run configuration options.
 * @param error Optional error information set if an error occurs.
 * @return Whether the model was run successfully.
 */
- (BOOL)runWithInputs:(NSDictionary<NSString*, ORTValue*>*)inputs
              outputs:(NSDictionary<NSString*, ORTValue*>*)outputs
           runOptions:(nullable ORTRunOptions*)runOptions
                error:(NSError**)error;
 
/**
 * Runs the model.
 * The inputs are pre-allocated and the outputs are allocated by ORT.
 *
 * @param inputs Dictionary of input names to input ORT values.
 * @param outputNames Set of output names.
 * @param runOptions Optional run configuration options.
 * @param error Optional error information set if an error occurs.
 * @return A dictionary of output names to output ORT values with the outputs
 *         requested in `outputNames`, or nil if an error occurs.
 */
- (nullable NSDictionary<NSString*, ORTValue*>*)runWithInputs:(NSDictionary<NSString*, ORTValue*>*)inputs
                                                  outputNames:(NSSet<NSString*>*)outputNames
                                                   runOptions:(nullable ORTRunOptions*)runOptions
                                                        error:(NSError**)error;
 
/**
 * Gets the model's input names.
 *
 * @param error Optional error information set if an error occurs.
 * @return An array of input names, or nil if an error occurs.
 */
- (nullable NSArray<NSString*>*)inputNamesWithError:(NSError**)error;
 
/**
 * Gets the model's overridable initializer names.
 *
 * @param error Optional error information set if an error occurs.
 * @return An array of overridable initializer names, or nil if an error occurs.
 */
- (nullable NSArray<NSString*>*)overridableInitializerNamesWithError:(NSError**)error;
 
/**
 * Gets the model's output names.
 *
 * @param error Optional error information set if an error occurs.
 * @return An array of output names, or nil if an error occurs.
 */
- (nullable NSArray<NSString*>*)outputNamesWithError:(NSError**)error;
 
@end
 
/**
 * Options for configuring a session.
 */
@interface ORTSessionOptions : NSObject
 
- (instancetype)init NS_UNAVAILABLE;
 
/**
 * Creates session configuration options.
 *
 * @param error Optional error information set if an error occurs.
 * @return The instance, or nil if an error occurs.
 */
- (nullable instancetype)initWithError:(NSError**)error NS_SWIFT_NAME(init());
 
/**
 * Appends an execution provider to the session options to enable the execution provider to be used when running
 * the model.
 *
 * Available since 1.14.
 *
 * The execution provider list is ordered by decreasing priority.
 * i.e. the first provider registered has the highest priority.
 *
 * @param providerName Provider name. For example, "xnnpack".
 * @param providerOptions Provider-specific options. For example, for provider "xnnpack", {"intra_op_num_threads": "2"}.
 * @param error Optional error information set if an error occurs.
 * @return Whether the execution provider was appended successfully
 */
- (BOOL)appendExecutionProvider:(NSString*)providerName
                providerOptions:(NSDictionary<NSString*, NSString*>*)providerOptions
                          error:(NSError**)error;
/**
 * Sets the number of threads used to parallelize the execution within nodes.
 * A value of 0 means ORT will pick a default value.
 *
 * @param intraOpNumThreads The number of threads.
 * @param error Optional error information set if an error occurs.
 * @return Whether the option was set successfully.
 */
- (BOOL)setIntraOpNumThreads:(int)intraOpNumThreads
                       error:(NSError**)error;
 
/**
 * Sets the graph optimization level.
 *
 * @param graphOptimizationLevel The graph optimization level.
 * @param error Optional error information set if an error occurs.
 * @return Whether the option was set successfully.
 */
- (BOOL)setGraphOptimizationLevel:(ORTGraphOptimizationLevel)graphOptimizationLevel
                            error:(NSError**)error;
 
/**
 * Sets the path to which the optimized model file will be saved.
 *
 * @param optimizedModelFilePath The optimized model file path.
 * @param error Optional error information set if an error occurs.
 * @return Whether the option was set successfully.
 */
- (BOOL)setOptimizedModelFilePath:(NSString*)optimizedModelFilePath
                            error:(NSError**)error;
 
/**
 * Sets the session log ID.
 *
 * @param logID The log ID.
 * @param error Optional error information set if an error occurs.
 * @return Whether the option was set successfully.
 */
- (BOOL)setLogID:(NSString*)logID
           error:(NSError**)error;
 
/**
 * Sets the session log severity level.
 *
 * @param loggingLevel The log severity level.
 * @param error Optional error information set if an error occurs.
 * @return Whether the option was set successfully.
 */
- (BOOL)setLogSeverityLevel:(ORTLoggingLevel)loggingLevel
                      error:(NSError**)error;
 
/**
 * Sets a session configuration key-value pair.
 * Any value for a previously set key will be overwritten.
 * The session configuration keys and values are documented here:
 * https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h
 *
 * @param key The key.
 * @param value The value.
 * @param error Optional error information set if an error occurs.
 * @return Whether the option was set successfully.
 */
- (BOOL)addConfigEntryWithKey:(NSString*)key
                        value:(NSString*)value
                        error:(NSError**)error;
 
/**
 * Registers a block that supplies application-managed external EPContext data during session initialization.
 *
 * Available since 1.31.
 *
 * The block is copied and retained by these options. Each `ORTSession` or `ORTTrainingSession` created from the options
 * takes its own strong registration snapshot for the session lifetime, so replacing or clearing the block only affects
 * future sessions.
 * ONNX Runtime may invoke the block concurrently from arbitrary threads; the block and any captured state must be
 * thread-safe. The returned bytes are copied before the block's returned `NSData` is released.
 *
 * Return zero-length `NSData` for a successful empty payload. Return nil only on failure and set the provided error.
 * Returning nil without an error produces an ONNX Runtime failure status. Data larger than `maxDataSize` is rejected
 * before the native output buffer is allocated.
 * This limit is retained and enforced by the Objective-C callback registration, not configured in the native API.
 * It does not constrain allocations made inside the block.
 *
 * The Objective-C API exposes only the application-side read callback. It does not currently expose model compilation,
 * so the EPContext data write callback is not applicable.
 *
 * @param block The synchronous block used to read EPContext data.
 * @param maxDataSize A finite maximum payload size in bytes. Must be greater than zero and less than `NSUIntegerMax`.
 * @param error Optional error information set if registration fails.
 * @return Whether the block was registered successfully.
 */
- (BOOL)setEpContextDataReadBlock:(ORTEpContextDataReadBlock)block
                      maxDataSize:(NSUInteger)maxDataSize
                            error:(NSError**)error;
 
/**
 * Clears the block that supplies application-managed external EPContext data for future sessions.
 *
 * Available since 1.31.
 *
 * `ORTSession` and `ORTTrainingSession` instances already created from these options retain their registration snapshot
 * for the session lifetime.
 *
 * @param error Optional error information set if clearing fails.
 * @return Whether the block was cleared successfully.
 */
- (BOOL)clearEpContextDataReadBlockWithError:(NSError**)error;
 
/**
 * Registers custom ops for use with `ORTSession`s using this SessionOptions by calling the specified
 * native function name. The custom ops library must either be linked against, or have previously been loaded
 * by the user.
 *
 * Available since 1.14.
 *
 * The registration function must have the signature:
 *    `OrtStatus* (*fn)(OrtSessionOptions* options, const OrtApiBase* api);`
 *
 * The signature is defined in the ONNX Runtime C API:
 * https://github.com/microsoft/onnxruntime/blob/67f4cd54fab321d83e4a75a40efeee95a6a17079/include/onnxruntime/core/session/onnxruntime_c_api.h#L697
 *
 * See https://onnxruntime.ai/docs/reference/operators/add-custom-op.html for more information on custom ops.
 * See https://github.com/microsoft/onnxruntime/blob/342a5bf2b756d1a1fc6fdc582cfeac15182632fe/onnxruntime/test/testdata/custom_op_library/custom_op_library.cc#L115
 * for an example of a custom op library registration function.
 *
 * @note The caller must ensure that `registrationFuncName` names a valid function that is visible to the native ONNX
 * Runtime code and has the correct signature.
 * They must ensure that the function does what they expect it to do because this method will just call it.
 *
 * @param registrationFuncName The name of the registration function to call.
 * @param error Optional error information set if an error occurs.
 * @return Whether the registration function was successfully called.
 */
- (BOOL)registerCustomOpsUsingFunction:(NSString*)registrationFuncName
                                 error:(NSError**)error;
 
/**
 * Registers custom ops for use with `ORTSession`s using this SessionOptions by calling the specified function
 * pointed to by `registerCustomOpsFn`.
 *
 * Available since 1.16.
 *
 * The registration function must have the signature:
 *    `OrtStatus* (*fn)(OrtSessionOptions* options, const OrtApiBase* api);`
 *
 * The signature is defined in the ONNX Runtime C API:
 * https://github.com/microsoft/onnxruntime/blob/67f4cd54fab321d83e4a75a40efeee95a6a17079/include/onnxruntime/core/session/onnxruntime_c_api.h#L697
 *
 * See https://onnxruntime.ai/docs/reference/operators/add-custom-op.html for more information on custom ops.
 * See https://github.com/microsoft/onnxruntime/blob/342a5bf2b756d1a1fc6fdc582cfeac15182632fe/onnxruntime/test/testdata/custom_op_library/custom_op_library.cc#L115
 * for an example of a custom op library registration function.
 *
 * @note The caller must ensure that `registerCustomOpsFn` is a valid function pointer and has the correct signature.
 * They must ensure that the function does what they expect it to do because this method will just call it.
 *
 * @param registerCustomOpsFn A pointer to the registration function to call.
 * @param error Optional error information set if an error occurs.
 * @return Whether the registration function was successfully called.
 */
- (BOOL)registerCustomOpsUsingFunctionPointer:(ORTCAPIRegisterCustomOpsFnPtr)registerCustomOpsFn
                                        error:(NSError**)error;
 
/**
 * Registers ONNX Runtime Extensions custom ops that have been built in to ONNX Runtime.
 *
 * Available since 1.16.
 *
 * @note ONNX Runtime must have been built with the `--use_extensions` flag for the ONNX Runtime Extensions custom ops
 * to be able to be registered with this method. When using a separate ONNX Runtime Extensions library, use
 * `registerCustomOpsUsingFunctionPointer:error:` instead.
 *
 * @param error Optional error information set if an error occurs.
 * @return Whether the ONNX Runtime Extensions custom ops were successfully registered.
 */
- (BOOL)enableOrtExtensionsCustomOpsWithError:(NSError**)error;
 
@end
 
/**
 * Options for configuring a run.
 */
@interface ORTRunOptions : NSObject
 
- (instancetype)init NS_UNAVAILABLE;
 
/**
 * Creates run configuration options.
 *
 * @param error Optional error information set if an error occurs.
 * @return The instance, or nil if an error occurs.
 */
- (nullable instancetype)initWithError:(NSError**)error NS_SWIFT_NAME(init());
 
/**
 * Sets the run log tag.
 *
 * @param logTag The log tag.
 * @param error Optional error information set if an error occurs.
 * @return Whether the option was set successfully.
 */
- (BOOL)setLogTag:(NSString*)logTag
            error:(NSError**)error;
 
/**
 * Sets the run log severity level.
 *
 * @param loggingLevel The log severity level.
 * @param error Optional error information set if an error occurs.
 * @return Whether the option was set successfully.
 */
- (BOOL)setLogSeverityLevel:(ORTLoggingLevel)loggingLevel
                      error:(NSError**)error;
 
/**
 * Sets a run configuration key-value pair.
 * Any value for a previously set key will be overwritten.
 * The run configuration keys and values are documented here:
 * https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/session/onnxruntime_run_options_config_keys.h
 *
 * @param key The key.
 * @param value The value.
 * @param error Optional error information set if an error occurs.
 * @return Whether the option was set successfully.
 */
- (BOOL)addConfigEntryWithKey:(NSString*)key
                        value:(NSString*)value
                        error:(NSError**)error;
 
@end
 
NS_ASSUME_NONNULL_END