com.github.asus4.onnxruntime 0.1.10 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/Plugins/Android/onnxruntime-android.aar +0 -0
  2. package/Plugins/Linux/x64/libonnxruntime.so +0 -0
  3. package/Plugins/Windows/x64/onnxruntime.dll +0 -0
  4. package/Plugins/iOS~/onnxruntime.xcframework/Info.plist +13 -0
  5. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/onnxruntime_c_api.h +182 -15
  6. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/onnxruntime_cxx_api.h +110 -4
  7. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/onnxruntime_cxx_inline.h +189 -0
  8. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/onnxruntime_run_options_config_keys.h +32 -0
  9. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/onnxruntime_session_options_config_keys.h +258 -0
  10. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Info.plist +2 -2
  11. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/onnxruntime +0 -0
  12. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Headers/onnxruntime_c_api.h +182 -15
  13. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Headers/onnxruntime_cxx_api.h +110 -4
  14. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Headers/onnxruntime_cxx_inline.h +189 -0
  15. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Headers/onnxruntime_run_options_config_keys.h +32 -0
  16. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Headers/onnxruntime_session_options_config_keys.h +258 -0
  17. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Info.plist +2 -2
  18. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/onnxruntime +0 -0
  19. package/Plugins/iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Headers/coreml_provider_factory.h +45 -0
  20. package/Plugins/iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Headers/cpu_provider_factory.h +19 -0
  21. package/Plugins/iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Headers/onnxruntime_c_api.h +4717 -0
  22. package/Plugins/iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Headers/onnxruntime_cxx_api.h +2372 -0
  23. package/Plugins/iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Headers/onnxruntime_cxx_inline.h +2075 -0
  24. package/Plugins/iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Headers/onnxruntime_float16.h +540 -0
  25. package/Plugins/iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Headers/onnxruntime_run_options_config_keys.h +32 -0
  26. package/Plugins/iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Headers/onnxruntime_session_options_config_keys.h +258 -0
  27. package/Plugins/iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Info.plist +20 -0
  28. package/Plugins/iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/onnxruntime +0 -0
  29. package/Plugins/macOS/libonnxruntime.dylib +0 -0
  30. package/README.md +8 -8
  31. package/Runtime/NativeMethods.shared.cs +270 -276
  32. package/Runtime/OrtValue.shared.cs +7 -3
  33. package/Runtime/Training/NativeTrainingMethods.shared.cs +2 -2
  34. package/package.json +1 -1
