1 module bindbc.onnxruntime.v12.types; 2 3 import core.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 them 8 enum ORT_API_VERSION = 2; 9 10 // SAL2 Definitions 11 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 alias ORTCHAR_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 limitation 20 // 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::DataType 24 // Currently, Ort doesn't support complex64, complex128, bfloat16 types 25 enum ONNXTensorElementDataType 26 { 27 ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED = 0, 28 ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT = 1, // maps to c type float 29 ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8 = 2, // maps to c type uint8_t 30 ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8 = 3, // maps to c type int8_t 31 ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16 = 4, // maps to c type uint16_t 32 ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16 = 5, // maps to c type int16_t 33 ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32 = 6, // maps to c type int32_t 34 ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64 = 7, // maps to c type int64_t 35 ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING = 8, // maps to c++ type std::string 36 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 double 39 ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32 = 12, // maps to c type uint32_t 40 ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64 = 13, // maps to c type uint64_t 41 ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX64 = 14, // complex with float32 real and imaginary components 42 ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX128 = 15, // complex with float64 real and imaginary components 43 ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16 = 16 // Non-IEEE floating-point format based on IEEE754 single-precision 44 } 45 46 // Synced with onnx TypeProto oneof 47 enum ONNXType 48 { 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 = 5 55 } 56 57 enum OrtLoggingLevel 58 { 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 = 4 64 } 65 66 enum OrtErrorCode 67 { 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 = 11 80 } 81 82 // __VA_ARGS__ on Windows and Linux are different 83 84 // Used in *.cc files. Almost as same as ORT_API_STATUS, except without ORT_MUST_USE_RESULT 85 86 // ORT_API(void, OrtRelease##X, _Frees_ptr_opt_ Ort##X* input); 87 88 // The actual types defined have an Ort prefix 89 struct OrtEnv; 90 struct OrtStatus; // nullptr for Status* indicates success 91 struct OrtMemoryInfo; 92 struct OrtSession; //Don't call OrtReleaseSession from Dllmain (because session owns a thread pool) 93 struct OrtValue; 94 struct OrtRunOptions; 95 struct OrtTypeInfo; 96 struct OrtTensorTypeAndShapeInfo; 97 struct OrtSessionOptions; 98 struct OrtCustomOpDomain; 99 struct OrtMapTypeInfo; 100 struct OrtSequenceTypeInfo; 101 struct OrtModelMetadata; 102 103 // When passing in an allocator to any ORT function, be sure that the allocator object 104 // is not destroyed until the last allocated object using it is freed. 105 struct OrtAllocator 106 { 107 uint version_; // Initialize to ORT_API_VERSION 108 void* function(OrtAllocator* this_, size_t size) Alloc; 109 void function(OrtAllocator* this_, void* p) Free; 110 const(OrtMemoryInfo)* function(const(OrtAllocator)* this_) Info; 111 } 112 113 alias OrtLoggingFunction = void function(void* param, OrtLoggingLevel severity, 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.md 119 // for in-depth undersrtanding of Graph Optimizations in ORT 120 enum GraphOptimizationLevel 121 { 122 ORT_DISABLE_ALL = 0, 123 ORT_ENABLE_BASIC = 1, 124 ORT_ENABLE_EXTENDED = 2, 125 ORT_ENABLE_ALL = 99 126 } 127 128 enum ExecutionMode 129 { 130 ORT_SEQUENTIAL = 0, 131 ORT_PARALLEL = 1 132 } 133 134 struct OrtKernelInfo; 135 struct OrtKernelContext; 136 137 enum OrtAllocatorType 138 { 139 Invalid = -1, 140 OrtDeviceAllocator = 0, 141 OrtArenaAllocator = 1 142 } 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 enum OrtMemType 149 { 150 OrtMemTypeCPUInput = -2, // Any CPU memory used by non-CPU execution provider 151 OrtMemTypeCPUOutput = -1, // CPU accessible memory outputted by non-CPU execution provider, i.e. CUDA_PINNED 152 OrtMemTypeCPU = OrtMemTypeCPUOutput, // temporary CPU accessible memory allocated by non-CPU execution provider, i.e. CUDA_PINNED 153 OrtMemTypeDefault = 0 // the default allocator for execution provider 154 } 155 156 struct OrtApiBase 157 { 158 const(OrtApi)* function(uint version_) GetApi; // Pass in ORT_API_VERSION 159 // nullptr will be returned if the version is unsupported, for example when using a runtime older than this header file 160 161 const(char)* GetVersionString; 162 } 163 164 struct OrtApi 165 { 166 /** 167 * \param msg A null-terminated string. Its content will be copied into the newly created OrtStatus 168 */ 169 OrtStatus* function(OrtErrorCode code, const(char)* msg) CreateStatus; 170 171 OrtErrorCode function(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(OrtLoggingLevel default_logging_level, const(char)* logid, OrtEnv** out_) CreateEnv; 183 184 /** 185 * \param out Should be freed by `OrtReleaseEnv` after use 186 */ 187 OrtStatus* function(OrtLoggingFunction logging_function, void* logger_param, 188 OrtLoggingLevel default_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 the 196 // execution of CreateSession, or does the OrtSession retain a handle to the file/directory 197 // 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_t model_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_t input_len, 207 const(char*)* output_names, size_t output_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 OrtSessionOptions 218 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 model 221 // 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, ExecutionMode execution_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 allocation 231 // and generate a memory pattern for future request. So next time we could just do one allocation 232 // 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 CPU 238 // 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 output 244 OrtStatus* function(OrtSessionOptions* options, const(char)* logid) SetSessionLogId; 245 246 // < applies to session load, initialization, etc 247 OrtStatus* function(OrtSessionOptions* options, int session_log_verbosity_level) SetSessionLogVerbosityLevel; 248 OrtStatus* function(OrtSessionOptions* options, int session_log_severity_level) SetSessionLogSeverityLevel; 249 250 OrtStatus* function(OrtSessionOptions* options, GraphOptimizationLevel graph_optimization_level) SetSessionGraphOptimizationLevel; 251 252 // Sets the number of threads used to parallelize the execution within nodes 253 // A value of 0 means ORT will pick a default 254 OrtStatus* function(OrtSessionOptions* options, int intra_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 ignored 258 // A value of 0 means ORT will pick a default 259 OrtStatus* function(OrtSessionOptions* options, int inter_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_t index, OrtTypeInfo** type_info) SessionGetInputTypeInfo; 307 308 /** 309 * \param out should be freed by OrtReleaseTypeInfo after use 310 */ 311 OrtStatus* function(const(OrtSession)* sess, size_t index, OrtTypeInfo** type_info) SessionGetOutputTypeInfo; 312 313 /** 314 * \param out should be freed by OrtReleaseTypeInfo after use 315 */ 316 OrtStatus* function(const(OrtSession)* sess, size_t index, 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_t index, 322 OrtAllocator* allocator, char** value) SessionGetInputName; 323 324 OrtStatus* function(const(OrtSession)* sess, size_t index, 325 OrtAllocator* allocator, char** value) SessionGetOutputName; 326 327 OrtStatus* function(const(OrtSession)* sess, size_t index, 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, int value) RunOptionsSetRunLogVerbosityLevel; 336 OrtStatus* function(OrtRunOptions* options, int value) 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 OrtRunOptions 344 // 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_t shape_len, ONNXTensorElementDataType type, 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_t p_data_len, 363 const(long)* shape, size_t shape_len, ONNXTensorElementDataType type, 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 tensor 371 // 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_t s_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_t s_len, 393 size_t* offsets, size_t offsets_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*, ONNXTensorElementDataType type) 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_t dim_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_t dim_values_length) GetDimensions; 423 OrtStatus* function(const(OrtTensorTypeAndShapeInfo)* info, 424 const(char*)* dim_params, size_t dim_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, OrtAllocatorType type, int id1, 452 OrtMemType mem_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(OrtAllocatorType type, OrtMemType mem_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_t size, 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 enable 482 // optimizations that can take advantage of fixed values (such as memory planning, etc) 483 OrtStatus* function(OrtSessionOptions* options, const(char)* symbolic_dim, long dim_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, int index, 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_t num_values, 533 ONNXType value_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_t data_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_t data_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_t index, const(OrtValue*)* out_) KernelContext_GetInput; 577 OrtStatus* function(OrtKernelContext* context, size_t index, 578 const(long)* dim_values, size_t dim_count, OrtValue** out_) KernelContext_GetOutput; 579 580 void function(OrtEnv* input) ReleaseEnv; 581 void function(OrtStatus* input) ReleaseStatus; // nullptr for Status* indicates success 582 void function(OrtMemoryInfo* input) ReleaseMemoryInfo; 583 void function(OrtSession* input) ReleaseSession; //Don't call OrtReleaseSession from Dllmain (because session owns a thread pool) 584 void function(OrtValue* input) ReleaseValue; 585 void function(OrtRunOptions* input) ReleaseRunOptions; 586 void function(OrtTypeInfo* input) ReleaseTypeInfo; 587 void function(OrtTensorTypeAndShapeInfo* input) ReleaseTensorTypeAndShapeInfo; 588 void function(OrtSessionOptions* input) ReleaseSessionOptions; 589 void function(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 here 594 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)*, const char** denotation, size_t* len) GetDenotationFromTypeInfo; 601 602 // OrtTypeInfo Casting methods 603 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 Accessors 625 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 Accessors 640 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 void function(OrtMapTypeInfo* input) ReleaseMapTypeInfo; 649 void function(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 void function(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 alias OrtCustomOpApi = 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 struct OrtCustomOp 703 { 704 uint version_; // Initialize to ORT_API_VERSION 705 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 op 710 const(char)* function(OrtCustomOp* op) GetName; 711 712 // Returns the type of the execution provider, return nullptr to use CPU execution provider 713 const(char)* function(OrtCustomOp* op) GetExecutionProviderType; 714 715 // Returns the count and types of the input & output tensors 716 ONNXTensorElementDataType function(OrtCustomOp* op, size_t index) GetInputType; 717 size_t function(OrtCustomOp* op) GetInputTypeCount; 718 ONNXTensorElementDataType function(OrtCustomOp* op, size_t index) GetOutputType; 719 size_t function(OrtCustomOp* op) GetOutputTypeCount; 720 721 // Op kernel callbacks 722 void function(void* op_kernel, OrtKernelContext* context) KernelCompute; 723 void function(void* op_kernel) KernelDestroy; 724 } 725 726 /* 727 * END EXPERIMENTAL 728 */