OnnxRuntime
onnxruntime_cxx_api.h
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4// Summary: The Ort C++ API is a header only wrapper around the Ort C API.
5//
6// The C++ API simplifies usage by returning values directly instead of error codes, throwing exceptions on errors
7// and automatically releasing resources in the destructors.
8//
9// Each of the C++ wrapper classes holds only a pointer to the C internal object. Treat them like smart pointers.
10// To create an empty object, pass 'nullptr' to the constructor (for example, Env e{nullptr};).
11//
12// Only move assignment between objects is allowed, there are no copy constructors. Some objects have explicit 'Clone'
13// methods for this purpose.
14
15#pragma once
16#include "onnxruntime_c_api.h"
17#include <cstddef>
18#include <array>
19#include <memory>
20#include <stdexcept>
21#include <string>
22#include <vector>
23#include <utility>
24#include <type_traits>
25
26#ifdef ORT_NO_EXCEPTIONS
27#include <iostream>
28#endif
29
33namespace Ort {
34
39struct Exception : std::exception {
40 Exception(std::string&& string, OrtErrorCode code) : message_{std::move(string)}, code_{code} {}
41
42 OrtErrorCode GetOrtErrorCode() const { return code_; }
43 const char* what() const noexcept override { return message_.c_str(); }
44
45 private:
46 std::string message_;
47 OrtErrorCode code_;
48};
49
50#ifdef ORT_NO_EXCEPTIONS
51#define ORT_CXX_API_THROW(string, code) \
52 do { \
53 std::cerr << Ort::Exception(string, code) \
54 .what() \
55 << std::endl; \
56 abort(); \
57 } while (false)
58#else
59#define ORT_CXX_API_THROW(string, code) \
60 throw Ort::Exception(string, code)
61#endif
62
63// This is used internally by the C++ API. This class holds the global variable that points to the OrtApi, it's in a template so that we can define a global variable in a header and make
64// it transparent to the users of the API.
65template <typename T>
66struct Global {
67 static const OrtApi* api_;
68};
69
70// If macro ORT_API_MANUAL_INIT is defined, no static initialization will be performed. Instead, user must call InitApi() before using it.
71template <typename T>
72#ifdef ORT_API_MANUAL_INIT
73const OrtApi* Global<T>::api_{};
74inline void InitApi() { Global<void>::api_ = OrtGetApiBase()->GetApi(ORT_API_VERSION); }
75#else
77#endif
78
80inline const OrtApi& GetApi() { return *Global<void>::api_; }
81
83std::vector<std::string> GetAvailableProviders();
84
85// This is used internally by the C++ API. This macro is to make it easy to generate overloaded methods for all of the various OrtRelease* functions for every Ort* type
86// This can't be done in the C API since C doesn't have function overloading.
87#define ORT_DEFINE_RELEASE(NAME) \
88 inline void OrtRelease(Ort##NAME* ptr) { GetApi().Release##NAME(ptr); }
89
90ORT_DEFINE_RELEASE(Allocator);
91ORT_DEFINE_RELEASE(MemoryInfo);
92ORT_DEFINE_RELEASE(CustomOpDomain);
93ORT_DEFINE_RELEASE(Env);
94ORT_DEFINE_RELEASE(RunOptions);
95ORT_DEFINE_RELEASE(Session);
96ORT_DEFINE_RELEASE(SessionOptions);
97ORT_DEFINE_RELEASE(TensorTypeAndShapeInfo);
98ORT_DEFINE_RELEASE(SequenceTypeInfo);
99ORT_DEFINE_RELEASE(MapTypeInfo);
100ORT_DEFINE_RELEASE(TypeInfo);
101ORT_DEFINE_RELEASE(Value);
102ORT_DEFINE_RELEASE(ModelMetadata);
103ORT_DEFINE_RELEASE(ThreadingOptions);
104ORT_DEFINE_RELEASE(IoBinding);
105ORT_DEFINE_RELEASE(ArenaCfg);
106
107#undef ORT_DEFINE_RELEASE
108
148struct Float16_t {
149 uint16_t value;
150 constexpr Float16_t() noexcept : value(0) {}
151 constexpr Float16_t(uint16_t v) noexcept : value(v) {}
152 constexpr operator uint16_t() const noexcept { return value; }
153 constexpr bool operator==(const Float16_t& rhs) const noexcept { return value == rhs.value; };
154 constexpr bool operator!=(const Float16_t& rhs) const noexcept { return value != rhs.value; };
155};
156
157static_assert(sizeof(Float16_t) == sizeof(uint16_t), "Sizes must match");
158
168 uint16_t value;
169 constexpr BFloat16_t() noexcept : value(0) {}
170 constexpr BFloat16_t(uint16_t v) noexcept : value(v) {}
171 constexpr operator uint16_t() const noexcept { return value; }
172 constexpr bool operator==(const BFloat16_t& rhs) const noexcept { return value == rhs.value; };
173 constexpr bool operator!=(const BFloat16_t& rhs) const noexcept { return value != rhs.value; };
174};
175
176static_assert(sizeof(BFloat16_t) == sizeof(uint16_t), "Sizes must match");
177
185template <typename T>
186struct Base {
187 using contained_type = T;
188
189 Base() = default;
190 Base(T* p) : p_{p} {
191 if (!p)
192 ORT_CXX_API_THROW("Allocation failure", ORT_FAIL);
193 }
195
196 operator T*() { return p_; }
197 operator const T*() const { return p_; }
198
200 T* release() {
201 T* p = p_;
202 p_ = nullptr;
203 return p;
204 }
205
206 protected:
207 Base(const Base&) = delete;
208 Base& operator=(const Base&) = delete;
209 Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }
210 void operator=(Base&& v) noexcept { OrtRelease(p_); p_ = v.release(); }
211
212 T* p_{};
213
214 template <typename> friend struct Unowned; // This friend line is needed to keep the centos C++ compiler from giving an error
215};
216
221template <typename T>
222struct Unowned : T {
223 Unowned(typename T::contained_type* p) : T{p} {}
224 Unowned(Unowned&& v) : T{v.p_} {}
225 ~Unowned() { this->release(); }
226};
227
228struct AllocatorWithDefaultOptions;
229struct MemoryInfo;
230struct Env;
231struct TypeInfo;
232struct Value;
233struct ModelMetadata;
234
240struct Env : Base<OrtEnv> {
241 explicit Env(std::nullptr_t) {}
242
244 Env(OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
245
247 Env(OrtLoggingLevel logging_level, const char* logid, OrtLoggingFunction logging_function, void* logger_param);
248
250 Env(const OrtThreadingOptions* tp_options, OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
251
253 Env(const OrtThreadingOptions* tp_options, OrtLoggingFunction logging_function, void* logger_param,
254 OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
255
257 explicit Env(OrtEnv* p) : Base<OrtEnv>{p} {}
258
261
262 Env& CreateAndRegisterAllocator(const OrtMemoryInfo* mem_info, const OrtArenaCfg* arena_cfg);
263};
264
268struct CustomOpDomain : Base<OrtCustomOpDomain> {
269 explicit CustomOpDomain(std::nullptr_t) {}
270
272 explicit CustomOpDomain(const char* domain);
273
274 void Add(OrtCustomOp* op);
275};
276
277struct RunOptions : Base<OrtRunOptions> {
278 explicit RunOptions(std::nullptr_t) {}
280
283
286
287 RunOptions& SetRunTag(const char* run_tag);
288 const char* GetRunTag() const;
289
290 RunOptions& AddConfigEntry(const char* config_key, const char* config_value);
291
298
304};
305
310struct SessionOptions : Base<OrtSessionOptions> {
311 explicit SessionOptions(std::nullptr_t) {}
314
316
317 SessionOptions& SetIntraOpNumThreads(int intra_op_num_threads);
318 SessionOptions& SetInterOpNumThreads(int inter_op_num_threads);
320
323
324 SessionOptions& SetOptimizedModelFilePath(const ORTCHAR_T* optimized_model_file);
325
326 SessionOptions& EnableProfiling(const ORTCHAR_T* profile_file_prefix);
328
330
333
335
336 SessionOptions& SetLogId(const char* logid);
338
340
342
343 SessionOptions& AddConfigEntry(const char* config_key, const char* config_value);
344 SessionOptions& AddInitializer(const char* name, const OrtValue* ort_val);
345
350};
351
355struct ModelMetadata : Base<OrtModelMetadata> {
356 explicit ModelMetadata(std::nullptr_t) {}
358
359 char* GetProducerName(OrtAllocator* allocator) const;
360 char* GetGraphName(OrtAllocator* allocator) const;
361 char* GetDomain(OrtAllocator* allocator) const;
362 char* GetDescription(OrtAllocator* allocator) const;
363 char* GetGraphDescription(OrtAllocator* allocator) const;
364 char** GetCustomMetadataMapKeys(OrtAllocator* allocator, _Out_ int64_t& num_keys) const;
365 char* LookupCustomMetadataMap(const char* key, OrtAllocator* allocator) const;
366 int64_t GetVersion() const;
367};
368
372struct Session : Base<OrtSession> {
373 explicit Session(std::nullptr_t) {}
374 Session(Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
375 Session(Env& env, const ORTCHAR_T* model_path, const SessionOptions& options, OrtPrepackedWeightsContainer* prepacked_weights_container);
376 Session(Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options);
377
395 std::vector<Value> Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
396 const char* const* output_names, size_t output_count);
397
401 void Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
402 const char* const* output_names, Value* output_values, size_t output_count);
403
404 void Run(const RunOptions& run_options, const struct IoBinding&);
405
406 size_t GetInputCount() const;
407 size_t GetOutputCount() const;
409
410 char* GetInputName(size_t index, OrtAllocator* allocator) const;
411 char* GetOutputName(size_t index, OrtAllocator* allocator) const;
412 char* GetOverridableInitializerName(size_t index, OrtAllocator* allocator) const;
413 char* EndProfiling(OrtAllocator* allocator) const;
414 uint64_t GetProfilingStartTimeNs() const;
416
417 TypeInfo GetInputTypeInfo(size_t index) const;
418 TypeInfo GetOutputTypeInfo(size_t index) const;
420};
421
425struct TensorTypeAndShapeInfo : Base<OrtTensorTypeAndShapeInfo> {
426 explicit TensorTypeAndShapeInfo(std::nullptr_t) {}
428
430 size_t GetElementCount() const;
431
432 size_t GetDimensionsCount() const;
433 void GetDimensions(int64_t* values, size_t values_count) const;
434 void GetSymbolicDimensions(const char** values, size_t values_count) const;
435
436 std::vector<int64_t> GetShape() const;
437};
438
442struct SequenceTypeInfo : Base<OrtSequenceTypeInfo> {
443 explicit SequenceTypeInfo(std::nullptr_t) {}
445
447};
448
452struct MapTypeInfo : Base<OrtMapTypeInfo> {
453 explicit MapTypeInfo(std::nullptr_t) {}
455
458};
459
460struct TypeInfo : Base<OrtTypeInfo> {
461 explicit TypeInfo(std::nullptr_t) {}
462 explicit TypeInfo(OrtTypeInfo* p) : Base<OrtTypeInfo>{p} {}
463
467
469};
470
471struct Value : Base<OrtValue> {
472 // This structure is used to feed sparse tensor values
473 // information for use with FillSparseTensor<Format>() API
474 // if the data type for the sparse tensor values is numeric
475 // use data.p_data, otherwise, use data.str pointer to feed
476 // values. data.str is an array of const char* that are zero terminated.
477 // number of strings in the array must match shape size.
478 // For fully sparse tensors use shape {0} and set p_data/str
479 // to nullptr.
481 const int64_t* values_shape;
483 union {
484 const void* p_data;
485 const char** str;
487 };
488
489 // Provides a way to pass shape in a single
490 // argument
491 struct Shape {
492 const int64_t* shape;
493 size_t shape_len;
494 };
495
497 template <typename T>
498 static Value CreateTensor(const OrtMemoryInfo* info, T* p_data, size_t p_data_element_count, const int64_t* shape, size_t shape_len);
500 static Value CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count, const int64_t* shape, size_t shape_len,
502
503#if !defined(DISABLE_SPARSE_TENSORS)
514 template <typename T>
515 static Value CreateSparseTensor(const OrtMemoryInfo* info, T* p_data, const Shape& dense_shape,
516 const Shape& values_shape);
517
534 static Value CreateSparseTensor(const OrtMemoryInfo* info, void* p_data, const Shape& dense_shape,
535 const Shape& values_shape, ONNXTensorElementDataType type);
536
545 void UseCooIndices(int64_t* indices_data, size_t indices_num);
546
557 void UseCsrIndices(int64_t* inner_data, size_t inner_num, int64_t* outer_data, size_t outer_num);
558
567 void UseBlockSparseIndices(const Shape& indices_shape, int32_t* indices_data);
568
569#endif // !defined(DISABLE_SPARSE_TENSORS)
570
571 // \brief Wraps OrtApi::CreateTensorAsOrtValue
572 template <typename T>
573 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len);
574 // \brief Wraps OrtApi::CreateTensorAsOrtValue
575 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type);
576
577#if !defined(DISABLE_SPARSE_TENSORS)
587 template <typename T>
588 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape);
589
601 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape, ONNXTensorElementDataType type);
602
612 void FillSparseTensorCoo(const OrtMemoryInfo* data_mem_info, const OrtSparseValuesParam& values_param,
613 const int64_t* indices_data, size_t indices_num);
614
626 void FillSparseTensorCsr(const OrtMemoryInfo* data_mem_info,
627 const OrtSparseValuesParam& values,
628 const int64_t* inner_indices_data, size_t inner_indices_num,
629 const int64_t* outer_indices_data, size_t outer_indices_num);
630
641 const OrtSparseValuesParam& values,
642 const Shape& indices_shape,
643 const int32_t* indices_data);
644
652
659
668
678 template <typename T>
679 const T* GetSparseTensorIndicesData(OrtSparseIndicesFormat indices_format, size_t& num_indices) const;
680
681#endif // !defined(DISABLE_SPARSE_TENSORS)
682
683 static Value CreateMap(Value& keys, Value& values);
684 static Value CreateSequence(std::vector<Value>& values);
685
686 template <typename T>
687 static Value CreateOpaque(const char* domain, const char* type_name, const T&);
688
689 template <typename T>
690 void GetOpaqueData(const char* domain, const char* type_name, T&) const;
691
692 explicit Value(std::nullptr_t) {}
693 explicit Value(OrtValue* p) : Base<OrtValue>{p} {}
694 Value(Value&&) = default;
695 Value& operator=(Value&&) = default;
696
697 bool IsTensor() const;
698
699#if !defined(DISABLE_SPARSE_TENSORS)
704 bool IsSparseTensor() const;
705#endif
706
707 size_t GetCount() const; // If a non tensor, returns 2 for map and N for sequence, where N is the number of elements
708 Value GetValue(int index, OrtAllocator* allocator) const;
709
717
732 void GetStringTensorContent(void* buffer, size_t buffer_length, size_t* offsets, size_t offsets_count) const;
733
734 template <typename T>
736
737 template <typename T>
738 const T* GetTensorData() const;
739
740#if !defined(DISABLE_SPARSE_TENSORS)
749 template <typename T>
750 const T* GetSparseTensorValues() const;
751#endif
752
753 template <typename T>
754 T& At(const std::vector<int64_t>& location);
755
763
771
778 size_t GetStringTensorElementLength(size_t element_index) const;
779
788 void GetStringTensorElement(size_t buffer_length, size_t element_index, void* buffer) const;
789
790 void FillStringTensor(const char* const* s, size_t s_len);
791 void FillStringTensorElement(const char* s, size_t index);
792};
793
794// Represents native memory allocation
796 MemoryAllocation(OrtAllocator* allocator, void* p, size_t size);
801 MemoryAllocation& operator=(MemoryAllocation&&) noexcept;
802
803 void* get() { return p_; }
804 size_t size() const { return size_; }
805
806 private:
807 OrtAllocator* allocator_;
808 void* p_;
809 size_t size_;
810};
811
814
815 operator OrtAllocator*() { return p_; }
816 operator const OrtAllocator*() const { return p_; }
817
818 void* Alloc(size_t size);
819 // The return value will own the allocation
821 void Free(void* p);
822
823 const OrtMemoryInfo* GetInfo() const;
824
825 private:
826 OrtAllocator* p_{};
827};
828
829struct MemoryInfo : Base<OrtMemoryInfo> {
831
832 explicit MemoryInfo(std::nullptr_t) {}
834 MemoryInfo(const char* name, OrtAllocatorType type, int id, OrtMemType mem_type);
835
836 std::string GetAllocatorName() const;
838 int GetDeviceId() const;
840
841 bool operator==(const MemoryInfo& o) const;
842};
843
844struct Allocator : public Base<OrtAllocator> {
845 Allocator(const Session& session, const MemoryInfo&);
846
847 void* Alloc(size_t size) const;
848 // The return value will own the allocation
850 void Free(void* p) const;
852};
853
854struct IoBinding : public Base<OrtIoBinding> {
855 explicit IoBinding(Session& session);
856 void BindInput(const char* name, const Value&);
857 void BindOutput(const char* name, const Value&);
858 void BindOutput(const char* name, const MemoryInfo&);
859 std::vector<std::string> GetOutputNames() const;
860 std::vector<std::string> GetOutputNames(Allocator&) const;
861 std::vector<Value> GetOutputValues() const;
862 std::vector<Value> GetOutputValues(Allocator&) const;
865
866 private:
867 std::vector<std::string> GetOutputNamesHelper(OrtAllocator*) const;
868 std::vector<Value> GetOutputValuesHelper(OrtAllocator*) const;
869};
870
875struct ArenaCfg : Base<OrtArenaCfg> {
876 explicit ArenaCfg(std::nullptr_t) {}
885 ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk);
886};
887
888//
889// Custom OPs (only needed to implement custom OPs)
890//
891
893 CustomOpApi(const OrtApi& api) : api_(api) {}
894
895 template <typename T> // T is only implemented for std::vector<float>, std::vector<int64_t>, float, int64_t, and string
896 T KernelInfoGetAttribute(_In_ const OrtKernelInfo* info, _In_ const char* name);
897
902 void GetDimensions(_In_ const OrtTensorTypeAndShapeInfo* info, _Out_ int64_t* dim_values, size_t dim_values_length);
903 void SetDimensions(OrtTensorTypeAndShapeInfo* info, _In_ const int64_t* dim_values, size_t dim_count);
904
905 template <typename T>
906 T* GetTensorMutableData(_Inout_ OrtValue* value);
907 template <typename T>
908 const T* GetTensorData(_Inout_ const OrtValue* value);
909
910 std::vector<int64_t> GetTensorShape(const OrtTensorTypeAndShapeInfo* info);
913 const OrtValue* KernelContext_GetInput(const OrtKernelContext* context, _In_ size_t index);
915 OrtValue* KernelContext_GetOutput(OrtKernelContext* context, _In_ size_t index, _In_ const int64_t* dim_values, size_t dim_count);
916
917 void ThrowOnError(OrtStatus* result);
918
919 private:
920 const OrtApi& api_;
921};
922
923template <typename TOp, typename TKernel>
927 OrtCustomOp::CreateKernel = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info) { return static_cast<const TOp*>(this_)->CreateKernel(*api, info); };
928 OrtCustomOp::GetName = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetName(); };
929
930 OrtCustomOp::GetExecutionProviderType = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetExecutionProviderType(); };
931
932 OrtCustomOp::GetInputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetInputTypeCount(); };
933 OrtCustomOp::GetInputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputType(index); };
934
935 OrtCustomOp::GetOutputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetOutputTypeCount(); };
936 OrtCustomOp::GetOutputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputType(index); };
937
938 OrtCustomOp::KernelCompute = [](void* op_kernel, OrtKernelContext* context) { static_cast<TKernel*>(op_kernel)->Compute(context); };
939 OrtCustomOp::KernelDestroy = [](void* op_kernel) { delete static_cast<TKernel*>(op_kernel); };
940
941 OrtCustomOp::GetInputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputCharacteristic(index); };
942 OrtCustomOp::GetOutputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputCharacteristic(index); };
943 }
944
945 // Default implementation of GetExecutionProviderType that returns nullptr to default to the CPU provider
946 const char* GetExecutionProviderType() const { return nullptr; }
947
948 // Default implementations of GetInputCharacteristic() and GetOutputCharacteristic() below
949 // (inputs and outputs are required by default)
952 }
953
956 }
957};
958
959} // namespace Ort
960
961#include "onnxruntime_cxx_inline.h"
struct OrtMemoryInfo OrtMemoryInfo
Definition: onnxruntime_c_api.h:238
struct OrtKernelInfo OrtKernelInfo
Definition: onnxruntime_c_api.h:310
OrtLoggingLevel
Logging severity levels.
Definition: onnxruntime_c_api.h:203
void(* OrtLoggingFunction)(void *param, OrtLoggingLevel severity, const char *category, const char *logid, const char *code_location, const char *message)
Definition: onnxruntime_c_api.h:275
OrtCustomOpInputOutputCharacteristic
Definition: onnxruntime_c_api.h:2960
struct OrtThreadingOptions OrtThreadingOptions
Definition: onnxruntime_c_api.h:251
struct OrtSequenceTypeInfo OrtSequenceTypeInfo
Definition: onnxruntime_c_api.h:248
OrtSparseIndicesFormat
Definition: onnxruntime_c_api.h:192
struct OrtPrepackedWeightsContainer OrtPrepackedWeightsContainer
Definition: onnxruntime_c_api.h:253
struct OrtCustomOpDomain OrtCustomOpDomain
Definition: onnxruntime_c_api.h:246
OrtAllocatorType
Definition: onnxruntime_c_api.h:316
struct OrtModelMetadata OrtModelMetadata
Definition: onnxruntime_c_api.h:249
struct OrtTypeInfo OrtTypeInfo
Definition: onnxruntime_c_api.h:243
struct OrtTensorTypeAndShapeInfo OrtTensorTypeAndShapeInfo
Definition: onnxruntime_c_api.h:244
struct OrtKernelContext OrtKernelContext
Definition: onnxruntime_c_api.h:312
struct OrtSessionOptions OrtSessionOptions
Definition: onnxruntime_c_api.h:245
struct OrtValue OrtValue
Definition: onnxruntime_c_api.h:241
GraphOptimizationLevel
Graph optimization level.
Definition: onnxruntime_c_api.h:284
OrtMemType
Memory types for allocated memory, execution provider specific types should be extended in each provi...
Definition: onnxruntime_c_api.h:325
OrtSparseFormat
Definition: onnxruntime_c_api.h:184
ONNXType
Definition: onnxruntime_c_api.h:173
struct OrtEnv OrtEnv
Definition: onnxruntime_c_api.h:236
OrtErrorCode
Definition: onnxruntime_c_api.h:211
struct OrtStatus OrtStatus
Definition: onnxruntime_c_api.h:237
#define ORT_API_VERSION
The API version defined in this header.
Definition: onnxruntime_c_api.h:31
struct OrtMapTypeInfo OrtMapTypeInfo
Definition: onnxruntime_c_api.h:247
struct OrtArenaCfg OrtArenaCfg
Definition: onnxruntime_c_api.h:252
ExecutionMode
Definition: onnxruntime_c_api.h:291
ONNXTensorElementDataType
Definition: onnxruntime_c_api.h:152
const OrtApiBase * OrtGetApiBase(void)
The Onnxruntime library's entry point to access the C API.
@ ORT_LOGGING_LEVEL_WARNING
Warning messages.
Definition: onnxruntime_c_api.h:206
@ INPUT_OUTPUT_REQUIRED
Definition: onnxruntime_c_api.h:2962
@ ORT_FAIL
Definition: onnxruntime_c_api.h:213
All C++ Onnxruntime APIs are defined inside this namespace.
Definition: onnxruntime_cxx_api.h:33
const OrtApi & GetApi()
This returns a reference to the OrtApi interface in use.
Definition: onnxruntime_cxx_api.h:80
void OrtRelease(OrtAllocator *ptr)
Definition: onnxruntime_cxx_api.h:90
std::vector< std::string > GetAvailableProviders()
This is a C++ wrapper for OrtApi::GetAvailableProviders() and returns a vector of strings representin...
Definition: onnxruntime_cxx_api.h:844
void Free(void *p) const
MemoryAllocation GetAllocation(size_t size)
void * Alloc(size_t size) const
Unowned< const MemoryInfo > GetInfo() const
Allocator(const Session &session, const MemoryInfo &)
Definition: onnxruntime_cxx_api.h:812
const OrtMemoryInfo * GetInfo() const
MemoryAllocation GetAllocation(size_t size)
it is a structure that represents the configuration of an arena based allocator
Definition: onnxruntime_cxx_api.h:875
ArenaCfg(std::nullptr_t)
Create an empty ArenaCfg object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:876
ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk)
bfloat16 (Brain Floating Point) data type
Definition: onnxruntime_cxx_api.h:167
uint16_t value
Definition: onnxruntime_cxx_api.h:168
constexpr bool operator!=(const BFloat16_t &rhs) const noexcept
Definition: onnxruntime_cxx_api.h:173
constexpr BFloat16_t(uint16_t v) noexcept
Definition: onnxruntime_cxx_api.h:170
constexpr bool operator==(const BFloat16_t &rhs) const noexcept
Definition: onnxruntime_cxx_api.h:172
constexpr BFloat16_t() noexcept
Definition: onnxruntime_cxx_api.h:169
Used internally by the C++ API. C++ wrapper types inherit from this.
Definition: onnxruntime_cxx_api.h:186
Base & operator=(const Base &)=delete
T * release()
Releases ownership of the contained pointer.
Definition: onnxruntime_cxx_api.h:200
~Base()
Definition: onnxruntime_cxx_api.h:194
Base()=default
Base(Base &&v) noexcept
Definition: onnxruntime_cxx_api.h:209
T * p_
Definition: onnxruntime_cxx_api.h:212
Base(const Base &)=delete
Base(T *p)
Definition: onnxruntime_cxx_api.h:190
void operator=(Base &&v) noexcept
Definition: onnxruntime_cxx_api.h:210
T contained_type
Definition: onnxruntime_cxx_api.h:187
Definition: onnxruntime_cxx_api.h:892
size_t KernelContext_GetOutputCount(const OrtKernelContext *context)
size_t GetDimensionsCount(const OrtTensorTypeAndShapeInfo *info)
size_t KernelContext_GetInputCount(const OrtKernelContext *context)
OrtValue * KernelContext_GetOutput(OrtKernelContext *context, size_t index, const int64_t *dim_values, size_t dim_count)
void ReleaseTensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo *input)
T KernelInfoGetAttribute(const OrtKernelInfo *info, const char *name)
OrtTensorTypeAndShapeInfo * GetTensorTypeAndShape(const OrtValue *value)
std::vector< int64_t > GetTensorShape(const OrtTensorTypeAndShapeInfo *info)
void GetDimensions(const OrtTensorTypeAndShapeInfo *info, int64_t *dim_values, size_t dim_values_length)
void ThrowOnError(OrtStatus *result)
size_t GetTensorShapeElementCount(const OrtTensorTypeAndShapeInfo *info)
ONNXTensorElementDataType GetTensorElementType(const OrtTensorTypeAndShapeInfo *info)
CustomOpApi(const OrtApi &api)
Definition: onnxruntime_cxx_api.h:893
void SetDimensions(OrtTensorTypeAndShapeInfo *info, const int64_t *dim_values, size_t dim_count)
T * GetTensorMutableData(OrtValue *value)
const OrtValue * KernelContext_GetInput(const OrtKernelContext *context, size_t index)
const T * GetTensorData(const OrtValue *value)
Definition: onnxruntime_cxx_api.h:924
OrtCustomOpInputOutputCharacteristic GetOutputCharacteristic(size_t) const
Definition: onnxruntime_cxx_api.h:954
CustomOpBase()
Definition: onnxruntime_cxx_api.h:925
const char * GetExecutionProviderType() const
Definition: onnxruntime_cxx_api.h:946
OrtCustomOpInputOutputCharacteristic GetInputCharacteristic(size_t) const
Definition: onnxruntime_cxx_api.h:950
Custom Op Domain.
Definition: onnxruntime_cxx_api.h:268
CustomOpDomain(std::nullptr_t)
Create an empty CustomOpDomain object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:269
CustomOpDomain(const char *domain)
Wraps OrtApi::CreateCustomOpDomain.
void Add(OrtCustomOp *op)
Wraps CustomOpDomain_Add.
The Env (Environment)
Definition: onnxruntime_cxx_api.h:240
Env & EnableTelemetryEvents()
Wraps OrtApi::EnableTelemetryEvents.
Env(OrtEnv *p)
C Interop Helper.
Definition: onnxruntime_cxx_api.h:257
Env(std::nullptr_t)
Create an empty Env object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:241
Env(OrtLoggingLevel logging_level=ORT_LOGGING_LEVEL_WARNING, const char *logid="")
Wraps OrtApi::CreateEnv.
Env(const OrtThreadingOptions *tp_options, OrtLoggingLevel logging_level=ORT_LOGGING_LEVEL_WARNING, const char *logid="")
Wraps OrtApi::CreateEnvWithGlobalThreadPools.
Env(const OrtThreadingOptions *tp_options, OrtLoggingFunction logging_function, void *logger_param, OrtLoggingLevel logging_level=ORT_LOGGING_LEVEL_WARNING, const char *logid="")
Wraps OrtApi::CreateEnvWithCustomLoggerAndGlobalThreadPools.
Env(OrtLoggingLevel logging_level, const char *logid, OrtLoggingFunction logging_function, void *logger_param)
Wraps OrtApi::CreateEnvWithCustomLogger.
Env & CreateAndRegisterAllocator(const OrtMemoryInfo *mem_info, const OrtArenaCfg *arena_cfg)
Wraps OrtApi::CreateAndRegisterAllocator.
Env & DisableTelemetryEvents()
Wraps OrtApi::DisableTelemetryEvents.
All C++ methods that can fail will throw an exception of this type.
Definition: onnxruntime_cxx_api.h:39
const char * what() const noexcept override
Definition: onnxruntime_cxx_api.h:43
OrtErrorCode GetOrtErrorCode() const
Definition: onnxruntime_cxx_api.h:42
Exception(std::string &&string, OrtErrorCode code)
Definition: onnxruntime_cxx_api.h:40
IEEE 754 half-precision floating point data type.
Definition: onnxruntime_cxx_api.h:148
constexpr bool operator!=(const Float16_t &rhs) const noexcept
Definition: onnxruntime_cxx_api.h:154
constexpr Float16_t(uint16_t v) noexcept
Definition: onnxruntime_cxx_api.h:151
uint16_t value
Definition: onnxruntime_cxx_api.h:149
constexpr bool operator==(const Float16_t &rhs) const noexcept
Definition: onnxruntime_cxx_api.h:153
constexpr Float16_t() noexcept
Definition: onnxruntime_cxx_api.h:150
Definition: onnxruntime_cxx_api.h:66
static const OrtApi * api_
Definition: onnxruntime_cxx_api.h:67
Definition: onnxruntime_cxx_api.h:854
void BindInput(const char *name, const Value &)
std::vector< Value > GetOutputValues() const
std::vector< std::string > GetOutputNames() const
std::vector< Value > GetOutputValues(Allocator &) const
std::vector< std::string > GetOutputNames(Allocator &) const
void BindOutput(const char *name, const MemoryInfo &)
void ClearBoundOutputs()
void ClearBoundInputs()
void BindOutput(const char *name, const Value &)
IoBinding(Session &session)
Wrapper around OrtMapTypeInfo.
Definition: onnxruntime_cxx_api.h:452
ONNXTensorElementDataType GetMapKeyType() const
Wraps OrtApi::GetMapKeyType.
TypeInfo GetMapValueType() const
Wraps OrtApi::GetMapValueType.
MapTypeInfo(OrtMapTypeInfo *p)
Used for interop with the C API.
Definition: onnxruntime_cxx_api.h:454
MapTypeInfo(std::nullptr_t)
Create an empty MapTypeInfo object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:453
Definition: onnxruntime_cxx_api.h:795
MemoryAllocation(MemoryAllocation &&) noexcept
MemoryAllocation & operator=(const MemoryAllocation &)=delete
void * get()
Definition: onnxruntime_cxx_api.h:803
MemoryAllocation(const MemoryAllocation &)=delete
MemoryAllocation(OrtAllocator *allocator, void *p, size_t size)
size_t size() const
Definition: onnxruntime_cxx_api.h:804
Definition: onnxruntime_cxx_api.h:829
OrtAllocatorType GetAllocatorType() const
MemoryInfo(const char *name, OrtAllocatorType type, int id, OrtMemType mem_type)
MemoryInfo(std::nullptr_t)
Definition: onnxruntime_cxx_api.h:832
MemoryInfo(OrtMemoryInfo *p)
Used for interop with the C API.
Definition: onnxruntime_cxx_api.h:833
static MemoryInfo CreateCpu(OrtAllocatorType type, OrtMemType mem_type1)
std::string GetAllocatorName() const
bool operator==(const MemoryInfo &o) const
int GetDeviceId() const
OrtMemType GetMemoryType() const
Wrapper around OrtModelMetadata.
Definition: onnxruntime_cxx_api.h:355
char * GetDomain(OrtAllocator *allocator) const
Wraps OrtApi::ModelMetadataGetDomain.
char * LookupCustomMetadataMap(const char *key, OrtAllocator *allocator) const
Wraps OrtApi::ModelMetadataLookupCustomMetadataMap.
ModelMetadata(std::nullptr_t)
Create an empty ModelMetadata object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:356
char * GetProducerName(OrtAllocator *allocator) const
Wraps OrtApi::ModelMetadataGetProducerName.
char * GetGraphName(OrtAllocator *allocator) const
Wraps OrtApi::ModelMetadataGetGraphName.
char * GetGraphDescription(OrtAllocator *allocator) const
Wraps OrtApi::ModelMetadataGetGraphDescription.
char * GetDescription(OrtAllocator *allocator) const
Wraps OrtApi::ModelMetadataGetDescription.
char ** GetCustomMetadataMapKeys(OrtAllocator *allocator, int64_t &num_keys) const
Wraps OrtApi::ModelMetadataGetCustomMetadataMapKeys.
ModelMetadata(OrtModelMetadata *p)
Used for interop with the C API.
Definition: onnxruntime_cxx_api.h:357
int64_t GetVersion() const
Wraps OrtApi::ModelMetadataGetVersion.
Definition: onnxruntime_cxx_api.h:277
int GetRunLogSeverityLevel() const
Wraps OrtApi::RunOptionsGetRunLogSeverityLevel.
RunOptions & SetTerminate()
Terminates all currently executing Session::Run calls that were made using this RunOptions instance.
RunOptions & SetRunTag(const char *run_tag)
wraps OrtApi::RunOptionsSetRunTag
RunOptions & UnsetTerminate()
Clears the terminate flag so this RunOptions instance can be used in a new Session::Run call without ...
int GetRunLogVerbosityLevel() const
Wraps OrtApi::RunOptionsGetRunLogVerbosityLevel.
RunOptions(std::nullptr_t)
Create an empty RunOptions object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:278
RunOptions & SetRunLogVerbosityLevel(int)
Wraps OrtApi::RunOptionsSetRunLogVerbosityLevel.
RunOptions & SetRunLogSeverityLevel(int)
Wraps OrtApi::RunOptionsSetRunLogSeverityLevel.
RunOptions & AddConfigEntry(const char *config_key, const char *config_value)
Wraps OrtApi::AddRunConfigEntry.
const char * GetRunTag() const
Wraps OrtApi::RunOptionsGetRunTag.
RunOptions()
Wraps OrtApi::CreateRunOptions.
Wrapper around OrtSequenceTypeInfo.
Definition: onnxruntime_cxx_api.h:442
TypeInfo GetSequenceElementType() const
Wraps OrtApi::GetSequenceElementType.
SequenceTypeInfo(std::nullptr_t)
Create an empty SequenceTypeInfo object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:443
SequenceTypeInfo(OrtSequenceTypeInfo *p)
Used for interop with the C API.
Definition: onnxruntime_cxx_api.h:444
Wrapper around OrtSession.
Definition: onnxruntime_cxx_api.h:372
Session(Env &env, const char *model_path, const SessionOptions &options)
Wraps OrtApi::CreateSession.
char * GetInputName(size_t index, OrtAllocator *allocator) const
Wraps OrtApi::SessionGetInputName.
char * GetOutputName(size_t index, OrtAllocator *allocator) const
Wraps OrtApi::SessionGetOutputName.
size_t GetInputCount() const
Returns the number of model inputs.
Session(Env &env, const char *model_path, const SessionOptions &options, OrtPrepackedWeightsContainer *prepacked_weights_container)
Wraps OrtApi::CreateSessionWithPrepackedWeightsContainer.
Session(std::nullptr_t)
Create an empty Session object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:373
TypeInfo GetOutputTypeInfo(size_t index) const
Wraps OrtApi::SessionGetOutputTypeInfo.
ModelMetadata GetModelMetadata() const
Wraps OrtApi::SessionGetModelMetadata.
void Run(const RunOptions &run_options, const char *const *input_names, const Value *input_values, size_t input_count, const char *const *output_names, Value *output_values, size_t output_count)
Run the model returning results in user provided outputs Same as Run(const RunOptions&,...
size_t GetOverridableInitializerCount() const
Returns the number of inputs that have defaults that can be overridden.
size_t GetOutputCount() const
Returns the number of model outputs.
Session(Env &env, const void *model_data, size_t model_data_length, const SessionOptions &options)
Wraps OrtApi::CreateSessionFromArray.
uint64_t GetProfilingStartTimeNs() const
Wraps OrtApi::SessionGetProfilingStartTimeNs.
char * EndProfiling(OrtAllocator *allocator) const
Wraps OrtApi::SessionEndProfiling.
TypeInfo GetInputTypeInfo(size_t index) const
Wraps OrtApi::SessionGetInputTypeInfo.
char * GetOverridableInitializerName(size_t index, OrtAllocator *allocator) const
Wraps OrtApi::SessionGetOverridableInitializerName.
TypeInfo GetOverridableInitializerTypeInfo(size_t index) const
Wraps OrtApi::SessionGetOverridableInitializerTypeInfo.
void Run(const RunOptions &run_options, const struct IoBinding &)
Wraps OrtApi::RunWithBinding.
std::vector< Value > Run(const RunOptions &run_options, const char *const *input_names, const Value *input_values, size_t input_count, const char *const *output_names, size_t output_count)
Run the model returning results in an Ort allocated vector.
Options object used when creating a new Session object.
Definition: onnxruntime_cxx_api.h:310
SessionOptions & SetGraphOptimizationLevel(GraphOptimizationLevel graph_optimization_level)
Wraps OrtApi::SetSessionGraphOptimizationLevel.
SessionOptions & EnableMemPattern()
Wraps OrtApi::EnableMemPattern.
SessionOptions & AddConfigEntry(const char *config_key, const char *config_value)
Wraps OrtApi::AddSessionConfigEntry.
SessionOptions & AppendExecutionProvider_TensorRT(const OrtTensorRTProviderOptions &provider_options)
Wraps OrtApi::SessionOptionsAppendExecutionProvider_TensorRT.
SessionOptions & SetIntraOpNumThreads(int intra_op_num_threads)
Wraps OrtApi::SetIntraOpNumThreads.
SessionOptions & DisableProfiling()
Wraps OrtApi::DisableProfiling.
SessionOptions & DisablePerSessionThreads()
Wraps OrtApi::DisablePerSessionThreads.
SessionOptions Clone() const
Creates and returns a copy of this SessionOptions object. Wraps OrtApi::CloneSessionOptions.
SessionOptions(std::nullptr_t)
Create an empty SessionOptions object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:311
SessionOptions & EnableOrtCustomOps()
Wraps OrtApi::EnableOrtCustomOps.
SessionOptions()
Wraps OrtApi::CreateSessionOptions.
SessionOptions & EnableProfiling(const char *profile_file_prefix)
Wraps OrtApi::EnableProfiling.
SessionOptions & SetOptimizedModelFilePath(const char *optimized_model_file)
Wraps OrtApi::SetOptimizedModelFilePath.
SessionOptions & EnableCpuMemArena()
Wraps OrtApi::EnableCpuMemArena.
SessionOptions & AppendExecutionProvider_OpenVINO(const OrtOpenVINOProviderOptions &provider_options)
Wraps OrtApi::SessionOptionsAppendExecutionProvider_OpenVINO.
SessionOptions & DisableMemPattern()
Wraps OrtApi::DisableMemPattern.
SessionOptions & AddInitializer(const char *name, const OrtValue *ort_val)
Wraps OrtApi::AddInitializer.
SessionOptions & SetLogSeverityLevel(int level)
Wraps OrtApi::SetSessionLogSeverityLevel.
SessionOptions & SetInterOpNumThreads(int inter_op_num_threads)
Wraps OrtApi::SetInterOpNumThreads.
SessionOptions & AppendExecutionProvider_ROCM(const OrtROCMProviderOptions &provider_options)
Wraps OrtApi::SessionOptionsAppendExecutionProvider_ROCM.
SessionOptions & DisableCpuMemArena()
Wraps OrtApi::DisableCpuMemArena.
SessionOptions & SetExecutionMode(ExecutionMode execution_mode)
Wraps OrtApi::SetSessionExecutionMode.
SessionOptions & SetLogId(const char *logid)
Wraps OrtApi::SetSessionLogId.
SessionOptions(OrtSessionOptions *p)
Used for interop with the C API.
Definition: onnxruntime_cxx_api.h:313
SessionOptions & Add(OrtCustomOpDomain *custom_op_domain)
Wraps OrtApi::AddCustomOpDomain.
SessionOptions & AppendExecutionProvider_CUDA(const OrtCUDAProviderOptions &provider_options)
Wraps OrtApi::SessionOptionsAppendExecutionProvider_CUDA.
Wrapper around OrtTensorTypeAndShapeInfo.
Definition: onnxruntime_cxx_api.h:425
TensorTypeAndShapeInfo(std::nullptr_t)
Create an empty TensorTypeAndShapeInfo object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:426
TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo *p)
Used for interop with the C API.
Definition: onnxruntime_cxx_api.h:427
void GetDimensions(int64_t *values, size_t values_count) const
Wraps OrtApi::GetDimensions.
std::vector< int64_t > GetShape() const
Uses GetDimensionsCount & GetDimensions to return a std::vector of the shape.
size_t GetDimensionsCount() const
Wraps OrtApi::GetDimensionsCount.
ONNXTensorElementDataType GetElementType() const
Wraps OrtApi::GetTensorElementType.
size_t GetElementCount() const
Wraps OrtApi::GetTensorShapeElementCount.
void GetSymbolicDimensions(const char **values, size_t values_count) const
Wraps OrtApi::GetSymbolicDimensions.
Definition: onnxruntime_cxx_api.h:460
Unowned< MapTypeInfo > GetMapTypeInfo() const
Wraps OrtApi::CastTypeInfoToMapTypeInfo.
Unowned< SequenceTypeInfo > GetSequenceTypeInfo() const
Wraps OrtApi::CastTypeInfoToSequenceTypeInfo.
ONNXType GetONNXType() const
Unowned< TensorTypeAndShapeInfo > GetTensorTypeAndShapeInfo() const
Wraps OrtApi::CastTypeInfoToTensorInfo.
TypeInfo(std::nullptr_t)
Create an empty TypeInfo object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:461
TypeInfo(OrtTypeInfo *p)
C API Interop.
Definition: onnxruntime_cxx_api.h:462
Wraps an object that inherits from Ort::Base and stops it from deleting the contained pointer on dest...
Definition: onnxruntime_cxx_api.h:222
Unowned(Unowned &&v)
Definition: onnxruntime_cxx_api.h:224
~Unowned()
Definition: onnxruntime_cxx_api.h:225
Unowned(typename T::contained_type *p)
Definition: onnxruntime_cxx_api.h:223
Definition: onnxruntime_cxx_api.h:480
const char ** str
Definition: onnxruntime_cxx_api.h:485
size_t values_shape_len
Definition: onnxruntime_cxx_api.h:482
const int64_t * values_shape
Definition: onnxruntime_cxx_api.h:481
const void * p_data
Definition: onnxruntime_cxx_api.h:484
union Ort::Value::OrtSparseValuesParam::@0 data
Definition: onnxruntime_cxx_api.h:491
const int64_t * shape
Definition: onnxruntime_cxx_api.h:492
size_t shape_len
Definition: onnxruntime_cxx_api.h:493
Definition: onnxruntime_cxx_api.h:471
T * GetTensorMutableData()
Wraps OrtApi::GetTensorMutableData.
static Value CreateMap(Value &keys, Value &values)
Wraps OrtApi::CreateValue.
static Value CreateSparseTensor(const OrtMemoryInfo *info, void *p_data, const Shape &dense_shape, const Shape &values_shape, ONNXTensorElementDataType type)
Creates an OrtValue instance containing SparseTensor. This constructs a sparse tensor that makes use ...
static Value CreateSparseTensor(const OrtMemoryInfo *info, T *p_data, const Shape &dense_shape, const Shape &values_shape)
This is a simple forwarding method to the other overload that helps deducing data type enum value fro...
const T * GetSparseTensorIndicesData(OrtSparseIndicesFormat indices_format, size_t &num_indices) const
The API retrieves a pointer to the internal indices buffer. The API merely performs a convenience dat...
Value & operator=(Value &&)=default
static Value CreateSparseTensor(OrtAllocator *allocator, const Shape &dense_shape, ONNXTensorElementDataType type)
Creates an instance of OrtValue containing sparse tensor. The created instance has no data....
void UseCooIndices(int64_t *indices_data, size_t indices_num)
Supplies COO format specific indices and marks the contained sparse tensor as being a COO format tens...
Value(Value &&)=default
Value(std::nullptr_t)
Create an empty Value object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:692
bool IsTensor() const
Returns true if Value is a tensor, false for other types like map/sequence/etc.
const T * GetTensorData() const
Wraps OrtApi::GetTensorMutableData.
static Value CreateTensor(const OrtMemoryInfo *info, T *p_data, size_t p_data_element_count, const int64_t *shape, size_t shape_len)
Wraps OrtApi::CreateTensorWithDataAsOrtValue.
TensorTypeAndShapeInfo GetTensorTypeAndShapeInfo() const
The API returns type information for data contained in a tensor. For sparse tensors it returns type i...
void UseCsrIndices(int64_t *inner_data, size_t inner_num, int64_t *outer_data, size_t outer_num)
Supplies CSR format specific indices and marks the contained sparse tensor as being a CSR format tens...
Value(OrtValue *p)
Used for interop with the C API.
Definition: onnxruntime_cxx_api.h:693
void GetStringTensorContent(void *buffer, size_t buffer_length, size_t *offsets, size_t offsets_count) const
The API copies all of the UTF-8 encoded string data contained within a tensor or a sparse tensor into...
static Value CreateSparseTensor(OrtAllocator *allocator, const Shape &dense_shape)
This is a simple forwarding method the below CreateSparseTensor. This helps to specify data type enum...
static Value CreateTensor(OrtAllocator *allocator, const int64_t *shape, size_t shape_len, ONNXTensorElementDataType type)
size_t GetCount() const
bool IsSparseTensor() const
Returns true if the OrtValue contains a sparse tensor
TensorTypeAndShapeInfo GetSparseTensorIndicesTypeShapeInfo(OrtSparseIndicesFormat format) const
The API returns type and shape information for the specified indices. Each supported indices have the...
size_t GetStringTensorElementLength(size_t element_index) const
The API returns a byte length of UTF-8 encoded string element contained in either a tensor or a spare...
TensorTypeAndShapeInfo GetSparseTensorValuesTypeAndShapeInfo() const
The API returns type and shape information for stored non-zero values of the sparse tensor....
void UseBlockSparseIndices(const Shape &indices_shape, int32_t *indices_data)
Supplies BlockSparse format specific indices and marks the contained sparse tensor as being a BlockSp...
void FillStringTensor(const char *const *s, size_t s_len)
void FillSparseTensorBlockSparse(const OrtMemoryInfo *data_mem_info, const OrtSparseValuesParam &values, const Shape &indices_shape, const int32_t *indices_data)
The API will allocate memory using the allocator instance supplied to the CreateSparseTensor() API an...
T & At(const std::vector< int64_t > &location)
TypeInfo GetTypeInfo() const
The API returns type information for data contained in a tensor. For sparse tensors it returns type i...
void FillSparseTensorCoo(const OrtMemoryInfo *data_mem_info, const OrtSparseValuesParam &values_param, const int64_t *indices_data, size_t indices_num)
The API will allocate memory using the allocator instance supplied to the CreateSparseTensor() API an...
static Value CreateTensor(const OrtMemoryInfo *info, void *p_data, size_t p_data_byte_count, const int64_t *shape, size_t shape_len, ONNXTensorElementDataType type)
Wraps OrtApi::CreateTensorWithDataAsOrtValue.
static Value CreateOpaque(const char *domain, const char *type_name, const T &)
Wraps OrtApi::CreateOpaqueValue.
Value GetValue(int index, OrtAllocator *allocator) const
static Value CreateTensor(OrtAllocator *allocator, const int64_t *shape, size_t shape_len)
static Value CreateSequence(std::vector< Value > &values)
Wraps OrtApi::CreateValue.
void GetStringTensorElement(size_t buffer_length, size_t element_index, void *buffer) const
The API copies UTF-8 encoded bytes for the requested string element contained within a tensor or a sp...
void FillSparseTensorCsr(const OrtMemoryInfo *data_mem_info, const OrtSparseValuesParam &values, const int64_t *inner_indices_data, size_t inner_indices_num, const int64_t *outer_indices_data, size_t outer_indices_num)
The API will allocate memory using the allocator instance supplied to the CreateSparseTensor() API an...
void FillStringTensorElement(const char *s, size_t index)
const T * GetSparseTensorValues() const
The API returns a pointer to an internal buffer of the sparse tensor containing non-zero values....
void GetOpaqueData(const char *domain, const char *type_name, T &) const
Wraps OrtApi::GetOpaqueValue.
OrtSparseFormat GetSparseFormat() const
The API returns the sparse data format this OrtValue holds in a sparse tensor. If the sparse tensor w...
size_t GetStringTensorDataLength() const
This API returns a full length of string data contained within either a tensor or a sparse Tensor....
Memory allocation interface.
Definition: onnxruntime_c_api.h:268
const OrtApi *(* GetApi)(uint32_t version)
Get a pointer to the requested version of the OrtApi.
Definition: onnxruntime_c_api.h:437
The C API.
Definition: onnxruntime_c_api.h:455
CUDA Provider Options.
Definition: onnxruntime_c_api.h:344
Definition: onnxruntime_c_api.h:2970
OrtCustomOpInputOutputCharacteristic(* GetOutputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition: onnxruntime_c_api.h:2995
size_t(* GetInputTypeCount)(const struct OrtCustomOp *op)
Definition: onnxruntime_c_api.h:2985
const char *(* GetName)(const struct OrtCustomOp *op)
Definition: onnxruntime_c_api.h:2978
size_t(* GetOutputTypeCount)(const struct OrtCustomOp *op)
Definition: onnxruntime_c_api.h:2987
void(* KernelDestroy)(void *op_kernel)
Definition: onnxruntime_c_api.h:2991
void *(* CreateKernel)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info)
Definition: onnxruntime_c_api.h:2974
uint32_t version
Definition: onnxruntime_c_api.h:2971
ONNXTensorElementDataType(* GetInputType)(const struct OrtCustomOp *op, size_t index)
Definition: onnxruntime_c_api.h:2984
OrtCustomOpInputOutputCharacteristic(* GetInputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition: onnxruntime_c_api.h:2994
const char *(* GetExecutionProviderType)(const struct OrtCustomOp *op)
Definition: onnxruntime_c_api.h:2981
ONNXTensorElementDataType(* GetOutputType)(const struct OrtCustomOp *op, size_t index)
Definition: onnxruntime_c_api.h:2986
void(* KernelCompute)(void *op_kernel, OrtKernelContext *context)
Definition: onnxruntime_c_api.h:2990
OpenVINO Provider Options.
Definition: onnxruntime_c_api.h:407
ROCM Provider Options.
Definition: onnxruntime_c_api.h:371
TensorRT Provider Options.
Definition: onnxruntime_c_api.h:382