1 modulebindbc.onnxruntime.v12.types;
2 3 importcore.stdc.stddef;
4 5 extern (C):
6 7 // This value is used in structures passed to ORT so that a newer version of ORT will still work with them8 enumORT_API_VERSION = 2;
9 10 // SAL2 Definitions11 12 // Define ORT_DLL_IMPORT if your program is dynamically linked to Ort.13 // dllexport is not used, we use a .def file.14 15 aliasORTCHAR_T = wchar_t;
16 17 // Any pointer marked with _In_ or _Out_, cannot be NULL.18 19 // Windows users should use unicode paths when possible to bypass the MAX_PATH limitation20 // Every pointer marked with _In_ or _Out_, cannot be NULL. Caller should ensure that.21 // for ReleaseXXX(...) functions, they can accept NULL pointer.22 23 // Copied from TensorProto::DataType24 // Currently, Ort doesn't support complex64, complex128, bfloat16 types25 enumONNXTensorElementDataType26 {
27 ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED = 0,
28 ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT = 1, // maps to c type float29 ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8 = 2, // maps to c type uint8_t30 ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8 = 3, // maps to c type int8_t31 ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16 = 4, // maps to c type uint16_t32 ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16 = 5, // maps to c type int16_t33 ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32 = 6, // maps to c type int32_t34 ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64 = 7, // maps to c type int64_t35 ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING = 8, // maps to c++ type std::string36 ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL = 9,
37 ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16 = 10,
38 ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE = 11, // maps to c type double39 ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32 = 12, // maps to c type uint32_t40 ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64 = 13, // maps to c type uint64_t41 ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX64 = 14, // complex with float32 real and imaginary components42 ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX128 = 15, // complex with float64 real and imaginary components43 ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16 = 16// Non-IEEE floating-point format based on IEEE754 single-precision44 }
45 46 // Synced with onnx TypeProto oneof47 enumONNXType48 {
49 ONNX_TYPE_UNKNOWN = 0,
50 ONNX_TYPE_TENSOR = 1,
51 ONNX_TYPE_SEQUENCE = 2,
52 ONNX_TYPE_MAP = 3,
53 ONNX_TYPE_OPAQUE = 4,
54 ONNX_TYPE_SPARSETENSOR = 555 }
56 57 enumOrtLoggingLevel58 {
59 ORT_LOGGING_LEVEL_VERBOSE = 0,
60 ORT_LOGGING_LEVEL_INFO = 1,
61 ORT_LOGGING_LEVEL_WARNING = 2,
62 ORT_LOGGING_LEVEL_ERROR = 3,
63 ORT_LOGGING_LEVEL_FATAL = 464 }
65 66 enumOrtErrorCode67 {
68 ORT_OK = 0,
69 ORT_FAIL = 1,
70 ORT_INVALID_ARGUMENT = 2,
71 ORT_NO_SUCHFILE = 3,
72 ORT_NO_MODEL = 4,
73 ORT_ENGINE_ERROR = 5,
74 ORT_RUNTIME_EXCEPTION = 6,
75 ORT_INVALID_PROTOBUF = 7,
76 ORT_MODEL_LOADED = 8,
77 ORT_NOT_IMPLEMENTED = 9,
78 ORT_INVALID_GRAPH = 10,
79 ORT_EP_FAIL = 1180 }
81 82 // __VA_ARGS__ on Windows and Linux are different83 84 // Used in *.cc files. Almost as same as ORT_API_STATUS, except without ORT_MUST_USE_RESULT85 86 // ORT_API(void, OrtRelease##X, _Frees_ptr_opt_ Ort##X* input);87 88 // The actual types defined have an Ort prefix89 structOrtEnv;
90 structOrtStatus; // nullptr for Status* indicates success91 structOrtMemoryInfo;
92 structOrtSession; //Don't call OrtReleaseSession from Dllmain (because session owns a thread pool)93 structOrtValue;
94 structOrtRunOptions;
95 structOrtTypeInfo;
96 structOrtTensorTypeAndShapeInfo;
97 structOrtSessionOptions;
98 structOrtCustomOpDomain;
99 structOrtMapTypeInfo;
100 structOrtSequenceTypeInfo;
101 structOrtModelMetadata;
102 103 // When passing in an allocator to any ORT function, be sure that the allocator object104 // is not destroyed until the last allocated object using it is freed.105 structOrtAllocator106 {
107 uintversion_; // Initialize to ORT_API_VERSION108 void* function(OrtAllocator* this_, size_tsize) Alloc;
109 voidfunction(OrtAllocator* this_, void* p) Free;
110 const(OrtMemoryInfo)* function(const(OrtAllocator)* this_) Info;
111 }
112 113 aliasOrtLoggingFunction = voidfunction(void* param, OrtLoggingLevelseverity,
114 const(char)* category, const(char)* logid,
115 const(char)* code_location, const(char)* message);
116 117 // Set Graph optimization level.118 // Refer https://github.com/microsoft/onnxruntime/blob/master/docs/ONNX_Runtime_Graph_Optimizations.md119 // for in-depth undersrtanding of Graph Optimizations in ORT120 enumGraphOptimizationLevel121 {
122 ORT_DISABLE_ALL = 0,
123 ORT_ENABLE_BASIC = 1,
124 ORT_ENABLE_EXTENDED = 2,
125 ORT_ENABLE_ALL = 99126 }
127 128 enumExecutionMode129 {
130 ORT_SEQUENTIAL = 0,
131 ORT_PARALLEL = 1132 }
133 134 structOrtKernelInfo;
135 structOrtKernelContext;
136 137 enumOrtAllocatorType138 {
139 Invalid = -1,
140 OrtDeviceAllocator = 0,
141 OrtArenaAllocator = 1142 }
143 144 /**
145 * memory types for allocator, exec provider specific types should be extended in each provider
146 * Whenever this struct is updated, please also update the MakeKey function in onnxruntime/core/framework/execution_provider.cc
147 */148 enumOrtMemType149 {
150 OrtMemTypeCPUInput = -2, // Any CPU memory used by non-CPU execution provider151 OrtMemTypeCPUOutput = -1, // CPU accessible memory outputted by non-CPU execution provider, i.e. CUDA_PINNED152 OrtMemTypeCPU = OrtMemTypeCPUOutput, // temporary CPU accessible memory allocated by non-CPU execution provider, i.e. CUDA_PINNED153 OrtMemTypeDefault = 0// the default allocator for execution provider154 }
155 156 structOrtApiBase157 {
158 const(OrtApi)* function(uintversion_) GetApi; // Pass in ORT_API_VERSION159 // nullptr will be returned if the version is unsupported, for example when using a runtime older than this header file160 161 const(char)* GetVersionString;
162 }
163 164 structOrtApi165 {
166 /**
167 * \param msg A null-terminated string. Its content will be copied into the newly created OrtStatus
168 */169 OrtStatus* function(OrtErrorCodecode, const(char)* msg) CreateStatus;
170 171 OrtErrorCodefunction(const(OrtStatus)* status) GetErrorCode;
172 173 /**
174 * \param status must not be NULL
175 * \return The error message inside the `status`. Do not free the returned value.
176 */177 const(char)* function(const(OrtStatus)* status) GetErrorMessage;
178 179 /**
180 * \param out Should be freed by `OrtReleaseEnv` after use
181 */182 OrtStatus* function(OrtLoggingLeveldefault_logging_level, const(char)* logid, OrtEnv** out_) CreateEnv;
183 184 /**
185 * \param out Should be freed by `OrtReleaseEnv` after use
186 */187 OrtStatus* function(OrtLoggingFunctionlogging_function, void* logger_param,
188 OrtLoggingLeveldefault_warning_level, const(char)* logid, OrtEnv** out_) CreateEnvWithCustomLogger;
189 190 // Platform telemetry events are on by default since they are lightweight. You can manually turn them off.191 OrtStatus* function(const(OrtEnv)* env) EnableTelemetryEvents;
192 OrtStatus* function(const(OrtEnv)* env) DisableTelemetryEvents;
193 194 // TODO: document the path separator convention? '/' vs '\'195 // TODO: should specify the access characteristics of model_path. Is this read only during the196 // execution of CreateSession, or does the OrtSession retain a handle to the file/directory197 // and continue to access throughout the OrtSession lifetime?198 // What sort of access is needed to model_path : read or read/write?199 OrtStatus* function(const(OrtEnv)* env, const(wchar_t)* model_path,
200 const(OrtSessionOptions)* options, OrtSession** out_) CreateSession;
201 202 OrtStatus* function(const(OrtEnv)* env, const(void)* model_data,
203 size_tmodel_data_length, const(OrtSessionOptions)* options, OrtSession** out_) CreateSessionFromArray;
204 205 OrtStatus* function(OrtSession* sess, const(OrtRunOptions)* run_options,
206 const(char*)* input_names, const(OrtValue*)* input, size_tinput_len,
207 const(char*)* output_names, size_toutput_names_len, OrtValue** output) Run;
208 209 /**
210 * \return A pointer of the newly created object. The pointer should be freed by OrtReleaseSessionOptions after use
211 */212 OrtStatus* function(OrtSessionOptions** options) CreateSessionOptions;
213 214 // Set filepath to save optimized model after graph level transformations.215 OrtStatus* function(OrtSessionOptions* options, const(wchar_t)* optimized_model_filepath) SetOptimizedModelFilePath;
216 217 // create a copy of an existing OrtSessionOptions218 OrtStatus* function(const(OrtSessionOptions)* in_options, OrtSessionOptions** out_options) CloneSessionOptions;
219 220 // Controls whether you want to execute operators in your graph sequentially or in parallel. Usually when the model221 // has many branches, setting this option to ExecutionMode.ORT_PARALLEL will give you better performance.222 // See [docs/ONNX_Runtime_Perf_Tuning.md] for more details.223 OrtStatus* function(OrtSessionOptions* options, ExecutionModeexecution_mode) SetSessionExecutionMode;
224 225 // Enable profiling for this session.226 OrtStatus* function(OrtSessionOptions* options, const(wchar_t)* profile_file_prefix) EnableProfiling;
227 OrtStatus* function(OrtSessionOptions* options) DisableProfiling;
228 229 // Enable the memory pattern optimization.230 // The idea is if the input shapes are the same, we could trace the internal memory allocation231 // and generate a memory pattern for future request. So next time we could just do one allocation232 // with a big chunk for all the internal memory allocation.233 // Note: memory pattern optimization is only available when SequentialExecution enabled.234 OrtStatus* function(OrtSessionOptions* options) EnableMemPattern;
235 OrtStatus* function(OrtSessionOptions* options) DisableMemPattern;
236 237 // Enable the memory arena on CPU238 // Arena may pre-allocate memory for future usage.239 // set this option to false if you don't want it.240 OrtStatus* function(OrtSessionOptions* options) EnableCpuMemArena;
241 OrtStatus* function(OrtSessionOptions* options) DisableCpuMemArena;
242 243 // < logger id to use for session output244 OrtStatus* function(OrtSessionOptions* options, const(char)* logid) SetSessionLogId;
245 246 // < applies to session load, initialization, etc247 OrtStatus* function(OrtSessionOptions* options, intsession_log_verbosity_level) SetSessionLogVerbosityLevel;
248 OrtStatus* function(OrtSessionOptions* options, intsession_log_severity_level) SetSessionLogSeverityLevel;
249 250 OrtStatus* function(OrtSessionOptions* options, GraphOptimizationLevelgraph_optimization_level) SetSessionGraphOptimizationLevel;
251 252 // Sets the number of threads used to parallelize the execution within nodes253 // A value of 0 means ORT will pick a default254 OrtStatus* function(OrtSessionOptions* options, intintra_op_num_threads) SetIntraOpNumThreads;
255 256 // Sets the number of threads used to parallelize the execution of the graph (across nodes)257 // If sequential execution is enabled this value is ignored258 // A value of 0 means ORT will pick a default259 OrtStatus* function(OrtSessionOptions* options, intinter_op_num_threads) SetInterOpNumThreads;
260 261 /*
262 Create a custom op domain. After all sessions using it are released, call OrtReleaseCustomOpDomain
263 */264 OrtStatus* function(const(char)* domain, OrtCustomOpDomain** out_) CreateCustomOpDomain;
265 266 /*
267 * Add custom ops to the OrtCustomOpDomain
268 * Note: The OrtCustomOp* pointer must remain valid until the OrtCustomOpDomain using it is released
269 */270 OrtStatus* function(OrtCustomOpDomain* custom_op_domain, OrtCustomOp* op) CustomOpDomain_Add;
271 272 /*
273 * Add a custom op domain to the OrtSessionOptions
274 * Note: The OrtCustomOpDomain* must not be deleted until the sessions using it are released
275 */276 OrtStatus* function(OrtSessionOptions* options, OrtCustomOpDomain* custom_op_domain) AddCustomOpDomain;
277 278 /*
279 * Loads a DLL named 'library_path' and looks for this entry point:
280 * OrtStatus* RegisterCustomOps(OrtSessionOptions * options, const OrtApiBase* api);
281 * It then passes in the provided session options to this function along with the api base.
282 * 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
283 * session options are destroyed, or if an error occurs and it is non null.
284 */285 OrtStatus* function(OrtSessionOptions* options, const(char)* library_path,
286 void** library_handle) RegisterCustomOpsLibrary;
287 288 /**
289 * To use additional providers, you must build ORT with the extra providers enabled. Then call one of these
290 * functions to enable them in the session:
291 * OrtSessionOptionsAppendExecutionProvider_CPU
292 * OrtSessionOptionsAppendExecutionProvider_CUDA
293 * OrtSessionOptionsAppendExecutionProvider_<remaining providers...>
294 * The order they care called indicates the preference order as well. In other words call this method
295 * on your most preferred execution provider first followed by the less preferred ones.
296 * If none are called Ort will use its internal CPU execution provider.
297 */298 299 OrtStatus* function(const(OrtSession)* sess, size_t* out_) SessionGetInputCount;
300 OrtStatus* function(const(OrtSession)* sess, size_t* out_) SessionGetOutputCount;
301 OrtStatus* function(const(OrtSession)* sess, size_t* out_) SessionGetOverridableInitializerCount;
302 303 /**
304 * \param out should be freed by OrtReleaseTypeInfo after use
305 */306 OrtStatus* function(const(OrtSession)* sess, size_tindex, OrtTypeInfo** type_info) SessionGetInputTypeInfo;
307 308 /**
309 * \param out should be freed by OrtReleaseTypeInfo after use
310 */311 OrtStatus* function(const(OrtSession)* sess, size_tindex, OrtTypeInfo** type_info) SessionGetOutputTypeInfo;
312 313 /**
314 * \param out should be freed by OrtReleaseTypeInfo after use
315 */316 OrtStatus* function(const(OrtSession)* sess, size_tindex, OrtTypeInfo** type_info) SessionGetOverridableInitializerTypeInfo;
317 318 /**
319 * \param value is set to a null terminated string allocated using 'allocator'. The caller is responsible for freeing it.
320 */321 OrtStatus* function(const(OrtSession)* sess, size_tindex,
322 OrtAllocator* allocator, char** value) SessionGetInputName;
323 324 OrtStatus* function(const(OrtSession)* sess, size_tindex,
325 OrtAllocator* allocator, char** value) SessionGetOutputName;
326 327 OrtStatus* function(const(OrtSession)* sess, size_tindex,
328 OrtAllocator* allocator, char** value) SessionGetOverridableInitializerName;
329 330 /**
331 * \return A pointer to the newly created object. The pointer should be freed by OrtReleaseRunOptions after use
332 */333 OrtStatus* function(OrtRunOptions** out_) CreateRunOptions;
334 335 OrtStatus* function(OrtRunOptions* options, intvalue) RunOptionsSetRunLogVerbosityLevel;
336 OrtStatus* function(OrtRunOptions* options, intvalue) RunOptionsSetRunLogSeverityLevel;
337 OrtStatus* function(OrtRunOptions*, const(char)* run_tag) RunOptionsSetRunTag;
338 339 OrtStatus* function(const(OrtRunOptions)* options, int* out_) RunOptionsGetRunLogVerbosityLevel;
340 OrtStatus* function(const(OrtRunOptions)* options, int* out_) RunOptionsGetRunLogSeverityLevel;
341 OrtStatus* function(const(OrtRunOptions)*, const(char*)* out_) RunOptionsGetRunTag;
342 343 // Set a flag so that ALL incomplete OrtRun calls that are using this instance of OrtRunOptions344 // will exit as soon as possible.345 OrtStatus* function(OrtRunOptions* options) RunOptionsSetTerminate;
346 // Unset the terminate flag to enable this OrtRunOptions instance being used in new OrtRun calls.347 OrtStatus* function(OrtRunOptions* options) RunOptionsUnsetTerminate;
348 349 /**
350 * Create a tensor from an allocator. OrtReleaseValue will also release the buffer inside the output value
351 * \param out Should be freed by calling OrtReleaseValue
352 * \param type must be one of TENSOR_ELEMENT_DATA_TYPE_xxxx
353 */354 OrtStatus* function(OrtAllocator* allocator, const(long)* shape,
355 size_tshape_len, ONNXTensorElementDataTypetype, OrtValue** out_) CreateTensorAsOrtValue;
356 357 /**
358 * Create a tensor with user's buffer. You can fill the buffer either before calling this function or after.
359 * p_data is owned by caller. OrtReleaseValue won't release p_data.
360 * \param out Should be freed by calling OrtReleaseValue
361 */362 OrtStatus* function(const(OrtMemoryInfo)* info, void* p_data, size_tp_data_len,
363 const(long)* shape, size_tshape_len, ONNXTensorElementDataTypetype, OrtValue** out_) CreateTensorWithDataAsOrtValue;
364 365 /**
366 * \Sets *out to 1 iff an OrtValue is a tensor, 0 otherwise
367 */368 OrtStatus* function(const(OrtValue)* value, int* out_) IsTensor;
369 370 // This function doesn't work with string tensor371 // this is a no-copy method whose pointer is only valid until the backing OrtValue is free'd.372 OrtStatus* function(OrtValue* value, void** out_) GetTensorMutableData;
373 374 /**
375 * \param value A tensor created from OrtCreateTensor... function.
376 * \param s each A string array. Each string in this array must be null terminated.
377 * \param s_len length of s
378 */379 OrtStatus* function(OrtValue* value, const(char*)* s, size_ts_len) FillStringTensor;
380 381 /**
382 * \param value A tensor created from OrtCreateTensor... function.
383 * \param len total data length, not including the trailing '\0' chars.
384 */385 OrtStatus* function(const(OrtValue)* value, size_t* len) GetStringTensorDataLength;
386 387 /**
388 * \param s string contents. Each string is NOT null-terminated.
389 * \param value A tensor created from OrtCreateTensor... function.
390 * \param s_len total data length, get it from OrtGetStringTensorDataLength
391 */392 OrtStatus* function(const(OrtValue)* value, void* s, size_ts_len,
393 size_t* offsets, size_toffsets_len) GetStringTensorContent;
394 395 /**
396 * Don't free the 'out' value
397 */398 OrtStatus* function(const(OrtTypeInfo)*, const(OrtTensorTypeAndShapeInfo*)* out_) CastTypeInfoToTensorInfo;
399 400 /**
401 * Return OnnxType from OrtTypeInfo
402 */403 OrtStatus* function(const(OrtTypeInfo)*, ONNXType* out_) GetOnnxTypeFromTypeInfo;
404 405 /**
406 * The 'out' value should be released by calling OrtReleaseTensorTypeAndShapeInfo
407 */408 OrtStatus* function(OrtTensorTypeAndShapeInfo** out_) CreateTensorTypeAndShapeInfo;
409 410 OrtStatus* function(OrtTensorTypeAndShapeInfo*, ONNXTensorElementDataTypetype) SetTensorElementType;
411 412 /**
413 * \param info Created from CreateTensorTypeAndShapeInfo() function
414 * \param dim_values An array with length of `dim_count`. Its elements can contain negative values.
415 * \param dim_count length of dim_values
416 */417 OrtStatus* function(OrtTensorTypeAndShapeInfo* info, const(long)* dim_values, size_tdim_count) SetDimensions;
418 419 OrtStatus* function(const(OrtTensorTypeAndShapeInfo)*, ONNXTensorElementDataType* out_) GetTensorElementType;
420 OrtStatus* function(const(OrtTensorTypeAndShapeInfo)* info, size_t* out_) GetDimensionsCount;
421 OrtStatus* function(const(OrtTensorTypeAndShapeInfo)* info,
422 long* dim_values, size_tdim_values_length) GetDimensions;
423 OrtStatus* function(const(OrtTensorTypeAndShapeInfo)* info,
424 const(char*)* dim_params, size_tdim_params_length) GetSymbolicDimensions;
425 426 /**
427 * Return the number of elements specified by the tensor shape.
428 * Return a negative value if unknown (i.e., any dimension is negative.)
429 * e.g.
430 * [] -> 1
431 * [1,3,4] -> 12
432 * [2,0,4] -> 0
433 * [-1,3,4] -> -1
434 */435 OrtStatus* function(const(OrtTensorTypeAndShapeInfo)* info, size_t* out_) GetTensorShapeElementCount;
436 437 /**
438 * \param out Should be freed by OrtReleaseTensorTypeAndShapeInfo after use
439 */440 OrtStatus* function(const(OrtValue)* value, OrtTensorTypeAndShapeInfo** out_) GetTensorTypeAndShape;
441 442 /**
443 * Get the type information of an OrtValue
444 * \param value
445 * \param out The returned value should be freed by OrtReleaseTypeInfo after use
446 */447 OrtStatus* function(const(OrtValue)* value, OrtTypeInfo** out_) GetTypeInfo;
448 449 OrtStatus* function(const(OrtValue)* value, ONNXType* out_) GetValueType;
450 451 OrtStatus* function(const(char)* name1, OrtAllocatorTypetype, intid1,
452 OrtMemTypemem_type1, OrtMemoryInfo** out_) CreateMemoryInfo;
453 454 /**
455 * Convenience function for special case of CreateMemoryInfo, for the CPU allocator. Uses name = "Cpu" and id = 0.
456 */457 OrtStatus* function(OrtAllocatorTypetype, OrtMemTypemem_type1, OrtMemoryInfo** out_) CreateCpuMemoryInfo;
458 459 /**
460 * Test if two memory info are equal
461 * \Sets 'out' to 0 if equal, -1 if not equal
462 */463 OrtStatus* function(const(OrtMemoryInfo)* info1, const(OrtMemoryInfo)* info2, int* out_) CompareMemoryInfo;
464 465 /**
466 * Do not free the returned value
467 */468 OrtStatus* function(const(OrtMemoryInfo)* ptr, const(char*)* out_) MemoryInfoGetName;
469 OrtStatus* function(const(OrtMemoryInfo)* ptr, int* out_) MemoryInfoGetId;
470 OrtStatus* function(const(OrtMemoryInfo)* ptr, OrtMemType* out_) MemoryInfoGetMemType;
471 OrtStatus* function(const(OrtMemoryInfo)* ptr, OrtAllocatorType* out_) MemoryInfoGetType;
472 473 OrtStatus* function(OrtAllocator* ptr, size_tsize, void** out_) AllocatorAlloc;
474 OrtStatus* function(OrtAllocator* ptr, void* p) AllocatorFree;
475 OrtStatus* function(const(OrtAllocator)* ptr, const(OrtMemoryInfo*)* out_) AllocatorGetInfo;
476 477 // The returned pointer doesn't have to be freed.478 // Always returns the same instance on every invocation.479 OrtStatus* function(OrtAllocator** out_) GetAllocatorWithDefaultOptions;
480 481 // Override symbolic dimensions with actual values if known at session initialization time to enable482 // optimizations that can take advantage of fixed values (such as memory planning, etc)483 OrtStatus* function(OrtSessionOptions* options, const(char)* symbolic_dim, longdim_override) AddFreeDimensionOverride;
484 485 /**
486 * APIs to support non-tensor types - map and sequence.
487 * Currently only the following types are supported
488 * Note: the following types should be kept in sync with data_types.h
489 * Map types
490 * =========
491 * std::map<std::string, std::string>
492 * std::map<std::string, int64_t>
493 * std::map<std::string, float>
494 * std::map<std::string, double>
495 * std::map<int64_t, std::string>
496 * std::map<int64_t, int64_t>
497 * std::map<int64_t, float>
498 * std::map<int64_t, double>
499 *
500 * Sequence types
501 * ==============
502 * std::vector<std::string>
503 * std::vector<int64_t>
504 * std::vector<float>
505 * std::vector<double>
506 * std::vector<std::map<std::string, float>>
507 * std::vector<std::map<int64_t, float>
508 */509 510 /**
511 * If input OrtValue represents a map, you need to retrieve the keys and values
512 * separately. Use index=0 to retrieve keys and index=1 to retrieve values.
513 * If input OrtValue represents a sequence, use index to retrieve the index'th element
514 * of the sequence.
515 */516 OrtStatus* function(const(OrtValue)* value, intindex,
517 OrtAllocator* allocator, OrtValue** out_) GetValue;
518 519 /**
520 * Returns 2 for type map and N for sequence where N is the number of elements
521 * in the sequence.
522 */523 OrtStatus* function(const(OrtValue)* value, size_t* out_) GetValueCount;
524 525 /**
526 * To construct a map, use num_values = 2 and 'in' should be an arrary of 2 OrtValues
527 * representing keys and values.
528 * To construct a sequence, use num_values = N where N is the number of the elements in the
529 * sequence. 'in' should be an arrary of N OrtValues.
530 * \value_type should be either map or sequence.
531 */532 OrtStatus* function(const(OrtValue*)* in_, size_tnum_values,
533 ONNXTypevalue_type, OrtValue** out_) CreateValue;
534 535 /**
536 * Construct OrtValue that contains a value of non-standard type created for
537 * experiments or while awaiting standardization. OrtValue in this case would contain
538 * an internal representation of the Opaque type. Opaque types are distinguished between
539 * each other by two strings 1) domain and 2) type name. The combination of the two
540 * must be unique, so the type representation is properly identified internally. The combination
541 * must be properly registered from within ORT at both compile/run time or by another API.
542 *
543 * To construct the OrtValue pass domain and type names, also a pointer to a data container
544 * the type of which must be know to both ORT and the client program. That data container may or may
545 * not match the internal representation of the Opaque type. The sizeof(data_container) is passed for
546 * verification purposes.
547 *
548 * \domain_name - domain name for the Opaque type, null terminated.
549 * \type_name - type name for the Opaque type, null terminated.
550 * \data_contianer - data to populate OrtValue
551 * \data_container_size - sizeof() of the data container. Must match the sizeof() of the expected
552 * data_container size internally.
553 */554 OrtStatus* function(const(char)* domain_name, const(char)* type_name,
555 const(void)* data_container, size_tdata_container_size, OrtValue** out_) CreateOpaqueValue;
556 557 /**
558 * Fetch data from an OrtValue that contains a value of non-standard type created for
559 * experiments or while awaiting standardization.
560 * \domain_name - domain name for the Opaque type, null terminated.
561 * \type_name - type name for the Opaque type, null terminated.
562 * \data_contianer - data to populate OrtValue
563 * \data_container_size - sizeof() of the data container. Must match the sizeof() of the expected
564 * data_container size internally.
565 */566 567 OrtStatus* function(const(char)* domain_name, const(char)* type_name,
568 const(OrtValue)* in_, void* data_container, size_tdata_container_size) GetOpaqueValue;
569 570 OrtStatus* function(const(OrtKernelInfo)* info, const(char)* name, float* out_) KernelInfoGetAttribute_float;
571 OrtStatus* function(const(OrtKernelInfo)* info, const(char)* name, long* out_) KernelInfoGetAttribute_int64;
572 OrtStatus* function(const(OrtKernelInfo)* info, const(char)* name, char* out_, size_t* size) KernelInfoGetAttribute_string;
573 574 OrtStatus* function(const(OrtKernelContext)* context, size_t* out_) KernelContext_GetInputCount;
575 OrtStatus* function(const(OrtKernelContext)* context, size_t* out_) KernelContext_GetOutputCount;
576 OrtStatus* function(const(OrtKernelContext)* context, size_tindex, const(OrtValue*)* out_) KernelContext_GetInput;
577 OrtStatus* function(OrtKernelContext* context, size_tindex,
578 const(long)* dim_values, size_tdim_count, OrtValue** out_) KernelContext_GetOutput;
579 580 voidfunction(OrtEnv* input) ReleaseEnv;
581 voidfunction(OrtStatus* input) ReleaseStatus; // nullptr for Status* indicates success582 voidfunction(OrtMemoryInfo* input) ReleaseMemoryInfo;
583 voidfunction(OrtSession* input) ReleaseSession; //Don't call OrtReleaseSession from Dllmain (because session owns a thread pool)584 voidfunction(OrtValue* input) ReleaseValue;
585 voidfunction(OrtRunOptions* input) ReleaseRunOptions;
586 voidfunction(OrtTypeInfo* input) ReleaseTypeInfo;
587 voidfunction(OrtTensorTypeAndShapeInfo* input) ReleaseTensorTypeAndShapeInfo;
588 voidfunction(OrtSessionOptions* input) ReleaseSessionOptions;
589 voidfunction(OrtCustomOpDomain* input) ReleaseCustomOpDomain;
590 591 // End of Version 1 - DO NOT MODIFY ABOVE (see above text for more information)592 593 // Version 2 - In development, feel free to add/remove/rearrange here594 595 /**
596 * GetDenotationFromTypeInfo
597 * This api augments OrtTypeInfo to return denotations on the type.
598 * This is used by WinML to determine if an input/output is intended to be an Image or a Tensor.
599 */600 OrtStatus* function(const(OrtTypeInfo)*, constchar** denotation, size_t* len) GetDenotationFromTypeInfo;
601 602 // OrtTypeInfo Casting methods603 604 /**
605 * CastTypeInfoToMapTypeInfo
606 * This api augments OrtTypeInfo to return an OrtMapTypeInfo when the type is a map.
607 * The OrtMapTypeInfo has additional information about the map's key type and value type.
608 * This is used by WinML to support model reflection APIs.
609 *
610 * Don't free the 'out' value
611 */612 OrtStatus* function(const(OrtTypeInfo)* type_info, const(OrtMapTypeInfo*)* out_) CastTypeInfoToMapTypeInfo;
613 614 /**
615 * CastTypeInfoToSequenceTypeInfo
616 * This api augments OrtTypeInfo to return an OrtSequenceTypeInfo when the type is a sequence.
617 * The OrtSequenceTypeInfo has additional information about the sequence's element type.
618 * This is used by WinML to support model reflection APIs.
619 *
620 * Don't free the 'out' value
621 */622 OrtStatus* function(const(OrtTypeInfo)* type_info, const(OrtSequenceTypeInfo*)* out_) CastTypeInfoToSequenceTypeInfo;
623 624 // OrtMapTypeInfo Accessors625 626 /**
627 * GetMapKeyType
628 * This api augments get the key type of a map. Key types are restricted to being scalar types and use ONNXTensorElementDataType.
629 * This is used by WinML to support model reflection APIs.
630 */631 OrtStatus* function(const(OrtMapTypeInfo)* map_type_info, ONNXTensorElementDataType* out_) GetMapKeyType;
632 633 /**
634 * GetMapValueType
635 * This api augments get the value type of a map.
636 */637 OrtStatus* function(const(OrtMapTypeInfo)* map_type_info, OrtTypeInfo** type_info) GetMapValueType;
638 639 // OrtSequenceTypeInfo Accessors640 641 /**
642 * GetSequenceElementType
643 * This api augments get the element type of a sequence.
644 * This is used by WinML to support model reflection APIs.
645 */646 OrtStatus* function(const(OrtSequenceTypeInfo)* sequence_type_info, OrtTypeInfo** type_info) GetSequenceElementType;
647 648 voidfunction(OrtMapTypeInfo* input) ReleaseMapTypeInfo;
649 voidfunction(OrtSequenceTypeInfo* input) ReleaseSequenceTypeInfo;
650 651 /**
652 * \param out is set to a null terminated string allocated using 'allocator'. The caller is responsible for freeing it.
653 * Profiling is turned ON automatically if enabled for the particular session by invoking EnableProfiling()
654 * on the SessionOptions instance used to create the session.
655 */656 OrtStatus* function(OrtSession* sess, OrtAllocator* allocator, char** out_) SessionEndProfiling;
657 658 /**
659 * \param out is a pointer to the newly created object. The pointer should be freed by calling ReleaseModelMetadata after use.
660 */661 OrtStatus* function(const(OrtSession)* sess, OrtModelMetadata** out_) SessionGetModelMetadata;
662 663 /**
664 * \param value is set to a null terminated string allocated using 'allocator'. The caller is responsible for freeing it.
665 */666 OrtStatus* function(const(OrtModelMetadata)* model_metadata,
667 OrtAllocator* allocator, char** value) ModelMetadataGetProducerName;
668 669 OrtStatus* function(const(OrtModelMetadata)* model_metadata,
670 OrtAllocator* allocator, char** value) ModelMetadataGetGraphName;
671 672 OrtStatus* function(const(OrtModelMetadata)* model_metadata,
673 OrtAllocator* allocator, char** value) ModelMetadataGetDomain;
674 675 OrtStatus* function(const(OrtModelMetadata)* model_metadata,
676 OrtAllocator* allocator, char** value) ModelMetadataGetDescription;
677 678 /**
679 * \param value is set to a null terminated string allocated using 'allocator'. The caller is responsible for freeing it.
680 * 'value' will be a nullptr if the given key is not found in the custom metadata map.
681 */682 OrtStatus* function(const(OrtModelMetadata)* model_metadata,
683 OrtAllocator* allocator, const(char)* key, char** value) ModelMetadataLookupCustomMetadataMap;
684 685 OrtStatus* function(const(OrtModelMetadata)* model_metadata, long* value) ModelMetadataGetVersion;
686 687 voidfunction(OrtModelMetadata* input) ReleaseModelMetadata;
688 }
689 690 /*
691 * Steps to use a custom op:
692 * 1 Create an OrtCustomOpDomain with the domain name used by the custom ops
693 * 2 Create an OrtCustomOp structure for each op and add them to the domain
694 * 3 Call OrtAddCustomOpDomain to add the custom domain of ops to the session options
695 */696 aliasOrtCustomOpApi = OrtApi;
697 698 /*
699 * The OrtCustomOp structure defines a custom op's schema and its kernel callbacks. The callbacks are filled in by
700 * the implementor of the custom op.
701 */702 structOrtCustomOp703 {
704 uintversion_; // Initialize to ORT_API_VERSION705 706 // This callback creates the kernel, which is a user defined parameter that is passed to the Kernel* callbacks below.707 void* function(OrtCustomOp* op, const(OrtApi)* api, const(OrtKernelInfo)* info) CreateKernel;
708 709 // Returns the name of the op710 const(char)* function(OrtCustomOp* op) GetName;
711 712 // Returns the type of the execution provider, return nullptr to use CPU execution provider713 const(char)* function(OrtCustomOp* op) GetExecutionProviderType;
714 715 // Returns the count and types of the input & output tensors716 ONNXTensorElementDataTypefunction(OrtCustomOp* op, size_tindex) GetInputType;
717 size_tfunction(OrtCustomOp* op) GetInputTypeCount;
718 ONNXTensorElementDataTypefunction(OrtCustomOp* op, size_tindex) GetOutputType;
719 size_tfunction(OrtCustomOp* op) GetOutputTypeCount;
720 721 // Op kernel callbacks722 voidfunction(void* op_kernel, OrtKernelContext* context) KernelCompute;
723 voidfunction(void* op_kernel) KernelDestroy;
724 }
725 726 /*
727 * END EXPERIMENTAL
728 */