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