@@ -0,0 +1,4717 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ // See docs\c_cxx\README.md on generating the Doxygen documentation from this file
5
+
6
+ /** \mainpage ONNX Runtime
7
+ *
8
+ * ONNX Runtime is a high-performance inference and training graph execution engine for deep learning models.
9
+ *
10
+ * ONNX Runtime's C, C++ APIs offer an easy to use interface to onboard and execute onnx models.
11
+ * - \subpage c_cpp_api "Core C, C++ APIs"
12
+ * - \subpage training_c_cpp_api "Training C, C++ APIs for on-device training"
13
+ *
14
+ * \page c_cpp_api Core C, C++ APIs
15
+ * <h1>C</h1>
16
+ *
17
+ * ::OrtApi - Click here to go to the structure with all C API functions.
18
+ *
19
+ * <h1>C++</h1>
20
+ *
21
+ * ::Ort - Click here to go to the namespace holding all of the C++ wrapper classes
22
+ *
23
+ * It is a set of header only wrapper classes around the C API. The goal is to turn the C style return value error codes into C++ exceptions, and to
24
+ * automate memory management through standard C++ RAII principles.
25
+ *
26
+ * \addtogroup Global
27
+ * ONNX Runtime C API
28
+ * @{
29
+ */
30
+
31
+ #pragma once
32
+ #include <stdbool.h>
33
+ #include <stdint.h>
34
+ #include <stdlib.h>
35
+ #include <string.h>
36
+
37
+ /** \brief The API version defined in this header
38
+ *
39
+ * This value is used by some API functions to behave as this version of the header expects.
40
+ */
41
+ #define ORT_API_VERSION 17
42
+
43
+ #ifdef __cplusplus
44
+ extern "C" {
45
+ #endif
46
+
47
+ //! @}
48
+ // SAL2 Definitions
49
+ #ifndef _WIN32
50
+ #define _In_
51
+ #define _In_z_
52
+ #define _In_opt_
53
+ #define _In_opt_z_
54
+ #define _Out_
55
+ #define _Outptr_
56
+ #define _Out_opt_
57
+ #define _Inout_
58
+ #define _Inout_opt_
59
+ #define _Frees_ptr_opt_
60
+ #define _Ret_maybenull_
61
+ #define _Ret_notnull_
62
+ #define _Check_return_
63
+ #define _Outptr_result_maybenull_
64
+ #define _In_reads_(X)
65
+ #define _Inout_updates_(X)
66
+ #define _Out_writes_(X)
67
+ #define _Inout_updates_all_(X)
68
+ #define _Out_writes_bytes_all_(X)
69
+ #define _Out_writes_all_(X)
70
+ #define _Success_(X)
71
+ #define _Outptr_result_buffer_maybenull_(X)
72
+ #define ORT_ALL_ARGS_NONNULL __attribute__((nonnull))
73
+ #else
74
+ #include <specstrings.h>
75
+ #define ORT_ALL_ARGS_NONNULL
76
+ #endif
77
+
78
+ #ifdef _WIN32
79
+ // Define ORT_DLL_IMPORT if your program is dynamically linked to Ort.
80
+ // dllexport is not used, we use a .def file.
81
+ #ifdef ORT_DLL_IMPORT
82
+ #define ORT_EXPORT __declspec(dllimport)
83
+ #else
84
+ #define ORT_EXPORT
85
+ #endif
86
+ #define ORT_API_CALL _stdcall
87
+ #define ORT_MUST_USE_RESULT
88
+ #define ORTCHAR_T wchar_t
89
+ #else
90
+ // To make symbols visible on macOS/iOS
91
+ #ifdef __APPLE__
92
+ #define ORT_EXPORT __attribute__((visibility("default")))
93
+ #else
94
+ #define ORT_EXPORT
95
+ #endif
96
+ #define ORT_API_CALL
97
+ #define ORT_MUST_USE_RESULT __attribute__((warn_unused_result))
98
+ #define ORTCHAR_T char
99
+ #endif
100
+
101
+ /// ORTCHAR_T, ORT_TSTR are reserved specifically for path handling.
102
+ /// All other strings are UTF-8 encoded, use char and std::string
103
+ #ifndef ORT_TSTR
104
+ #ifdef _WIN32
105
+ #define ORT_TSTR(X) L##X
106
+ // When X is a macro, L##X is not defined. In this case, we need to use ORT_TSTR_ON_MACRO.
107
+ #define ORT_TSTR_ON_MACRO(X) L"" X
108
+ #else
109
+ #define ORT_TSTR(X) X
110
+ #define ORT_TSTR_ON_MACRO(X) X
111
+ #endif
112
+ #endif
113
+
114
+ // On Windows, ORT_FILE is a wchar_t version of the __FILE__ macro.
115
+ // Otherwise, ORT_FILE is equivalent to __FILE__.
116
+ #ifndef ORT_FILE
117
+ #define ORT_FILE_INTERNAL(x) ORT_TSTR(x)
118
+ #define ORT_FILE ORT_FILE_INTERNAL(__FILE__)
119
+ #endif
120
+
121
+ // Any pointer marked with _In_ or _Out_, cannot be NULL.
122
+
123
+ // Windows users should use unicode paths when possible to bypass the MAX_PATH limitation
124
+ // Every pointer marked with _In_ or _Out_, cannot be NULL. Caller should ensure that.
125
+ // for ReleaseXXX(...) functions, they can accept NULL pointer.
126
+
127
+ #ifdef __cplusplus
128
+ // For any compiler with C++11 support, MSVC 2015 and greater, or Clang version supporting noexcept.
129
+ // Such complex condition is needed because compilers set __cplusplus value differently.
130
+ #ifndef __has_feature
131
+ #define __has_feature(x) 0
132
+ #endif
133
+ #if ((__cplusplus >= 201103L) || (_MSC_VER >= 1900) || (defined(__has_feature) && __has_feature(cxx_noexcept)))
134
+ #define NO_EXCEPTION noexcept
135
+ #else
136
+ #define NO_EXCEPTION throw()
137
+ #endif
138
+ #else
139
+ #define NO_EXCEPTION
140
+ #endif
141
+
142
+ // __VA_ARGS__ on Windows and Linux are different
143
+ #define ORT_API(RETURN_TYPE, NAME, ...) RETURN_TYPE ORT_API_CALL NAME(__VA_ARGS__) NO_EXCEPTION
144
+
145
+ #define ORT_API_STATUS(NAME, ...) \
146
+ _Success_(return == 0) _Check_return_ _Ret_maybenull_ OrtStatusPtr ORT_API_CALL NAME(__VA_ARGS__) \
147
+ NO_EXCEPTION ORT_MUST_USE_RESULT
148
+
149
+ // XXX: Unfortunately, SAL annotations are known to not work with function pointers
150
+ #define ORT_API2_STATUS(NAME, ...) \
151
+ _Check_return_ _Ret_maybenull_ OrtStatusPtr(ORT_API_CALL* NAME)(__VA_ARGS__) NO_EXCEPTION ORT_MUST_USE_RESULT
152
+
153
+ // Used in *.cc files. Almost as same as ORT_API_STATUS, except without ORT_MUST_USE_RESULT and ORT_EXPORT
154
+ #define ORT_API_STATUS_IMPL(NAME, ...) \
155
+ _Success_(return == 0) _Check_return_ _Ret_maybenull_ OrtStatusPtr ORT_API_CALL NAME(__VA_ARGS__) NO_EXCEPTION
156
+
157
+ #define ORT_CLASS_RELEASE(X) void(ORT_API_CALL * Release##X)(_Frees_ptr_opt_ Ort##X * input)
158
+
159
+ #ifdef __DOXYGEN__
160
+ #undef ORT_API_STATUS
161
+ #define ORT_API_STATUS(NAME, ...) OrtStatus* NAME(__VA_ARGS__)
162
+ #undef ORT_API2_STATUS
163
+ #define ORT_API2_STATUS(NAME, ...) OrtStatus* NAME(__VA_ARGS__)
164
+ #undef ORT_CLASS_RELEASE
165
+ #define ORT_CLASS_RELEASE(X) void Release##X(Ort##X* input)
166
+ #undef NO_EXCEPTION
167
+ #define NO_EXCEPTION
168
+ #endif
169
+ /** \addtogroup Global
170
+ * ONNX Runtime C API
171
+ * @{
172
+ */
173
+
174
+ /** Copied from TensorProto::DataType
175
+ * Currently, Ort doesn't support complex64, complex128
176
+ */
177
+ typedef enum ONNXTensorElementDataType {
178
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED,
179
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT, // maps to c type float
180
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8, // maps to c type uint8_t
181
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8, // maps to c type int8_t
182
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16, // maps to c type uint16_t
183
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16, // maps to c type int16_t
184
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32, // maps to c type int32_t
185
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64, // maps to c type int64_t
186
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING, // maps to c++ type std::string
187
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL,
188
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16,
189
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE, // maps to c type double
190
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32, // maps to c type uint32_t
191
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64, // maps to c type uint64_t
192
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX64, // complex with float32 real and imaginary components
193
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX128, // complex with float64 real and imaginary components
194
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16, // Non-IEEE floating-point format based on IEEE754 single-precision
195
+ // float 8 types were introduced in onnx 1.14, see https://onnx.ai/onnx/technical/float8.html
196
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E4M3FN, // Non-IEEE floating-point format based on IEEE754 single-precision
197
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E4M3FNUZ, // Non-IEEE floating-point format based on IEEE754 single-precision
198
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E5M2, // Non-IEEE floating-point format based on IEEE754 single-precision
199
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E5M2FNUZ // Non-IEEE floating-point format based on IEEE754 single-precision
200
+ } ONNXTensorElementDataType;
201
+
202
+ // Synced with onnx TypeProto oneof
203
+ typedef enum ONNXType {
204
+ ONNX_TYPE_UNKNOWN,
205
+ ONNX_TYPE_TENSOR,
206
+ ONNX_TYPE_SEQUENCE,
207
+ ONNX_TYPE_MAP,
208
+ ONNX_TYPE_OPAQUE,
209
+ ONNX_TYPE_SPARSETENSOR,
210
+ ONNX_TYPE_OPTIONAL
211
+ } ONNXType;
212
+
213
+ // These types are synced with internal
214
+ // SparseFormatFlags
215
+ typedef enum OrtSparseFormat {
216
+ ORT_SPARSE_UNDEFINED = 0,
217
+ ORT_SPARSE_COO = 0x1,
218
+ ORT_SPARSE_CSRC = 0x2,
219
+ ORT_SPARSE_BLOCK_SPARSE = 0x4
220
+ } OrtSparseFormat;
221
+
222
+ // Enum allows to query sparse tensor indices
223
+ enum OrtSparseIndicesFormat {
224
+ ORT_SPARSE_COO_INDICES,
225
+ ORT_SPARSE_CSR_INNER_INDICES,
226
+ ORT_SPARSE_CSR_OUTER_INDICES,
227
+ ORT_SPARSE_BLOCK_SPARSE_INDICES
228
+ };
229
+
230
+ /** \brief Logging severity levels
231
+ *
232
+ * In typical API usage, specifying a logging severity level specifies the minimum severity of log messages to show.
233
+ */
234
+ typedef enum OrtLoggingLevel {
235
+ ORT_LOGGING_LEVEL_VERBOSE, ///< Verbose informational messages (least severe).
236
+ ORT_LOGGING_LEVEL_INFO, ///< Informational messages.
237
+ ORT_LOGGING_LEVEL_WARNING, ///< Warning messages.
238
+ ORT_LOGGING_LEVEL_ERROR, ///< Error messages.
239
+ ORT_LOGGING_LEVEL_FATAL, ///< Fatal error messages (most severe).
240
+ } OrtLoggingLevel;
241
+
242
+ typedef enum OrtErrorCode {
243
+ ORT_OK,
244
+ ORT_FAIL,
245
+ ORT_INVALID_ARGUMENT,
246
+ ORT_NO_SUCHFILE,
247
+ ORT_NO_MODEL,
248
+ ORT_ENGINE_ERROR,
249
+ ORT_RUNTIME_EXCEPTION,
250
+ ORT_INVALID_PROTOBUF,
251
+ ORT_MODEL_LOADED,
252
+ ORT_NOT_IMPLEMENTED,
253
+ ORT_INVALID_GRAPH,
254
+ ORT_EP_FAIL,
255
+ } OrtErrorCode;
256
+
257
+ typedef enum OrtOpAttrType {
258
+ ORT_OP_ATTR_UNDEFINED = 0,
259
+ ORT_OP_ATTR_INT,
260
+ ORT_OP_ATTR_INTS,
261
+ ORT_OP_ATTR_FLOAT,
262
+ ORT_OP_ATTR_FLOATS,
263
+ ORT_OP_ATTR_STRING,
264
+ ORT_OP_ATTR_STRINGS,
265
+ } OrtOpAttrType;
266
+
267
+ //! @}
268
+ #define ORT_RUNTIME_CLASS(X) \
269
+ struct Ort##X; \
270
+ typedef struct Ort##X Ort##X;
271
+
272
+ /** \addtogroup Global
273
+ * ONNX Runtime C API
274
+ * @{
275
+ */
276
+ // The actual types defined have an Ort prefix
277
+ ORT_RUNTIME_CLASS(Env);
278
+ ORT_RUNTIME_CLASS(Status); // nullptr for Status* indicates success
279
+ ORT_RUNTIME_CLASS(MemoryInfo);
280
+ ORT_RUNTIME_CLASS(IoBinding);
281
+ ORT_RUNTIME_CLASS(Session); // Don't call ReleaseSession from Dllmain (because session owns a thread pool)
282
+ ORT_RUNTIME_CLASS(Value);
283
+ ORT_RUNTIME_CLASS(RunOptions);
284
+ ORT_RUNTIME_CLASS(TypeInfo);
285
+ ORT_RUNTIME_CLASS(TensorTypeAndShapeInfo);
286
+ ORT_RUNTIME_CLASS(MapTypeInfo);
287
+ ORT_RUNTIME_CLASS(SequenceTypeInfo);
288
+ ORT_RUNTIME_CLASS(OptionalTypeInfo);
289
+ ORT_RUNTIME_CLASS(SessionOptions);
290
+ ORT_RUNTIME_CLASS(CustomOpDomain);
291
+ ORT_RUNTIME_CLASS(ModelMetadata);
292
+ ORT_RUNTIME_CLASS(ThreadPoolParams);
293
+ ORT_RUNTIME_CLASS(ThreadingOptions);
294
+ ORT_RUNTIME_CLASS(ArenaCfg);
295
+ ORT_RUNTIME_CLASS(PrepackedWeightsContainer);
296
+ ORT_RUNTIME_CLASS(TensorRTProviderOptionsV2);
297
+ ORT_RUNTIME_CLASS(CUDAProviderOptionsV2);
298
+ ORT_RUNTIME_CLASS(CANNProviderOptions);
299
+ ORT_RUNTIME_CLASS(DnnlProviderOptions);
300
+ ORT_RUNTIME_CLASS(Op);
301
+ ORT_RUNTIME_CLASS(OpAttr);
302
+ ORT_RUNTIME_CLASS(Logger);
303
+ ORT_RUNTIME_CLASS(ShapeInferContext);
304
+
305
+ #ifdef _WIN32
306
+ typedef _Return_type_success_(return == 0) OrtStatus* OrtStatusPtr;
307
+ #else
308
+ typedef OrtStatus* OrtStatusPtr;
309
+ #endif
310
+
311
+ /** \brief Memory allocation interface
312
+ *
313
+ * Structure of function pointers that defines a memory allocator. This can be created and filled in by the user for custom allocators.
314
+ *
315
+ * When an allocator is passed to any function, be sure that the allocator object is not destroyed until the last allocated object using it is freed.
316
+ */
317
+ typedef struct OrtAllocator {
318
+ uint32_t version; ///< Must be initialized to ORT_API_VERSION
319
+ void*(ORT_API_CALL* Alloc)(struct OrtAllocator* this_, size_t size); ///< Returns a pointer to an allocated block of `size` bytes
320
+ void(ORT_API_CALL* Free)(struct OrtAllocator* this_, void* p); ///< Free a block of memory previously allocated with OrtAllocator::Alloc
321
+ const struct OrtMemoryInfo*(ORT_API_CALL* Info)(const struct OrtAllocator* this_); ///< Return a pointer to an ::OrtMemoryInfo that describes this allocator
322
+ } OrtAllocator;
323
+
324
+ typedef void(ORT_API_CALL* OrtLoggingFunction)(
325
+ void* param, OrtLoggingLevel severity, const char* category, const char* logid, const char* code_location,
326
+ const char* message);
327
+
328
+ /** \brief Graph optimization level
329
+ *
330
+ * Refer to https://www.onnxruntime.ai/docs/performance/graph-optimizations.html#graph-optimization-levels
331
+ * for an in-depth understanding of the Graph Optimization Levels.
332
+ */
333
+ typedef enum GraphOptimizationLevel {
334
+ ORT_DISABLE_ALL = 0,
335
+ ORT_ENABLE_BASIC = 1,
336
+ ORT_ENABLE_EXTENDED = 2,
337
+ ORT_ENABLE_ALL = 99
338
+ } GraphOptimizationLevel;
339
+
340
+ typedef enum ExecutionMode {
341
+ ORT_SEQUENTIAL = 0,
342
+ ORT_PARALLEL = 1,
343
+ } ExecutionMode;
344
+
345
+ /** \brief Language projection identifiers
346
+ * /see OrtApi::SetLanguageProjection
347
+ */
348
+ typedef enum OrtLanguageProjection {
349
+ ORT_PROJECTION_C = 0,
350
+ ORT_PROJECTION_CPLUSPLUS = 1,
351
+ ORT_PROJECTION_CSHARP = 2,
352
+ ORT_PROJECTION_PYTHON = 3,
353
+ ORT_PROJECTION_JAVA = 4,
354
+ ORT_PROJECTION_WINML = 5,
355
+ ORT_PROJECTION_NODEJS = 6,
356
+ } OrtLanguageProjection;
357
+
358
+ struct OrtKernelInfo;
359
+ typedef struct OrtKernelInfo OrtKernelInfo;
360
+ struct OrtKernelContext;
361
+ typedef struct OrtKernelContext OrtKernelContext;
362
+ struct OrtCustomOp;
363
+ typedef struct OrtCustomOp OrtCustomOp;
364
+
365
+ typedef enum OrtAllocatorType {
366
+ OrtInvalidAllocator = -1,
367
+ OrtDeviceAllocator = 0,
368
+ OrtArenaAllocator = 1
369
+ } OrtAllocatorType;
370
+
371
+ /** \brief Memory types for allocated memory, execution provider specific types should be extended in each provider.
372
+ */
373
+ // Whenever this struct is updated, please also update the MakeKey function in onnxruntime / core / framework / execution_provider.cc
374
+ typedef enum OrtMemType {
375
+ OrtMemTypeCPUInput = -2, ///< Any CPU memory used by non-CPU execution provider
376
+ OrtMemTypeCPUOutput = -1, ///< CPU accessible memory outputted by non-CPU execution provider, i.e. CUDA_PINNED
377
+ OrtMemTypeCPU = OrtMemTypeCPUOutput, ///< Temporary CPU accessible memory allocated by non-CPU execution provider, i.e. CUDA_PINNED
378
+ OrtMemTypeDefault = 0, ///< The default allocator for execution provider
379
+ } OrtMemType;
380
+
381
+ /** \brief This mimics OrtDevice type constants so they can be returned in the API
382
+ */
383
+ typedef enum OrtMemoryInfoDeviceType {
384
+ OrtMemoryInfoDeviceType_CPU = 0,
385
+ OrtMemoryInfoDeviceType_GPU = 1,
386
+ OrtMemoryInfoDeviceType_FPGA = 2
387
+ } OrtMemoryInfoDeviceType;
388
+
389
+ /** \brief Algorithm to use for cuDNN Convolution Op
390
+ */
391
+ typedef enum OrtCudnnConvAlgoSearch {
392
+ OrtCudnnConvAlgoSearchExhaustive, // expensive exhaustive benchmarking using cudnnFindConvolutionForwardAlgorithmEx
393
+ OrtCudnnConvAlgoSearchHeuristic, // lightweight heuristic based search using cudnnGetConvolutionForwardAlgorithm_v7
394
+ OrtCudnnConvAlgoSearchDefault, // default algorithm using CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_PRECOMP_GEMM
395
+ } OrtCudnnConvAlgoSearch;
396
+
397
+ /** \brief CUDA Provider Options
398
+ *
399
+ * \see OrtApi::SessionOptionsAppendExecutionProvider_CUDA
400
+ */
401
+ typedef struct OrtCUDAProviderOptions {
402
+ #ifdef __cplusplus
403
+ OrtCUDAProviderOptions()
404
+ : device_id{},
405
+ cudnn_conv_algo_search{OrtCudnnConvAlgoSearchExhaustive},
406
+ gpu_mem_limit{SIZE_MAX},
407
+ arena_extend_strategy{},
408
+ do_copy_in_default_stream{1},
409
+ has_user_compute_stream{},
410
+ user_compute_stream{},
411
+ default_memory_arena_cfg{},
412
+ tunable_op_enable{false},
413
+ tunable_op_tuning_enable{false},
414
+ tunable_op_max_tuning_duration_ms{} {}
415
+ #endif
416
+
417
+ /** \brief CUDA device Id
418
+ * Defaults to 0.
419
+ */
420
+ int device_id;
421
+
422
+ /** \brief CUDA Convolution algorithm search configuration.
423
+ * See enum OrtCudnnConvAlgoSearch for more details.
424
+ * Defaults to OrtCudnnConvAlgoSearchExhaustive.
425
+ */
426
+ OrtCudnnConvAlgoSearch cudnn_conv_algo_search;
427
+
428
+ /** \brief CUDA memory limit (To use all possible memory pass in maximum size_t)
429
+ * Defaults to SIZE_MAX.
430
+ * \note If a ::OrtArenaCfg has been applied, it will override this field
431
+ */
432
+ size_t gpu_mem_limit;
433
+
434
+ /** \brief Strategy used to grow the memory arena
435
+ * 0 = kNextPowerOfTwo<br>
436
+ * 1 = kSameAsRequested<br>
437
+ * Defaults to 0.
438
+ * \note If a ::OrtArenaCfg has been applied, it will override this field
439
+ */
440
+ int arena_extend_strategy;
441
+
442
+ /** \brief Flag indicating if copying needs to take place on the same stream as the compute stream in the CUDA EP
443
+ * 0 = Use separate streams for copying and compute.
444
+ * 1 = Use the same stream for copying and compute.
445
+ * Defaults to 1.
446
+ * WARNING: Setting this to 0 may result in data races for some models.
447
+ * Please see issue #4829 for more details.
448
+ */
449
+ int do_copy_in_default_stream;
450
+
451
+ /** \brief Flag indicating if there is a user provided compute stream
452
+ * Defaults to 0.
453
+ */
454
+ int has_user_compute_stream;
455
+
456
+ /** \brief User provided compute stream.
457
+ * If provided, please set `has_user_compute_stream` to 1.
458
+ */
459
+ void* user_compute_stream;
460
+
461
+ /** \brief CUDA memory arena configuration parameters
462
+ */
463
+ OrtArenaCfg* default_memory_arena_cfg;
464
+
465
+ /** \brief Enable TunableOp for using.
466
+ * Set it to 1/0 to enable/disable TunableOp. Otherwise, it is disabled by default.
467
+ * This option can be overriden by environment variable ORT_CUDA_TUNABLE_OP_ENABLE.
468
+ */
469
+ int tunable_op_enable;
470
+
471
+ /** \brief Enable TunableOp for tuning.
472
+ * Set it to 1/0 to enable/disable TunableOp tuning. Otherwise, it is disabled by default.
473
+ * This option can be overriden by environment variable ORT_CUDA_TUNABLE_OP_TUNING_ENABLE.
474
+ */
475
+ int tunable_op_tuning_enable;
476
+
477
+ /** \brief Max tuning duration time limit for each instance of TunableOp.
478
+ * Defaults to 0 to disable the limit.
479
+ */
480
+ int tunable_op_max_tuning_duration_ms;
481
+
482
+ } OrtCUDAProviderOptions;
483
+
484
+ /** \brief ROCM Provider Options
485
+ *
486
+ * \see OrtApi::SessionOptionsAppendExecutionProvider_ROCM
487
+ */
488
+ typedef struct OrtROCMProviderOptions {
489
+ #ifdef __cplusplus
490
+ OrtROCMProviderOptions()
491
+ : device_id{},
492
+ miopen_conv_exhaustive_search{0},
493
+ gpu_mem_limit{SIZE_MAX},
494
+ arena_extend_strategy{},
495
+ do_copy_in_default_stream{1},
496
+ has_user_compute_stream{},
497
+ user_compute_stream{},
498
+ default_memory_arena_cfg{},
499
+ tunable_op_enable{false},
500
+ tunable_op_tuning_enable{false},
501
+ tunable_op_max_tuning_duration_ms{} {}
502
+ #endif
503
+
504
+ /** \brief ROCM device Id
505
+ * Defaults to 0.
506
+ */
507
+ int device_id;
508
+
509
+ /** \brief ROCM MIOpen Convolution algorithm exaustive search option.
510
+ * Defaults to 0 (false).
511
+ */
512
+ int miopen_conv_exhaustive_search;
513
+
514
+ /** \brief ROCM memory limit (To use all possible memory pass in maximum size_t)
515
+ * Defaults to SIZE_MAX.
516
+ * \note If a ::OrtArenaCfg has been applied, it will override this field
517
+ */
518
+ size_t gpu_mem_limit;
519
+
520
+ /** \brief Strategy used to grow the memory arena
521
+ * 0 = kNextPowerOfTwo<br>
522
+ * 1 = kSameAsRequested<br>
523
+ * Defaults to 0.
524
+ * \note If a ::OrtArenaCfg has been applied, it will override this field
525
+ */
526
+ int arena_extend_strategy;
527
+
528
+ /** \brief Flag indicating if copying needs to take place on the same stream as the compute stream in the ROCM EP
529
+ * 0 = Use separate streams for copying and compute.
530
+ * 1 = Use the same stream for copying and compute.
531
+ * Defaults to 1.
532
+ * WARNING: Setting this to 0 may result in data races for some models.
533
+ * Please see issue #4829 for more details.
534
+ */
535
+ int do_copy_in_default_stream;
536
+
537
+ /** \brief Flag indicating if there is a user provided compute stream
538
+ * Defaults to 0.
539
+ */
540
+ int has_user_compute_stream;
541
+
542
+ /** \brief User provided compute stream.
543
+ * If provided, please set `has_user_compute_stream` to 1.
544
+ */
545
+ void* user_compute_stream;
546
+
547
+ /** \brief ROCM memory arena configuration parameters
548
+ */
549
+ OrtArenaCfg* default_memory_arena_cfg;
550
+
551
+ /** \brief Enable TunableOp for using.
552
+ * Set it to 1/0 to enable/disable TunableOp. Otherwise, it is disabled by default.
553
+ * This option can be overriden by environment variable ORT_ROCM_TUNABLE_OP_ENABLE.
554
+ */
555
+ int tunable_op_enable;
556
+
557
+ /** \brief Enable TunableOp for tuning.
558
+ * Set it to 1/0 to enable/disable TunableOp tuning. Otherwise, it is disabled by default.
559
+ * This option can be overriden by environment variable ORT_ROCM_TUNABLE_OP_TUNING_ENABLE.
560
+ */
561
+ int tunable_op_tuning_enable;
562
+
563
+ /** \brief Max tuning duration time limit for each instance of TunableOp.
564
+ * Defaults to 0 to disable the limit.
565
+ */
566
+ int tunable_op_max_tuning_duration_ms;
567
+
568
+ } OrtROCMProviderOptions;
569
+
570
+ /** \brief TensorRT Provider Options
571
+ *
572
+ * \see OrtApi::SessionOptionsAppendExecutionProvider_TensorRT
573
+ */
574
+ typedef struct OrtTensorRTProviderOptions {
575
+ int device_id; ///< CUDA device id (0 = default device)
576
+ int has_user_compute_stream; // indicator of user specified CUDA compute stream.
577
+ void* user_compute_stream; // user specified CUDA compute stream.
578
+ int trt_max_partition_iterations; // maximum iterations for TensorRT parser to get capability
579
+ int trt_min_subgraph_size; // minimum size of TensorRT subgraphs
580
+ size_t trt_max_workspace_size; // maximum workspace size for TensorRT.
581
+ int trt_fp16_enable; // enable TensorRT FP16 precision. Default 0 = false, nonzero = true
582
+ int trt_int8_enable; // enable TensorRT INT8 precision. Default 0 = false, nonzero = true
583
+ const char* trt_int8_calibration_table_name; // TensorRT INT8 calibration table name.
584
+ int trt_int8_use_native_calibration_table; // use native TensorRT generated calibration table. Default 0 = false, nonzero = true
585
+ int trt_dla_enable; // enable DLA. Default 0 = false, nonzero = true
586
+ int trt_dla_core; // DLA core number. Default 0
587
+ int trt_dump_subgraphs; // dump TRT subgraph. Default 0 = false, nonzero = true
588
+ int trt_engine_cache_enable; // enable engine caching. Default 0 = false, nonzero = true
589
+ const char* trt_engine_cache_path; // specify engine cache path
590
+ int trt_engine_decryption_enable; // enable engine decryption. Default 0 = false, nonzero = true
591
+ const char* trt_engine_decryption_lib_path; // specify engine decryption library path
592
+ int trt_force_sequential_engine_build; // force building TensorRT engine sequentially. Default 0 = false, nonzero = true
593
+ // This is the legacy struct and don't add new fields here.
594
+ // For new field that can be represented by string, please add it in include/onnxruntime/core/providers/tensorrt/tensorrt_provider_options.h
595
+ // For non-string field, need to create a new separate api to handle it.
596
+ } OrtTensorRTProviderOptions;
597
+
598
+ /** \brief MIGraphX Provider Options
599
+ *
600
+ * \see OrtApi::SessionOptionsAppendExecutionProvider_MIGraphX
601
+ */
602
+ typedef struct OrtMIGraphXProviderOptions {
603
+ int device_id; // hip device id.
604
+ int migraphx_fp16_enable; // MIGraphX FP16 precision. Default 0 = false, nonzero = true
605
+ int migraphx_int8_enable; // MIGraphX INT8 precision. Default 0 = false, nonzero = true
606
+ int migraphx_use_native_calibration_table; // MIGraphx INT8 cal table. Default 0 = false, noznero = true
607
+ const char* migraphx_int8_calibration_table_name; // MIGraphx INT8 calibration table name
608
+ } OrtMIGraphXProviderOptions;
609
+
610
+ /** \brief OpenVINO Provider Options
611
+ *
612
+ * \see OrtApi::SessionOptionsAppendExecutionProvider_OpenVINO
613
+ */
614
+ typedef struct OrtOpenVINOProviderOptions {
615
+ #ifdef __cplusplus
616
+ OrtOpenVINOProviderOptions() : device_type{},
617
+ enable_npu_fast_compile{},
618
+ device_id{},
619
+ num_of_threads{},
620
+ cache_dir{},
621
+ context{},
622
+ enable_opencl_throttling{},
623
+ enable_dynamic_shapes{} {}
624
+ #endif
625
+ /** \brief Device type string
626
+ *
627
+ * Valid settings are one of: "CPU_FP32", "CPU_FP16", "GPU_FP32", "GPU_FP16"
628
+ */
629
+ const char* device_type;
630
+ unsigned char enable_npu_fast_compile; ///< 0 = disabled, nonzero = enabled
631
+ const char* device_id;
632
+ size_t num_of_threads; ///< 0 = Use default number of threads
633
+ const char* cache_dir; // path is set to empty by default
634
+ void* context;
635
+ unsigned char enable_opencl_throttling; ///< 0 = disabled, nonzero = enabled
636
+ unsigned char enable_dynamic_shapes; ///< 0 = disabled, nonzero = enabled
637
+ } OrtOpenVINOProviderOptions;
638
+
639
+ struct OrtApi;
640
+ typedef struct OrtApi OrtApi;
641
+
642
+ struct OrtTrainingApi;
643
+ typedef struct OrtTrainingApi OrtTrainingApi;
644
+
645
+ /** \brief The helper interface to get the right version of OrtApi
646
+ *
647
+ * Get a pointer to this structure through ::OrtGetApiBase
648
+ */
649
+ struct OrtApiBase {
650
+ /** \brief Get a pointer to the requested version of the ::OrtApi
651
+ *
652
+ * \param[in] version Must be ::ORT_API_VERSION
653
+ * \return The ::OrtApi for the version requested, nullptr will be returned if this version is unsupported, for example when using a runtime
654
+ * older than the version created with this header file.
655
+ *
656
+ * One can call GetVersionString() to get the version of the Onnxruntime library for logging
657
+ * and error reporting purposes.
658
+ */
659
+ const OrtApi*(ORT_API_CALL* GetApi)(uint32_t version)NO_EXCEPTION;
660
+
661
+ /** \brief Returns a null terminated string of the version of the Onnxruntime library (eg: "1.8.1")
662
+ *
663
+ * \return UTF-8 encoded version string. Do not deallocate the returned buffer.
664
+ */
665
+ const char*(ORT_API_CALL* GetVersionString)(void)NO_EXCEPTION;
666
+ };
667
+
668
+ typedef struct OrtApiBase OrtApiBase;
669
+
670
+ /** \brief The Onnxruntime library's entry point to access the C API
671
+ *
672
+ * Call this to get the a pointer to an ::OrtApiBase
673
+ */
674
+ ORT_EXPORT const OrtApiBase* ORT_API_CALL OrtGetApiBase(void) NO_EXCEPTION;
675
+
676
+ /** \brief Thread work loop function
677
+ *
678
+ * Onnxruntime will provide the working loop on custom thread creation
679
+ * Argument is an onnxruntime built-in type which will be provided when thread pool calls OrtCustomCreateThreadFn
680
+ */
681
+ typedef void (*OrtThreadWorkerFn)(void* ort_worker_fn_param);
682
+
683
+ typedef const struct OrtCustomHandleType {
684
+ char __place_holder;
685
+ }* OrtCustomThreadHandle;
686
+
687
+ /** \brief Ort custom thread creation function
688
+ *
689
+ * The function should return a thread handle to be used in onnxruntime thread pools
690
+ * Onnxruntime will throw exception on return value of nullptr or 0, indicating that the function failed to create a thread
691
+ */
692
+ typedef OrtCustomThreadHandle (*OrtCustomCreateThreadFn)(void* ort_custom_thread_creation_options, OrtThreadWorkerFn ort_thread_worker_fn, void* ort_worker_fn_param);
693
+
694
+ /** \brief Custom thread join function
695
+ *
696
+ * Onnxruntime thread pool destructor will call the function to join a custom thread.
697
+ * Argument ort_custom_thread_handle is the value returned by OrtCustomCreateThreadFn
698
+ */
699
+ typedef void (*OrtCustomJoinThreadFn)(OrtCustomThreadHandle ort_custom_thread_handle);
700
+
701
+ typedef OrtStatus*(ORT_API_CALL* RegisterCustomOpsFn)(OrtSessionOptions* options, const OrtApiBase* api);
702
+
703
+ /** \brief Callback function for RunAsync
704
+ *
705
+ * \param[in] user_data User specific data that passed back to the callback
706
+ * \param[out] outputs On succeed, outputs host inference results, on error, the value will be nullptr
707
+ * \param[out] num_outputs Number of outputs, on error, the value will be zero
708
+ * \param[out] status On error, status will provide details
709
+ */
710
+ typedef void (*RunAsyncCallbackFn)(void* user_data, OrtValue** outputs, size_t num_outputs, OrtStatusPtr status);
711
+
712
+ /** \brief The C API
713
+ *
714
+ * All C API functions are defined inside this structure as pointers to functions.
715
+ * Call OrtApiBase::GetApi to get a pointer to it
716
+ *
717
+ * \nosubgrouping
718
+ */
719
+ struct OrtApi {
720
+ /// \name OrtStatus
721
+ /// @{
722
+
723
+ /**
724
+ * \brief Create an OrtStatus from a null terminated string
725
+ *
726
+ * \param[in] code
727
+ * \param[in] msg A null-terminated string. Its contents will be copied.
728
+ * \return A new OrtStatus object, must be destroyed with OrtApi::ReleaseStatus
729
+ */
730
+ OrtStatus*(ORT_API_CALL* CreateStatus)(OrtErrorCode code, _In_ const char* msg)NO_EXCEPTION ORT_ALL_ARGS_NONNULL;
731
+
732
+ /** \brief Get OrtErrorCode from OrtStatus
733
+ *
734
+ * \param[in] status
735
+ * \return OrtErrorCode that \p status was created with
736
+ */
737
+ OrtErrorCode(ORT_API_CALL* GetErrorCode)(_In_ const OrtStatus* status) NO_EXCEPTION ORT_ALL_ARGS_NONNULL;
738
+
739
+ /** \brief Get error string from OrtStatus
740
+ *
741
+ * \param[in] status
742
+ * \return The error message inside the `status`. Do not free the returned value.
743
+ */
744
+ const char*(ORT_API_CALL* GetErrorMessage)(_In_ const OrtStatus* status)NO_EXCEPTION ORT_ALL_ARGS_NONNULL;
745
+
746
+ /// @}
747
+ /// \name OrtEnv
748
+ /// @{
749
+
750
+ /** \brief Create an OrtEnv
751
+ *
752
+ * \note Invoking this function will return the same instance of the environment as that returned by a previous call
753
+ * to another env creation function; all arguments to this function will be ignored.
754
+ * \param[in] log_severity_level The log severity level.
755
+ * \param[in] logid The log identifier.
756
+ * \param[out] out Returned newly created OrtEnv. Must be freed with OrtApi::ReleaseEnv
757
+ *
758
+ * \snippet{doc} snippets.dox OrtStatus Return Value
759
+ */
760
+ ORT_API2_STATUS(CreateEnv, OrtLoggingLevel log_severity_level, _In_ const char* logid, _Outptr_ OrtEnv** out);
761
+
762
+ /** \brief Create an OrtEnv
763
+ *
764
+ * \note Invoking this function will return the same instance of the environment as that returned by a previous call
765
+ * to another env creation function; all arguments to this function will be ignored. If you want to provide your
766
+ * own logging function, consider setting it using the SetUserLoggingFunction API instead.
767
+ * \param[in] logging_function A pointer to a logging function.
768
+ * \param[in] logger_param A pointer to arbitrary data passed as the ::OrtLoggingFunction `param` parameter to
769
+ * `logging_function`. This parameter is optional.
770
+ * \param[in] log_severity_level The log severity level.
771
+ * \param[in] logid The log identifier.
772
+ * \param[out] out Returned newly created OrtEnv. Must be freed with OrtApi::ReleaseEnv
773
+ *
774
+ * \snippet{doc} snippets.dox OrtStatus Return Value
775
+ */
776
+ ORT_API2_STATUS(CreateEnvWithCustomLogger, _In_ OrtLoggingFunction logging_function, _In_opt_ void* logger_param,
777
+ _In_ OrtLoggingLevel log_severity_level, _In_ const char* logid, _Outptr_ OrtEnv** out);
778
+
779
+ /** \brief Enable Telemetry
780
+ *
781
+ * \note Telemetry events are on by default since they are lightweight
782
+ * \param[in] env
783
+ *
784
+ * \snippet{doc} snippets.dox OrtStatus Return Value
785
+ */
786
+ ORT_API2_STATUS(EnableTelemetryEvents, _In_ const OrtEnv* env);
787
+ /** \brief Disable Telemetry
788
+ *
789
+ * \see OrtApi::EnableTelemetryEvents
790
+ * \param[in] env
791
+ *
792
+ * \snippet{doc} snippets.dox OrtStatus Return Value
793
+ */
794
+ ORT_API2_STATUS(DisableTelemetryEvents, _In_ const OrtEnv* env);
795
+
796
+ /// @}
797
+ /// \name OrtSession
798
+ /// @{
799
+
800
+ /** \brief Create an OrtSession from a model file
801
+ *
802
+ * \param[in] env
803
+ * \param[in] model_path
804
+ * \param[in] options
805
+ * \param[out] out Returned newly created OrtSession. Must be freed with OrtApi::ReleaseSession
806
+ *
807
+ * \snippet{doc} snippets.dox OrtStatus Return Value
808
+ */
809
+ // TODO: document the path separator convention? '/' vs '\'
810
+ // TODO: should specify the access characteristics of model_path. Is this read only during the
811
+ // execution of CreateSession, or does the OrtSession retain a handle to the file/directory
812
+ // and continue to access throughout the OrtSession lifetime?
813
+ // What sort of access is needed to model_path : read or read/write?
814
+ ORT_API2_STATUS(CreateSession, _In_ const OrtEnv* env, _In_ const ORTCHAR_T* model_path,
815
+ _In_ const OrtSessionOptions* options, _Outptr_ OrtSession** out);
816
+
817
+ /** \brief Create an OrtSession from memory
818
+ *
819
+ * \param[in] env
820
+ * \param[in] model_data
821
+ * \param[in] model_data_length
822
+ * \param[in] options
823
+ * \param[out] out Returned newly created OrtSession. Must be freed with OrtApi::ReleaseSession
824
+ *
825
+ * \snippet{doc} snippets.dox OrtStatus Return Value
826
+ */
827
+ ORT_API2_STATUS(CreateSessionFromArray, _In_ const OrtEnv* env, _In_ const void* model_data, size_t model_data_length,
828
+ _In_ const OrtSessionOptions* options, _Outptr_ OrtSession** out);
829
+
830
+ /** \brief Run the model in an ::OrtSession
831
+ *
832
+ * Will not return until the model run has completed. Multiple threads might be used to run the model based on
833
+ * the options in the ::OrtSession and settings used when creating the ::OrtEnv
834
+ *
835
+ * \param[in] session
836
+ * \param[in] run_options If nullptr, will use a default ::OrtRunOptions
837
+ * \param[in] input_names Array of null terminated UTF8 encoded strings of the input names
838
+ * \param[in] inputs Array of ::OrtValue%s of the input values
839
+ * \param[in] input_len Number of elements in the input_names and inputs arrays
840
+ * \param[in] output_names Array of null terminated UTF8 encoded strings of the output names
841
+ * \param[in] output_names_len Number of elements in the output_names and outputs array
842
+ * \param[out] outputs Array of ::OrtValue%s that the outputs are stored in. This can also be
843
+ * an array of nullptr values, in this case ::OrtValue objects will be allocated and pointers
844
+ * to them will be set into the `outputs` array.
845
+ *
846
+ * \snippet{doc} snippets.dox OrtStatus Return Value
847
+ */
848
+ ORT_API2_STATUS(Run, _Inout_ OrtSession* session, _In_opt_ const OrtRunOptions* run_options,
849
+ _In_reads_(input_len) const char* const* input_names,
850
+ _In_reads_(input_len) const OrtValue* const* inputs, size_t input_len,
851
+ _In_reads_(output_names_len) const char* const* output_names, size_t output_names_len,
852
+ _Inout_updates_all_(output_names_len) OrtValue** outputs);
853
+
854
+ /// @}
855
+ /// \name OrtSessionOptions
856
+ /// @{
857
+
858
+ /** \brief Create an ::OrtSessionOptions object
859
+ *
860
+ * To use additional providers, you must build ORT with the extra providers enabled. Then call one of these
861
+ * functions to enable them in the session:<br>
862
+ * OrtSessionOptionsAppendExecutionProvider_CPU<br>
863
+ * OrtSessionOptionsAppendExecutionProvider_CUDA<br>
864
+ * OrtSessionOptionsAppendExecutionProvider_(remaining providers...)<br>
865
+ * The order they are called indicates the preference order as well. In other words call this method
866
+ * on your most preferred execution provider first followed by the less preferred ones.
867
+ * If none are called Ort will use its internal CPU execution provider.
868
+ *
869
+ * \param[out] options The newly created OrtSessionOptions. Must be freed with OrtApi::ReleaseSessionOptions
870
+ *
871
+ * \snippet{doc} snippets.dox OrtStatus Return Value
872
+ */
873
+ ORT_API2_STATUS(CreateSessionOptions, _Outptr_ OrtSessionOptions** options);
874
+
875
+ /** \brief Set filepath to save optimized model after graph level transformations
876
+ *
877
+ * \param[in] options
878
+ * \param[in] optimized_model_filepath
879
+ *
880
+ * \snippet{doc} snippets.dox OrtStatus Return Value
881
+ */
882
+ ORT_API2_STATUS(SetOptimizedModelFilePath, _Inout_ OrtSessionOptions* options,
883
+ _In_ const ORTCHAR_T* optimized_model_filepath);
884
+
885
+ /** \brief Create a copy of an existing ::OrtSessionOptions
886
+ *
887
+ * \param[in] in_options OrtSessionOptions to copy
888
+ * \param[out] out_options Returned newly created ::OrtSessionOptions. Must be freed with OrtApi::ReleaseSessionOptions
889
+ *
890
+ * \snippet{doc} snippets.dox OrtStatus Return Value
891
+ */
892
+ ORT_API2_STATUS(CloneSessionOptions, _In_ const OrtSessionOptions* in_options,
893
+ _Outptr_ OrtSessionOptions** out_options);
894
+
895
+ /** \brief Set execution mode
896
+ *
897
+ * Controls whether you want to execute operators in your graph sequentially or in parallel. Usually when the model
898
+ * has many branches, setting this option to ExecutionMode.ORT_PARALLEL will give you better performance.
899
+ * See [docs/ONNX_Runtime_Perf_Tuning.md] for more details.
900
+ *
901
+ * \param[in] options
902
+ * \param[in] execution_mode
903
+ *
904
+ * \snippet{doc} snippets.dox OrtStatus Return Value
905
+ */
906
+ ORT_API2_STATUS(SetSessionExecutionMode, _Inout_ OrtSessionOptions* options, ExecutionMode execution_mode);
907
+
908
+ /** \brief Enable profiling for a session
909
+ *
910
+ * \param[in] options
911
+ * \param[in] profile_file_prefix
912
+ *
913
+ * \snippet{doc} snippets.dox OrtStatus Return Value
914
+ */
915
+ ORT_API2_STATUS(EnableProfiling, _Inout_ OrtSessionOptions* options, _In_ const ORTCHAR_T* profile_file_prefix);
916
+
917
+ /** \brief Disable profiling for a session
918
+ *
919
+ * \param[in] options
920
+ *
921
+ * \snippet{doc} snippets.dox OrtStatus Return Value
922
+ */
923
+ ORT_API2_STATUS(DisableProfiling, _Inout_ OrtSessionOptions* options);
924
+
925
+ /** \brief Enable the memory pattern optimization
926
+ *
927
+ * The idea is if the input shapes are the same, we could trace the internal memory allocation
928
+ * and generate a memory pattern for future request. So next time we could just do one allocation
929
+ * with a big chunk for all the internal memory allocation.
930
+ * \note Memory pattern optimization is only available when Sequential Execution mode is enabled (see OrtApi::SetSessionExecutionMode)
931
+ *
932
+ * \see OrtApi::DisableMemPattern
933
+ *
934
+ * \param[in] options
935
+ *
936
+ * \snippet{doc} snippets.dox OrtStatus Return Value
937
+ */
938
+ ORT_API2_STATUS(EnableMemPattern, _Inout_ OrtSessionOptions* options);
939
+
940
+ /** \brief Disable the memory pattern optimization
941
+ *
942
+ * \see OrtApi::EnableMemPattern
943
+ *
944
+ * \param[in] options
945
+ *
946
+ * \snippet{doc} snippets.dox OrtStatus Return Value
947
+ */
948
+ ORT_API2_STATUS(DisableMemPattern, _Inout_ OrtSessionOptions* options);
949
+
950
+ /** \brief Enable the memory arena on CPU
951
+ *
952
+ * Arena may pre-allocate memory for future usage.
953
+ *
954
+ * \param[in] options
955
+ *
956
+ * \snippet{doc} snippets.dox OrtStatus Return Value
957
+ */
958
+ ORT_API2_STATUS(EnableCpuMemArena, _Inout_ OrtSessionOptions* options);
959
+
960
+ /** \brief Disable the memory arena on CPU
961
+ *
962
+ * \param[in] options
963
+ *
964
+ * \snippet{doc} snippets.dox OrtStatus Return Value
965
+ */
966
+ ORT_API2_STATUS(DisableCpuMemArena, _Inout_ OrtSessionOptions* options);
967
+
968
+ /** \brief Set session log id
969
+ *
970
+ * \param[in] options
971
+ * \param[in] logid The log identifier.
972
+ *
973
+ * \snippet{doc} snippets.dox OrtStatus Return Value
974
+ */
975
+ ORT_API2_STATUS(SetSessionLogId, _Inout_ OrtSessionOptions* options, const char* logid);
976
+
977
+ /** \brief Set session log verbosity level
978
+ *
979
+ * Applies to session load, initialization, etc
980
+ *
981
+ * \param[in] options
982
+ * \param[in] session_log_verbosity_level \snippet{doc} snippets.dox Log Verbosity Level
983
+ *
984
+ * \snippet{doc} snippets.dox OrtStatus Return Value
985
+ */
986
+ ORT_API2_STATUS(SetSessionLogVerbosityLevel, _Inout_ OrtSessionOptions* options, int session_log_verbosity_level);
987
+
988
+ /** \brief Set session log severity level
989
+ *
990
+ * \param[in] options
991
+ * \param[in] session_log_severity_level The log severity level (refer to ::OrtLoggingLevel for possible values).
992
+ *
993
+ * \snippet{doc} snippets.dox OrtStatus Return Value
994
+ */
995
+ ORT_API2_STATUS(SetSessionLogSeverityLevel, _Inout_ OrtSessionOptions* options, int session_log_severity_level);
996
+
997
+ /** \brief Set the optimization level to apply when loading a graph
998
+ *
999
+ * Please see https://onnxruntime.ai/docs/performance/model-optimizations/graph-optimizations.html for an in-depth explanation
1000
+ * \param[in,out] options The session options object
1001
+ * \param[in] graph_optimization_level The optimization level
1002
+ *
1003
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1004
+ */
1005
+ ORT_API2_STATUS(SetSessionGraphOptimizationLevel, _Inout_ OrtSessionOptions* options,
1006
+ GraphOptimizationLevel graph_optimization_level);
1007
+
1008
+ /** \brief Sets the number of threads used to parallelize the execution within nodes
1009
+ *
1010
+ * When running a single node operation, ex. add, this sets the maximum number of threads to use.
1011
+ *
1012
+ * \note If built with OpenMP, this has no effect on the number of threads used. In this case
1013
+ * use the OpenMP env variables to configure the number of intra op num threads.
1014
+ *
1015
+ * \param[in] options
1016
+ * \param[in] intra_op_num_threads Number of threads to use<br>
1017
+ * A value of 0 will use the default number of threads<br>
1018
+ *
1019
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1020
+ */
1021
+ ORT_API2_STATUS(SetIntraOpNumThreads, _Inout_ OrtSessionOptions* options, int intra_op_num_threads);
1022
+
1023
+ /** \brief Sets the number of threads used to parallelize the execution of the graph
1024
+ *
1025
+ * If nodes can be run in parallel, this sets the maximum number of threads to use to run them in parallel.
1026
+ *
1027
+ * \note If sequential execution is enabled this value is ignored, it acts as if it was set to 1.
1028
+ *
1029
+ * \param[in] options
1030
+ * \param[in] inter_op_num_threads Number of threads to use<br>
1031
+ * A value of 0 will use the default number of threads<br>
1032
+ *
1033
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1034
+ */
1035
+ ORT_API2_STATUS(SetInterOpNumThreads, _Inout_ OrtSessionOptions* options, int inter_op_num_threads);
1036
+
1037
+ /// @}
1038
+ /// \name OrtCustomOpDomain
1039
+ /// @{
1040
+
1041
+ /** \brief Create a custom op domain
1042
+ *
1043
+ * \param[in] domain
1044
+ * \param[out] out Newly created domain. Must be freed with OrtApi::ReleaseCustomOpDomain
1045
+ *
1046
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1047
+ */
1048
+ ORT_API2_STATUS(CreateCustomOpDomain, _In_ const char* domain, _Outptr_ OrtCustomOpDomain** out);
1049
+
1050
+ /** \brief Add a custom op to a custom op domain
1051
+ *
1052
+ * \note The OrtCustomOp* pointer must remain valid until the ::OrtCustomOpDomain using it is released
1053
+ *
1054
+ * \param[in] custom_op_domain
1055
+ * \param[in] op
1056
+ *
1057
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1058
+ */
1059
+ ORT_API2_STATUS(CustomOpDomain_Add, _Inout_ OrtCustomOpDomain* custom_op_domain, _In_ const OrtCustomOp* op);
1060
+
1061
+ /// @}
1062
+ /// \name OrtSessionOptions
1063
+ /// @{
1064
+
1065
+ /** \brief Add custom op domain to a session options
1066
+ *
1067
+ * \note The OrtCustomOpDomain* must not be deleted until all sessions using it are released
1068
+ *
1069
+ * \param[in] options
1070
+ * \param[in] custom_op_domain
1071
+ *
1072
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1073
+ */
1074
+ ORT_API2_STATUS(AddCustomOpDomain, _Inout_ OrtSessionOptions* options, _In_ OrtCustomOpDomain* custom_op_domain);
1075
+
1076
+ /** \deprecated Use OrtApi::RegisterCustomOpsLibrary_V2.
1077
+ *
1078
+ * Registers custom ops from a shared library.
1079
+ *
1080
+ * Loads a shared library (dll on windows, so on linux, etc) named 'library_path' and looks for this entry point:
1081
+ * OrtStatus* RegisterCustomOps(OrtSessionOptions * options, const OrtApiBase* api);
1082
+ * It then passes in the provided session options to this function along with the api base.
1083
+ * The handle to the loaded library is returned in library_handle. It can be freed by the caller after all sessions using the passed in
1084
+ * session options are destroyed, or if an error occurs and it is non null.
1085
+ *
1086
+ * \param[in] options
1087
+ * \param[in] library_path
1088
+ * \param[out] library_handle OS specific handle to the loaded library (Use FreeLibrary on Windows, dlclose on Linux, etc.. to unload)
1089
+ *
1090
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1091
+ */
1092
+ ORT_API2_STATUS(RegisterCustomOpsLibrary, _Inout_ OrtSessionOptions* options, _In_ const char* library_path, _Outptr_ void** library_handle);
1093
+
1094
+ /// @}
1095
+ /// \name OrtSession
1096
+ /// @{
1097
+
1098
+ /** \brief Get input count for a session
1099
+ *
1100
+ * This number must also match the number of inputs passed to OrtApi::Run
1101
+ *
1102
+ * \see OrtApi::SessionGetInputTypeInfo, OrtApi::SessionGetInputName, OrtApi::Session
1103
+ *
1104
+ * \param[in] session
1105
+ * \param[out] out Number of inputs
1106
+ *
1107
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1108
+ */
1109
+ ORT_API2_STATUS(SessionGetInputCount, _In_ const OrtSession* session, _Out_ size_t* out);
1110
+
1111
+ /** \brief Get output count for a session
1112
+ *
1113
+ * This number must also match the number of outputs returned by OrtApi::Run
1114
+ *
1115
+ * \see OrtApi::SessionGetOutputTypeInfo, OrtApi::SessionGetOutputName, OrtApi::Session
1116
+ *
1117
+ * \param[in] session
1118
+ * \param[out] out Number of outputs
1119
+ *
1120
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1121
+ */
1122
+ ORT_API2_STATUS(SessionGetOutputCount, _In_ const OrtSession* session, _Out_ size_t* out);
1123
+
1124
+ /** \brief Get overridable initializer count
1125
+ *
1126
+ * \see OrtApi::SessionGetOverridableInitializerTypeInfo, OrtApi::SessionGetOverridableInitializerName
1127
+ *
1128
+ * \param[in] session
1129
+ * \param[in] out
1130
+ *
1131
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1132
+ */
1133
+ ORT_API2_STATUS(SessionGetOverridableInitializerCount, _In_ const OrtSession* session, _Out_ size_t* out);
1134
+
1135
+ /** \brief Get input type information
1136
+ *
1137
+ * \param[in] session
1138
+ * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetInputCount returns (exclusive)
1139
+ * \param[out] type_info Must be freed with OrtApi::ReleaseTypeInfo
1140
+ *
1141
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1142
+ */
1143
+ ORT_API2_STATUS(SessionGetInputTypeInfo, _In_ const OrtSession* session, size_t index, _Outptr_ OrtTypeInfo** type_info);
1144
+
1145
+ /** \brief Get output type information
1146
+ *
1147
+ * \param[in] session
1148
+ * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetOutputCount returns (exclusive)
1149
+ * \param[out] type_info Must be freed with OrtApi::ReleaseTypeInfo
1150
+ *
1151
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1152
+ */
1153
+ ORT_API2_STATUS(SessionGetOutputTypeInfo, _In_ const OrtSession* session, size_t index, _Outptr_ OrtTypeInfo** type_info);
1154
+
1155
+ /** \brief Get overridable initializer type information
1156
+ *
1157
+ * \param[in] session
1158
+ * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetOverridableInitializerCount returns (exclusive)
1159
+ * \param[out] type_info Must be freed with OrtApi::ReleaseTypeInfo
1160
+ *
1161
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1162
+ */
1163
+ ORT_API2_STATUS(SessionGetOverridableInitializerTypeInfo, _In_ const OrtSession* session, size_t index, _Outptr_ OrtTypeInfo** type_info);
1164
+
1165
+ /** \brief Get input name
1166
+ *
1167
+ * \param[in] session
1168
+ * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetInputCount returns (exclusive)
1169
+ * \param[in] allocator
1170
+ * \param[out] value Set to a null terminated UTF-8 encoded string allocated using `allocator`. Must be freed using `allocator`.
1171
+ *
1172
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1173
+ */
1174
+ ORT_API2_STATUS(SessionGetInputName, _In_ const OrtSession* session, size_t index, _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
1175
+
1176
+ /** \brief Get output name
1177
+ *
1178
+ * \param[in] session
1179
+ * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetOutputCount returns (exclusive)
1180
+ * \param[in] allocator
1181
+ * \param[out] value Set to a null terminated UTF-8 encoded string allocated using `allocator`. Must be freed using `allocator`.
1182
+ *
1183
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1184
+ */
1185
+ ORT_API2_STATUS(SessionGetOutputName, _In_ const OrtSession* session, size_t index, _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
1186
+
1187
+ /** \brief Get overridable initializer name
1188
+ *
1189
+ * \param[in] session
1190
+ * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetOverridableInitializerCount returns (exclusive)
1191
+ * \param[in] allocator
1192
+ * \param[out] value Set to a null terminated UTF-8 encoded string allocated using `allocator`. Must be freed using `allocator`.
1193
+ *
1194
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1195
+ */
1196
+ ORT_API2_STATUS(SessionGetOverridableInitializerName, _In_ const OrtSession* session, size_t index,
1197
+ _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
1198
+
1199
+ /// @}
1200
+ /// \name OrtRunOptions
1201
+ /// @{
1202
+
1203
+ /** \brief Create an OrtRunOptions
1204
+ *
1205
+ * \param[out] out Returned newly created ::OrtRunOptions. Must be freed with OrtApi::ReleaseRunOptions
1206
+ *
1207
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1208
+ */
1209
+ ORT_API2_STATUS(CreateRunOptions, _Outptr_ OrtRunOptions** out);
1210
+
1211
+ /** \brief Set per-run log verbosity level
1212
+ *
1213
+ * \see OrtApi::RunOptionsGetRunLogVerbosityLevel
1214
+ *
1215
+ * \param[in] options
1216
+ * \param[in] log_verbosity_level \snippet{doc} snippets.dox Log Verbosity Level
1217
+ *
1218
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1219
+ */
1220
+ ORT_API2_STATUS(RunOptionsSetRunLogVerbosityLevel, _Inout_ OrtRunOptions* options, int log_verbosity_level);
1221
+
1222
+ /** \brief Set per-run log severity level
1223
+ *
1224
+ * \see OrtApi::RunOptionsGetRunLogSeverityLevel
1225
+ *
1226
+ * \param[in] options
1227
+ * \param[in] log_severity_level The log severity level (refer to ::OrtLoggingLevel for possible values).
1228
+ */
1229
+ ORT_API2_STATUS(RunOptionsSetRunLogSeverityLevel, _Inout_ OrtRunOptions* options, int log_severity_level);
1230
+
1231
+ /** \brief Set per-run tag
1232
+ *
1233
+ * This is used in a per-run log identifier.
1234
+ *
1235
+ * \see OrtApi::RunOptionsGetRunTag
1236
+ *
1237
+ * \param[in] options
1238
+ * \param[in] run_tag The run tag.
1239
+ */
1240
+ ORT_API2_STATUS(RunOptionsSetRunTag, _Inout_ OrtRunOptions* options, _In_ const char* run_tag);
1241
+
1242
+ /** \brief Get per-run log verbosity level
1243
+ *
1244
+ * \see OrtApi::RunOptionsSetRunLogVerbosityLevel
1245
+ *
1246
+ * \param[in] options
1247
+ * \param[out] log_verbosity_level \snippet{doc} snippets.dox Log Verbosity Level
1248
+ *
1249
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1250
+ */
1251
+ ORT_API2_STATUS(RunOptionsGetRunLogVerbosityLevel, _In_ const OrtRunOptions* options,
1252
+ _Out_ int* log_verbosity_level);
1253
+
1254
+ /** \brief Get per-run log severity level
1255
+ *
1256
+ * \see OrtApi::RunOptionsSetRunLogSeverityLevel
1257
+ *
1258
+ * \param[in] options
1259
+ * \param[out] log_severity_level The log severity level (refer to ::OrtLoggingLevel for possible values).
1260
+ */
1261
+ ORT_API2_STATUS(RunOptionsGetRunLogSeverityLevel, _In_ const OrtRunOptions* options, _Out_ int* log_severity_level);
1262
+
1263
+ /** \brief Get per-run tag
1264
+ *
1265
+ * This is used in a per-run log identifier.
1266
+ *
1267
+ * \see OrtApi::RunOptionsSetRunTag
1268
+ *
1269
+ * \param[in] options
1270
+ * \param[out] run_tag The run tag.
1271
+ * Do not free this value, it is owned by `options`. It will be invalidated if the run tag
1272
+ * changes (i.e., with OrtApi::RunOptionsSetRunTag) or `options` is freed.
1273
+ */
1274
+ ORT_API2_STATUS(RunOptionsGetRunTag, _In_ const OrtRunOptions* options, _Out_ const char** run_tag);
1275
+
1276
+ /** \brief Set terminate flag
1277
+ *
1278
+ * If a currently executing session needs to be force terminated, this can be called from another thread to force it to fail with an error.
1279
+ *
1280
+ * \param[in] options
1281
+ *
1282
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1283
+ */
1284
+ ORT_API2_STATUS(RunOptionsSetTerminate, _Inout_ OrtRunOptions* options);
1285
+
1286
+ /** \brief Clears the terminate flag
1287
+ *
1288
+ * Used so the OrtRunOptions instance can be used in a new OrtApi::Run call without it instantly terminating
1289
+ *
1290
+ * \param[in] options
1291
+ *
1292
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1293
+ */
1294
+ ORT_API2_STATUS(RunOptionsUnsetTerminate, _Inout_ OrtRunOptions* options);
1295
+
1296
+ /// @}
1297
+ /// \name OrtValue
1298
+ /// @{
1299
+
1300
+ /** \brief Create a tensor
1301
+ *
1302
+ * Create a tensor using a supplied ::OrtAllocator
1303
+ *
1304
+ * \param[in] allocator
1305
+ * \param[in] shape Pointer to the tensor shape dimensions.
1306
+ * \param[in] shape_len The number of tensor shape dimensions.
1307
+ * \param[in] type
1308
+ * \param[out] out Returns newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue
1309
+ *
1310
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1311
+ */
1312
+ ORT_API2_STATUS(CreateTensorAsOrtValue, _Inout_ OrtAllocator* allocator, _In_ const int64_t* shape, size_t shape_len,
1313
+ ONNXTensorElementDataType type, _Outptr_ OrtValue** out);
1314
+
1315
+ /** \brief Create a tensor backed by a user supplied buffer
1316
+ *
1317
+ * Create a tensor with user's buffer. You can fill the buffer either before calling this function or after.
1318
+ * p_data is owned by caller. ReleaseValue won't release p_data.
1319
+ *
1320
+ * \param[in] info Memory description of where the p_data buffer resides (CPU vs GPU etc).
1321
+ * \param[in] p_data Pointer to the data buffer.
1322
+ * \param[in] p_data_len The number of bytes in the data buffer.
1323
+ * \param[in] shape Pointer to the tensor shape dimensions.
1324
+ * \param[in] shape_len The number of tensor shape dimensions.
1325
+ * \param[in] type The data type.
1326
+ * \param[out] out Returns newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue
1327
+ *
1328
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1329
+ */
1330
+ ORT_API2_STATUS(CreateTensorWithDataAsOrtValue, _In_ const OrtMemoryInfo* info, _Inout_ void* p_data,
1331
+ size_t p_data_len, _In_ const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type,
1332
+ _Outptr_ OrtValue** out);
1333
+
1334
+ /** \brief Return if an ::OrtValue is a tensor type
1335
+ *
1336
+ * \param[in] value A tensor type (string tensors are not supported)
1337
+ * \param[out] out Set to 1 iff ::OrtValue is a tensor, 0 otherwise
1338
+ *
1339
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1340
+ */
1341
+ ORT_API2_STATUS(IsTensor, _In_ const OrtValue* value, _Out_ int* out);
1342
+
1343
+ /** \brief Get a pointer to the raw data inside a tensor
1344
+ *
1345
+ * Used to read/write/modify the internal tensor data directly.
1346
+ * \note The returned pointer is valid until the \p value is destroyed.
1347
+ *
1348
+ * \param[in] value A tensor type (string tensors are not supported)
1349
+ * \param[out] out Filled in with a pointer to the internal storage
1350
+ *
1351
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1352
+ */
1353
+ ORT_API2_STATUS(GetTensorMutableData, _In_ OrtValue* value, _Outptr_ void** out);
1354
+
1355
+ /** \brief Set all strings at once in a string tensor
1356
+ *
1357
+ * \param[in,out] value A tensor of type ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING
1358
+ * \param[in] s An array of strings. Each string in this array must be null terminated.
1359
+ * \param[in] s_len Count of strings in s (Must match the size of \p value's tensor shape)
1360
+ *
1361
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1362
+ */
1363
+ ORT_API2_STATUS(FillStringTensor, _Inout_ OrtValue* value, _In_ const char* const* s, size_t s_len);
1364
+
1365
+ /** \brief Get total byte length for all strings in a string tensor
1366
+ *
1367
+ * Typically used with OrtApi::GetStringTensorContent
1368
+ *
1369
+ * \param[in] value A tensor of type ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING
1370
+ * \param[out] len Total byte length of all strings (does not include trailing nulls)
1371
+ *
1372
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1373
+ */
1374
+ ORT_API2_STATUS(GetStringTensorDataLength, _In_ const OrtValue* value, _Out_ size_t* len);
1375
+
1376
+ /** \brief Get all strings from a string tensor
1377
+ *
1378
+ * An example of the results:<br>
1379
+ * Given \p value is a string tensor with the strings { "This" "is" "a" "test" }<br>
1380
+ * \p s must have a size of 11 bytes<br>
1381
+ * \p offsets must have 4 elements<br>
1382
+ * After the call, these values will be filled in:<br>
1383
+ * \p s will contain "Thisisatest"<br>
1384
+ * \p offsets will contain { 0, 4, 6, 7 }<br>
1385
+ * The length of the last string is just s_len - offsets[last]
1386
+ *
1387
+ * \param[in] value A tensor of type ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING
1388
+ * \param[in] s Buffer to sequentially write all tensor strings to. Each string is NOT null-terminated.
1389
+ * \param[in] s_len Number of bytes of buffer pointed to by \p s (Get it from OrtApi::GetStringTensorDataLength)
1390
+ * \param[out] offsets Array of start offsets into the strings written to \p s
1391
+ * \param[in] offsets_len Number of elements in offsets
1392
+ *
1393
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1394
+ */
1395
+ ORT_API2_STATUS(GetStringTensorContent, _In_ const OrtValue* value, _Out_writes_bytes_all_(s_len) void* s,
1396
+ size_t s_len, _Out_writes_all_(offsets_len) size_t* offsets, size_t offsets_len);
1397
+
1398
+ /// @}
1399
+ /// \name OrtTypeInfo
1400
+ /// @{
1401
+
1402
+ /** \brief Get ::OrtTensorTypeAndShapeInfo from an ::OrtTypeInfo
1403
+ *
1404
+ * \param[in] type_info
1405
+ * \param[out] out Do not free this value, it will be valid until type_info is freed.
1406
+ * If type_info does not represent tensor, this value will be set to nullptr.
1407
+ *
1408
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1409
+ */
1410
+ ORT_API2_STATUS(CastTypeInfoToTensorInfo, _In_ const OrtTypeInfo* type_info,
1411
+ _Outptr_result_maybenull_ const OrtTensorTypeAndShapeInfo** out);
1412
+
1413
+ /** \brief Get ::ONNXType from ::OrtTypeInfo
1414
+ *
1415
+ * \param[in] type_info
1416
+ * \param[out] out
1417
+ *
1418
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1419
+ */
1420
+ ORT_API2_STATUS(GetOnnxTypeFromTypeInfo, _In_ const OrtTypeInfo* type_info, _Out_ enum ONNXType* out);
1421
+
1422
+ /// @}
1423
+ /// \name OrtTensorTypeAndShapeInfo
1424
+ /// @{
1425
+
1426
+ /** \brief Create an ::OrtTensorTypeAndShapeInfo object
1427
+ *
1428
+ * \param[out] out Returns newly created ::OrtTensorTypeAndShapeInfo. Must be freed with OrtApi::ReleaseTensorTypeAndShapeInfo
1429
+ *
1430
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1431
+ */
1432
+ ORT_API2_STATUS(CreateTensorTypeAndShapeInfo, _Outptr_ OrtTensorTypeAndShapeInfo** out);
1433
+
1434
+ /** \brief Set element type in ::OrtTensorTypeAndShapeInfo
1435
+ *
1436
+ * \param[in] info
1437
+ * \param[in] type
1438
+ *
1439
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1440
+ */
1441
+ ORT_API2_STATUS(SetTensorElementType, _Inout_ OrtTensorTypeAndShapeInfo* info, enum ONNXTensorElementDataType type);
1442
+
1443
+ /** \brief Set shape information in ::OrtTensorTypeAndShapeInfo
1444
+ *
1445
+ * \param[in] info
1446
+ * \param[in] dim_values Array with `dim_count` elements. Can contain negative values.
1447
+ * \param[in] dim_count Number of elements in `dim_values`
1448
+ *
1449
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1450
+ */
1451
+ ORT_API2_STATUS(SetDimensions, OrtTensorTypeAndShapeInfo* info, _In_ const int64_t* dim_values, size_t dim_count);
1452
+
1453
+ /** \brief Get element type in ::OrtTensorTypeAndShapeInfo
1454
+ *
1455
+ * \see OrtApi::SetTensorElementType
1456
+ *
1457
+ * \param[in] info
1458
+ * \param[out] out
1459
+ *
1460
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1461
+ */
1462
+ ORT_API2_STATUS(GetTensorElementType, _In_ const OrtTensorTypeAndShapeInfo* info,
1463
+ _Out_ enum ONNXTensorElementDataType* out);
1464
+
1465
+ /** \brief Get dimension count in ::OrtTensorTypeAndShapeInfo
1466
+ *
1467
+ * \see OrtApi::GetDimensions
1468
+ *
1469
+ * \param[in] info
1470
+ * \param[out] out
1471
+ *
1472
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1473
+ */
1474
+ ORT_API2_STATUS(GetDimensionsCount, _In_ const OrtTensorTypeAndShapeInfo* info, _Out_ size_t* out);
1475
+
1476
+ /** \brief Get dimensions in ::OrtTensorTypeAndShapeInfo
1477
+ *
1478
+ * \param[in] info
1479
+ * \param[out] dim_values Array with `dim_values_length` elements. On return, filled with the dimensions stored in the ::OrtTensorTypeAndShapeInfo
1480
+ * \param[in] dim_values_length Number of elements in `dim_values`. Use OrtApi::GetDimensionsCount to get this value
1481
+ *
1482
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1483
+ */
1484
+ ORT_API2_STATUS(GetDimensions, _In_ const OrtTensorTypeAndShapeInfo* info, _Out_ int64_t* dim_values,
1485
+ size_t dim_values_length);
1486
+
1487
+ /** \brief Get symbolic dimension names in ::OrtTensorTypeAndShapeInfo
1488
+ *
1489
+ * \param[in] info
1490
+ * \param[in] dim_params Array with `dim_params_length` elements. On return filled with pointers to null terminated strings of the dimension names
1491
+ * \param[in] dim_params_length Number of elements in `dim_params`. Use OrtApi::GetDimensionsCount to get this value
1492
+ *
1493
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1494
+ */
1495
+ ORT_API2_STATUS(GetSymbolicDimensions, _In_ const OrtTensorTypeAndShapeInfo* info,
1496
+ _Out_writes_all_(dim_params_length) const char* dim_params[], size_t dim_params_length);
1497
+
1498
+ /** \brief Get total number of elements in a tensor shape from an ::OrtTensorTypeAndShapeInfo
1499
+ *
1500
+ * Return the number of elements specified by the tensor shape (all dimensions multiplied by each other).
1501
+ * For 0 dimensions, 1 is returned. If any dimension is less than 0, the result is always -1.
1502
+ *
1503
+ * Examples:<br>
1504
+ * [] = 1<br>
1505
+ * [1,3,4] = 12<br>
1506
+ * [2,0,4] = 0<br>
1507
+ * [-1,3,4] = -1<br>
1508
+ *
1509
+ * \param[in] info
1510
+ * \param[out] out Number of elements
1511
+ *
1512
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1513
+ */
1514
+ ORT_API2_STATUS(GetTensorShapeElementCount, _In_ const OrtTensorTypeAndShapeInfo* info, _Out_ size_t* out);
1515
+
1516
+ /// @}
1517
+ /// \name OrtValue
1518
+ /// @{
1519
+
1520
+ /** \brief Get type and shape information from a tensor ::OrtValue
1521
+ *
1522
+ * \param[in] value Must be a tensor (not a map/sequence/etc) or will return failure
1523
+ * \param[out] out Newly created ::OrtTensorTypeAndShapeInfo. Must be freed with OrtApi::ReleaseTensorTypeAndShapeInfo
1524
+ *
1525
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1526
+ */
1527
+ ORT_API2_STATUS(GetTensorTypeAndShape, _In_ const OrtValue* value, _Outptr_ OrtTensorTypeAndShapeInfo** out);
1528
+
1529
+ /** \brief Get type information of an OrtValue
1530
+ *
1531
+ * \param[in] value
1532
+ * \param[out] out Newly created ::OrtTypeInfo. Must be freed with OrtApi::ReleaseTypeInfo
1533
+ *
1534
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1535
+ */
1536
+ ORT_API2_STATUS(GetTypeInfo, _In_ const OrtValue* value, _Outptr_result_maybenull_ OrtTypeInfo** out);
1537
+
1538
+ /** \brief Get ONNXType of an ::OrtValue
1539
+ *
1540
+ * \param[in] value
1541
+ * \param[out] out
1542
+ *
1543
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1544
+ */
1545
+ ORT_API2_STATUS(GetValueType, _In_ const OrtValue* value, _Out_ enum ONNXType* out);
1546
+
1547
+ /// @}
1548
+ /// \name OrtMemoryInfo
1549
+ /// @{
1550
+
1551
+ /** \brief Create an ::OrtMemoryInfo
1552
+ *
1553
+ * \param[in] name
1554
+ * \param[in] type
1555
+ * \param[in] id
1556
+ * \param[in] mem_type
1557
+ * \param[out] out Newly created ::OrtMemoryInfo. Must be freed with OrtAPi::ReleaseMemoryInfo
1558
+ *
1559
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1560
+ */
1561
+ ORT_API2_STATUS(CreateMemoryInfo, _In_ const char* name, enum OrtAllocatorType type, int id,
1562
+ enum OrtMemType mem_type, _Outptr_ OrtMemoryInfo** out);
1563
+
1564
+ /** \brief Create an ::OrtMemoryInfo for CPU memory
1565
+ *
1566
+ * Special case version of OrtApi::CreateMemoryInfo for CPU based memory. Same as using OrtApi::CreateMemoryInfo with name = "Cpu" and id = 0.
1567
+ *
1568
+ * \param[in] type
1569
+ * \param[in] mem_type
1570
+ * \param[out] out
1571
+ *
1572
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1573
+ */
1574
+ ORT_API2_STATUS(CreateCpuMemoryInfo, enum OrtAllocatorType type, enum OrtMemType mem_type,
1575
+ _Outptr_ OrtMemoryInfo** out);
1576
+
1577
+ /** \brief Compare ::OrtMemoryInfo objects for equality
1578
+ *
1579
+ * Compares all settings of each ::OrtMemoryInfo for equality
1580
+ *
1581
+ * \param[in] info1
1582
+ * \param[in] info2
1583
+ * \param[out] out Set to 0 if equal, -1 if not equal
1584
+ *
1585
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1586
+ */
1587
+ ORT_API2_STATUS(CompareMemoryInfo, _In_ const OrtMemoryInfo* info1, _In_ const OrtMemoryInfo* info2, _Out_ int* out);
1588
+
1589
+ /** \brief Get name from ::OrtMemoryInfo
1590
+ *
1591
+ * \param[in] ptr
1592
+ * \param[out] out Writes null terminated string to this pointer. Do NOT free the returned pointer. It is valid for the lifetime of the ::OrtMemoryInfo
1593
+ *
1594
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1595
+ */
1596
+ ORT_API2_STATUS(MemoryInfoGetName, _In_ const OrtMemoryInfo* ptr, _Out_ const char** out);
1597
+
1598
+ /** \brief Get the id from ::OrtMemoryInfo
1599
+ */
1600
+ ORT_API2_STATUS(MemoryInfoGetId, _In_ const OrtMemoryInfo* ptr, _Out_ int* out);
1601
+
1602
+ /** \brief Get the ::OrtMemType from ::OrtMemoryInfo
1603
+ */
1604
+ ORT_API2_STATUS(MemoryInfoGetMemType, _In_ const OrtMemoryInfo* ptr, _Out_ OrtMemType* out);
1605
+
1606
+ /** \brief Get the ::OrtAllocatorType from ::OrtMemoryInfo
1607
+ */
1608
+ ORT_API2_STATUS(MemoryInfoGetType, _In_ const OrtMemoryInfo* ptr, _Out_ OrtAllocatorType* out);
1609
+
1610
+ /// @}
1611
+ /// \name OrtAllocator
1612
+ /// @{
1613
+
1614
+ /// \brief Calls OrtAllocator::Alloc function
1615
+ ORT_API2_STATUS(AllocatorAlloc, _Inout_ OrtAllocator* ort_allocator, size_t size, _Outptr_ void** out);
1616
+ /// \brief Calls OrtAllocator::Free function
1617
+ ORT_API2_STATUS(AllocatorFree, _Inout_ OrtAllocator* ort_allocator, void* p);
1618
+ /// \brief Calls OrtAllocator::Info function
1619
+ ORT_API2_STATUS(AllocatorGetInfo, _In_ const OrtAllocator* ort_allocator, _Outptr_ const struct OrtMemoryInfo** out);
1620
+
1621
+ /** \brief Get the default allocator
1622
+ *
1623
+ * The default allocator is a CPU based, non-arena. Always returns the same pointer to the same default allocator.
1624
+ *
1625
+ * \param[out] out Returned value should NOT be freed
1626
+ *
1627
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1628
+ */
1629
+ ORT_API2_STATUS(GetAllocatorWithDefaultOptions, _Outptr_ OrtAllocator** out);
1630
+
1631
+ /// @}
1632
+ /// \name OrtSessionOptions
1633
+ /// @{
1634
+
1635
+ /** \brief Override session symbolic dimensions
1636
+ *
1637
+ * Override symbolic dimensions (by specific denotation strings) with actual values if known at session initialization time to enable
1638
+ * optimizations that can take advantage of fixed values (such as memory planning, etc)
1639
+ *
1640
+ * \param[in] options
1641
+ * \param[in] dim_denotation
1642
+ * \param[in] dim_value
1643
+ *
1644
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1645
+ */
1646
+ ORT_API2_STATUS(AddFreeDimensionOverride, _Inout_ OrtSessionOptions* options, _In_ const char* dim_denotation,
1647
+ _In_ int64_t dim_value);
1648
+
1649
+ /// @}
1650
+ /// \name OrtValue
1651
+ /// @{
1652
+
1653
+ /* Internal information (not seen in Doxygen)
1654
+ *
1655
+ * APIs to support non-tensor types - map and sequence.
1656
+ * Currently only the following types are supported
1657
+ * Note: the following types should be kept in sync with data_types.h
1658
+ * Map types
1659
+ * =========
1660
+ * std::map<std::string, std::string>
1661
+ * std::map<std::string, int64_t>
1662
+ * std::map<std::string, float>
1663
+ * std::map<std::string, double>
1664
+ * std::map<int64_t, std::string>
1665
+ * std::map<int64_t, int64_t>
1666
+ * std::map<int64_t, float>
1667
+ * std::map<int64_t, double>
1668
+ *
1669
+ * Sequence types
1670
+ * ==============
1671
+ * std::vector<std::string>
1672
+ * std::vector<int64_t>
1673
+ * std::vector<float>
1674
+ * std::vector<double>
1675
+ * std::vector<std::map<std::string, float>>
1676
+ * std::vector<std::map<int64_t, float>
1677
+ */
1678
+
1679
+ /** \brief Get non tensor data from an ::OrtValue
1680
+ *
1681
+ * If `value` is of type ONNX_TYPE_MAP, you need to retrieve the keys and values
1682
+ * separately. Use index=0 to retrieve keys and index=1 to retrieve values.
1683
+ * If `value` is of type ONNX_TYPE_SEQUENCE, use index to retrieve the index'th element
1684
+ * of the sequence.
1685
+ *
1686
+ * \param[in] value
1687
+ * \param[in] index See above for usage based on `value` type
1688
+ * \param[in] allocator Allocator used to allocate ::OrtValue
1689
+ * \param[out] out Created ::OrtValue that holds the element requested. Must be freed with OrtApi::ReleaseValue
1690
+ *
1691
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1692
+ */
1693
+ ORT_API2_STATUS(GetValue, _In_ const OrtValue* value, int index, _Inout_ OrtAllocator* allocator,
1694
+ _Outptr_ OrtValue** out);
1695
+
1696
+ /** \brief Get non tensor value count from an ::OrtValue
1697
+ *
1698
+ * If `value` is of type ONNX_TYPE_MAP 2 will always be returned. For ONNX_TYPE_SEQUENCE
1699
+ * the number of elements in the sequence will be returned
1700
+ *
1701
+ * \param[in] value
1702
+ * \param[out] out
1703
+ *
1704
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1705
+ */
1706
+ ORT_API2_STATUS(GetValueCount, _In_ const OrtValue* value, _Out_ size_t* out);
1707
+
1708
+ /** \brief Create a map or sequence ::OrtValue
1709
+ *
1710
+ * To construct a map (ONNX_TYPE_MAP), use num_values = 2 and `in` should be an array of 2 ::OrtValue%s
1711
+ * representing keys and values.<br>
1712
+ *
1713
+ * To construct a sequence (ONNX_TYPE_SEQUENCE), use num_values = N where N is the number of the elements in the
1714
+ * sequence. 'in' should be an array of N ::OrtValue%s.
1715
+ *
1716
+ * \param[in] in See above for details
1717
+ * \param[in] num_values
1718
+ * \param[in] value_type Must be either ONNX_TYPE_MAP or ONNX_TYPE_SEQUENCE
1719
+ * \param[out] out Newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue
1720
+ *
1721
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1722
+ */
1723
+ ORT_API2_STATUS(CreateValue, _In_reads_(num_values) const OrtValue* const* in, size_t num_values,
1724
+ enum ONNXType value_type, _Outptr_ OrtValue** out);
1725
+
1726
+ /** \brief Create an opaque (custom user defined type) ::OrtValue
1727
+ *
1728
+ * Constructs an ::OrtValue that contains a value of non-standard type created for
1729
+ * experiments or while awaiting standardization. ::OrtValue in this case would contain
1730
+ * an internal representation of the Opaque type. Opaque types are distinguished from
1731
+ * each other by two strings 1) domain and 2) type name. The combination of the two
1732
+ * must be unique, so the type representation is properly identified internally. The combination
1733
+ * must be properly registered from within ORT at both compile/run time or by another API.
1734
+ *
1735
+ * To construct the ::OrtValue pass domain and type names, also a pointer to a data container
1736
+ * the type of which must be known to both ORT and the client program. That data container may or may
1737
+ * not match the internal representation of the Opaque type. The sizeof(data_container) is passed for
1738
+ * verification purposes.
1739
+ *
1740
+ * \param[in] domain_name Null terminated string of the domain name
1741
+ * \param[in] type_name Null terminated string of the type name
1742
+ * \param[in] data_container User pointer Data to populate ::OrtValue
1743
+ * \param[in] data_container_size Size in bytes of what `data_container` points to
1744
+ * \param[out] out Newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue
1745
+ *
1746
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1747
+ */
1748
+ ORT_API2_STATUS(CreateOpaqueValue, _In_z_ const char* domain_name, _In_z_ const char* type_name,
1749
+ _In_ const void* data_container, size_t data_container_size, _Outptr_ OrtValue** out);
1750
+
1751
+ /** \brief Get internal data from an opaque (custom user defined type) ::OrtValue
1752
+ *
1753
+ * Copies internal data from an opaque value into a user provided buffer
1754
+ *
1755
+ * \see OrtApi::CreateOpaqueValue
1756
+ *
1757
+ * \param[in] domain_name Null terminated string of the domain name
1758
+ * \param[in] type_name Null terminated string of the type name
1759
+ * \param[in] in The opaque ::OrtValue
1760
+ * \param[out] data_container Buffer to copy data into
1761
+ * \param[out] data_container_size Size in bytes of the buffer pointed to by data_container. Must match the size of the internal buffer.
1762
+ *
1763
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1764
+ */
1765
+ ORT_API2_STATUS(GetOpaqueValue, _In_ const char* domain_name, _In_ const char* type_name, _In_ const OrtValue* in,
1766
+ _Out_ void* data_container, size_t data_container_size);
1767
+
1768
+ /// @}
1769
+ /// \name OrtKernelInfo
1770
+ /// Custom operator APIs.
1771
+ /// @{
1772
+
1773
+ /** \brief Get a float stored as an attribute in the graph node
1774
+ *
1775
+ * \param[in] info ::OrtKernelInfo instance
1776
+ * \param[in] name Null terminated string of the name of the attribute
1777
+ * \param[out] out Pointer to memory where the attribute will be stored
1778
+ *
1779
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1780
+ */
1781
+ ORT_API2_STATUS(KernelInfoGetAttribute_float, _In_ const OrtKernelInfo* info, _In_ const char* name,
1782
+ _Out_ float* out);
1783
+
1784
+ /** \brief Fetch a 64-bit int stored as an attribute in the graph node
1785
+ *
1786
+ * \param[in] info ::OrtKernelInfo instance
1787
+ * \param[in] name Null terminated string of the name of the attribute
1788
+ * \param[out] out Pointer to memory where the attribute will be stored
1789
+ *
1790
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1791
+ */
1792
+ ORT_API2_STATUS(KernelInfoGetAttribute_int64, _In_ const OrtKernelInfo* info, _In_ const char* name,
1793
+ _Out_ int64_t* out);
1794
+
1795
+ /** \brief Fetch a string stored as an attribute in the graph node
1796
+ *
1797
+ * If `out` is nullptr, the value of `size` is set to the true size of the string
1798
+ * attribute, and a success status is returned.
1799
+ *
1800
+ * If the `size` parameter is greater than or equal to the actual string attribute's size,
1801
+ * the value of `size` is set to the true size of the string attribute, the provided memory
1802
+ * is filled with the attribute's contents, and a success status is returned.
1803
+ *
1804
+ * If the `size` parameter is less than the actual string attribute's size and `out`
1805
+ * is not nullptr, the value of `size` is set to the true size of the string attribute
1806
+ * and a failure status is returned.)
1807
+ *
1808
+ * \param[in] info ::OrtKernelInfo instance
1809
+ * \param[in] name Null terminated string of the name of the attribute
1810
+ * \param[out] out Pointer to memory where the attribute will be stored
1811
+ * \param[in,out] size See above comments for details
1812
+ *
1813
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1814
+ */
1815
+ ORT_API2_STATUS(KernelInfoGetAttribute_string, _In_ const OrtKernelInfo* info, _In_ const char* name, _Out_ char* out,
1816
+ _Inout_ size_t* size);
1817
+
1818
+ /// @}
1819
+ /// \name OrtKernelContext
1820
+ /// Custom operator APIs.
1821
+ /// @{
1822
+
1823
+ /** \brief Used for custom operators, get the input count of a kernel
1824
+ *
1825
+ * \see ::OrtCustomOp
1826
+ */
1827
+ ORT_API2_STATUS(KernelContext_GetInputCount, _In_ const OrtKernelContext* context, _Out_ size_t* out);
1828
+
1829
+ /** \brief Used for custom operators, get the output count of a kernel
1830
+ *
1831
+ * \see ::OrtCustomOp
1832
+ */
1833
+ ORT_API2_STATUS(KernelContext_GetOutputCount, _In_ const OrtKernelContext* context, _Out_ size_t* out);
1834
+
1835
+ /** \brief Used for custom operators, get an input of a kernel
1836
+ *
1837
+ * \see ::OrtCustomOp
1838
+ */
1839
+ ORT_API2_STATUS(KernelContext_GetInput, _In_ const OrtKernelContext* context, _In_ size_t index,
1840
+ _Out_ const OrtValue** out);
1841
+
1842
+ /** \brief Used for custom operators, get an output of a kernel
1843
+ *
1844
+ * \see ::OrtCustomOp
1845
+ */
1846
+ ORT_API2_STATUS(KernelContext_GetOutput, _Inout_ OrtKernelContext* context, _In_ size_t index,
1847
+ _In_ const int64_t* dim_values, size_t dim_count, _Outptr_ OrtValue** out);
1848
+
1849
+ /// @}
1850
+ /// \name OrtEnv
1851
+ /// @{
1852
+ ORT_CLASS_RELEASE(Env);
1853
+ /// @}
1854
+ /// \name OrtStatus
1855
+ /// @{
1856
+ ORT_CLASS_RELEASE(Status);
1857
+ /// @}
1858
+ /// \name OrtMemoryInfo
1859
+ /// @{
1860
+ ORT_CLASS_RELEASE(MemoryInfo);
1861
+ /// @}
1862
+ /// \name OrtSession
1863
+ /// @{
1864
+ ORT_CLASS_RELEASE(Session); // Don't call ReleaseSession from Dllmain (because session owns a thread pool)
1865
+ /// @}
1866
+ /// \name OrtValue
1867
+ /// @{
1868
+ ORT_CLASS_RELEASE(Value);
1869
+ /// @}
1870
+ /// \name OrtRunOptions
1871
+ /// @{
1872
+ ORT_CLASS_RELEASE(RunOptions);
1873
+ /// @}
1874
+ /// \name OrtTypeInfo
1875
+ /// @{
1876
+ ORT_CLASS_RELEASE(TypeInfo);
1877
+ /// @}
1878
+ /// \name OrtTensorTypeAndShapeInfo
1879
+ /// @{
1880
+ ORT_CLASS_RELEASE(TensorTypeAndShapeInfo);
1881
+ /// @}
1882
+ /// \name OrtSessionOptions
1883
+ /// @{
1884
+ ORT_CLASS_RELEASE(SessionOptions);
1885
+ /// @}
1886
+ /// \name OrtCustomOpDomain
1887
+ /// @{
1888
+ ORT_CLASS_RELEASE(CustomOpDomain);
1889
+
1890
+ /// @}
1891
+ /// \name OrtTypeInfo
1892
+ /// @{
1893
+
1894
+ /** \brief Get denotation from type information
1895
+ *
1896
+ * Augments ::OrtTypeInfo to return denotations on the type.
1897
+ *
1898
+ * This is used by WinML to determine if an input/output is intended to be an Image or a Tensor.
1899
+ *
1900
+ * \param[in] type_info
1901
+ * \param[out] denotation Pointer to the null terminated denotation string is written to this pointer. This pointer is valid until the object is destroyed or the name is changed, do not free.
1902
+ * \param[out] len Length in bytes of the string returned in `denotation`
1903
+ *
1904
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1905
+ */
1906
+ ORT_API2_STATUS(GetDenotationFromTypeInfo, _In_ const OrtTypeInfo* type_info, _Out_ const char** const denotation,
1907
+ _Out_ size_t* len);
1908
+
1909
+ /** \brief Get detailed map information from an ::OrtTypeInfo
1910
+ *
1911
+ * This augments ::OrtTypeInfo to return an ::OrtMapTypeInfo when the type is a map.
1912
+ * The OrtMapTypeInfo has additional information about the map's key type and value type.
1913
+ *
1914
+ * This is used by WinML to support model reflection APIs.
1915
+ *
1916
+ * \param[out] type_info
1917
+ * \param[out] out A pointer to the ::OrtMapTypeInfo. Do not free this value. If type_info
1918
+ * does not contain a map, this value will be set to nullptr.
1919
+ *
1920
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1921
+ */
1922
+ ORT_API2_STATUS(CastTypeInfoToMapTypeInfo, _In_ const OrtTypeInfo* type_info,
1923
+ _Outptr_result_maybenull_ const OrtMapTypeInfo** out);
1924
+
1925
+ /** \brief Cast ::OrtTypeInfo to an ::OrtSequenceTypeInfo
1926
+ *
1927
+ * This api augments ::OrtTypeInfo to return an ::OrtSequenceTypeInfo when the type is a sequence.
1928
+ * The ::OrtSequenceTypeInfo has additional information about the sequence's element type.
1929
+ *
1930
+ * This is used by WinML to support model reflection APIs.
1931
+ *
1932
+ * \param[in] type_info
1933
+ * \param[out] out A pointer to the OrtSequenceTypeInfo. Do not free this value. If type_info
1934
+ * doesn not contain a sequence, this value will be set to nullptr.
1935
+ *
1936
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1937
+ */
1938
+ ORT_API2_STATUS(CastTypeInfoToSequenceTypeInfo, _In_ const OrtTypeInfo* type_info,
1939
+ _Outptr_result_maybenull_ const OrtSequenceTypeInfo** out);
1940
+
1941
+ /// @}
1942
+ /// \name OrtMapTypeInfo
1943
+ /// @{
1944
+
1945
+ /** \brief Get key type from an ::OrtMapTypeInfo
1946
+ *
1947
+ * Key types are restricted to being scalar types.
1948
+ *
1949
+ * This is used by WinML to support model reflection APIs.
1950
+ *
1951
+ * \param[in] map_type_info
1952
+ * \param[out] out
1953
+ *
1954
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1955
+ */
1956
+ ORT_API2_STATUS(GetMapKeyType, _In_ const OrtMapTypeInfo* map_type_info, _Out_ enum ONNXTensorElementDataType* out);
1957
+
1958
+ /** \brief Get the value type from an ::OrtMapTypeInfo
1959
+ *
1960
+ * \param[in] map_type_info
1961
+ * \param[out] type_info
1962
+ *
1963
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1964
+ */
1965
+ ORT_API2_STATUS(GetMapValueType, _In_ const OrtMapTypeInfo* map_type_info, _Outptr_ OrtTypeInfo** type_info);
1966
+
1967
+ /// @}
1968
+ /// \name OrtSequenceTypeInfo
1969
+ /// @{
1970
+
1971
+ /** \brief Get element type from an ::OrtSequenceTypeInfo
1972
+ *
1973
+ * This is used by WinML to support model reflection APIs.
1974
+ *
1975
+ * \param[in] sequence_type_info
1976
+ * \param[out] type_info
1977
+ *
1978
+ * \snippet{doc} snippets.dox OrtStatus Return Value
1979
+ */
1980
+ ORT_API2_STATUS(GetSequenceElementType, _In_ const OrtSequenceTypeInfo* sequence_type_info,
1981
+ _Outptr_ OrtTypeInfo** type_info);
1982
+
1983
+ /// @}
1984
+ /// \name OrtMapTypeInfo
1985
+ /// @{
1986
+ ORT_CLASS_RELEASE(MapTypeInfo);
1987
+ /// @}
1988
+ /// \name OrtSequenceTypeInfo
1989
+ /// @{
1990
+ ORT_CLASS_RELEASE(SequenceTypeInfo);
1991
+
1992
+ /// @}
1993
+ /// \name OrtSession
1994
+ /// @{
1995
+
1996
+ /** \brief End profiling and return filename of the profile data
1997
+ *
1998
+ * Profiling is turned on through OrtApi::EnableProfiling
1999
+ *
2000
+ * \param[in] session
2001
+ * \param[in] allocator
2002
+ * \param[out] out Null terminated string of the filename, allocated using `allocator`. Must be freed using `allocator`
2003
+ *
2004
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2005
+ */
2006
+ ORT_API2_STATUS(SessionEndProfiling, _In_ OrtSession* session, _Inout_ OrtAllocator* allocator, _Outptr_ char** out);
2007
+
2008
+ /** \brief Get ::OrtModelMetadata from an ::OrtSession
2009
+ *
2010
+ * \param[in] session
2011
+ * \param[out] out Newly created ::OrtModelMetadata. Must be freed using OrtApi::ReleaseModelMetadata
2012
+ *
2013
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2014
+ */
2015
+ ORT_API2_STATUS(SessionGetModelMetadata, _In_ const OrtSession* session, _Outptr_ OrtModelMetadata** out);
2016
+
2017
+ /// @}
2018
+ /// \name OrtModelMetadata
2019
+ /// @{
2020
+
2021
+ /** \brief Get `producer name` from an ::OrtModelMetadata
2022
+ *
2023
+ * \param[in] model_metadata
2024
+ * \param[in] allocator
2025
+ * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator`
2026
+ *
2027
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2028
+ */
2029
+ ORT_API2_STATUS(ModelMetadataGetProducerName, _In_ const OrtModelMetadata* model_metadata,
2030
+ _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
2031
+
2032
+ /** \brief Get `graph name` from an ::OrtModelMetadata
2033
+ *
2034
+ * \param[in] model_metadata
2035
+ * \param[in] allocator
2036
+ * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator`
2037
+ *
2038
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2039
+ */
2040
+ ORT_API2_STATUS(ModelMetadataGetGraphName, _In_ const OrtModelMetadata* model_metadata,
2041
+ _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
2042
+
2043
+ /** \brief Get `domain` from an ::OrtModelMetadata
2044
+ *
2045
+ * \param[in] model_metadata
2046
+ * \param[in] allocator
2047
+ * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator`
2048
+ *
2049
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2050
+ */
2051
+ ORT_API2_STATUS(ModelMetadataGetDomain, _In_ const OrtModelMetadata* model_metadata, _Inout_ OrtAllocator* allocator,
2052
+ _Outptr_ char** value);
2053
+
2054
+ /** \brief Get `description` from an ::OrtModelMetadata
2055
+ *
2056
+ * \param[in] model_metadata
2057
+ * \param[in] allocator
2058
+ * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator`
2059
+ *
2060
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2061
+ */
2062
+ ORT_API2_STATUS(ModelMetadataGetDescription, _In_ const OrtModelMetadata* model_metadata,
2063
+ _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
2064
+
2065
+ /** \brief Return data for a key in the custom metadata map in an ::OrtModelMetadata
2066
+ *
2067
+ * \param[in] model_metadata
2068
+ * \param[in] allocator
2069
+ * \param[in] key Null terminated string
2070
+ * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator`
2071
+ * `value` will be set to nullptr if the given key is not found in the custom metadata map.
2072
+ *
2073
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2074
+ */
2075
+ ORT_API2_STATUS(ModelMetadataLookupCustomMetadataMap, _In_ const OrtModelMetadata* model_metadata,
2076
+ _Inout_ OrtAllocator* allocator, _In_ const char* key, _Outptr_result_maybenull_ char** value);
2077
+
2078
+ /** \brief Get version number from an ::OrtModelMetadata
2079
+ *
2080
+ * \param[in] model_metadata
2081
+ * \param[out] value Set to the version number
2082
+ *
2083
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2084
+ */
2085
+ ORT_API2_STATUS(ModelMetadataGetVersion, _In_ const OrtModelMetadata* model_metadata, _Out_ int64_t* value);
2086
+
2087
+ ORT_CLASS_RELEASE(ModelMetadata);
2088
+
2089
+ /// @}
2090
+ /// \name OrtEnv
2091
+ /// @{
2092
+
2093
+ /** \brief Create an OrtEnv
2094
+ *
2095
+ * Create an environment with global threadpools that will be shared across sessions.
2096
+ * Use this in conjunction with OrtApi::DisablePerSessionThreads or else the session will use
2097
+ * its own thread pools.
2098
+ *
2099
+ * \param[in] log_severity_level The log severity level.
2100
+ * \param[in] logid The log identifier.
2101
+ * \param[in] tp_options
2102
+ * \param[out] out Returned newly created OrtEnv. Must be freed with OrtApi::ReleaseEnv
2103
+ *
2104
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2105
+ */
2106
+ ORT_API2_STATUS(CreateEnvWithGlobalThreadPools, OrtLoggingLevel log_severity_level, _In_ const char* logid,
2107
+ _In_ const OrtThreadingOptions* tp_options, _Outptr_ OrtEnv** out);
2108
+
2109
+ /// @}
2110
+ /// \name OrtSessionOptions
2111
+ /// @{
2112
+
2113
+ /** \brief Use global thread pool on a session
2114
+ *
2115
+ * Disable using per session thread pool and use the shared global threadpool.
2116
+ * This should be used in conjunction with OrtApi::CreateEnvWithGlobalThreadPools.
2117
+ *
2118
+ * \param[in] options
2119
+ *
2120
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2121
+ */
2122
+ ORT_API2_STATUS(DisablePerSessionThreads, _Inout_ OrtSessionOptions* options);
2123
+
2124
+ /// @}
2125
+ /// \name OrtThreadingOptions
2126
+ /// @{
2127
+
2128
+ /** \brief Create an ::OrtThreadingOptions
2129
+ *
2130
+ * \param[out] out Newly created ::OrtThreadingOptions. Must be freed with OrtApi::ReleaseThreadingOptions
2131
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2132
+ */
2133
+ ORT_API2_STATUS(CreateThreadingOptions, _Outptr_ OrtThreadingOptions** out);
2134
+
2135
+ ORT_CLASS_RELEASE(ThreadingOptions);
2136
+
2137
+ /// @}
2138
+ /// \name OrtModelMetadata
2139
+ /// @{
2140
+
2141
+ /**
2142
+ *
2143
+ * \param[in] model_metadata
2144
+ * \param[in] allocator
2145
+ * \param[out] keys Array of null terminated strings (array count = num_keys) allocated using `allocator`.
2146
+ * The strings and the pointer array must be freed using `allocator`
2147
+ * `keys` will be set to nullptr if the custom metadata map is empty.
2148
+ * \param[out] num_keys Set to the number of elements in the `keys` array
2149
+ *
2150
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2151
+ */
2152
+ ORT_API2_STATUS(ModelMetadataGetCustomMetadataMapKeys, _In_ const OrtModelMetadata* model_metadata,
2153
+ _Inout_ OrtAllocator* allocator, _Outptr_result_buffer_maybenull_(*num_keys) char*** keys, _Out_ int64_t* num_keys);
2154
+
2155
+ /// @}
2156
+ /// \name OrtSessionOptions
2157
+ /// @{
2158
+
2159
+ /**
2160
+ *
2161
+ * Override symbolic dimensions (by specific name strings) with actual values
2162
+ * if known at session initialization time to enable optimizations that can
2163
+ * take advantage of fixed values (such as memory planning, etc)
2164
+ *
2165
+ */
2166
+ ORT_API2_STATUS(AddFreeDimensionOverrideByName,
2167
+ _Inout_ OrtSessionOptions* options, _In_ const char* dim_name,
2168
+ _In_ int64_t dim_value);
2169
+
2170
+ /// @}
2171
+ /// \name Misc
2172
+ /// @{
2173
+
2174
+ /** \brief Get the names of all available providers
2175
+ *
2176
+ * \note The providers in the list are not guaranteed to be usable. They may fail to load due to missing system dependencies.
2177
+ * For example, if the CUDA/cuDNN libraries are not installed, the CUDA provider will report an error when it is added to the session options.
2178
+ *
2179
+ * \param[out] out_ptr Set to a pointer to an array of null terminated strings of the available providers. The entries and the
2180
+ * array itself must be freed using OrtApi::ReleaseAvailableProviders
2181
+ * \param[out] provider_length Set to the number of entries in the `out_ptr` array
2182
+ *
2183
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2184
+ */
2185
+ ORT_API2_STATUS(GetAvailableProviders, _Outptr_ char*** out_ptr, _Out_ int* provider_length);
2186
+
2187
+ /** \brief Release data from OrtApi::GetAvailableProviders. This API will never fail
2188
+ * so you can rely on it in a noexcept code.
2189
+ *
2190
+ * \param[in] ptr The `out_ptr` result from OrtApi::GetAvailableProviders.
2191
+ * \param[in] providers_length The `provider_length` result from OrtApi::GetAvailableProviders
2192
+ *
2193
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2194
+ */
2195
+ ORT_API2_STATUS(ReleaseAvailableProviders, _In_ char** ptr,
2196
+ _In_ int providers_length);
2197
+
2198
+ /// @}
2199
+ /// \name OrtValue
2200
+ /// @{
2201
+
2202
+ /** \brief Get the length of a single string in a string tensor
2203
+ *
2204
+ * \param[in] value A string tensor
2205
+ * \param[in] index Index of the string in the tensor
2206
+ * \param[out] out Set to number of bytes of the string element
2207
+ *
2208
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2209
+ */
2210
+ ORT_API2_STATUS(GetStringTensorElementLength, _In_ const OrtValue* value, size_t index, _Out_ size_t* out);
2211
+
2212
+ /** \brief Get a single string from a string tensor
2213
+ *
2214
+ * \param[in] value A string tensor
2215
+ * \param[in] s_len Number of bytes in the `s` buffer. Must match the value returned by OrtApi::GetStringTensorElementLength.
2216
+ * \param[in] index Index of the string in the tensor
2217
+ * \param[out] s The string element contents in UTF-8 encoding. The string is NOT null-terminated.
2218
+ *
2219
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2220
+ */
2221
+ ORT_API2_STATUS(GetStringTensorElement, _In_ const OrtValue* value, size_t s_len, size_t index, _Out_writes_bytes_all_(s_len) void* s);
2222
+
2223
+ /** \brief Set a single string in a string tensor
2224
+ *
2225
+ * \param[in] value A string tensor
2226
+ * \param[in] s A null terminated UTF-8 encoded string
2227
+ * \param[in] index Index of the string in the tensor to set
2228
+ *
2229
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2230
+ */
2231
+ ORT_API2_STATUS(FillStringTensorElement, _Inout_ OrtValue* value, _In_ const char* s, size_t index);
2232
+
2233
+ /// @}
2234
+ /// \name OrtSessionOptions
2235
+ /// @{
2236
+
2237
+ /** \brief Set a session configuration entry as a pair of strings
2238
+ *
2239
+ * If a configuration with same key exists, this will overwrite the configuration with the given config_value.
2240
+ *
2241
+ * The config_key and the format of config_value are defined in onnxruntime_session_options_config_keys.h
2242
+ *
2243
+ * \param[in] options
2244
+ * \param[in] config_key A null terminated string representation of the config key
2245
+ * \param[in] config_value A null terminated string representation of the config value
2246
+ *
2247
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2248
+ */
2249
+ ORT_API2_STATUS(AddSessionConfigEntry, _Inout_ OrtSessionOptions* options,
2250
+ _In_z_ const char* config_key, _In_z_ const char* config_value);
2251
+
2252
+ /// @}
2253
+ /// \name OrtAllocator
2254
+ /// @{
2255
+
2256
+ /** \brief Create an allocator for an ::OrtSession following an ::OrtMemoryInfo
2257
+ *
2258
+ * \param[in] session
2259
+ * \param[in] mem_info valid ::OrtMemoryInfo instance
2260
+ * \param[out] out Newly created ::OrtAllocator. Must be freed with OrtApi::ReleaseAllocator
2261
+ *
2262
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2263
+ */
2264
+ ORT_API2_STATUS(CreateAllocator, _In_ const OrtSession* session, _In_ const OrtMemoryInfo* mem_info,
2265
+ _Outptr_ OrtAllocator** out);
2266
+
2267
+ /** \brief Release an ::OrtAllocator obtained from OrtApi::CreateAllocator
2268
+ */
2269
+ ORT_CLASS_RELEASE(Allocator);
2270
+
2271
+ /// @}
2272
+ /// \name OrtSession
2273
+ /// @{
2274
+
2275
+ /** \brief Run a model using Io Bindings for the inputs & outputs
2276
+ *
2277
+ * \see OrtApi::Run
2278
+ *
2279
+ * \param[in] session
2280
+ * \param[in] run_options
2281
+ * \param[in] binding_ptr
2282
+ *
2283
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2284
+ */
2285
+ ORT_API2_STATUS(RunWithBinding, _Inout_ OrtSession* session, _In_ const OrtRunOptions* run_options, _In_ const OrtIoBinding* binding_ptr);
2286
+
2287
+ /** \brief Create an ::OrtIoBinding instance
2288
+ *
2289
+ * An IoBinding object allows one to bind pre-allocated ::OrtValue%s to input names.
2290
+ * Thus if you want to use a raw on device buffer as input or output you can avoid
2291
+ * extra copy during runtime.
2292
+ *
2293
+ * \param[in] session
2294
+ * \param[out] out Newly created ::OrtIoBinding. Must be freed with OrtApi::ReleaseIoBinding
2295
+ *
2296
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2297
+ */
2298
+ ORT_API2_STATUS(CreateIoBinding, _Inout_ OrtSession* session, _Outptr_ OrtIoBinding** out);
2299
+
2300
+ /// @}
2301
+ /// \name OrtIoBinding
2302
+ /// @{
2303
+
2304
+ /** \brief Release an ::OrtIoBinding obtained from OrtApi::CreateIoBinding
2305
+ */
2306
+ ORT_CLASS_RELEASE(IoBinding);
2307
+
2308
+ /** \brief Bind an ::OrtValue to an ::OrtIoBinding input
2309
+ *
2310
+ * When using OrtApi::RunWithBinding this value is used for the named input
2311
+ *
2312
+ * \param[in] binding_ptr
2313
+ * \param[in] name Name for the model input
2314
+ * \param[in] val_ptr ::OrtValue of Tensor type.
2315
+ *
2316
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2317
+ */
2318
+ ORT_API2_STATUS(BindInput, _Inout_ OrtIoBinding* binding_ptr, _In_ const char* name, _In_ const OrtValue* val_ptr);
2319
+
2320
+ /** \brief Bind an ::OrtValue to an ::OrtIoBinding output
2321
+ *
2322
+ * When using OrtApi::RunWithBinding this value is used for the named output
2323
+ *
2324
+ * \param[in] binding_ptr
2325
+ * \param[in] name Null terminated string of the model output name
2326
+ * \param[in] val_ptr ::OrtValue of Tensor type.
2327
+ *
2328
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2329
+ */
2330
+ ORT_API2_STATUS(BindOutput, _Inout_ OrtIoBinding* binding_ptr, _In_ const char* name, _In_ const OrtValue* val_ptr);
2331
+
2332
+ /** \brief Bind an ::OrtIoBinding output to a device
2333
+ *
2334
+ * Binds the ::OrtValue to a device which is specified by ::OrtMemoryInfo.
2335
+ * You can either create an instance of ::OrtMemoryInfo with a device id or obtain one from the allocator that you have created/are using
2336
+ * This is useful when one or more outputs have dynamic shapes and, it is hard to pre-allocate and bind a chunk of
2337
+ * memory within ::OrtValue ahead of time.
2338
+ *
2339
+ * \see OrtApi::RunWithBinding
2340
+ *
2341
+ * \param[in] binding_ptr
2342
+ * \param[in] name Null terminated string of the device name
2343
+ * \param[in] mem_info_ptr
2344
+ *
2345
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2346
+ */
2347
+ ORT_API2_STATUS(BindOutputToDevice, _Inout_ OrtIoBinding* binding_ptr, _In_ const char* name, _In_ const OrtMemoryInfo* mem_info_ptr);
2348
+
2349
+ /** \brief Get the names of an ::OrtIoBinding's outputs
2350
+ *
2351
+ * Returns the names of the outputs in the order they were bound. This is useful after running the model
2352
+ * with bound outputs because the returned names are in order in which output ::OrtValue are returned. This is useful if
2353
+ * the order of outputs and their names is not known.
2354
+ *
2355
+ * \param[in] binding_ptr
2356
+ * \param[in] allocator Allocator used to allocate continuous buffers for output strings and lengths.
2357
+ * \param[out] buffer Returns an array of non-null terminated UTF-8 strings. The number of strings stored is returned in the count parameter.
2358
+ * This buffer is allocated using `allocator` and must be freed using it.
2359
+ * \param[out] lengths Returns an array of `count` lengths of the strings returned in `buffer`
2360
+ * This buffer is allocated using `allocator` and must be freed using it.
2361
+ * \param[out] count Number of strings returned. If `binding_ptr` has no bound outputs, zero is returned,
2362
+ * no memory allocation is performed and buffer and lengths are set to nullptr.
2363
+ *
2364
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2365
+ */
2366
+ ORT_API2_STATUS(GetBoundOutputNames, _In_ const OrtIoBinding* binding_ptr, _In_ OrtAllocator* allocator,
2367
+ _Out_ char** buffer, _Out_writes_all_(count) size_t** lengths, _Out_ size_t* count);
2368
+
2369
+ /** \brief Get the output ::OrtValue objects from an ::OrtIoBinding
2370
+ *
2371
+ * Returns an array of pointers to individually allocated ::OrtValue%s that contain results of a model execution with OrtApi::RunWithBinding
2372
+ * The array contains the same number of ::OrtValue%s and they are in the same order as they were bound with OrtApi::BindOutput
2373
+ * or OrtApi::BindOutputToDevice.
2374
+ *
2375
+ * The returned ::OrtValue%s must be released using OrtApi::ReleaseValue after they are no longer needed.
2376
+ * The array is allocated using the specified instance of the allocator and must be freed using the same allocator after
2377
+ * all the ::OrtValue%s contained therein are individually released.
2378
+ *
2379
+ * \param[in] binding_ptr
2380
+ * \param[in] allocator Allocator used to allocate output array
2381
+ * \param[out] output Set to the allocated array of allocated ::OrtValue outputs. Set to nullptr if there are 0 outputs.
2382
+ * \param[out] output_count Set to number of ::OrtValue%s returned
2383
+ *
2384
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2385
+ */
2386
+ ORT_API2_STATUS(GetBoundOutputValues, _In_ const OrtIoBinding* binding_ptr, _In_ OrtAllocator* allocator,
2387
+ _Out_writes_all_(output_count) OrtValue*** output, _Out_ size_t* output_count);
2388
+
2389
+ /** \brief Clears any previously set Inputs for an ::OrtIoBinding
2390
+ */
2391
+ void(ORT_API_CALL* ClearBoundInputs)(_Inout_ OrtIoBinding* binding_ptr) NO_EXCEPTION ORT_ALL_ARGS_NONNULL;
2392
+
2393
+ /** \brief Clears any previously set Outputs for an ::OrtIoBinding
2394
+ */
2395
+ void(ORT_API_CALL* ClearBoundOutputs)(_Inout_ OrtIoBinding* binding_ptr) NO_EXCEPTION ORT_ALL_ARGS_NONNULL;
2396
+
2397
+ /// @}
2398
+ /// \name OrtValue
2399
+ /// @{
2400
+
2401
+ /** \brief Direct memory access to a specified tensor element
2402
+ *
2403
+ * For example, given a tensor with shape of [3,224,224], a pointer to the element at location [2,150,128] can be retrieved
2404
+ *
2405
+ * This function only works for numeric type tensors (No strings, etc).
2406
+ * This is a no-copy method whose returned pointer is valid until the passed in ::OrtValue is free'd.
2407
+ *
2408
+ * \param[in] value
2409
+ * \param[in] location_values Pointer to an array of index values that specify an element's location relative to its shape
2410
+ * \param[in] location_values_count Number of elements in location_values. Must match the number of elements in the tensor's shape.
2411
+ * \param[out] out Set to a pointer to the element specified
2412
+ *
2413
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2414
+ */
2415
+ ORT_API2_STATUS(TensorAt, _Inout_ OrtValue* value, const int64_t* location_values, size_t location_values_count, _Outptr_ void** out);
2416
+
2417
+ /// @}
2418
+ /// \name OrtEnv
2419
+ /// @{
2420
+
2421
+ /** \brief Create an allocator and register it with the ::OrtEnv
2422
+ *
2423
+ * Enables sharing the allocator between multiple sessions that use the same env instance.
2424
+ * Lifetime of the created allocator will be valid for the duration of the environment.
2425
+ * Returns an error if an allocator with the same ::OrtMemoryInfo is already registered.
2426
+ *
2427
+ * See https://onnxruntime.ai/docs/get-started/with-c.html for details.
2428
+ *
2429
+ * \param[in] env ::OrtEnv instance
2430
+ * \param[in] mem_info
2431
+ * \param[in] arena_cfg Pass nullptr for defaults
2432
+ *
2433
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2434
+ */
2435
+ ORT_API2_STATUS(CreateAndRegisterAllocator, _Inout_ OrtEnv* env, _In_ const OrtMemoryInfo* mem_info,
2436
+ _In_ const OrtArenaCfg* arena_cfg);
2437
+
2438
+ /** \brief Set language projection
2439
+ *
2440
+ * Set the language projection for collecting telemetry data when Env is created.
2441
+ *
2442
+ * The default is ORT_PROJECTION_C, which means it will classify the language not in the list to C also.
2443
+ *
2444
+ * \param[in] ort_env
2445
+ * \param[in] projection
2446
+ *
2447
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2448
+ */
2449
+ ORT_API2_STATUS(SetLanguageProjection, _In_ const OrtEnv* ort_env, _In_ OrtLanguageProjection projection);
2450
+
2451
+ /// @}
2452
+ /// \name OrtSession
2453
+ /// @{
2454
+
2455
+ /** \brief Return the time that profiling was started
2456
+ *
2457
+ * \note The timer precision varies per platform. On Windows and MacOS, the precision will be ~100ns
2458
+ *
2459
+ * \param[in] session
2460
+ * \param[out] out nanoseconds of profiling's start time
2461
+ *
2462
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2463
+ */
2464
+ ORT_API2_STATUS(SessionGetProfilingStartTimeNs, _In_ const OrtSession* session, _Outptr_ uint64_t* out);
2465
+
2466
+ /// @}
2467
+ /// \name OrtThreadingOptions
2468
+ /// @{
2469
+
2470
+ /** \brief Set global intra-op thread count
2471
+ *
2472
+ * This configures the global thread pool options to be used in the call to OrtApi::CreateEnvWithGlobalThreadPools
2473
+ *
2474
+ * \param[in] tp_options
2475
+ * \param[in] intra_op_num_threads Number of threads, special values:<br>
2476
+ * 0 = Use default thread count<br>
2477
+ * 1 = The invoking thread will be used; no threads will be created in the thread pool.
2478
+ *
2479
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2480
+ */
2481
+ ORT_API2_STATUS(SetGlobalIntraOpNumThreads, _Inout_ OrtThreadingOptions* tp_options, int intra_op_num_threads);
2482
+
2483
+ /** \brief Set global inter-op thread count
2484
+ *
2485
+ * This configures the global thread pool options to be used in the call to OrtApi::CreateEnvWithGlobalThreadPools
2486
+ *
2487
+ * \param[in] tp_options
2488
+ * \param[in] inter_op_num_threads Number of threads, special values:<br>
2489
+ * 0 = Use default thread count<br>
2490
+ * 1 = The invoking thread will be used; no threads will be created in the thread pool.
2491
+ *
2492
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2493
+ */
2494
+ ORT_API2_STATUS(SetGlobalInterOpNumThreads, _Inout_ OrtThreadingOptions* tp_options, int inter_op_num_threads);
2495
+
2496
+ /** \brief Set global spin control options
2497
+ *
2498
+ * This will configure the global thread pool options to be used in the call to OrtApi::CreateEnvWithGlobalThreadPools.
2499
+ * Allow spinning of thread pools when their queues are empty. This will set the value for both
2500
+ * inter_op and intra_op threadpools.
2501
+ *
2502
+ * \param[in] tp_options
2503
+ * \param[in] allow_spinning Valid values are 0 or 1.<br>
2504
+ * 0 = It won't spin (recommended if CPU usage is high)<br>
2505
+ * 1 = Threadpool will spin to wait for queue to become non-empty
2506
+ *
2507
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2508
+ */
2509
+ ORT_API2_STATUS(SetGlobalSpinControl, _Inout_ OrtThreadingOptions* tp_options, int allow_spinning);
2510
+
2511
+ /// @}
2512
+ /// \name OrtSessionOptions
2513
+ /// @{
2514
+
2515
+ /** \brief Add a pre-allocated initializer to a session
2516
+ *
2517
+ * If a model contains an initializer with a name that is same as the name passed to this call,
2518
+ * ORT will use this initializer instance instead of deserializing one from the model file. This
2519
+ * is useful when you want to share the same initializer across sessions.
2520
+ *
2521
+ * \param[in] options
2522
+ * \param[in] name Null terminated string of the initializer name
2523
+ * \param[in] val ::OrtValue containing the initializer. Its lifetime and the underlying initializer buffer must be
2524
+ * managed by the user (created using the OrtApi::CreateTensorWithDataAsOrtValue) and it must outlive the session object
2525
+ * to which it is added.
2526
+ *
2527
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2528
+ */
2529
+ ORT_API2_STATUS(AddInitializer, _Inout_ OrtSessionOptions* options, _In_z_ const char* name,
2530
+ _In_ const OrtValue* val);
2531
+
2532
+ /// @}
2533
+ /// \name OrtEnv
2534
+ /// @{
2535
+
2536
+ /**
2537
+ * Create a custom environment with global threadpools and logger that will be shared across sessions.
2538
+ * Use this in conjunction with OrtApi::DisablePerSessionThreads or else the session will use
2539
+ * its own thread pools.
2540
+ *
2541
+ * \param[in] logging_function A pointer to a logging function.
2542
+ * \param[in] logger_param A pointer to arbitrary data passed as the ::OrtLoggingFunction `param` parameter to
2543
+ * `logging_function`.
2544
+ * \param[in] log_severity_level The log severity level.
2545
+ * \param[in] logid The log identifier.
2546
+ * \param[in] tp_options
2547
+ * \param[out] out Newly created OrtEnv. Must be freed with OrtApi::ReleaseEnv
2548
+ *
2549
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2550
+ */
2551
+ ORT_API2_STATUS(CreateEnvWithCustomLoggerAndGlobalThreadPools, OrtLoggingFunction logging_function, _In_opt_ void* logger_param, OrtLoggingLevel log_severity_level,
2552
+ _In_ const char* logid, _In_ const struct OrtThreadingOptions* tp_options, _Outptr_ OrtEnv** out);
2553
+
2554
+ /// @}
2555
+ /// \name OrtSessionOptions
2556
+ /// @{
2557
+
2558
+ /** \brief Append CUDA provider to session options
2559
+ *
2560
+ * If CUDA is not available (due to a non CUDA enabled build, or if CUDA is not installed on the system), this function will return failure.
2561
+ *
2562
+ * \param[in] options
2563
+ * \param[in] cuda_options
2564
+ *
2565
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2566
+ */
2567
+ ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_CUDA,
2568
+ _In_ OrtSessionOptions* options, _In_ const OrtCUDAProviderOptions* cuda_options);
2569
+
2570
+ /** \brief Append ROCM execution provider to the session options
2571
+ *
2572
+ * If ROCM is not available (due to a non ROCM enabled build, or if ROCM is not installed on the system), this function will return failure.
2573
+ *
2574
+ * \param[in] options
2575
+ * \param[in] rocm_options
2576
+ *
2577
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2578
+ */
2579
+ ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_ROCM,
2580
+ _In_ OrtSessionOptions* options, _In_ const OrtROCMProviderOptions* rocm_options);
2581
+
2582
+ /** \brief Append OpenVINO execution provider to the session options
2583
+ *
2584
+ * If OpenVINO is not available (due to a non OpenVINO enabled build, or if OpenVINO is not installed on the system), this function will fail.
2585
+ *
2586
+ * \param[in] options
2587
+ * \param[in] provider_options
2588
+ *
2589
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2590
+ */
2591
+ ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_OpenVINO,
2592
+ _In_ OrtSessionOptions* options, _In_ const OrtOpenVINOProviderOptions* provider_options);
2593
+
2594
+ /// @}
2595
+ /// \name OrtThreadingOptions
2596
+ /// @{
2597
+
2598
+ /** \brief Set threading flush-to-zero and denormal-as-zero
2599
+ *
2600
+ * Sets global thread pool options to be used in the call to OrtApi::CreateEnvWithGlobalThreadPools.
2601
+ * Flush-to-zero and denormal-as-zero are applied to threads in both intra and inter global thread pool.
2602
+ * \note This option is not needed if the models used have no denormals. Having no denormals is recommended as this option may hurt model accuracy.
2603
+ *
2604
+ * \param[in] tp_options
2605
+ *
2606
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2607
+ */
2608
+ ORT_API2_STATUS(SetGlobalDenormalAsZero, _Inout_ OrtThreadingOptions* tp_options);
2609
+
2610
+ /// @}
2611
+ /// \name OrtArenaCfg
2612
+ /// @{
2613
+
2614
+ /** \deprecated Use OrtApi::CreateArenaCfgV2
2615
+ *
2616
+ * This will create the configuration of an arena that can eventually be used to define an arena based allocator's behavior
2617
+ *
2618
+ * \param[in] max_mem Use 0 to allow ORT to choose the default
2619
+ * \param[in] arena_extend_strategy Use -1 to allow ORT to choose the default, 0 = kNextPowerOfTwo, 1 = kSameAsRequested
2620
+ * \param[in] initial_chunk_size_bytes Use -1 to allow ORT to choose the default
2621
+ * \param[in] max_dead_bytes_per_chunk Use -1 to allow ORT to choose the default
2622
+ * \param[in] out A pointer to an OrtArenaCfg instance
2623
+ *
2624
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2625
+ */
2626
+ ORT_API2_STATUS(CreateArenaCfg, _In_ size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes,
2627
+ int max_dead_bytes_per_chunk, _Outptr_ OrtArenaCfg** out);
2628
+
2629
+ ORT_CLASS_RELEASE(ArenaCfg);
2630
+
2631
+ /// @}
2632
+ /// \name OrtModelMetadata
2633
+ /// @{
2634
+
2635
+ /**
2636
+ * Use this to obtain the description of the graph present in the model
2637
+ * (doc_string field of the GraphProto message within the ModelProto message).
2638
+ * If it doesn't exist, an empty string will be returned.
2639
+ *
2640
+ * \param[in] model_metadata An instance of ::OrtModelMetadata
2641
+ * \param[in] allocator Allocator used to allocate the string that will be returned back
2642
+ * \param[out] value Set to a null terminated string allocated using `allocator`. The caller is responsible for freeing it using `allocator`
2643
+ *
2644
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2645
+ */
2646
+ ORT_API2_STATUS(ModelMetadataGetGraphDescription, _In_ const OrtModelMetadata* model_metadata,
2647
+ _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
2648
+
2649
+ /// @}
2650
+ /// \name OrtSessionOptions
2651
+ /// @{
2652
+
2653
+ /** \brief Append TensorRT provider to session options
2654
+ *
2655
+ * If TensorRT is not available (due to a non TensorRT enabled build, or if TensorRT is not installed on the system), this function will return failure.
2656
+ *
2657
+ * \param[in] options
2658
+ * \param[in] tensorrt_options
2659
+ *
2660
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2661
+ */
2662
+ ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_TensorRT,
2663
+ _In_ OrtSessionOptions* options, _In_ const OrtTensorRTProviderOptions* tensorrt_options);
2664
+
2665
+ /// @}
2666
+ /// \name Misc
2667
+ /// @{
2668
+
2669
+ /** \brief Set current GPU device ID
2670
+ *
2671
+ * Set the current device id of the GPU execution provider (CUDA/tensorrt/rocm). The device id should be less
2672
+ * than the total number of devices available. This is only useful when multiple-GPUs are installed and it is
2673
+ * required to restrict execution to a single GPU.
2674
+ *
2675
+ * \param[in] device_id
2676
+ *
2677
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2678
+ */
2679
+ ORT_API2_STATUS(SetCurrentGpuDeviceId, _In_ int device_id);
2680
+
2681
+ /** \brief Get current GPU device ID
2682
+ *
2683
+ * Get the current device id of the GPU execution provider (CUDA/tensorrt/rocm).
2684
+ *
2685
+ * \see OrtApi::SetCurrentGpuDeviceId
2686
+ *
2687
+ * \param[out] device_id
2688
+ *
2689
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2690
+ */
2691
+ ORT_API2_STATUS(GetCurrentGpuDeviceId, _In_ int* device_id);
2692
+
2693
+ /// @}
2694
+ /// \name OrtKernelInfo
2695
+ /// Custom operator APIs.
2696
+ /// @{
2697
+
2698
+ /** \brief Fetch an array of int64_t values stored as an attribute in the graph node
2699
+ *
2700
+ *
2701
+ * If `out` is nullptr, the value of `size` is set to the true size of the attribute
2702
+ * array's size, and a success status is returned.
2703
+ *
2704
+ * If the `size` parameter is greater than or equal to the actual attribute array's size,
2705
+ * the value of `size` is set to the true size of the attribute array's size,
2706
+ * the provided memory is filled with the attribute's contents,
2707
+ * and a success status is returned.
2708
+ *
2709
+ * If the `size` parameter is less than the actual attribute array's size and `out`
2710
+ * is not nullptr, the value of `size` is set to the true size of the attribute array's size
2711
+ * and a failure status is returned.)
2712
+ *
2713
+ * \param[in] info instance
2714
+ * \param[in] name name of the attribute to be parsed
2715
+ * \param[out] out pointer to memory where the attribute's contents are to be stored
2716
+ * \param[in, out] size actual size of attribute array
2717
+ *
2718
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2719
+ */
2720
+ ORT_API2_STATUS(KernelInfoGetAttributeArray_float, _In_ const OrtKernelInfo* info, _In_ const char* name,
2721
+ _Out_ float* out, _Inout_ size_t* size);
2722
+
2723
+ /** \brief Fetch an array of int64_t values stored as an attribute in the graph node
2724
+ *
2725
+ * If `out` is nullptr, the value of `size` is set to the true size of the attribute
2726
+ * array's size, and a success status is returned.
2727
+ *
2728
+ * If the `size` parameter is greater than or equal to the actual attribute array's size,
2729
+ * the value of `size` is set to the true size of the attribute array's size,
2730
+ * the provided memory is filled with the attribute's contents,
2731
+ * and a success status is returned.
2732
+ *
2733
+ * If the `size` parameter is less than the actual attribute array's size and `out`
2734
+ * is not nullptr, the value of `size` is set to the true size of the attribute array's size
2735
+ * and a failure status is returned.)
2736
+ *
2737
+ * \param[in] info instance
2738
+ * \param[in] name name of the attribute to be parsed
2739
+ * \param[out] out pointer to memory where the attribute's contents are to be stored
2740
+ * \param[in, out] size actual size of attribute array
2741
+ *
2742
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2743
+ */
2744
+ ORT_API2_STATUS(KernelInfoGetAttributeArray_int64, _In_ const OrtKernelInfo* info, _In_ const char* name,
2745
+ _Out_ int64_t* out, _Inout_ size_t* size);
2746
+
2747
+ /// @}
2748
+ /// \name OrtArenaCfg
2749
+ /// @{
2750
+
2751
+ /** \brief Create an ::OrtArenaCfg
2752
+ *
2753
+ * Create the configuration of an arena that can eventually be used to define an arena based allocator's behavior.
2754
+ *
2755
+ * Supported keys are (See https://onnxruntime.ai/docs/get-started/with-c.html for details on what the
2756
+ * following parameters mean and how to choose these values.):
2757
+ * "max_mem": Maximum memory that can be allocated by the arena based allocator.
2758
+ * Use 0 for ORT to pick the best value. Default is 0.
2759
+ * "arena_extend_strategy": 0 = kNextPowerOfTwo, 1 = kSameAsRequested.
2760
+ * Use -1 to allow ORT to choose the default.
2761
+ * "initial_chunk_size_bytes": (Possible) Size of the first allocation in the arena.
2762
+ * Only relevant if arena strategy is `kNextPowerOfTwo`. Use -1 to allow ORT to choose the default.
2763
+ * Ultimately, the first allocation size is determined by the allocation memory request.
2764
+ * "max_dead_bytes_per_chunk": Threshold of unused memory in an allocated chunk of arena memory after
2765
+ * crossing which the current chunk is chunked into 2.
2766
+ * "initial_growth_chunk_size_bytes": (Possible) Size of the second allocation in the arena.
2767
+ * Only relevant if arena strategy is `kNextPowerOfTwo`. Use -1 to allow ORT to choose the default.
2768
+ * "max_power_of_two_extend_bytes": The maximum enxtend size if arena strategy is `kNextPowerOfTwo`.
2769
+ * It is not an allocation limit, it is only a limit for extention when requested byte is less than the limit.
2770
+ * When requested bytes is more than the limit, allocator will still return as requested.
2771
+ * Use -1 to allow ORT to choose the default 1GB for max_power_of_two_extend_bytes.
2772
+ * Ultimately, the allocation size is determined by the allocation memory request.
2773
+ * Further allocation sizes are governed by the arena extend strategy.
2774
+ *
2775
+ * \param[in] arena_config_keys Keys to configure the arena
2776
+ * \param[in] arena_config_values Values to configure the arena
2777
+ * \param[in] num_keys Number of keys in `arena_config_keys` and `arena_config_values`
2778
+ * \param[out] out Newly created ::OrtArenaCfg. Must be freed with OrtApi::ReleaseArenaCfg
2779
+ *
2780
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2781
+ */
2782
+ ORT_API2_STATUS(CreateArenaCfgV2, _In_reads_(num_keys) const char* const* arena_config_keys,
2783
+ _In_reads_(num_keys) const size_t* arena_config_values, _In_ size_t num_keys,
2784
+ _Outptr_ OrtArenaCfg** out);
2785
+
2786
+ /// @}
2787
+ /// \name OrtRunOptions
2788
+ /// @{
2789
+
2790
+ /** \brief Set a single run configuration entry as a pair of strings
2791
+ *
2792
+ * If a configuration with same key exists, this will overwrite the configuration with the given config_value
2793
+ *
2794
+ * The config_key and the format of config_value are defined in onnxruntime_run_options_config_keys.h
2795
+ *
2796
+ * \param[in] options
2797
+ * \param[in] config_key A null terminated string representation of the config key
2798
+ * \param[in] config_value A null terminated string representation of the config value
2799
+ *
2800
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2801
+ */
2802
+ ORT_API2_STATUS(AddRunConfigEntry, _Inout_ OrtRunOptions* options,
2803
+ _In_z_ const char* config_key, _In_z_ const char* config_value);
2804
+
2805
+ /// @}
2806
+ /// \name OrtPrepackedWeightsContainer
2807
+ /// @{
2808
+
2809
+ /** \brief Create an ::OrtPrepackedWeightsContainer
2810
+ *
2811
+ * This container will hold pre-packed buffers of shared initializers for sharing between sessions
2812
+ * (i.e.) if there are shared initializers that can be shared between sessions, the pre-packed buffers
2813
+ * of these (if any) may possibly be shared to provide memory footprint savings. Pass this container
2814
+ * to sessions that you would like to share pre-packed buffers of shared initializers at session
2815
+ * creation time.
2816
+ *
2817
+ * \param[out] out Newly created ::OrtPrepackedWeightsContainer. Must be freed with OrtApi::ReleasePrepackedWeightsContainer
2818
+ *
2819
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2820
+ */
2821
+ ORT_API2_STATUS(CreatePrepackedWeightsContainer, _Outptr_ OrtPrepackedWeightsContainer** out);
2822
+
2823
+ /** \brief Release OrtPrepackedWeightsContainer instance
2824
+ *
2825
+ * \note instance must not be released until the sessions using it are released
2826
+ */
2827
+ ORT_CLASS_RELEASE(PrepackedWeightsContainer);
2828
+
2829
+ /// @}
2830
+ /// \name OrtSession
2831
+ /// @{
2832
+
2833
+ /** \brief Create session with prepacked weights container
2834
+ *
2835
+ * Same functionality offered by OrtApi::CreateSession except that a container that contains
2836
+ * pre-packed weights' buffers is written into/read from by the created session.
2837
+ * This is useful when used in conjunction with OrtApi::AddInitializer which injects
2838
+ * shared initializer info into sessions. Wherever possible, the pre-packed versions of these
2839
+ * shared initializers are cached in this container so that multiple sessions can just re-use
2840
+ * these instead of duplicating these in memory.
2841
+ *
2842
+ * \param[in] env OrtEnv instance instance
2843
+ * \param[in] model_path Null terminated string of the path (wchar on Windows, char otherwise)
2844
+ * \param[in] options
2845
+ * \param[in] prepacked_weights_container
2846
+ * \param[out] out Newly created ::OrtSession. Must be freed with OrtApi::ReleaseSession
2847
+ *
2848
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2849
+ */
2850
+ ORT_API2_STATUS(CreateSessionWithPrepackedWeightsContainer, _In_ const OrtEnv* env, _In_ const ORTCHAR_T* model_path,
2851
+ _In_ const OrtSessionOptions* options, _Inout_ OrtPrepackedWeightsContainer* prepacked_weights_container,
2852
+ _Outptr_ OrtSession** out);
2853
+
2854
+ /** \brief Create session from memory with prepacked weights container
2855
+ *
2856
+ * Same functionality offered by OrtApi::CreateSessionFromArray except that a container that contains
2857
+ * pre-packed weights' buffers is written into/read from by the created session.
2858
+ * This is useful when used in conjunction with OrtApi::AddInitializer which injects
2859
+ * shared initializer info into sessions. Wherever possible, the pre-packed versions of these
2860
+ * shared initializers are cached in this container so that multiple sessions can just re-use
2861
+ * these instead of duplicating these in memory.
2862
+ *
2863
+ * \param[in] env
2864
+ * \param[in] model_data Array of bytes holding the model
2865
+ * \param[in] model_data_length Number of bytes in `model_data_model`
2866
+ * \param[in] options
2867
+ * \param[in] prepacked_weights_container
2868
+ * \param[out] out Newly created ::OrtSession. Must be freed with OrtApi::ReleaseSession
2869
+ *
2870
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2871
+ */
2872
+ ORT_API2_STATUS(CreateSessionFromArrayWithPrepackedWeightsContainer, _In_ const OrtEnv* env,
2873
+ _In_ const void* model_data, size_t model_data_length,
2874
+ _In_ const OrtSessionOptions* options, _Inout_ OrtPrepackedWeightsContainer* prepacked_weights_container,
2875
+ _Outptr_ OrtSession** out);
2876
+
2877
+ /// @}
2878
+ /// \name OrtSessionOptions
2879
+ /// @{
2880
+
2881
+ /** \brief Append TensorRT execution provider to the session options
2882
+ *
2883
+ * If TensorRT is not available (due to a non TensorRT enabled build), this function will return failure.
2884
+ *
2885
+ * This is slightly different from OrtApi::SessionOptionsAppendExecutionProvider_TensorRT, it takes an
2886
+ * ::OrtTensorRTProviderOptions which is publicly defined. This takes an opaque ::OrtTensorRTProviderOptionsV2
2887
+ * which must be created with OrtApi::CreateTensorRTProviderOptions.
2888
+ *
2889
+ * For OrtApi::SessionOptionsAppendExecutionProvider_TensorRT, the user needs to instantiate ::OrtTensorRTProviderOptions
2890
+ * as well as allocate/release buffers for some members of ::OrtTensorRTProviderOptions.
2891
+ * Here, OrtApi::CreateTensorRTProviderOptions and Ortapi::ReleaseTensorRTProviderOptions will do the memory management for you.
2892
+ *
2893
+ * \param[in] options
2894
+ * \param[in] tensorrt_options
2895
+ *
2896
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2897
+ */
2898
+ ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_TensorRT_V2,
2899
+ _In_ OrtSessionOptions* options, _In_ const OrtTensorRTProviderOptionsV2* tensorrt_options);
2900
+
2901
+ /// @}
2902
+ /// \name OrtTensorRTProviderOptionsV2
2903
+ /// @{
2904
+
2905
+ /** \brief Create an OrtTensorRTProviderOptionsV2
2906
+ *
2907
+ * \param[out] out Newly created ::OrtTensorRTProviderOptionsV2. Must be released with OrtApi::ReleaseTensorRTProviderOptions
2908
+ *
2909
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2910
+ */
2911
+ ORT_API2_STATUS(CreateTensorRTProviderOptions, _Outptr_ OrtTensorRTProviderOptionsV2** out);
2912
+
2913
+ /** \brief Set options in a TensorRT Execution Provider.
2914
+ *
2915
+ * Please refer to https://onnxruntime.ai/docs/execution-providers/TensorRT-ExecutionProvider.html#cc
2916
+ * to know the available keys and values. Key should be in null terminated string format of the member of ::OrtTensorRTProviderOptionsV2
2917
+ * and value should be its related range.
2918
+ *
2919
+ * For example, key="trt_max_workspace_size" and value="2147483648"
2920
+ *
2921
+ * \param[in] tensorrt_options
2922
+ * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys
2923
+ * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values
2924
+ * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays
2925
+ *
2926
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2927
+ */
2928
+ ORT_API2_STATUS(UpdateTensorRTProviderOptions, _Inout_ OrtTensorRTProviderOptionsV2* tensorrt_options,
2929
+ _In_reads_(num_keys) const char* const* provider_options_keys,
2930
+ _In_reads_(num_keys) const char* const* provider_options_values,
2931
+ _In_ size_t num_keys);
2932
+
2933
+ /** \brief Get serialized TensorRT provider options string.
2934
+ *
2935
+ * For example, "trt_max_workspace_size=2147483648;trt_max_partition_iterations=10;trt_int8_enable=1;......"
2936
+ *
2937
+ * \param tensorrt_options - OrtTensorRTProviderOptionsV2 instance
2938
+ * \param allocator - a ptr to an instance of OrtAllocator obtained with OrtApi::CreateAllocator or OrtApi::GetAllocatorWithDefaultOptions
2939
+ * the specified allocator will be used to allocate continuous buffers for output strings and lengths.
2940
+ * \param ptr - is a UTF-8 null terminated string allocated using 'allocator'. The caller is responsible for using the same allocator to free it.
2941
+ *
2942
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2943
+ */
2944
+ ORT_API2_STATUS(GetTensorRTProviderOptionsAsString, _In_ const OrtTensorRTProviderOptionsV2* tensorrt_options, _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr);
2945
+
2946
+ /** \brief Release an ::OrtTensorRTProviderOptionsV2
2947
+ *
2948
+ * \note This is an exception in the naming convention of other Release* functions, as the name of the method does not have the V2 suffix, but the type does
2949
+ */
2950
+ void(ORT_API_CALL* ReleaseTensorRTProviderOptions)(_Frees_ptr_opt_ OrtTensorRTProviderOptionsV2* input);
2951
+
2952
+ /// @}
2953
+ /// \name OrtSessionOptions
2954
+ /// @{
2955
+
2956
+ /** \brief Enable custom operators
2957
+ *
2958
+ * See onnxruntime-extensions: https://github.com/microsoft/onnxruntime-extensions.git
2959
+ *
2960
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2961
+ */
2962
+ ORT_API2_STATUS(EnableOrtCustomOps, _Inout_ OrtSessionOptions* options);
2963
+
2964
+ /// @}
2965
+ /// \name OrtAllocator
2966
+ /// @{
2967
+
2968
+ /** \brief Register a custom allocator
2969
+ *
2970
+ * Enables sharing between multiple sessions that use the same env instance.
2971
+ * Returns an error if an allocator with the same ::OrtMemoryInfo is already registered.
2972
+ *
2973
+ * The behavior of this is exactly the same as OrtApi::CreateAndRegisterAllocator except
2974
+ * instead of ORT creating an allocator based on provided info, in this case
2975
+ * ORT uses the user-provided custom allocator.
2976
+ * See https://onnxruntime.ai/docs/get-started/with-c.html for details.
2977
+ *
2978
+ * \param[in] env
2979
+ * \param[in] allocator User provided allocator
2980
+ *
2981
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2982
+ */
2983
+ ORT_API2_STATUS(RegisterAllocator, _Inout_ OrtEnv* env, _In_ OrtAllocator* allocator);
2984
+
2985
+ /** \brief Unregister a custom allocator
2986
+ *
2987
+ * It is an error if you provide an ::OrtMemoryInfo not corresponding to any
2988
+ * registered allocators for sharing.
2989
+ *
2990
+ * \param[in] env
2991
+ * \param[in] mem_info
2992
+ *
2993
+ * \snippet{doc} snippets.dox OrtStatus Return Value
2994
+ */
2995
+ ORT_API2_STATUS(UnregisterAllocator, _Inout_ OrtEnv* env,
2996
+ _In_ const OrtMemoryInfo* mem_info);
2997
+
2998
+ /// @}
2999
+ /// \name OrtValue
3000
+ /// @{
3001
+
3002
+ /** \brief Sets *out to 1 iff an ::OrtValue is a SparseTensor, and 0 otherwise
3003
+ *
3004
+ * \param[in] value existing ::OrtValue
3005
+ * \param[out] out unless an error occurs, contains 1 iff the value contains an instance
3006
+ * of sparse tensor or 0 otherwise.
3007
+ *
3008
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3009
+ */
3010
+ ORT_API2_STATUS(IsSparseTensor, _In_ const OrtValue* value, _Out_ int* out);
3011
+
3012
+ /** \brief Create an ::OrtValue with a sparse tensor that is empty.
3013
+ *
3014
+ * Use FillSparseTensor<Format>() functions to populate sparse tensor with non-zero values and
3015
+ * format specific indices data.
3016
+ * Use ReleaseValue to destroy the sparse tensor, this will also release the buffer inside the output value
3017
+ * if any was allocated.
3018
+ * \param[in,out] allocator allocator to use when performing an allocation. Allocation will be performed
3019
+ * by FillSparseTensor<Format>() APIs. The lifespan of the allocator instance must eclipse the lifespan
3020
+ * this sparse tensor instance as the same allocator will be used to free memory.
3021
+ * \param[in] dense_shape shape of the original dense tensor
3022
+ * \param[in] dense_shape_len number of shape dimensions being passed
3023
+ * \param[in] type must be one of TENSOR_ELEMENT_DATA_TYPE_xxxx
3024
+ * \param[out] out Should be freed by calling ReleaseValue
3025
+ *
3026
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3027
+ */
3028
+ ORT_API2_STATUS(CreateSparseTensorAsOrtValue, _Inout_ OrtAllocator* allocator, _In_ const int64_t* dense_shape,
3029
+ size_t dense_shape_len, ONNXTensorElementDataType type, _Outptr_ OrtValue** out);
3030
+
3031
+ /**
3032
+ * This fills populates an empty tensor that was created using OrtApi::CreateSparseTensorAsOrtValue.
3033
+ * This will allocate required memory and copy the supplied NNZ values and COO indices into that memory allocation.
3034
+ * Memory allocation is performed using the allocator that was specified with OrtApi::CreateSparseTensorAsOrtValue.
3035
+ *
3036
+ * \param[in,out] ort_value ::OrtValue to populate with data
3037
+ * \param[in] data_mem_info serves to identify the location of the data to be copied. If the allocator specified
3038
+ * at the creation time has memory info that is not the same as mem_info argument to this function a X-device copy will be performed.
3039
+ * String data is assumed to be on CPU and will only be copied into a CPU allocated buffer.
3040
+ * \param[in] values_shape pointer to values shape array
3041
+ * \param[in] values_shape_len length of the values_shape
3042
+ * \param[in] values pointer to an array of values. For strings, pass const char**.
3043
+ * \param[in] indices_data pointer to a location of COO indices
3044
+ * \param[in] indices_num number of COO indices
3045
+ *
3046
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3047
+ */
3048
+ ORT_API2_STATUS(FillSparseTensorCoo, _Inout_ OrtValue* ort_value, _In_ const OrtMemoryInfo* data_mem_info,
3049
+ _In_ const int64_t* values_shape, size_t values_shape_len, _In_ const void* values,
3050
+ _In_ const int64_t* indices_data, size_t indices_num);
3051
+
3052
+ /**
3053
+ * This fills populates an empty tensor that was created using OrtApi::CreateSparseTensorAsOrtValue.
3054
+ * This will allocate required memory and copy the supplied NNZ values and CSR indices into that memory allocation.
3055
+ * Memory allocation is performed using the allocator that was specified with OrtApi::CreateSparseTensorAsOrtValue.
3056
+ *
3057
+ * \param[in,out] ort_value ::OrtValue to populate with data
3058
+ * \param[in] data_mem_info serves to identify the location of the data to be copied. If the allocator specified
3059
+ * at the creation time has memory info that is not the same as mem_info argument to this function a X-device copy will be performed.
3060
+ * String data is assumed to be on CPU and will only be copied into a CPU allocated buffer.
3061
+ * \param[in] values_shape pointer to values shape array
3062
+ * \param[in] values_shape_len length of the values_shape
3063
+ * \param[in] values - pointer to an array of values. For strings, pass const char**.
3064
+ * \param[in] inner_indices_data pointer to a location of CSR inner indices
3065
+ * \param[in] inner_indices_num number of CSR inner indices
3066
+ * \param[in] outer_indices_data pointer to a location of CSR outer indices
3067
+ * \param[in] outer_indices_num number of CSR outer indices
3068
+ *
3069
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3070
+ */
3071
+ ORT_API2_STATUS(FillSparseTensorCsr, _Inout_ OrtValue* ort_value, _In_ const OrtMemoryInfo* data_mem_info,
3072
+ _In_ const int64_t* values_shape, size_t values_shape_len, _In_ const void* values,
3073
+ _In_ const int64_t* inner_indices_data, size_t inner_indices_num,
3074
+ _In_ const int64_t* outer_indices_data, size_t outer_indices_num);
3075
+
3076
+ /**
3077
+ * This fills populates an empty tensor that was created using OrtApi::CreateSparseTensorAsOrtValue.
3078
+ * This will allocate required memory and copy the supplied NNZ values and BlockSparse indices into that memory allocation.
3079
+ * Memory allocation is performed using the allocator that was specified with OrtApi::CreateSparseTensorAsOrtValue.
3080
+ *
3081
+ * \param[in,out] ort_value ::OrtValue to populate with data
3082
+ * \param[in] data_mem_info serves to identify the location of the data to be copied. If the allocator specified
3083
+ * at the creation time has memory info that is not the same as mem_info argument to this function a X-device copy will be performed.
3084
+ * String data is assumed to be on CPU and will only be copied into a CPU allocated buffer.
3085
+ * \param[in] values_shape
3086
+ * \param[in] values_shape_len
3087
+ * \param[in] values structure with values information
3088
+ * \param[in] indices_shape_data pointer to a location of indices shape
3089
+ * \param[in] indices_shape_len length of the block sparse indices shape
3090
+ * \param[in] indices_data pointer to a location of indices data. Shape will determine the length of the indices data.
3091
+ *
3092
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3093
+ */
3094
+ ORT_API2_STATUS(FillSparseTensorBlockSparse, _Inout_ OrtValue* ort_value, _In_ const OrtMemoryInfo* data_mem_info,
3095
+ _In_ const int64_t* values_shape, size_t values_shape_len, _In_ const void* values,
3096
+ _In_ const int64_t* indices_shape_data, size_t indices_shape_len,
3097
+ _In_ const int32_t* indices_data);
3098
+
3099
+ /**
3100
+ * Create an ::OrtValue with a sparse tensor. This is the first step.
3101
+ * Next, use Use<Format>Indices() functions to supply sparse tensor with
3102
+ * format specific indices data and set its sparse format to a specific enum value.
3103
+ * This will not perform memory allocations. It will
3104
+ * use supplied user buffer which should outlive the created sparse tensor.
3105
+ * Use OrtApi::ReleaseValue to destroy the sparse tensor. It would not release the supplied values buffer.
3106
+ * This function can not be used to map strings from the user allocated memory. Strings must always be copied
3107
+ * and have UTF-8 encoding. Therefore, use OrtApi::CreateSparseTensorAsOrtValue above and then fill it with data
3108
+ * using appropriate Make*() function.
3109
+ *
3110
+ * \param[in] info memory info where sparse values reside.
3111
+ * \param[in,out] p_data pointer to a user allocated buffer with values. To create a full sparse tensor with no non-zero
3112
+ * values, pass nullptr
3113
+ * \param[in] dense_shape shape of the original dense tensor
3114
+ * \param[in] dense_shape_len number of shape dimensions being passed
3115
+ * \param[in] values_shape shape of the values data. To create a fully sparse tensor with no non-zero values,
3116
+ * pass {0} shape.
3117
+ * \param[in] values_shape_len number of values shape dimensions
3118
+ * \param[in] type must be one of TENSOR_ELEMENT_DATA_TYPE_xxxx
3119
+ * \param[out] out Should be freed by calling ReleaseValue
3120
+ *
3121
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3122
+ */
3123
+ ORT_API2_STATUS(CreateSparseTensorWithValuesAsOrtValue, _In_ const OrtMemoryInfo* info, _Inout_ void* p_data,
3124
+ _In_ const int64_t* dense_shape, size_t dense_shape_len,
3125
+ _In_ const int64_t* values_shape, size_t values_shape_len,
3126
+ ONNXTensorElementDataType type, _Outptr_ OrtValue** out);
3127
+
3128
+ /**
3129
+ * This assigns Coo format indices to the SparseTensor that was created by
3130
+ * OrtApi::CreateSparseTensorWithValuesAsOrtValue above. It also sets OrtSparseFormat to
3131
+ * ORT_SPARSE_COO. This will not allocate any additional memory for data. The life span of
3132
+ * indices_data buffer should eclipse the life span of this ::OrtValue.
3133
+ *
3134
+ * \param[in,out] ort_value ::OrtValue instance constructed with OrtApi::CreateSparseTensorWithValuesAsOrtValue
3135
+ * \param[in,out] indices_data pointer to a user pre-allocated buffer or nullptr for fully sparse tensors.
3136
+ * \param[in] indices_num number of COO indices. Should either be 0 for fully sparse tensors, be equal
3137
+ * to the number of nnz values specified to OrtApi::CreateSparseTensorWithValuesAsOrtValue for 1-D {nnz} indices or
3138
+ * be twice as number of nnz values for a 2-D indices {nnz, 2}
3139
+ *
3140
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3141
+ */
3142
+ ORT_API2_STATUS(UseCooIndices, _Inout_ OrtValue* ort_value, _Inout_ int64_t* indices_data, size_t indices_num);
3143
+
3144
+ /**
3145
+ * The assigns CSR format indices to the SparseTensor that was created by
3146
+ * OrtApi::CreateSparseTensorWithValuesAsOrtValue above. It also sets OrtSparseFormat to
3147
+ * ORT_SPARSE_CSRC. This will not allocate any additional memory for data. The life spans of
3148
+ * inner_data and outer_data buffers should eclipse the life span of this ::OrtValue.
3149
+ *
3150
+ * \param[in,out] ort_value ::OrtValue instance constructed with OrtApi::CreateSparseTensorWithValuesAsOrtValue
3151
+ * \param[in,out] inner_data pointer to a user pre-allocated buffer or nullptr for fully sparse tensors.
3152
+ * \param[in] inner_num number of inner CSR indices. Should either be 0 for fully sparse tensors or be equal
3153
+ * to the number of nnz values specified to OrtApi::CreateSparseTensorWithValuesAsOrtValue.
3154
+ * \param[in,out] outer_data pointer to user pre-allocated buffer or nullptr for fully sparse tensors.
3155
+ * \param[in] outer_num number of CSR outer indices. Should either be 0 for fully sparse tensors or
3156
+ * equal to rows + 1 of the dense shape.
3157
+ *
3158
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3159
+ */
3160
+ ORT_API2_STATUS(UseCsrIndices, _Inout_ OrtValue* ort_value, _Inout_ int64_t* inner_data, size_t inner_num,
3161
+ _Inout_ int64_t* outer_data, size_t outer_num);
3162
+
3163
+ /**
3164
+ * The assigns BlockSparse format indices to the SparseTensor that was created by
3165
+ * OrtApi::CreateSparseTensorWithValuesAsOrtValue above. It also sets OrtSparseFormat to
3166
+ * ORT_SPARSE_BLOCK_SPARSE. This will not allocate any additional memory for data. The life span of
3167
+ * indices_data buffer must eclipse the lifespan of this ::OrtValue.
3168
+ *
3169
+ * \param[in,out] ort_value OrtValue instance constructed with OrtApi::CreateSparseTensorWithValuesAsOrtValue
3170
+ * \param[in] indices_shape pointer to indices shape. Use {0} for fully sparse tensors
3171
+ * \param[in] indices_shape_len length of the indices shape
3172
+ * \param[in,out] indices_data pointer to user pre-allocated buffer or nullptr for fully sparse tensors.
3173
+ *
3174
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3175
+ */
3176
+ ORT_API2_STATUS(UseBlockSparseIndices, _Inout_ OrtValue* ort_value, const int64_t* indices_shape, size_t indices_shape_len, _Inout_ int32_t* indices_data);
3177
+
3178
+ /** \brief Returns sparse tensor format enum iff a given ort value contains an instance of sparse tensor.
3179
+ *
3180
+ * \param[in] ort_value ::OrtValue that contains an instance of sparse tensor
3181
+ * \param[out] out pointer to out parameter
3182
+ *
3183
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3184
+ */
3185
+ ORT_API2_STATUS(GetSparseTensorFormat, _In_ const OrtValue* ort_value, _Out_ enum OrtSparseFormat* out);
3186
+
3187
+ /** \brief Returns data type and shape of sparse tensor values (nnz) iff ::OrtValue contains a SparseTensor.
3188
+ *
3189
+ * \param[in] ort_value An ::OrtValue that contains a fully constructed sparse tensor
3190
+ * \param[out] out Must be freed by OrtApi::ReleaseTensorTypeAndShapeInfo
3191
+ *
3192
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3193
+ */
3194
+ ORT_API2_STATUS(GetSparseTensorValuesTypeAndShape, _In_ const OrtValue* ort_value, _Outptr_ OrtTensorTypeAndShapeInfo** out);
3195
+
3196
+ /** \brief Returns numeric data for sparse tensor values (nnz). For string values use GetStringTensor*().
3197
+ *
3198
+ * \param[in] ort_value an instance of ::OrtValue containing sparse tensor
3199
+ * \param[out] out returns a pointer to values data. Do not attempt to free this ptr.
3200
+ *
3201
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3202
+ */
3203
+ ORT_API2_STATUS(GetSparseTensorValues, _In_ const OrtValue* ort_value, _Outptr_ const void** out);
3204
+
3205
+ /** \brief Returns data type, shape for the type of indices specified by indices_format.
3206
+ *
3207
+ * \param[in] ort_value ::OrtValue containing sparse tensor.
3208
+ * \param[in] indices_format One of the indices formats. It is an error to request a format that the sparse
3209
+ * tensor does not contain.
3210
+ * \param[out] out an instance of ::OrtTensorTypeAndShapeInfo. Must be freed by OrtApi::ReleaseTensorTypeAndShapeInfo
3211
+ *
3212
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3213
+ */
3214
+ ORT_API2_STATUS(GetSparseTensorIndicesTypeShape, _In_ const OrtValue* ort_value, enum OrtSparseIndicesFormat indices_format, _Outptr_ OrtTensorTypeAndShapeInfo** out);
3215
+
3216
+ /** \brief Returns indices data for the type of the indices specified by indices_format
3217
+ *
3218
+ * \param[in] ort_value ::OrtValue containing sparse tensor.
3219
+ * \param[in] indices_format One of the indices formats. It is an error to request a format that the sparse tensor does not contain.
3220
+ * \param[out] num_indices Pointer to where the number of indices entries is returned
3221
+ * \param[out] indices Returned pointer to the indices data. Do not free the returned pointer as it refers to internal data owned by the ::OrtValue
3222
+ *
3223
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3224
+ */
3225
+ ORT_API2_STATUS(GetSparseTensorIndices, _In_ const OrtValue* ort_value, enum OrtSparseIndicesFormat indices_format, _Out_ size_t* num_indices, _Outptr_ const void** indices);
3226
+ /// @}
3227
+ /// \name OrtSessionOptions
3228
+ /// @{
3229
+
3230
+ /**
3231
+ * \brief Sets out to 1 iff an optional type OrtValue has an element, 0 otherwise (OrtValue is None)
3232
+ * Use this API to find if the optional type OrtValue is None or not.
3233
+ * If the optional type OrtValue is not None, use the OrtValue just like any other OrtValue.
3234
+ * For example, if you get an OrtValue that corresponds to Optional(tensor) and
3235
+ * if HasValue() returns true, use it as tensor and so on.
3236
+
3237
+ * \param[in] value Input OrtValue.
3238
+ * \param[out] out indicating if the input OrtValue contains data (1) or if it is a None (0)
3239
+ *
3240
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3241
+ */
3242
+ ORT_API2_STATUS(HasValue, _In_ const OrtValue* value, _Out_ int* out);
3243
+
3244
+ /// @}
3245
+ /// \name OrtKernelContext
3246
+ /// Custom operator APIs.
3247
+ /// @{
3248
+
3249
+ /** \brief Used for custom operators, gets the GPU compute stream to use to launch the custom a GPU kernel
3250
+ * \see ::OrtCustomOp
3251
+ * \param[in] context OrtKernelContext instance
3252
+ * \param[out] out Returns pointer to a GPU compute stream that can be used to launch the custom GPU kernel.
3253
+ * If retrieving the GPU compute stream is not relevant (GPU not enabled in the build, kernel partitioned to
3254
+ * some other EP), then a nullptr is returned as the output param.
3255
+ * Do not free or mutate the returned pointer as it refers to internal data owned by the underlying session.
3256
+ * Only use it for custom kernel launching.
3257
+ *
3258
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3259
+ */
3260
+ ORT_API2_STATUS(KernelContext_GetGPUComputeStream, _In_ const OrtKernelContext* context, _Outptr_ void** out);
3261
+
3262
+ /// @}
3263
+ /// \name GetTensorMemoryInfo
3264
+ /// @{
3265
+ /** \brief Returns a pointer to the ::OrtMemoryInfo of a Tensor
3266
+ * \param[in] value ::OrtValue containing tensor.
3267
+ * \param[out] mem_info ::OrtMemoryInfo of the tensor. Do NOT free the returned pointer. It is valid for the lifetime of the ::OrtValue
3268
+ *
3269
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3270
+ */
3271
+ ORT_API2_STATUS(GetTensorMemoryInfo, _In_ const OrtValue* value, _Out_ const OrtMemoryInfo** mem_info);
3272
+
3273
+ /// @}
3274
+ /// \name GetExecutionProviderApi
3275
+ /// @{
3276
+ /** \brief Get a pointer to the requested version of the Execution Provider specific
3277
+ * API extensions to the OrtApi
3278
+ * \param[in] provider_name The name of the execution provider name. Currently only the following
3279
+ * values are supported: "DML".
3280
+ * \param[in] version Must be ::ORT_API_VERSION.
3281
+ * \param[out] provider_api A void pointer containing a reference to the execution provider versioned api structure.
3282
+ * For example, the provider_api pointer can be cast to the OrtDmlApi* when the provider_name is "DML".
3283
+ *
3284
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3285
+ */
3286
+ ORT_API2_STATUS(GetExecutionProviderApi, _In_ const char* provider_name, _In_ uint32_t version, _Outptr_ const void** provider_api);
3287
+
3288
+ /// @}
3289
+
3290
+ /// \name SessionOptions
3291
+ /// @{
3292
+ /** \brief Set custom thread creation function
3293
+ *
3294
+ * \param[in] options Session options
3295
+ * \param[in] ort_custom_create_thread_fn Custom thread creation function
3296
+ *
3297
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3298
+ */
3299
+ ORT_API2_STATUS(SessionOptionsSetCustomCreateThreadFn, _Inout_ OrtSessionOptions* options, _In_ OrtCustomCreateThreadFn ort_custom_create_thread_fn);
3300
+
3301
+ /** \brief Set creation options for custom thread
3302
+ *
3303
+ * \param[in] options Session options
3304
+ * \param[in] ort_custom_thread_creation_options Custom thread creation options (can be nullptr)
3305
+ *
3306
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3307
+ */
3308
+ ORT_API2_STATUS(SessionOptionsSetCustomThreadCreationOptions, _Inout_ OrtSessionOptions* options, _In_ void* ort_custom_thread_creation_options);
3309
+
3310
+ /** \brief Set custom thread join function
3311
+ *
3312
+ * \param[in] options Session options
3313
+ * \param[in] ort_custom_join_thread_fn Custom join thread function, must not be nullptr when ort_custom_create_thread_fn is set
3314
+ *
3315
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3316
+ */
3317
+ ORT_API2_STATUS(SessionOptionsSetCustomJoinThreadFn, _Inout_ OrtSessionOptions* options, _In_ OrtCustomJoinThreadFn ort_custom_join_thread_fn);
3318
+ /// @}
3319
+
3320
+ /// \name OrtThreadingOptions
3321
+ /// @{
3322
+ /** \brief Set custom thread creation function for global thread pools
3323
+ *
3324
+ * \param[inout] tp_options
3325
+ * \param[in] ort_custom_create_thread_fn Custom thread creation function
3326
+ *
3327
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3328
+ */
3329
+ ORT_API2_STATUS(SetGlobalCustomCreateThreadFn, _Inout_ OrtThreadingOptions* tp_options, _In_ OrtCustomCreateThreadFn ort_custom_create_thread_fn);
3330
+
3331
+ /** \brief Set custom thread creation options for global thread pools
3332
+ *
3333
+ * \param[inout] tp_options
3334
+ * \param[in] ort_custom_thread_creation_options Custom thread creation options (can be nullptr)
3335
+ *
3336
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3337
+ */
3338
+ ORT_API2_STATUS(SetGlobalCustomThreadCreationOptions, _Inout_ OrtThreadingOptions* tp_options, _In_ void* ort_custom_thread_creation_options);
3339
+
3340
+ /** \brief Set custom thread join function for global thread pools
3341
+ *
3342
+ * \param[inout] tp_options
3343
+ * \param[in] ort_custom_join_thread_fn Custom thread join function, must not be nullptr when global ort_custom_create_thread_fn is set
3344
+ *
3345
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3346
+ */
3347
+ ORT_API2_STATUS(SetGlobalCustomJoinThreadFn, _Inout_ OrtThreadingOptions* tp_options, _In_ OrtCustomJoinThreadFn ort_custom_join_thread_fn);
3348
+ /// @}
3349
+
3350
+ /** \brief Synchronize bound inputs. The call may be necessary for some providers, such as cuda,
3351
+ * in case the system that allocated bound memory operated on a different stream. However, the
3352
+ * operation is provider specific and could be a no-op.
3353
+ *
3354
+ * \param[inout] binding_ptr
3355
+ *
3356
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3357
+ */
3358
+ ORT_API2_STATUS(SynchronizeBoundInputs, _Inout_ OrtIoBinding* binding_ptr);
3359
+
3360
+ /** \brief Synchronize bound outputs. The call may be necessary for some providers, such as cuda,
3361
+ * in case the system that allocated bound memory operated on a different stream. However, the
3362
+ * operation is provider specific and could be a no-op.
3363
+ *
3364
+ * \param[inout] binding_ptr
3365
+ *
3366
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3367
+ */
3368
+ ORT_API2_STATUS(SynchronizeBoundOutputs, _Inout_ OrtIoBinding* binding_ptr);
3369
+
3370
+ /// \name OrtSessionOptions
3371
+ /// @{
3372
+
3373
+ /** \brief Append CUDA execution provider to the session options
3374
+ *
3375
+ * If CUDA is not available (due to a non CUDA enabled build), this function will return failure.
3376
+ *
3377
+ * This is slightly different from OrtApi::SessionOptionsAppendExecutionProvider_CUDA, it takes an
3378
+ * ::OrtCUDAProviderOptions which is publicly defined. This takes an opaque ::OrtCUDAProviderOptionsV2
3379
+ * which must be created with OrtApi::CreateCUDAProviderOptions.
3380
+ *
3381
+ * For OrtApi::SessionOptionsAppendExecutionProvider_CUDA, the user needs to instantiate ::OrtCUDAProviderOptions
3382
+ * as well as allocate/release buffers for some members of ::OrtCUDAProviderOptions.
3383
+ * Here, OrtApi::CreateCUDAProviderOptions and Ortapi::ReleaseCUDAProviderOptions will do the memory management for you.
3384
+ *
3385
+ * \param[in] options
3386
+ * \param[in] cuda_options
3387
+ *
3388
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3389
+ *
3390
+ * \since Version 1.11.
3391
+ */
3392
+ ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_CUDA_V2,
3393
+ _In_ OrtSessionOptions* options, _In_ const OrtCUDAProviderOptionsV2* cuda_options);
3394
+
3395
+ /// @}
3396
+ /// \name OrtCUDAProviderOptionsV2
3397
+ /// @{
3398
+
3399
+ /** \brief Create an OrtCUDAProviderOptionsV2
3400
+ *
3401
+ * \param[out] out Newly created ::OrtCUDAProviderOptionsV2. Must be released with OrtApi::ReleaseCudaProviderOptions
3402
+ *
3403
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3404
+ *
3405
+ * \since Version 1.11.
3406
+ */
3407
+ ORT_API2_STATUS(CreateCUDAProviderOptions, _Outptr_ OrtCUDAProviderOptionsV2** out);
3408
+
3409
+ /** \brief Set options in a CUDA Execution Provider.
3410
+ *
3411
+ * Please refer to https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#configuration-options
3412
+ * to know the available keys and values. Key should be in null terminated string format of the member of ::OrtCUDAProviderOptionsV2
3413
+ * and value should be its related range.
3414
+ *
3415
+ * For example, key="device_id" and value="0"
3416
+ *
3417
+ * \param[in] cuda_options
3418
+ * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys
3419
+ * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values
3420
+ * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays
3421
+ *
3422
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3423
+ *
3424
+ * \since Version 1.11.
3425
+ */
3426
+ ORT_API2_STATUS(UpdateCUDAProviderOptions, _Inout_ OrtCUDAProviderOptionsV2* cuda_options,
3427
+ _In_reads_(num_keys) const char* const* provider_options_keys,
3428
+ _In_reads_(num_keys) const char* const* provider_options_values,
3429
+ _In_ size_t num_keys);
3430
+
3431
+ /**
3432
+ * Get serialized CUDA provider options string.
3433
+ *
3434
+ * For example, "device_id=0;arena_extend_strategy=0;......"
3435
+ *
3436
+ * \param cuda_options - OrtCUDAProviderOptionsV2 instance
3437
+ * \param allocator - a ptr to an instance of OrtAllocator obtained with CreateAllocator() or GetAllocatorWithDefaultOptions()
3438
+ * the specified allocator will be used to allocate continuous buffers for output strings and lengths.
3439
+ * \param ptr - is a UTF-8 null terminated string allocated using 'allocator'. The caller is responsible for using the same allocator to free it.
3440
+ *
3441
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3442
+ *
3443
+ * \since Version 1.11.
3444
+ */
3445
+ ORT_API2_STATUS(GetCUDAProviderOptionsAsString, _In_ const OrtCUDAProviderOptionsV2* cuda_options, _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr);
3446
+
3447
+ /** \brief Release an ::OrtCUDAProviderOptionsV2
3448
+ *
3449
+ * \note This is an exception in the naming convention of other Release* functions, as the name of the method does not have the V2 suffix, but the type does
3450
+ *
3451
+ * \since Version 1.11.
3452
+ */
3453
+ void(ORT_API_CALL* ReleaseCUDAProviderOptions)(_Frees_ptr_opt_ OrtCUDAProviderOptionsV2* input);
3454
+
3455
+ /// @}
3456
+
3457
+ /** \brief Append MIGraphX provider to session options
3458
+ *
3459
+ * If MIGraphX is not available (due to a non MIGraphX enabled build, or if MIGraphX is not installed on the system), this function will return failure.
3460
+ *
3461
+ * \param[in] options
3462
+ * \param[in] migraphx_options
3463
+ *
3464
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3465
+ *
3466
+ * \since Version 1.11.
3467
+ */
3468
+ ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_MIGraphX,
3469
+ _In_ OrtSessionOptions* options, _In_ const OrtMIGraphXProviderOptions* migraphx_options);
3470
+
3471
+ /** \brief Replace initialized Tensors with external data with the data provided in initializers.
3472
+ *
3473
+ * The function will find the initialized TensorProtos with external data in the graph with the provided names and
3474
+ * replace them with the provided tensors. The API verifies that the TensorProto being replaced
3475
+ * has an external data reference and has the same name, dimensions and data type as its replacement. The replacement
3476
+ * will occur before any of the optimizations take place. The data will be copied into the graph
3477
+ * since TensorProto can't refer to the user provided buffers.
3478
+ *
3479
+ * Once the model has been loaded, the OrtValue(s) added to SessionOptions instance will be removed
3480
+ * from the internal SessionOptions copy to save memory, the user provided buffers can then be deallocated
3481
+ * and the SessionOptions instance that refers to them can be destroyed.
3482
+ *
3483
+ * \param[in] options
3484
+ * \param[in] initializer_names Array of null terminated UTF-8 encoded strings of the initializers names.
3485
+ * \param[in] initializers Array of ::OrtValue type
3486
+ * \param[in] initializers_num Number of elements in the initializer_names and initializers
3487
+ *
3488
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3489
+ *
3490
+ * \since Version 1.12.
3491
+ */
3492
+ ORT_API2_STATUS(AddExternalInitializers, _In_ OrtSessionOptions* options,
3493
+ _In_reads_(input_len) const char* const* initializer_names,
3494
+ _In_reads_(input_len) const OrtValue* const* initializers, size_t initializers_num);
3495
+
3496
+ /** \brief: Create attribute of onnxruntime operator
3497
+ *
3498
+ * \param[in] name Name of the attribute
3499
+ * \param[in] data Data content of the attribute
3500
+ * \param[in] len Number of bytes stored in data
3501
+ * \param[in] type Data type
3502
+ * \param[out] op_attr Attribute that has been created, which must be released by OrtApi::ReleaseOpAttr
3503
+ *
3504
+ * \since Version 1.12.
3505
+ */
3506
+ ORT_API2_STATUS(CreateOpAttr,
3507
+ _In_ const char* name,
3508
+ _In_ const void* data,
3509
+ _In_ int len,
3510
+ _In_ OrtOpAttrType type,
3511
+ _Outptr_ OrtOpAttr** op_attr);
3512
+
3513
+ /* \brief: Release op attribute
3514
+ *
3515
+ * \param[in] opAttr Attribute created by OrtApi::CreateOpAttr
3516
+ *
3517
+ * \since Version 1.12.
3518
+ */
3519
+ ORT_CLASS_RELEASE(OpAttr);
3520
+
3521
+ /** \brief: Create onnxruntime native operator
3522
+ *
3523
+ * \param[in] info Kernel info
3524
+ * \param[in] op_name Operator name
3525
+ * \param[in] domain Operator domain
3526
+ * \param[in] version Operator opset version
3527
+ * \param[in] type_constraint_names Name of the type contraints, such as "T" or "T1"
3528
+ * \param[in] type_constraint_values Type of each contraints
3529
+ * \param[in] type_constraint_count Number of contraints
3530
+ * \param[in] attr_values Attributes used to initialize the operator
3531
+ * \param[in] attr_count Number of the attributes
3532
+ * \param[in] input_count Number of inputs
3533
+ * \param[in] output_count Number of outputs
3534
+ * \param[out] ort_op Operator that has been created
3535
+ *
3536
+ * \since Version 1.12.
3537
+ */
3538
+ ORT_API2_STATUS(CreateOp,
3539
+ _In_ const OrtKernelInfo* info,
3540
+ _In_z_ const char* op_name,
3541
+ _In_z_ const char* domain,
3542
+ int version,
3543
+ _In_reads_(type_constraint_count) const char** type_constraint_names,
3544
+ _In_reads_(type_constraint_count) const ONNXTensorElementDataType* type_constraint_values,
3545
+ int type_constraint_count,
3546
+ _In_reads_(attr_count) const OrtOpAttr* const* attr_values,
3547
+ int attr_count,
3548
+ int input_count,
3549
+ int output_count,
3550
+ _Outptr_ OrtOp** ort_op);
3551
+
3552
+ /** \brief: Invoke the operator created by OrtApi::CreateOp
3553
+ * The inputs must follow the order as specified in onnx specification
3554
+ *
3555
+ * \param[in] context Kernel context
3556
+ * \param[in] ort_op Operator that has been created
3557
+ * \param[in] input_values Array of inputs
3558
+ * \param[in] input_count Number of inputs
3559
+ * \param[in] output_values Array of outputs
3560
+ * \param[in] output_count Number of outputs
3561
+ *
3562
+ * \since Version 1.12.
3563
+ */
3564
+ ORT_API2_STATUS(InvokeOp,
3565
+ _In_ const OrtKernelContext* context,
3566
+ _In_ const OrtOp* ort_op,
3567
+ _In_ const OrtValue* const* input_values,
3568
+ _In_ int input_count,
3569
+ _Inout_ OrtValue* const* output_values,
3570
+ _In_ int output_count);
3571
+
3572
+ /* \brief: Release an onnxruntime operator
3573
+ *
3574
+ * \param[in] Op Operator created by OrtApi::CreateOp
3575
+ *
3576
+ * \since Version 1.12.
3577
+ */
3578
+ ORT_CLASS_RELEASE(Op);
3579
+
3580
+ /** \brief: Append execution provider to the session options.
3581
+ * \param[in] options
3582
+ * \param[in] provider_name - provider to add.
3583
+ * \param[in] provider_options_keys - keys to configure the provider options
3584
+ * \param[in] provider_options_values - values to configure the provider options
3585
+ * \param[in] num_keys - number of keys passed in
3586
+ *
3587
+ * Currently supported providers:
3588
+ * QNN
3589
+ * SNPE
3590
+ * XNNPACK
3591
+ *
3592
+ * Note: If an execution provider has a dedicated SessionOptionsAppendExecutionProvider_<provider name> function
3593
+ * that should be used to add it.
3594
+ *
3595
+ * QNN supported keys:
3596
+ * "backend_path": file path to QNN backend library.
3597
+ * "profiling_level": QNN profiling level, options: "off", "basic", "detailed". Default to off.
3598
+ * "rpc_control_latency": QNN RPC control latency.
3599
+ * "vtcm_mb": QNN VTCM size in MB. default to 0(not set).
3600
+ * "htp_performance_mode": QNN performance mode, options: "burst", "balanced", "default", "high_performance",
3601
+ * "high_power_saver", "low_balanced", "extreme_power_saver", "low_power_saver", "power_saver", "sustained_high_performance". Default to "default".
3602
+ * "qnn_saver_path": File path to the QNN Saver backend library. If specified, QNN Saver will be enabled and will
3603
+ * dump QNN API calls to disk for replay/debugging. QNN Saver produces incorrect model inference results and
3604
+ * may alter model/EP partitioning. Use only for debugging.
3605
+ * "qnn_context_priority": QNN context priority, options: "low", "normal", "normal_high", "high". Default to "normal".
3606
+ * "htp_graph_finalization_optimization_mode": Set the optimization mode for graph finalization on the HTP backend. Available options:
3607
+ * - "0": Default.
3608
+ * - "1": Faster preparation time, less optimal graph.
3609
+ * - "2": Longer preparation time, more optimal graph.
3610
+ * - "3": Longest preparation time, most likely even more optimal graph. See QNN SDK documentation for specific details.
3611
+ * "soc_model": The SoC model number. Refer to the QNN SDK documentation for valid values. Defaults to "0" (unknown).
3612
+ * "htp_arch": The minimum HTP architecture the driver will use to select compatible QNN operators. Available options:
3613
+ * - "0": Default (none).
3614
+ * - "68"
3615
+ * - "69"
3616
+ * - "73"
3617
+ * - "75"
3618
+ * "device_id": The ID of the device to use when setting 'htp_arch'. Defaults to "0" (for single device).
3619
+ *
3620
+ * SNPE supported keys:
3621
+ * "runtime": SNPE runtime engine, options: "CPU", "CPU_FLOAT32", "GPU", "GPU_FLOAT32_16_HYBRID", "GPU_FLOAT16",
3622
+ * "DSP", "DSP_FIXED8_TF", "AIP_FIXED_TF", "AIP_FIXED8_TF".
3623
+ * Mapping to SNPE Runtime_t definition: CPU, CPU_FLOAT32 => zdl::DlSystem::Runtime_t::CPU;
3624
+ * GPU, GPU_FLOAT32_16_HYBRID => zdl::DlSystem::Runtime_t::GPU;
3625
+ * GPU_FLOAT16 => zdl::DlSystem::Runtime_t::GPU_FLOAT16;
3626
+ * DSP, DSP_FIXED8_TF => zdl::DlSystem::Runtime_t::DSP.
3627
+ * AIP_FIXED_TF, AIP_FIXED8_TF => zdl::DlSystem::Runtime_t::AIP_FIXED_TF.
3628
+ * "priority": execution priority, options: "low", "normal".
3629
+ * "buffer_type": ITensor or user buffers, options: "ITENSOR", user buffer with different types - "TF8", "TF16", "UINT8", "FLOAT".
3630
+ * "ITENSOR" -- default, ITensor which is float only.
3631
+ * "TF8" -- quantized model required, "FLOAT" -- for both quantized or non-quantized model
3632
+ * "enable_init_cache": enable SNPE init caching feature, set to 1 to enabled it. Disabled by default.
3633
+ * If SNPE is not available (due to a non Snpe enabled build or its dependencies not being installed), this function will fail.
3634
+ *
3635
+ * XNNPACK supported keys:
3636
+ * "intra_op_num_threads": number of thread-pool size to use for XNNPACK execution provider.
3637
+ * default value is 0, which means to use the session thread-pool size.
3638
+ *
3639
+ * \since Version 1.12.
3640
+ */
3641
+ ORT_API2_STATUS(SessionOptionsAppendExecutionProvider, _In_ OrtSessionOptions* options,
3642
+ _In_ const char* provider_name,
3643
+ _In_reads_(num_keys) const char* const* provider_options_keys,
3644
+ _In_reads_(num_keys) const char* const* provider_options_values,
3645
+ _In_ size_t num_keys);
3646
+
3647
+ /* \brief: Get a copy of kernel info
3648
+ *
3649
+ * \param[in] info Kernel info
3650
+ * \param[out] info_copy Copy of kernel info
3651
+ *
3652
+ * \since Version 1.12.
3653
+ */
3654
+ ORT_API2_STATUS(CopyKernelInfo,
3655
+ _In_ const OrtKernelInfo* info,
3656
+ _Outptr_ OrtKernelInfo** info_copy);
3657
+
3658
+ /* \brief: Release kernel info
3659
+ *
3660
+ * \param[in] KernelInfo A copy of kernel info returned by CopyKernelInfo
3661
+ *
3662
+ * \since Version 1.12.
3663
+ */
3664
+ ORT_CLASS_RELEASE(KernelInfo);
3665
+
3666
+ /// \name Ort Training
3667
+ /// @{
3668
+ /** \brief Gets the Training C Api struct
3669
+ *
3670
+ * Call this function to access the ::OrtTrainingApi structure that holds pointers to functions that enable
3671
+ * training with onnxruntime.
3672
+ * \note A NULL pointer will be returned and no error message will be printed if the training api
3673
+ * is not supported with this build. A NULL pointer will be returned and an error message will be
3674
+ * printed if the provided version is unsupported, for example when using a runtime older than the
3675
+ * version created with this header file.
3676
+ *
3677
+ * \param[in] version Must be ::ORT_API_VERSION
3678
+ * \return The ::OrtTrainingApi struct for the version requested.
3679
+ *
3680
+ * \since Version 1.13
3681
+ */
3682
+ const OrtTrainingApi*(ORT_API_CALL* GetTrainingApi)(uint32_t version)NO_EXCEPTION;
3683
+
3684
+ /// @}
3685
+
3686
+ /** \brief Append CANN provider to session options
3687
+ *
3688
+ * If CANN is not available (due to a non CANN enabled build, or if CANN is not installed on the system), this function will return failure.
3689
+ *
3690
+ * \param[in] options
3691
+ * \param[in] cann_options
3692
+ *
3693
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3694
+ *
3695
+ * \since Version 1.13.
3696
+ */
3697
+ ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_CANN,
3698
+ _In_ OrtSessionOptions* options, _In_ const OrtCANNProviderOptions* cann_options);
3699
+
3700
+ /** \brief Create an OrtCANNProviderOptions
3701
+ *
3702
+ * \param[out] out created ::OrtCANNProviderOptions. Must be released with OrtApi::ReleaseCANNProviderOptions
3703
+ *
3704
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3705
+ *
3706
+ * \since Version 1.13.
3707
+ */
3708
+ ORT_API2_STATUS(CreateCANNProviderOptions, _Outptr_ OrtCANNProviderOptions** out);
3709
+
3710
+ /** \brief Set options in a CANN Execution Provider.
3711
+ *
3712
+ * \param[in] cann_options
3713
+ * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys
3714
+ * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values
3715
+ * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays
3716
+ *
3717
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3718
+ *
3719
+ * \since Version 1.13.
3720
+ */
3721
+ ORT_API2_STATUS(UpdateCANNProviderOptions, _Inout_ OrtCANNProviderOptions* cann_options,
3722
+ _In_reads_(num_keys) const char* const* provider_options_keys,
3723
+ _In_reads_(num_keys) const char* const* provider_options_values,
3724
+ _In_ size_t num_keys);
3725
+
3726
+ /** \brief Get serialized CANN provider options string.
3727
+ *
3728
+ * \param[in] cann_options OrtCANNProviderOptions instance
3729
+ * \param[in] allocator a ptr to an instance of OrtAllocator obtained with CreateAllocator()
3730
+ * or GetAllocatorWithDefaultOptions(), the specified allocator will be used to allocate
3731
+ * continuous buffers for output strings and lengths.
3732
+ * \param[out] ptr is a UTF-8 null terminated string allocated using 'allocator'.
3733
+ * The caller is responsible for using the same allocator to free it.
3734
+ *
3735
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3736
+ *
3737
+ * \since Version 1.13.
3738
+ */
3739
+ ORT_API2_STATUS(GetCANNProviderOptionsAsString, _In_ const OrtCANNProviderOptions* cann_options,
3740
+ _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr);
3741
+
3742
+ /** \brief Release an OrtCANNProviderOptions
3743
+ *
3744
+ * \param[in] the pointer of OrtCANNProviderOptions which will been deleted
3745
+ *
3746
+ * \since Version 1.13.
3747
+ */
3748
+ void(ORT_API_CALL* ReleaseCANNProviderOptions)(_Frees_ptr_opt_ OrtCANNProviderOptions* input);
3749
+
3750
+ /* \brief Get OrtDevice type from MemoryInfo
3751
+ *
3752
+ * \since Version 1.14
3753
+ */
3754
+ void(ORT_API_CALL* MemoryInfoGetDeviceType)(_In_ const OrtMemoryInfo* ptr, _Out_ OrtMemoryInfoDeviceType* out);
3755
+
3756
+ /* \brief Update the OrtEnv instance with custom log severity level
3757
+ *
3758
+ * \param[in] ort_env The OrtEnv instance being used
3759
+ * \param[in] log_severity_level The log severity level.
3760
+ *
3761
+ * \since Version 1.14.
3762
+ */
3763
+ ORT_API2_STATUS(UpdateEnvWithCustomLogLevel, _In_ OrtEnv* ort_env, OrtLoggingLevel log_severity_level);
3764
+
3765
+ /* \brief Set affinities for intra op threads
3766
+ *
3767
+ * Affinity string follows format:
3768
+ * logical_processor_id,logical_processor_id;logical_processor_id,logical_processor_id
3769
+ * Semicolon isolates configurations among threads, while comma split processors where ith thread expected to attach to.
3770
+ * e.g. 1,2,3;4,5
3771
+ * specifies affinities for two threads, with the 1st thread attach to the 1st, 2nd, and 3rd processor, and 2nd thread to the 4th and 5th.
3772
+ * To ease the configuration, an "interval" is also allowed:
3773
+ * e.g. 1-8;8-16;17-24
3774
+ * orders that the 1st thread runs on first eight processors, 2nd thread runs on next eight processors, and so forth.
3775
+ * Note:
3776
+ * 1. Once set, the number of thread affinities must equal to intra_op_num_threads - 1,
3777
+ * ort does not set affinity on the main thread which is started and managed by the calling app;
3778
+ * 2. For windows, ort will infer the group id from a logical processor id, for example, assuming there are two groups with each has 64 logical processors,
3779
+ * an id of 64 will be inferred as the last processor of the 1st group, while 65 will be interpreted as the 1st processor of the second group.
3780
+ * Hence 64-65 is an invalid configuration, because a windows thread cannot be attached to processors across group boundary.
3781
+ *
3782
+ * \since Version 1.14
3783
+ */
3784
+ ORT_API2_STATUS(SetGlobalIntraOpThreadAffinity, _Inout_ OrtThreadingOptions* tp_options, const char* affinity_string);
3785
+
3786
+ /** \brief Register custom ops from a shared library.
3787
+ *
3788
+ * Loads a shared library (.dll on windows, .so on linux, etc) named 'library_name' and looks for this entry point:
3789
+ * OrtStatus* RegisterCustomOps(OrtSessionOptions * options, const OrtApiBase* api);
3790
+ * It then passes in the provided session options to this function along with the api base.
3791
+ *
3792
+ * The handle to the loaded library is automatically released by ORT when the last OrtSession that references the
3793
+ * library handle is released. If no OrtSession is created, then the library handle is released when the provided
3794
+ * OrtSessionOptions is released.
3795
+ *
3796
+ * \param[in] options The session options.
3797
+ * \param[in] library_name The name of the shared library to load and register. Refer to OS-specific dynamic library
3798
+ * loading utilities (e.g., LoadLibraryEx on Windows or dlopen on Linux/MacOS) for information
3799
+ * on the format of library names and search paths.
3800
+ *
3801
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3802
+ * \since Version 1.14
3803
+ */
3804
+ ORT_API2_STATUS(RegisterCustomOpsLibrary_V2, _Inout_ OrtSessionOptions* options, _In_ const ORTCHAR_T* library_name);
3805
+
3806
+ /** \brief Register custom ops by calling a RegisterCustomOpsFn function.
3807
+ *
3808
+ * Searches for registration_func_name and if found calls it.
3809
+ *
3810
+ * The library containing the function must either be linked against or previously loaded by the executable.
3811
+ *
3812
+ * If you want ONNX Runtime to load the library and manage its lifetime, use RegisterCustomOpsLibrary_V2.
3813
+ *
3814
+ * RegisterCustomOpsUsingFunction can be used in scenarios where it may not be possible for ONNX Runtime to load
3815
+ * the library from a path. e.g. mobile platforms where the library must be linked into the app.
3816
+ *
3817
+ * The registration function must have the signature of RegisterCustomOpsFn:
3818
+ * OrtStatus* (*fn)(OrtSessionOptions* options, const OrtApiBase* api);
3819
+ *
3820
+ * See https://onnxruntime.ai/docs/reference/operators/add-custom-op.html for details on how the registration
3821
+ * function should be implemented.
3822
+ *
3823
+ * \param[in] options OrtSessionOptions that is passed through as the first argument in the call to the
3824
+ * registration function.
3825
+ * \param[in] registration_func_name Name of registration function to use.
3826
+ *
3827
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3828
+ * \since Version 1.14
3829
+ */
3830
+ ORT_API2_STATUS(RegisterCustomOpsUsingFunction, _Inout_ OrtSessionOptions* options,
3831
+ _In_ const char* registration_func_name);
3832
+
3833
+ /// \name OrtKernelInfo
3834
+ /// Custom operator APIs.
3835
+ /// @{
3836
+
3837
+ /** \brief Get the number of inputs from ::OrtKernelInfo.
3838
+ *
3839
+ * Used in the CreateKernel callback of an OrtCustomOp to query the number of inputs
3840
+ * during kernel/session creation.
3841
+ *
3842
+ * \param[in] info Instance of ::OrtKernelInfo.
3843
+ * \param[out] out Pointer to variable assigned with the result on success.
3844
+ *
3845
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3846
+ * \since Version 1.14
3847
+ */
3848
+ ORT_API2_STATUS(KernelInfo_GetInputCount, _In_ const OrtKernelInfo* info, _Out_ size_t* out);
3849
+
3850
+ /** \brief Get the number of outputs from ::OrtKernelInfo.
3851
+ *
3852
+ * Used in the CreateKernel callback of an OrtCustomOp to query the number of outputs
3853
+ * during kernel/session creation.
3854
+ *
3855
+ * \param[in] info Instance of ::OrtKernelInfo.
3856
+ * \param[out] out Pointer to variable assigned with the result on success.
3857
+ *
3858
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3859
+ * \since Version 1.14
3860
+ */
3861
+ ORT_API2_STATUS(KernelInfo_GetOutputCount, _In_ const OrtKernelInfo* info, _Out_ size_t* out);
3862
+
3863
+ /** \brief Get the name of a ::OrtKernelInfo's input.
3864
+ *
3865
+ * Used in the CreateKernel callback of an OrtCustomOp to query an input's name
3866
+ * during kernel/session creation.
3867
+ *
3868
+ * If `out` is nullptr, the value of `size` is set to the size of the name
3869
+ * string (including null-terminator), and a success status is returned.
3870
+ *
3871
+ * If the `size` parameter is greater than or equal to the name string's size,
3872
+ * the value of `size` is set to the true size of the string (including null-terminator),
3873
+ * the provided memory is filled with the string's contents, and a success status is returned.
3874
+ *
3875
+ * If the `size` parameter is less than the actual string's size and `out`
3876
+ * is not nullptr, the value of `size` is set to the true size of the string
3877
+ * and a failure status is returned.
3878
+ *
3879
+ * \param[in] info An instance of ::OrtKernelInfo.
3880
+ * \param[in] index The index of the input name to get. Returns a failure status if out-of-bounds.
3881
+ * \param[out] out Memory location into which to write the UTF-8 null-terminated string representing the input's name.
3882
+ * \param[in,out] size Pointer to the size of the `out` buffer. See above comments for details.
3883
+ *
3884
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3885
+ * \since Version 1.14
3886
+ */
3887
+ ORT_API2_STATUS(KernelInfo_GetInputName, _In_ const OrtKernelInfo* info, size_t index, _Out_ char* out,
3888
+ _Inout_ size_t* size);
3889
+
3890
+ /** \brief Get the name of a ::OrtKernelInfo's output.
3891
+ *
3892
+ * Used in the CreateKernel callback of an OrtCustomOp to query an output's name
3893
+ * during kernel/session creation.
3894
+ *
3895
+ * If `out` is nullptr, the value of `size` is set to the size of the name
3896
+ * string (including null-terminator), and a success status is returned.
3897
+ *
3898
+ * If the `size` parameter is greater than or equal to the name string's size,
3899
+ * the value of `size` is set to the true size of the string (including null-terminator),
3900
+ * the provided memory is filled with the string's contents, and a success status is returned.
3901
+ *
3902
+ * If the `size` parameter is less than the actual string's size and `out`
3903
+ * is not nullptr, the value of `size` is set to the true size of the string
3904
+ * and a failure status is returned.
3905
+ *
3906
+ * \param[in] info An instance of ::OrtKernelInfo.
3907
+ * \param[in] index The index of the output name to get. Returns a failure status if out-of-bounds.
3908
+ * \param[out] out Memory location into which to write the UTF-8 null-terminated string representing the output's
3909
+ * name.
3910
+ * \param[in,out] size Pointer to the size of the `out` buffer. See above comments for details.
3911
+ *
3912
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3913
+ * \since Version 1.14
3914
+ */
3915
+ ORT_API2_STATUS(KernelInfo_GetOutputName, _In_ const OrtKernelInfo* info, size_t index, _Out_ char* out,
3916
+ _Inout_ size_t* size);
3917
+
3918
+ /** \brief Get the type information for a ::OrtKernelInfo's input.
3919
+ *
3920
+ * Used in the CreateKernel callback of an OrtCustomOp to query the shape and type information
3921
+ * of an input during kernel/session creation.
3922
+ *
3923
+ * \param[in] info An instance of ::OrtKernelInfo.
3924
+ * \param[in] index Which input to get the type information for
3925
+ * \param[out] type_info Pointer set to the resulting ::OrtTypeInfo. Must be freed with OrtApi::ReleaseTypeInfo.
3926
+ *
3927
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3928
+ * \since Version 1.14
3929
+ */
3930
+ ORT_API2_STATUS(KernelInfo_GetInputTypeInfo, _In_ const OrtKernelInfo* info, size_t index,
3931
+ _Outptr_ OrtTypeInfo** type_info);
3932
+
3933
+ /** \brief Get the type information for a ::OrtKernelInfo's output.
3934
+ *
3935
+ * Used in the CreateKernel callback of an OrtCustomOp to query the shape and type information
3936
+ * of an output during kernel/session creation.
3937
+ *
3938
+ * \param[in] info An instance of ::OrtKernelInfo.
3939
+ * \param[in] index Which input to get the type information for
3940
+ * \param[out] type_info Pointer set to the resulting ::OrtTypeInfo. Must be freed with OrtApi::ReleaseTypeInfo.
3941
+ *
3942
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3943
+ * \since Version 1.14
3944
+ */
3945
+ ORT_API2_STATUS(KernelInfo_GetOutputTypeInfo, _In_ const OrtKernelInfo* info, size_t index,
3946
+ _Outptr_ OrtTypeInfo** type_info);
3947
+
3948
+ /** \brief Get a ::OrtValue tensor stored as an attribute in the graph node.
3949
+ *
3950
+ * Used in the CreateKernel callback of an OrtCustomOp to get a tensor attribute.
3951
+ *
3952
+ * \param[in] info ::OrtKernelInfo instance.
3953
+ * \param[in] name UTF-8 null-terminated string representing the attribute's name.
3954
+ * \param[in] allocator Allocator used to allocate the internal tensor state.
3955
+ * \param[out] out Returns newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue,
3956
+ * which will also free internal tensor state allocated with the provided allocator.
3957
+ *
3958
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3959
+ */
3960
+ ORT_API2_STATUS(KernelInfoGetAttribute_tensor, _In_ const OrtKernelInfo* info, _In_z_ const char* name,
3961
+ _Inout_ OrtAllocator* allocator, _Outptr_ OrtValue** out);
3962
+
3963
+ /// @}
3964
+ /// \name OrtSessionOptions
3965
+ /// Custom operator APIs
3966
+ /// @{
3967
+
3968
+ /** \brief Checks if the given session configuration entry exists.
3969
+ *
3970
+ * The config_key formats are defined in onnxruntime_session_options_config_keys.h
3971
+ *
3972
+ * Can be used in a custom operator library to check for session configuration entries
3973
+ * that target one or more custom operators in the library. Example: The config entry
3974
+ * custom_op.myop.some_key targets a custom op named "myop".
3975
+ *
3976
+ * \param[in] options The ::OrtSessionOptions instance.
3977
+ * \param[in] config_key A null-terminated UTF-8 string representation of the configuration key.
3978
+ * \param[out] out Pointer set to 1 if the entry exists and 0 otherwise.
3979
+ *
3980
+ * \snippet{doc} snippets.dox OrtStatus Return Value
3981
+ * \since Version 1.14
3982
+ */
3983
+ ORT_API2_STATUS(HasSessionConfigEntry, _In_ const OrtSessionOptions* options,
3984
+ _In_z_ const char* config_key, _Out_ int* out);
3985
+
3986
+ /** \brief Get a session configuration value.
3987
+ *
3988
+ * Returns a failure status if the configuration key does not exist.
3989
+ * The config_key and the format of config_value are defined in onnxruntime_session_options_config_keys.h
3990
+ *
3991
+ * If `config_value` is nullptr, the value of `size` is set to the true size of the string
3992
+ * value (including null-terminator), and a success status is returned.
3993
+ *
3994
+ * If the `size` parameter is greater than or equal to the actual string value's size,
3995
+ * the value of `size` is set to the true size of the string value, the provided memory
3996
+ * is filled with the value's contents, and a success status is returned.
3997
+ *
3998
+ * If the `size` parameter is less than the actual string value's size and `config_value`
3999
+ * is not nullptr, the value of `size` is set to the true size of the string value
4000
+ * and a failure status is returned.
4001
+ *
4002
+ * Can be used in a custom operator library to get session configuration entries
4003
+ * that target one or more custom operators in the library. Example: The config entry
4004
+ * custom_op.myop.some_key targets a custom op named "myop".
4005
+ *
4006
+ * \param[in] options The session options.
4007
+ * \param[in] config_key A null-terminated UTF-8 string representation of the config key.
4008
+ * \param[in] config_value Pointer to memory where the null-terminated UTF-8 string value will be stored.
4009
+ * \param[in,out] size Pointer to the size of the `config_value` buffer. See above comments for details.
4010
+ *
4011
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4012
+ * \since Version 1.14
4013
+ */
4014
+ ORT_API2_STATUS(GetSessionConfigEntry, _In_ const OrtSessionOptions* options,
4015
+ _In_z_ const char* config_key, _Out_ char* config_value, _Inout_ size_t* size);
4016
+
4017
+ /// @}
4018
+
4019
+ /** \brief Append dnnl provider to session options
4020
+ *
4021
+ * If oneDNN is not available, this function will return failure.
4022
+ *
4023
+ * \param[in] options
4024
+ * \param[in] dnnl_options
4025
+ *
4026
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4027
+ *
4028
+ * \since Version 1.15.
4029
+ */
4030
+ ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_Dnnl,
4031
+ _In_ OrtSessionOptions* options, _In_ const OrtDnnlProviderOptions* dnnl_options);
4032
+
4033
+ /** \brief Create an OrtDnnlProviderOptions
4034
+ *
4035
+ * \param[out] out Newly created ::OrtDnnlProviderOptions. Must be released with OrtApi::ReleaseDnnlProviderOptions
4036
+ *
4037
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4038
+ *
4039
+ * \since Version 1.15.
4040
+ */
4041
+ ORT_API2_STATUS(CreateDnnlProviderOptions, _Outptr_ OrtDnnlProviderOptions** out);
4042
+
4043
+ /** \brief Set options in a oneDNN Execution Provider.
4044
+ *
4045
+ * Key should be in null terminated string format of the member of ::OrtDnnlProviderOptions
4046
+ * and value should be its related range.
4047
+ *
4048
+ * For example, key="use_arena" and value="1"
4049
+ *
4050
+ * \param[in] dnnl_options
4051
+ * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys
4052
+ * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values
4053
+ * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays
4054
+ *
4055
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4056
+ *
4057
+ * \since Version 1.15.
4058
+ */
4059
+ ORT_API2_STATUS(UpdateDnnlProviderOptions, _Inout_ OrtDnnlProviderOptions* dnnl_options,
4060
+ _In_reads_(num_keys) const char* const* provider_options_keys,
4061
+ _In_reads_(num_keys) const char* const* provider_options_values,
4062
+ _In_ size_t num_keys);
4063
+
4064
+ /**
4065
+ * Get serialized oneDNN provider options string.
4066
+ *
4067
+ * For example, "use_arena=1;......"
4068
+ *
4069
+ * \param dnnl_options - OrtDnnlProviderOptions instance
4070
+ * \param allocator - a ptr to an instance of OrtAllocator obtained with CreateAllocator() or GetAllocatorWithDefaultOptions()
4071
+ * the specified allocator will be used to allocate continuous buffers for output strings and lengths.
4072
+ * \param ptr - is a UTF-8 null terminated string allocated using 'allocator'. The caller is responsible for using the same allocator to free it.
4073
+ *
4074
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4075
+ *
4076
+ * \since Version 1.15.
4077
+ */
4078
+ ORT_API2_STATUS(GetDnnlProviderOptionsAsString, _In_ const OrtDnnlProviderOptions* dnnl_options, _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr);
4079
+
4080
+ /** \brief Release an ::OrtDnnlProviderOptions
4081
+ *
4082
+ * \since Version 1.15.
4083
+ */
4084
+ void(ORT_API_CALL* ReleaseDnnlProviderOptions)(_Frees_ptr_opt_ OrtDnnlProviderOptions* input);
4085
+
4086
+ /// \name OrtKernelInfo
4087
+ /// Custom operator APIs.
4088
+ /// @{
4089
+
4090
+ /** \brief Get the graph node name from ::OrtKernelInfo.
4091
+ *
4092
+ * If `out` is nullptr, the value of `size` is set to the size of the name
4093
+ * string (including null-terminator), and a success status is returned.
4094
+ *
4095
+ * If the `size` parameter is greater than or equal to the name string's size,
4096
+ * the value of `size` is set to the true size of the string (including null-terminator),
4097
+ * the provided memory is filled with the string's contents, and a success status is returned.
4098
+ *
4099
+ * If the `size` parameter is less than the actual string's size and `out`
4100
+ * is not nullptr, the value of `size` is set to the true size of the string
4101
+ * and a failure status is returned.
4102
+ *
4103
+ * Can be used in a custom operator's CreateKernel callback to get the name of the operator's node name in the graph.
4104
+ *
4105
+ * \param[in] info An instance of ::OrtKernelInfo.
4106
+ * \param[out] out Memory location into which to write the UTF-8 null-terminated string representing the name.
4107
+ * \param[in,out] size Pointer to the size of the `out` buffer. See above comments for details.
4108
+ *
4109
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4110
+ * \since Version 1.15
4111
+ */
4112
+ ORT_API2_STATUS(KernelInfo_GetNodeName, _In_ const OrtKernelInfo* info, _Out_ char* out, _Inout_ size_t* size);
4113
+
4114
+ /** \brief Get the session logger from ::OrtKernelInfo.
4115
+ *
4116
+ * Used in the CreateKernel callback of an OrtCustomOp to get a logger that can be used to log
4117
+ * messages.
4118
+ *
4119
+ * \param[in] info An instance of ::OrtKernelInfo.
4120
+ * \param[out] logger Pointer set to the session's ::OrtLogger. Owned by ONNX Runtime, so do not free.
4121
+ *
4122
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4123
+ * \since Version 1.15
4124
+ */
4125
+ ORT_API2_STATUS(KernelInfo_GetLogger, _In_ const OrtKernelInfo* info, _Outptr_ const OrtLogger** logger);
4126
+
4127
+ /// @}
4128
+ /// \name OrtKernelContext
4129
+ /// Custom operator APIs.
4130
+ /// @{
4131
+
4132
+ /** \brief Get the runtime logger from ::OrtKernelContext.
4133
+ *
4134
+ * Used in the KernelCompute callback of an OrtCustomOp to get a logger that can be used to log
4135
+ * messages during inference.
4136
+ *
4137
+ * \param[in] context An instance of ::OrtKernelContext.
4138
+ * \param[out] logger Pointer set to the kernel context's ::OrtLogger. Owned by ONNX Runtime, so do not free.
4139
+ *
4140
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4141
+ * \since Version 1.15
4142
+ */
4143
+ ORT_API2_STATUS(KernelContext_GetLogger, _In_ const OrtKernelContext* context, _Outptr_ const OrtLogger** logger);
4144
+
4145
+ /// @}
4146
+ /// \name OrtLogger
4147
+ /// Custom operator APIs.
4148
+ /// @{
4149
+
4150
+ /** \brief Logs a message at the given severity level using the provided ::OrtLogger.
4151
+ *
4152
+ * Only messages with a severity level equal or greater than the ::OrtLogger's logging severity level
4153
+ * are logged. Use OrtApi::Logger_GetLoggingSeverityLevel to get the ::OrtLogger's logging severity
4154
+ * level.
4155
+ *
4156
+ * Can be used in custom operators to log messages with the logger retrieved via OrtApi::KernelInfo_GetLogger.
4157
+ *
4158
+ * \param[in] logger The ::OrtLogger instance.
4159
+ * \param[in] log_severity_level The message's severity level.
4160
+ * \param[in] message The message to log.
4161
+ * \param[in] file_path The filepath of the file in which the message is logged. Usually the value of ORT_FILE.
4162
+ * \param[in] line_number The file line number in which the message is logged. Usually the value of __LINE__.
4163
+ * \param[in] func_name The name of the function in which the message is logged. Usually the value of __FUNCTION__.
4164
+ *
4165
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4166
+ * \since Version 1.15
4167
+ */
4168
+ ORT_API2_STATUS(Logger_LogMessage, _In_ const OrtLogger* logger, OrtLoggingLevel log_severity_level,
4169
+ _In_z_ const char* message, _In_z_ const ORTCHAR_T* file_path, int line_number,
4170
+ _In_z_ const char* func_name);
4171
+
4172
+ /** \brief Get the logging severity level of the ::OrtLogger.
4173
+ *
4174
+ * Can be used in a custom operator to get the logging serverity level of the ::OrtLogger associated with
4175
+ * the ::OrtKernelInfo.
4176
+ *
4177
+ * \param[in] logger The ::OrtLogger instance.
4178
+ * \param[out] out Pointer to variable assigned with the logging severity level on success.
4179
+ *
4180
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4181
+ * \since Version 1.15
4182
+ */
4183
+ ORT_API2_STATUS(Logger_GetLoggingSeverityLevel, _In_ const OrtLogger* logger, _Out_ OrtLoggingLevel* out);
4184
+
4185
+ /// @}
4186
+
4187
+ /** \brief Get a ::OrtValue tensor stored as a constant initializer in the graph node.
4188
+ *
4189
+ * Used in the CreateKernel callback of an OrtCustomOp to get a tensor value.
4190
+ *
4191
+ * \param[in] info ::OrtKernelInfo instance.
4192
+ * \param[in] index The node index.
4193
+ * \param[out] is_constant Is it a constant node input or not.
4194
+ * \param[out] out The OrtValue tensor value.
4195
+ *
4196
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4197
+ *
4198
+ * \since Version 1.15.
4199
+ */
4200
+ ORT_API2_STATUS(KernelInfoGetConstantInput_tensor, _In_ const OrtKernelInfo* info, size_t index, _Out_ int* is_constant, _Outptr_ const OrtValue** out);
4201
+
4202
+ /** \brief Get Optional Type information from an ::OrtTypeInfo
4203
+ *
4204
+ * This augments ::OrtTypeInfo to return an ::OrtOptionalTypeInfo when the type is optional.
4205
+ * The OrtOptionalTypeInfo also has a nested ::OrtTypeInfo that describes the type of the optional value.
4206
+ * ::OrtOptionalTypeInfo type can only appear within model metadata to describe inputs/outputs.
4207
+ * The actual OrtValues that are supplied in place of optional type inputs should contain
4208
+ * specific type that is described by ::OrtOptionalTypeInfo.
4209
+ *
4210
+ * So the picture: ::OrtTypeInfo -> ::OrtOptionalTypeInfo -> ::OrtTypeInfo (describes the type that can be supplied
4211
+ * in place of the optional type when creating the actual ::OrtValue).
4212
+ *
4213
+ * \param[in] type_info
4214
+ * \param[out] out A pointer to the ::OrtOptionalTypeInfo. Do not free this value,
4215
+ * it is owned by OrtTypeInfo instance. When the type_info does not represent
4216
+ * optional type, nullptr is returned in out.
4217
+ *
4218
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4219
+ *
4220
+ * \since Version 1.15.
4221
+ */
4222
+ ORT_API2_STATUS(CastTypeInfoToOptionalTypeInfo, _In_ const OrtTypeInfo* type_info,
4223
+ _Outptr_result_maybenull_ const OrtOptionalTypeInfo** out);
4224
+
4225
+ /** \brief Get OrtTypeInfo for the allowed contained type from an ::OrtOptionalTypeInfo.
4226
+ *
4227
+ * This augments ::OrtOptionalTypeInfo to return an ::OrtTypeInfo for the contained type.
4228
+ * The OrtOptionalTypeInfo has a nested ::OrtTypeInfo that describes the type of the optional value.
4229
+ * ::OrtOptionalTypeInfo type can only appear within model metadata to describe inputs/outputs.
4230
+ * The actual OrtValues that are supplied in place of optional type inputs should contain
4231
+ * specific type that is described by the returned ::OrtTypeInfo.
4232
+ *
4233
+ * \param[in] optional_type_info
4234
+ * \param[out] out A pointer to the ::OrtTypeInfo for what the optional value could be.
4235
+ * it is owned by OrtOptionalTypeInfo instance.
4236
+ *
4237
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4238
+ *
4239
+ * \since Version 1.15.
4240
+ */
4241
+ ORT_API2_STATUS(GetOptionalContainedTypeInfo, _In_ const OrtOptionalTypeInfo* optional_type_info,
4242
+ _Outptr_ OrtTypeInfo** out);
4243
+
4244
+ /** \brief Set a single string in a string tensor
4245
+ * Do not zero terminate the string data.
4246
+ *
4247
+ * \param[in] value A string tensor
4248
+ * \param[in] index - flat index of the element
4249
+ * \param[in] length_in_bytes length of the buffer in utf-8 bytes (without the null terminator)
4250
+ * \param[inout] buffer - address of return value
4251
+ *
4252
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4253
+ */
4254
+ ORT_API2_STATUS(GetResizedStringTensorElementBuffer, _Inout_ OrtValue* value, _In_ size_t index, _In_ size_t length_in_bytes, _Inout_ char** buffer);
4255
+
4256
+ /** \brief Get Allocator from KernelContext for a specific memoryInfo. Please use C API ReleaseAllocator to release out object
4257
+ *
4258
+ * \param[in] context OrtKernelContext instance
4259
+ * \param[in] mem_info OrtMemoryInfo instance
4260
+ * \param[out] out A pointer to OrtAllocator.
4261
+ *
4262
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4263
+ *
4264
+ * \since Version 1.15.
4265
+ */
4266
+ ORT_API2_STATUS(KernelContext_GetAllocator, _In_ const OrtKernelContext* context, _In_ const OrtMemoryInfo* mem_info, _Outptr_ OrtAllocator** out);
4267
+
4268
+ /** \brief Returns a null terminated string of the build info including git info and cxx flags
4269
+ *
4270
+ * \return UTF-8 encoded version string. Do not deallocate the returned buffer.
4271
+ *
4272
+ * \since Version 1.15.
4273
+ */
4274
+ const char*(ORT_API_CALL* GetBuildInfoString)(void);
4275
+
4276
+ /// \name OrtROCMProviderOptions
4277
+ /// @{
4278
+
4279
+ /** \brief Create an OrtROCMProviderOptions
4280
+ *
4281
+ * \param[out] out Newly created ::OrtROCMProviderOptions. Must be released with OrtApi::ReleaseROCMProviderOptions
4282
+ *
4283
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4284
+ *
4285
+ * \since Version 1.16.
4286
+ */
4287
+ ORT_API2_STATUS(CreateROCMProviderOptions, _Outptr_ OrtROCMProviderOptions** out);
4288
+
4289
+ /** \brief Set options in a ROCm Execution Provider.
4290
+ *
4291
+ * Please refer to https://onnxruntime.ai/docs/execution-providers/ROCm-ExecutionProvider.html
4292
+ * to know the available keys and values. Key should be in null terminated string format of the member of
4293
+ * ::OrtROCMProviderOptions and value should be its related range.
4294
+ *
4295
+ * For example, key="device_id" and value="0"
4296
+ *
4297
+ * \param[in] rocm_options
4298
+ * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys
4299
+ * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values
4300
+ * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays
4301
+ *
4302
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4303
+ *
4304
+ * \since Version 1.16.
4305
+ */
4306
+ ORT_API2_STATUS(UpdateROCMProviderOptions, _Inout_ OrtROCMProviderOptions* rocm_options,
4307
+ _In_reads_(num_keys) const char* const* provider_options_keys,
4308
+ _In_reads_(num_keys) const char* const* provider_options_values,
4309
+ _In_ size_t num_keys);
4310
+
4311
+ /**
4312
+ * Get serialized ROCm provider options string.
4313
+ *
4314
+ * For example, "device_id=0;arena_extend_strategy=0;......"
4315
+ *
4316
+ * \param rocm_options - OrtROCMProviderOptions instance
4317
+ * \param allocator - a ptr to an instance of OrtAllocator obtained with CreateAllocator() or GetAllocatorWithDefaultOptions()
4318
+ * the specified allocator will be used to allocate continuous buffers for output strings and lengths.
4319
+ * \param ptr - is a UTF-8 null terminated string allocated using 'allocator'. The caller is responsible for using the same allocator to free it.
4320
+ *
4321
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4322
+ *
4323
+ * \since Version 1.16.
4324
+ */
4325
+ ORT_API2_STATUS(GetROCMProviderOptionsAsString, _In_ const OrtROCMProviderOptions* rocm_options, _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr);
4326
+
4327
+ /** \brief Release an ::OrtROCMProviderOptions
4328
+ *
4329
+ * \note This is an exception in the naming convention of other Release* functions, as the name of the method does not have the V2 suffix, but the type does
4330
+ *
4331
+ * \since Version 1.16.
4332
+ */
4333
+ void(ORT_API_CALL* ReleaseROCMProviderOptions)(_Frees_ptr_opt_ OrtROCMProviderOptions* input);
4334
+
4335
+ /** \brief Create an allocator with specific type and register it with the ::OrtEnv
4336
+ * This API enhance CreateAndRegisterAllocator that it can create an allocator with specific type, not just CPU allocator
4337
+ * Enables sharing the allocator between multiple sessions that use the same env instance.
4338
+ * Lifetime of the created allocator will be valid for the duration of the environment.
4339
+ * Returns an error if an allocator with the same ::OrtMemoryInfo is already registered.
4340
+ * \param[in] env OrtEnv instance
4341
+ * \param[in] provider_type ExecutionProvider type
4342
+ * \param[in] mem_info OrtMemoryInfo instance
4343
+ * \param[in] arena_cfg Arena configuration
4344
+ * \param[in] provider_options_keys key of the provider options map
4345
+ * \param[in] provider_options_values value of the provider options map
4346
+ * \param[in] num_keys Length of the provider options map
4347
+ */
4348
+ ORT_API2_STATUS(CreateAndRegisterAllocatorV2, _Inout_ OrtEnv* env, _In_ const char* provider_type, _In_ const OrtMemoryInfo* mem_info, _In_ const OrtArenaCfg* arena_cfg,
4349
+ _In_reads_(num_keys) const char* const* provider_options_keys, _In_reads_(num_keys) const char* const* provider_options_values, _In_ size_t num_keys);
4350
+
4351
+ /** \brief Run the model asynchronously in a thread owned by intra op thread pool
4352
+ *
4353
+ * \param[in] session
4354
+ * \param[in] run_options If nullptr, will use a default ::OrtRunOptions
4355
+ * \param[in] input_names Array of null terminated UTF8 encoded strings of the input names
4356
+ * \param[in] input Array of ::OrtValue%s of the input values
4357
+ * \param[in] input_len Number of elements in the input_names and inputs arrays
4358
+ * \param[in] output_names Array of null terminated UTF8 encoded strings of the output names
4359
+ * \param[in] output_names_len Number of elements in the output_names and outputs array
4360
+ * \param[out] output OrtValue* array of size output_names_len.
4361
+ * On calling RunAsync, output[i] could either be a null or a pointer to a preallocated OrtValue.
4362
+ * Later, the output array will be passed to run_async_callback with all null(s) filled with valid
4363
+ * OrtValue pointer(s) allocated by onnxruntime.
4364
+ * NOTE: it is customer's duty to finally release the output array and each of its member,
4365
+ * regardless of whether the member (OrtValue*) is allocated by onnxruntime or preallocated by the customer.
4366
+ * \param[in] run_async_callback Callback function on model run completion
4367
+ * \param[in] user_data User data that pass back to run_async_callback
4368
+ */
4369
+ ORT_API2_STATUS(RunAsync, _Inout_ OrtSession* session, _In_opt_ const OrtRunOptions* run_options,
4370
+ _In_reads_(input_len) const char* const* input_names,
4371
+ _In_reads_(input_len) const OrtValue* const* input, size_t input_len,
4372
+ _In_reads_(output_names_len) const char* const* output_names, size_t output_names_len,
4373
+ _Inout_updates_all_(output_names_len) OrtValue** output,
4374
+ _In_ RunAsyncCallbackFn run_async_callback, _In_opt_ void* user_data);
4375
+
4376
+ /**
4377
+ * Update TensorRT EP provider option where its data type is pointer, for example 'user_compute_stream'.
4378
+ * If the data type of the provider option can be represented by string please use UpdateTensorRTProviderOptions.
4379
+ *
4380
+ * Note: It's caller's responsibility to properly manage the lifetime of the instance pointed by this pointer.
4381
+ *
4382
+ * \param tensorrt_options - OrtTensorRTProviderOptionsV2 instance
4383
+ * \param key - Name of the provider option
4384
+ * \param value - A pointer to the instance that will be assigned to this provider option
4385
+ *
4386
+ * \since Version 1.16.
4387
+ */
4388
+ ORT_API2_STATUS(UpdateTensorRTProviderOptionsWithValue, _Inout_ OrtTensorRTProviderOptionsV2* tensorrt_options, _In_ const char* key, _In_ void* value);
4389
+
4390
+ /**
4391
+ * Get TensorRT EP provider option where its data type is pointer.
4392
+ * If the data type of the provider option can be represented by string please use GetTensorRTProviderOptionsAsString.
4393
+ *
4394
+ * \param tensorrt_options - OrtTensorRTProviderOptionsV2 instance
4395
+ * \param key - Name of the provider option
4396
+ * \param ptr - A pointer to the instance that is kept by the provider option
4397
+ *
4398
+ * \since Version 1.16.
4399
+ */
4400
+ ORT_API2_STATUS(GetTensorRTProviderOptionsByName, _In_ const OrtTensorRTProviderOptionsV2* tensorrt_options, _In_ const char* key, _Outptr_ void** ptr);
4401
+
4402
+ /**
4403
+ * Update CUDA EP provider option where its data type is pointer, for example 'user_compute_stream'.
4404
+ * If the data type of the provider option can be represented by string please use UpdateCUDAProviderOptions.
4405
+ *
4406
+ * Note: It's caller's responsibility to properly manage the lifetime of the instance pointed by this pointer.
4407
+ *
4408
+ * \param cuda_options - OrtCUDAProviderOptionsV2 instance
4409
+ * \param key - Name of the provider option
4410
+ * \param value - A pointer to the instance that will be assigned to this provider option
4411
+ *
4412
+ * \since Version 1.16.
4413
+ */
4414
+ ORT_API2_STATUS(UpdateCUDAProviderOptionsWithValue, _Inout_ OrtCUDAProviderOptionsV2* cuda_options, _In_ const char* key, _In_ void* value);
4415
+
4416
+ /**
4417
+ * Get CUDA EP provider option where its data type is pointer.
4418
+ * If the data type of the provider option can be represented by string please use GetCUDAProviderOptionsAsString.
4419
+ *
4420
+ * \param cuda_options - OrtCUDAProviderOptionsV2 instance
4421
+ * \param key - Name of the provider option
4422
+ * \param ptr - A pointer to the instance that is kept by the provider option
4423
+ *
4424
+ * \since Version 1.16.
4425
+ */
4426
+ ORT_API2_STATUS(GetCUDAProviderOptionsByName, _In_ const OrtCUDAProviderOptionsV2* cuda_options, _In_ const char* key, _Outptr_ void** ptr);
4427
+
4428
+ /**
4429
+ * Get a EP resource.
4430
+ * E.g. a cuda stream or a cublas handle
4431
+ *
4432
+ * \param context - Kernel context
4433
+ * \param resouce_version - Version of the resource
4434
+ * \param resource_id - Type of resource
4435
+ * \param resource - A pointer to returned resource
4436
+ *
4437
+ * \since Version 1.16.
4438
+ */
4439
+ ORT_API2_STATUS(KernelContext_GetResource, _In_ const OrtKernelContext* context, _In_ int resouce_version, _In_ int resource_id, _Outptr_ void** resource);
4440
+
4441
+ /** \brief Set user logging function
4442
+ *
4443
+ * By default the logger created by the CreateEnv* functions is used to create the session logger as well.
4444
+ * This function allows a user to override this default session logger with a logger of their own choosing. This way
4445
+ * the user doesn't have to create a separate environment with a custom logger. This addresses the problem when
4446
+ * the user already created an env but now wants to use a different logger for a specific session (for debugging or
4447
+ * other reasons).
4448
+ *
4449
+ * \param[in] options
4450
+ * \param[in] user_logging_function A pointer to a logging function.
4451
+ * \param[in] user_logging_param A pointer to arbitrary data passed as the ::OrtLoggingFunction `param` parameter to
4452
+ * `user_logging_function`. This parameter is optional.
4453
+ *
4454
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4455
+ *
4456
+ * \since Version 1.17.
4457
+ */
4458
+ ORT_API2_STATUS(SetUserLoggingFunction, _Inout_ OrtSessionOptions* options,
4459
+ _In_ OrtLoggingFunction user_logging_function, _In_opt_ void* user_logging_param);
4460
+
4461
+ /**
4462
+ * Get number of input from OrtShapeInferContext
4463
+ *
4464
+ * \param[in] context
4465
+ * \param[out] out The number of inputs
4466
+ *
4467
+ * \since Version 1.17.
4468
+ */
4469
+ ORT_API2_STATUS(ShapeInferContext_GetInputCount, _In_ const OrtShapeInferContext* context, _Out_ size_t* out);
4470
+
4471
+ /**
4472
+ * Get type and shape info of an input
4473
+ *
4474
+ * \param[in] context
4475
+ * \param[in] index The index of the input
4476
+ * \param[out] info Type shape info of the input
4477
+ *
4478
+ * \since Version 1.17.
4479
+ */
4480
+ ORT_API2_STATUS(ShapeInferContext_GetInputTypeShape, _In_ const OrtShapeInferContext* context, _In_ size_t index, _Outptr_ OrtTensorTypeAndShapeInfo** info);
4481
+
4482
+ /**
4483
+ * Get attribute from OrtShapeInferContext. Note that OrtShapeInferContext is a per-node context, one could only read attribute from current node.
4484
+ *
4485
+ * \param[in] context
4486
+ * \param[in] attr_name Name of the attribute
4487
+ * \param[out] attr Handle of the attribute fetched
4488
+ *
4489
+ * \since Version 1.17.
4490
+ */
4491
+ ORT_API2_STATUS(ShapeInferContext_GetAttribute, _In_ const OrtShapeInferContext* context, _In_ const char* attr_name, _Outptr_ const OrtOpAttr** attr);
4492
+
4493
+ /**
4494
+ * Set type and shape info of an ouput
4495
+ *
4496
+ * \param[in] context
4497
+ * \param[in] index The index of the ouput
4498
+ * \param[out] info Type shape info of the output
4499
+ *
4500
+ * \since Version 1.17.
4501
+ */
4502
+ ORT_API2_STATUS(ShapeInferContext_SetOutputTypeShape, _In_ const OrtShapeInferContext* context, _In_ size_t index, _In_ const OrtTensorTypeAndShapeInfo* info);
4503
+
4504
+ /**
4505
+ * Set symbolic shape to type shape info
4506
+ *
4507
+ * \param[in] info Type shape info
4508
+ * \param[in] dim_params Symbolic strings
4509
+ * \param[in] dim_params_length Number of strings
4510
+ *
4511
+ * \since Version 1.17.
4512
+ */
4513
+ ORT_API2_STATUS(SetSymbolicDimensions, _In_ OrtTensorTypeAndShapeInfo* info, _In_ const char* dim_params[], _In_ size_t dim_params_length);
4514
+
4515
+ /**
4516
+ * Read contents of an attribute to data
4517
+ *
4518
+ * \param[in] op_attr
4519
+ * \param[in] type Attribute type
4520
+ * \param[out] data Memory address to save raw content of the attribute
4521
+ * \param[in] len Number of bytes allowed to store in data
4522
+ * \param[out] out Number of bytes required to save the data when the call failed, or the real number of bytes saved to data on success
4523
+ *
4524
+ * \since Version 1.17.
4525
+ */
4526
+ ORT_API2_STATUS(ReadOpAttr, _In_ const OrtOpAttr* op_attr, _In_ OrtOpAttrType type, _Inout_ void* data, _In_ size_t len, _Out_ size_t* out);
4527
+
4528
+ /** \brief Set whether to use deterministic compute.
4529
+ *
4530
+ * Default is false. If set to true, this will enable deterministic compute for GPU kernels where possible.
4531
+ * Note that this most likely will have a performance cost.
4532
+ *
4533
+ * \param[in] options
4534
+ * \param[in] value
4535
+ *
4536
+ * \since Version 1.17.
4537
+ */
4538
+ ORT_API2_STATUS(SetDeterministicCompute, _Inout_ OrtSessionOptions* options, bool value);
4539
+
4540
+ /**
4541
+ * Run fn in parallel
4542
+ *
4543
+ * \param[in] context
4544
+ * \param[in] fn Function accepting usr_data and an integer as iterator
4545
+ * \param[in] total The number of times fn is to be invoked
4546
+ * \param[in] num_batch Number of batches by which the "total" is to be divided in maximum. When zero, there is no limit
4547
+ * \param[in] usr_data User data to be passed back to fn
4548
+ *
4549
+ * \since Version 1.17.
4550
+ */
4551
+ ORT_API2_STATUS(KernelContext_ParallelFor, _In_ const OrtKernelContext* context, _In_ void (*fn)(void*, size_t), _In_ size_t total, _In_ size_t num_batch, _In_ void* usr_data);
4552
+
4553
+ /** \brief Append OpenVINO execution provider to the session options
4554
+ *
4555
+ * If OpenVINO is not available (due to a non OpenVINO enabled build, or if OpenVINO is not installed on the system), this function will fail.
4556
+ *
4557
+ * \param[in] options
4558
+ * \param[in] provider_options_keys
4559
+ * \param[in] provider_options_values
4560
+ * \param[in] num_keys
4561
+ *
4562
+ * \snippet{doc} snippets.dox OrtStatus Return Value
4563
+ */
4564
+ ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_OpenVINO_V2,
4565
+ _In_ OrtSessionOptions* options,
4566
+ _In_reads_(num_keys) const char* const* provider_options_keys,
4567
+ _In_reads_(num_keys) const char* const* provider_options_values,
4568
+ _In_ size_t num_keys);
4569
+ };
4570
+
4571
+ /*
4572
+ * Steps to use a custom op:
4573
+ * 1 Create an OrtCustomOpDomain with the domain name used by the custom ops
4574
+ * 2 Create an OrtCustomOp structure for each op and add them to the domain
4575
+ * 3 Call OrtAddCustomOpDomain to add the custom domain of ops to the session options
4576
+ */
4577
+
4578
+ // Specifies some characteristics of inputs/outputs of custom ops:
4579
+ // Specify if the inputs/outputs are one of:
4580
+ // 1) Non-optional (input/output must be present in the node)
4581
+ // 2) Optional (input/output may be absent in the node)
4582
+ // 3) Variadic: A variadic input or output specifies N (i.e., the minimum arity) or more operands.
4583
+ // Only the last input or output of a custom op may be marked as variadic.
4584
+ // The homogeneity of the variadic input or output determines whether all operands must be of the same
4585
+ // tensor element type.
4586
+ typedef enum OrtCustomOpInputOutputCharacteristic {
4587
+ INPUT_OUTPUT_REQUIRED = 0,
4588
+ INPUT_OUTPUT_OPTIONAL,
4589
+ INPUT_OUTPUT_VARIADIC,
4590
+ } OrtCustomOpInputOutputCharacteristic;
4591
+
4592
+ /*
4593
+ * The OrtCustomOp structure defines a custom op's schema and its kernel callbacks. The callbacks are filled in by
4594
+ * the implementor of the custom op.
4595
+ */
4596
+ struct OrtCustomOp {
4597
+ uint32_t version; // Must be initialized to ORT_API_VERSION
4598
+
4599
+ // This callback creates the kernel, which is a user defined
4600
+ // parameter that is passed to the Kernel* callbacks below. It is
4601
+ // recommended to use CreateKernelV2 which allows for a safe error
4602
+ // propagation by returning an OrtStatusPtr.
4603
+ void*(ORT_API_CALL* CreateKernel)(_In_ const struct OrtCustomOp* op, _In_ const OrtApi* api,
4604
+ _In_ const OrtKernelInfo* info);
4605
+
4606
+ // Returns the name of the op
4607
+ const char*(ORT_API_CALL* GetName)(_In_ const struct OrtCustomOp* op);
4608
+
4609
+ // Returns the type of the execution provider, return nullptr to use CPU execution provider
4610
+ const char*(ORT_API_CALL* GetExecutionProviderType)(_In_ const struct OrtCustomOp* op);
4611
+
4612
+ // Returns the count and types of the input & output tensors
4613
+ ONNXTensorElementDataType(ORT_API_CALL* GetInputType)(_In_ const struct OrtCustomOp* op, _In_ size_t index);
4614
+ size_t(ORT_API_CALL* GetInputTypeCount)(_In_ const struct OrtCustomOp* op);
4615
+ ONNXTensorElementDataType(ORT_API_CALL* GetOutputType)(_In_ const struct OrtCustomOp* op, _In_ size_t index);
4616
+ size_t(ORT_API_CALL* GetOutputTypeCount)(_In_ const struct OrtCustomOp* op);
4617
+
4618
+ // Perform a computation step. It is recommended to use
4619
+ // KernelComputeV2 which allows for a safe error propagation by
4620
+ // returning an OrtStatusPtr.
4621
+ void(ORT_API_CALL* KernelCompute)(_In_ void* op_kernel, _In_ OrtKernelContext* context);
4622
+ void(ORT_API_CALL* KernelDestroy)(_In_ void* op_kernel);
4623
+
4624
+ // Returns the characteristics of the input & output tensors
4625
+ OrtCustomOpInputOutputCharacteristic(ORT_API_CALL* GetInputCharacteristic)(_In_ const struct OrtCustomOp* op, _In_ size_t index);
4626
+ OrtCustomOpInputOutputCharacteristic(ORT_API_CALL* GetOutputCharacteristic)(_In_ const struct OrtCustomOp* op, _In_ size_t index);
4627
+
4628
+ // Returns the memory type of the input tensors. This API allows the custom op
4629
+ // to place the inputs on specific devices. By default, it returns
4630
+ // OrtMemTypeDefault, which means the input is placed on the default device for
4631
+ // the execution provider. If the inputs need to be with different memory tyeps,
4632
+ // this function can be overridden to return the specific memory types.
4633
+ OrtMemType(ORT_API_CALL* GetInputMemoryType)(_In_ const struct OrtCustomOp* op, _In_ size_t index);
4634
+
4635
+ // Returns the minimum number of input arguments expected for the variadic input.
4636
+ // Applicable only for custom ops that have a variadic input.
4637
+ int(ORT_API_CALL* GetVariadicInputMinArity)(_In_ const struct OrtCustomOp* op);
4638
+
4639
+ // Returns true (non-zero) if all arguments of a variadic input have to be of the same type (homogeneous),
4640
+ // and false (zero) otherwise.
4641
+ // Applicable only for custom ops that have a variadic input.
4642
+ int(ORT_API_CALL* GetVariadicInputHomogeneity)(_In_ const struct OrtCustomOp* op);
4643
+
4644
+ // Returns the minimum number of output values expected for the variadic output.
4645
+ // Applicable only for custom ops that have a variadic output.
4646
+ int(ORT_API_CALL* GetVariadicOutputMinArity)(_In_ const struct OrtCustomOp* op);
4647
+
4648
+ // Returns true (non-zero) if all outputs values of a variadic output have to be of the same type (homogeneous),
4649
+ // and false (zero) otherwise.
4650
+ // Applicable only for custom ops that have a variadic output.
4651
+ int(ORT_API_CALL* GetVariadicOutputHomogeneity)(_In_ const struct OrtCustomOp* op);
4652
+
4653
+ // Create the kernel state which is passed to each compute call.
4654
+ OrtStatusPtr(ORT_API_CALL* CreateKernelV2)(_In_ const struct OrtCustomOp* op, _In_ const OrtApi* api,
4655
+ _In_ const OrtKernelInfo* info,
4656
+ _Out_ void** kernel);
4657
+
4658
+ // Perform the computation step.
4659
+ OrtStatusPtr(ORT_API_CALL* KernelComputeV2)(_In_ void* op_kernel, _In_ OrtKernelContext* context);
4660
+
4661
+ OrtStatusPtr(ORT_API_CALL* InferOutputShapeFn)(_In_ const struct OrtCustomOp* op, _In_ OrtShapeInferContext*);
4662
+
4663
+ // Get start range
4664
+ int(ORT_API_CALL* GetStartVersion)(_In_ const struct OrtCustomOp* op);
4665
+ int(ORT_API_CALL* GetEndVersion)(_In_ const struct OrtCustomOp* op);
4666
+ };
4667
+
4668
+ /*
4669
+ * This is the old way to add the CUDA provider to the session, please use SessionOptionsAppendExecutionProvider_CUDA above to access the latest functionality
4670
+ * This function always exists, but will only succeed if Onnxruntime was built with CUDA support and the CUDA provider shared library exists
4671
+ *
4672
+ * \param device_id CUDA device id, starts from zero.
4673
+ */
4674
+ ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_CUDA, _In_ OrtSessionOptions* options, int device_id);
4675
+
4676
+ /*
4677
+ * This is the old way to add the ROCm provider to the session, please use
4678
+ * SessionOptionsAppendExecutionProvider_ROCM above to access the latest functionality
4679
+ * This function always exists, but will only succeed if Onnxruntime was built with
4680
+ * HIP support and the ROCm provider shared library exists
4681
+ *
4682
+ * \param device_id HIP device id, starts from zero.
4683
+ */
4684
+ ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_ROCM, _In_ OrtSessionOptions* options, int device_id);
4685
+
4686
+ /*
4687
+ * This is the old way to add the MIGraphX provider to the session, please use
4688
+ * SessionOptionsAppendExecutionProvider_MIGraphX above to access the latest functionality
4689
+ * This function always exists, but will only succeed if Onnxruntime was built with
4690
+ * HIP support and the MIGraphX provider shared library exists
4691
+ *
4692
+ * \param device_id HIP device id, starts from zero.
4693
+ */
4694
+ ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_MIGraphX, _In_ OrtSessionOptions* options, int device_id);
4695
+
4696
+ /*
4697
+ * This is the old way to add the oneDNN provider to the session, please use
4698
+ * SessionOptionsAppendExecutionProvider_oneDNN above to access the latest functionality
4699
+ * This function always exists, but will only succeed if Onnxruntime was built with
4700
+ * oneDNN support and the oneDNN provider shared library exists
4701
+ *
4702
+ * \param use_arena zero: false. non-zero: true.
4703
+ */
4704
+ ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Dnnl, _In_ OrtSessionOptions* options, int use_arena);
4705
+
4706
+ /*
4707
+ * This is the old way to add the TensorRT provider to the session, please use SessionOptionsAppendExecutionProvider_TensorRT_V2 above to access the latest functionality
4708
+ * This function always exists, but will only succeed if Onnxruntime was built with TensorRT support and the TensorRT provider shared library exists
4709
+ *
4710
+ * \param device_id CUDA device id, starts from zero.
4711
+ */
4712
+ ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Tensorrt, _In_ OrtSessionOptions* options, int device_id);
4713
+
4714
+ #ifdef __cplusplus
4715
+ }
4716
+ #endif
4717
+ /// @}