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 {
211 OrtRelease(p_);
212 p_ = v.release();
213 }
214
215 T* p_{};
216
217 template <typename>
218 friend struct Unowned; // This friend line is needed to keep the centos C++ compiler from giving an error
219};
220
225template <typename T>
226struct Unowned : T {
227 Unowned(typename T::contained_type* p) : T{p} {}
228 Unowned(Unowned&& v) : T{v.p_} {}
229 ~Unowned() { this->release(); }
230};
231
232struct AllocatorWithDefaultOptions;
233struct MemoryInfo;
234struct Env;
235struct TypeInfo;
236struct Value;
237struct ModelMetadata;
238
244struct Env : Base<OrtEnv> {
245 explicit Env(std::nullptr_t) {}
246
248 Env(OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
249
251 Env(OrtLoggingLevel logging_level, const char* logid, OrtLoggingFunction logging_function, void* logger_param);
252
254 Env(const OrtThreadingOptions* tp_options, OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
255
257 Env(const OrtThreadingOptions* tp_options, OrtLoggingFunction logging_function, void* logger_param,
258 OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
259
261 explicit Env(OrtEnv* p) : Base<OrtEnv>{p} {}
262
265
266 Env& CreateAndRegisterAllocator(const OrtMemoryInfo* mem_info, const OrtArenaCfg* arena_cfg);
267};
268
272struct CustomOpDomain : Base<OrtCustomOpDomain> {
273 explicit CustomOpDomain(std::nullptr_t) {}
274
276 explicit CustomOpDomain(const char* domain);
277
278 void Add(OrtCustomOp* op);
279};
280
281struct RunOptions : Base<OrtRunOptions> {
282 explicit RunOptions(std::nullptr_t) {}
284
287
290
291 RunOptions& SetRunTag(const char* run_tag);
292 const char* GetRunTag() const;
293
294 RunOptions& AddConfigEntry(const char* config_key, const char* config_value);
295
302
308};
309
314struct SessionOptions : Base<OrtSessionOptions> {
315 explicit SessionOptions(std::nullptr_t) {}
318
320
321 SessionOptions& SetIntraOpNumThreads(int intra_op_num_threads);
322 SessionOptions& SetInterOpNumThreads(int inter_op_num_threads);
324
327
328 SessionOptions& SetOptimizedModelFilePath(const ORTCHAR_T* optimized_model_file);
329
330 SessionOptions& EnableProfiling(const ORTCHAR_T* profile_file_prefix);
332
334
337
339
340 SessionOptions& SetLogId(const char* logid);
342
344
346
347 SessionOptions& AddConfigEntry(const char* config_key, const char* config_value);
348 SessionOptions& AddInitializer(const char* name, const OrtValue* ort_val);
349
354
356 SessionOptions& SetCustomThreadCreationOptions(void* ort_custom_thread_creation_options);
358};
359
363struct ModelMetadata : Base<OrtModelMetadata> {
364 explicit ModelMetadata(std::nullptr_t) {}
366
367 char* GetProducerName(OrtAllocator* allocator) const;
368 char* GetGraphName(OrtAllocator* allocator) const;
369 char* GetDomain(OrtAllocator* allocator) const;
370 char* GetDescription(OrtAllocator* allocator) const;
371 char* GetGraphDescription(OrtAllocator* allocator) const;
372 char** GetCustomMetadataMapKeys(OrtAllocator* allocator, _Out_ int64_t& num_keys) const;
373 char* LookupCustomMetadataMap(const char* key, OrtAllocator* allocator) const;
374 int64_t GetVersion() const;
375};
376
380struct Session : Base<OrtSession> {
381 explicit Session(std::nullptr_t) {}
382 Session(Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
383 Session(Env& env, const ORTCHAR_T* model_path, const SessionOptions& options, OrtPrepackedWeightsContainer* prepacked_weights_container);
384 Session(Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options);
385
403 std::vector<Value> Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
404 const char* const* output_names, size_t output_count);
405
409 void Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
410 const char* const* output_names, Value* output_values, size_t output_count);
411
412 void Run(const RunOptions& run_options, const struct IoBinding&);
413
414 size_t GetInputCount() const;
415 size_t GetOutputCount() const;
417
418 char* GetInputName(size_t index, OrtAllocator* allocator) const;
419 char* GetOutputName(size_t index, OrtAllocator* allocator) const;
420 char* GetOverridableInitializerName(size_t index, OrtAllocator* allocator) const;
421 char* EndProfiling(OrtAllocator* allocator) const;
422 uint64_t GetProfilingStartTimeNs() const;
424
425 TypeInfo GetInputTypeInfo(size_t index) const;
426 TypeInfo GetOutputTypeInfo(size_t index) const;
428};
429
433struct TensorTypeAndShapeInfo : Base<OrtTensorTypeAndShapeInfo> {
434 explicit TensorTypeAndShapeInfo(std::nullptr_t) {}
436
438 size_t GetElementCount() const;
439
440 size_t GetDimensionsCount() const;
441 void GetDimensions(int64_t* values, size_t values_count) const;
442 void GetSymbolicDimensions(const char** values, size_t values_count) const;
443
444 std::vector<int64_t> GetShape() const;
445};
446
450struct SequenceTypeInfo : Base<OrtSequenceTypeInfo> {
451 explicit SequenceTypeInfo(std::nullptr_t) {}
453
455};
456
460struct MapTypeInfo : Base<OrtMapTypeInfo> {
461 explicit MapTypeInfo(std::nullptr_t) {}
463
466};
467
468struct TypeInfo : Base<OrtTypeInfo> {
469 explicit TypeInfo(std::nullptr_t) {}
470 explicit TypeInfo(OrtTypeInfo* p) : Base<OrtTypeInfo>{p} {}
471
475
477};
478
479struct Value : Base<OrtValue> {
480 // This structure is used to feed sparse tensor values
481 // information for use with FillSparseTensor<Format>() API
482 // if the data type for the sparse tensor values is numeric
483 // use data.p_data, otherwise, use data.str pointer to feed
484 // values. data.str is an array of const char* that are zero terminated.
485 // number of strings in the array must match shape size.
486 // For fully sparse tensors use shape {0} and set p_data/str
487 // to nullptr.
489 const int64_t* values_shape;
491 union {
492 const void* p_data;
493 const char** str;
495 };
496
497 // Provides a way to pass shape in a single
498 // argument
499 struct Shape {
500 const int64_t* shape;
501 size_t shape_len;
502 };
503
505 template <typename T>
506 static Value CreateTensor(const OrtMemoryInfo* info, T* p_data, size_t p_data_element_count, const int64_t* shape, size_t shape_len);
508 static Value CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count, const int64_t* shape, size_t shape_len,
510
511#if !defined(DISABLE_SPARSE_TENSORS)
522 template <typename T>
523 static Value CreateSparseTensor(const OrtMemoryInfo* info, T* p_data, const Shape& dense_shape,
524 const Shape& values_shape);
525
542 static Value CreateSparseTensor(const OrtMemoryInfo* info, void* p_data, const Shape& dense_shape,
543 const Shape& values_shape, ONNXTensorElementDataType type);
544
553 void UseCooIndices(int64_t* indices_data, size_t indices_num);
554
565 void UseCsrIndices(int64_t* inner_data, size_t inner_num, int64_t* outer_data, size_t outer_num);
566
575 void UseBlockSparseIndices(const Shape& indices_shape, int32_t* indices_data);
576
577#endif // !defined(DISABLE_SPARSE_TENSORS)
578
579 // \brief Wraps OrtApi::CreateTensorAsOrtValue
580 template <typename T>
581 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len);
582 // \brief Wraps OrtApi::CreateTensorAsOrtValue
583 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type);
584
585#if !defined(DISABLE_SPARSE_TENSORS)
595 template <typename T>
596 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape);
597
609 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape, ONNXTensorElementDataType type);
610
620 void FillSparseTensorCoo(const OrtMemoryInfo* data_mem_info, const OrtSparseValuesParam& values_param,
621 const int64_t* indices_data, size_t indices_num);
622
634 void FillSparseTensorCsr(const OrtMemoryInfo* data_mem_info,
635 const OrtSparseValuesParam& values,
636 const int64_t* inner_indices_data, size_t inner_indices_num,
637 const int64_t* outer_indices_data, size_t outer_indices_num);
638
649 const OrtSparseValuesParam& values,
650 const Shape& indices_shape,
651 const int32_t* indices_data);
652
660
667
676
686 template <typename T>
687 const T* GetSparseTensorIndicesData(OrtSparseIndicesFormat indices_format, size_t& num_indices) const;
688
689#endif // !defined(DISABLE_SPARSE_TENSORS)
690
691 static Value CreateMap(Value& keys, Value& values);
692 static Value CreateSequence(std::vector<Value>& values);
693
694 template <typename T>
695 static Value CreateOpaque(const char* domain, const char* type_name, const T&);
696
697 template <typename T>
698 void GetOpaqueData(const char* domain, const char* type_name, T&) const;
699
700 explicit Value(std::nullptr_t) {}
701 explicit Value(OrtValue* p) : Base<OrtValue>{p} {}
702 Value(Value&&) = default;
703 Value& operator=(Value&&) = default;
704
705 bool IsTensor() const;
706 bool HasValue() const;
707
708#if !defined(DISABLE_SPARSE_TENSORS)
713 bool IsSparseTensor() const;
714#endif
715
716 size_t GetCount() const; // If a non tensor, returns 2 for map and N for sequence, where N is the number of elements
717 Value GetValue(int index, OrtAllocator* allocator) const;
718
726
741 void GetStringTensorContent(void* buffer, size_t buffer_length, size_t* offsets, size_t offsets_count) const;
742
743 template <typename T>
745
746 template <typename T>
747 const T* GetTensorData() const;
748
749#if !defined(DISABLE_SPARSE_TENSORS)
758 template <typename T>
759 const T* GetSparseTensorValues() const;
760#endif
761
762 template <typename T>
763 T& At(const std::vector<int64_t>& location);
764
772
780
787 size_t GetStringTensorElementLength(size_t element_index) const;
788
797 void GetStringTensorElement(size_t buffer_length, size_t element_index, void* buffer) const;
798
799 void FillStringTensor(const char* const* s, size_t s_len);
800 void FillStringTensorElement(const char* s, size_t index);
801};
802
803// Represents native memory allocation
805 MemoryAllocation(OrtAllocator* allocator, void* p, size_t size);
810 MemoryAllocation& operator=(MemoryAllocation&&) noexcept;
811
812 void* get() { return p_; }
813 size_t size() const { return size_; }
814
815 private:
816 OrtAllocator* allocator_;
817 void* p_;
818 size_t size_;
819};
820
823
824 operator OrtAllocator*() { return p_; }
825 operator const OrtAllocator*() const { return p_; }
826
827 void* Alloc(size_t size);
828 // The return value will own the allocation
830 void Free(void* p);
831
832 const OrtMemoryInfo* GetInfo() const;
833
834 private:
835 OrtAllocator* p_{};
836};
837
838struct MemoryInfo : Base<OrtMemoryInfo> {
840
841 explicit MemoryInfo(std::nullptr_t) {}
843 MemoryInfo(const char* name, OrtAllocatorType type, int id, OrtMemType mem_type);
844
845 std::string GetAllocatorName() const;
847 int GetDeviceId() const;
849
850 bool operator==(const MemoryInfo& o) const;
851};
852
853struct Allocator : public Base<OrtAllocator> {
854 Allocator(const Session& session, const MemoryInfo&);
855
856 void* Alloc(size_t size) const;
857 // The return value will own the allocation
859 void Free(void* p) const;
861};
862
863struct IoBinding : public Base<OrtIoBinding> {
864 explicit IoBinding(Session& session);
865 void BindInput(const char* name, const Value&);
866 void BindOutput(const char* name, const Value&);
867 void BindOutput(const char* name, const MemoryInfo&);
868 std::vector<std::string> GetOutputNames() const;
869 std::vector<std::string> GetOutputNames(Allocator&) const;
870 std::vector<Value> GetOutputValues() const;
871 std::vector<Value> GetOutputValues(Allocator&) const;
876
877 private:
878 std::vector<std::string> GetOutputNamesHelper(OrtAllocator*) const;
879 std::vector<Value> GetOutputValuesHelper(OrtAllocator*) const;
880};
881
886struct ArenaCfg : Base<OrtArenaCfg> {
887 explicit ArenaCfg(std::nullptr_t) {}
896 ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk);
897};
898
899//
900// Custom OPs (only needed to implement custom OPs)
901//
902
904 CustomOpApi(const OrtApi& api) : api_(api) {}
905
906 template <typename T> // T is only implemented for std::vector<float>, std::vector<int64_t>, float, int64_t, and string
907 T KernelInfoGetAttribute(_In_ const OrtKernelInfo* info, _In_ const char* name);
908
913 void GetDimensions(_In_ const OrtTensorTypeAndShapeInfo* info, _Out_ int64_t* dim_values, size_t dim_values_length);
914 void SetDimensions(OrtTensorTypeAndShapeInfo* info, _In_ const int64_t* dim_values, size_t dim_count);
915
916 template <typename T>
917 T* GetTensorMutableData(_Inout_ OrtValue* value);
918 template <typename T>
919 const T* GetTensorData(_Inout_ const OrtValue* value);
920
921 const OrtMemoryInfo* GetTensorMemoryInfo(_In_ const OrtValue* value);
922
923 std::vector<int64_t> GetTensorShape(const OrtTensorTypeAndShapeInfo* info);
926 const OrtValue* KernelContext_GetInput(const OrtKernelContext* context, _In_ size_t index);
928 OrtValue* KernelContext_GetOutput(OrtKernelContext* context, _In_ size_t index, _In_ const int64_t* dim_values, size_t dim_count);
930
931 void ThrowOnError(OrtStatus* result);
932
933 private:
934 const OrtApi& api_;
935};
936
937template <typename TOp, typename TKernel>
941 OrtCustomOp::CreateKernel = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info) { return static_cast<const TOp*>(this_)->CreateKernel(*api, info); };
942 OrtCustomOp::GetName = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetName(); };
943
944 OrtCustomOp::GetExecutionProviderType = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetExecutionProviderType(); };
945
946 OrtCustomOp::GetInputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetInputTypeCount(); };
947 OrtCustomOp::GetInputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputType(index); };
948
949 OrtCustomOp::GetOutputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetOutputTypeCount(); };
950 OrtCustomOp::GetOutputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputType(index); };
951
952 OrtCustomOp::KernelCompute = [](void* op_kernel, OrtKernelContext* context) { static_cast<TKernel*>(op_kernel)->Compute(context); };
953#if defined(_MSC_VER) && !defined(__clang__)
954#pragma warning(push)
955#pragma warning(disable : 26409)
956#endif
957 OrtCustomOp::KernelDestroy = [](void* op_kernel) { delete static_cast<TKernel*>(op_kernel); };
958#if defined(_MSC_VER) && !defined(__clang__)
959#pragma warning(pop)
960#endif
961 OrtCustomOp::GetInputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputCharacteristic(index); };
962 OrtCustomOp::GetOutputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputCharacteristic(index); };
963 }
964
965 // Default implementation of GetExecutionProviderType that returns nullptr to default to the CPU provider
966 const char* GetExecutionProviderType() const { return nullptr; }
967
968 // Default implementations of GetInputCharacteristic() and GetOutputCharacteristic() below
969 // (inputs and outputs are required by default)
972 }
973
976 }
977};
978
979} // namespace Ort
980
981#include "onnxruntime_cxx_inline.h"
struct OrtMemoryInfo OrtMemoryInfo
Definition: onnxruntime_c_api.h:242
struct OrtKernelInfo OrtKernelInfo
Definition: onnxruntime_c_api.h:315
OrtLoggingLevel
Logging severity levels.
Definition: onnxruntime_c_api.h:207
void(* OrtLoggingFunction)(void *param, OrtLoggingLevel severity, const char *category, const char *logid, const char *code_location, const char *message)
Definition: onnxruntime_c_api.h:280
void(* OrtCustomJoinThreadFn)(OrtCustomThreadHandle ort_custom_thread_handle)
Custom thread join function.
Definition: onnxruntime_c_api.h:554
OrtCustomOpInputOutputCharacteristic
Definition: onnxruntime_c_api.h:3278
struct OrtThreadingOptions OrtThreadingOptions
Definition: onnxruntime_c_api.h:255
struct OrtSequenceTypeInfo OrtSequenceTypeInfo
Definition: onnxruntime_c_api.h:252
OrtSparseIndicesFormat
Definition: onnxruntime_c_api.h:196
struct OrtPrepackedWeightsContainer OrtPrepackedWeightsContainer
Definition: onnxruntime_c_api.h:257
struct OrtCustomOpDomain OrtCustomOpDomain
Definition: onnxruntime_c_api.h:250
OrtAllocatorType
Definition: onnxruntime_c_api.h:321
struct OrtModelMetadata OrtModelMetadata
Definition: onnxruntime_c_api.h:253
struct OrtTypeInfo OrtTypeInfo
Definition: onnxruntime_c_api.h:247
struct OrtTensorTypeAndShapeInfo OrtTensorTypeAndShapeInfo
Definition: onnxruntime_c_api.h:248
struct OrtKernelContext OrtKernelContext
Definition: onnxruntime_c_api.h:317
struct OrtSessionOptions OrtSessionOptions
Definition: onnxruntime_c_api.h:249
struct OrtValue OrtValue
Definition: onnxruntime_c_api.h:245
GraphOptimizationLevel
Graph optimization level.
Definition: onnxruntime_c_api.h:289
OrtMemType
Memory types for allocated memory, execution provider specific types should be extended in each provi...
Definition: onnxruntime_c_api.h:330
OrtSparseFormat
Definition: onnxruntime_c_api.h:188
ONNXType
Definition: onnxruntime_c_api.h:176
struct OrtEnv OrtEnv
Definition: onnxruntime_c_api.h:240
OrtErrorCode
Definition: onnxruntime_c_api.h:215
struct OrtStatus OrtStatus
Definition: onnxruntime_c_api.h:241
#define ORT_API_VERSION
The API version defined in this header.
Definition: onnxruntime_c_api.h:33
struct OrtMapTypeInfo OrtMapTypeInfo
Definition: onnxruntime_c_api.h:251
struct OrtArenaCfg OrtArenaCfg
Definition: onnxruntime_c_api.h:256
ExecutionMode
Definition: onnxruntime_c_api.h:296
OrtCustomThreadHandle(* OrtCustomCreateThreadFn)(void *ort_custom_thread_creation_options, OrtThreadWorkerFn ort_thread_worker_fn, void *ort_worker_fn_param)
Ort custom thread creation function.
Definition: onnxruntime_c_api.h:547
ONNXTensorElementDataType
Definition: onnxruntime_c_api.h:155
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:210
@ INPUT_OUTPUT_REQUIRED
Definition: onnxruntime_c_api.h:3280
@ ORT_FAIL
Definition: onnxruntime_c_api.h:217
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:853
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:821
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:886
ArenaCfg(std::nullptr_t)
Create an empty ArenaCfg object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:887
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:215
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:903
size_t KernelContext_GetOutputCount(const OrtKernelContext *context)
size_t GetDimensionsCount(const OrtTensorTypeAndShapeInfo *info)
void * KernelContext_GetGPUComputeStream(const OrtKernelContext *context)
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:904
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 OrtMemoryInfo * GetTensorMemoryInfo(const OrtValue *value)
const T * GetTensorData(const OrtValue *value)
Definition: onnxruntime_cxx_api.h:938
OrtCustomOpInputOutputCharacteristic GetOutputCharacteristic(size_t) const
Definition: onnxruntime_cxx_api.h:974
CustomOpBase()
Definition: onnxruntime_cxx_api.h:939
const char * GetExecutionProviderType() const
Definition: onnxruntime_cxx_api.h:966
OrtCustomOpInputOutputCharacteristic GetInputCharacteristic(size_t) const
Definition: onnxruntime_cxx_api.h:970
Custom Op Domain.
Definition: onnxruntime_cxx_api.h:272
CustomOpDomain(std::nullptr_t)
Create an empty CustomOpDomain object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:273
CustomOpDomain(const char *domain)
Wraps OrtApi::CreateCustomOpDomain.
void Add(OrtCustomOp *op)
Wraps CustomOpDomain_Add.
The Env (Environment)
Definition: onnxruntime_cxx_api.h:244
Env & EnableTelemetryEvents()
Wraps OrtApi::EnableTelemetryEvents.
Env(OrtEnv *p)
C Interop Helper.
Definition: onnxruntime_cxx_api.h:261
Env(std::nullptr_t)
Create an empty Env object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:245
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:863
void BindInput(const char *name, const Value &)
std::vector< Value > GetOutputValues() const
void SynchronizeOutputs()
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 SynchronizeInputs()
void ClearBoundInputs()
void BindOutput(const char *name, const Value &)
IoBinding(Session &session)
Wrapper around OrtMapTypeInfo.
Definition: onnxruntime_cxx_api.h:460
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:462
MapTypeInfo(std::nullptr_t)
Create an empty MapTypeInfo object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:461
Definition: onnxruntime_cxx_api.h:804
MemoryAllocation(MemoryAllocation &&) noexcept
MemoryAllocation & operator=(const MemoryAllocation &)=delete
void * get()
Definition: onnxruntime_cxx_api.h:812
MemoryAllocation(const MemoryAllocation &)=delete
MemoryAllocation(OrtAllocator *allocator, void *p, size_t size)
size_t size() const
Definition: onnxruntime_cxx_api.h:813
Definition: onnxruntime_cxx_api.h:838
OrtAllocatorType GetAllocatorType() const
MemoryInfo(const char *name, OrtAllocatorType type, int id, OrtMemType mem_type)
MemoryInfo(std::nullptr_t)
Definition: onnxruntime_cxx_api.h:841
MemoryInfo(OrtMemoryInfo *p)
Used for interop with the C API.
Definition: onnxruntime_cxx_api.h:842
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:363
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:364
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:365
int64_t GetVersion() const
Wraps OrtApi::ModelMetadataGetVersion.
Definition: onnxruntime_cxx_api.h:281
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:282
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:450
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:451
SequenceTypeInfo(OrtSequenceTypeInfo *p)
Used for interop with the C API.
Definition: onnxruntime_cxx_api.h:452
Wrapper around OrtSession.
Definition: onnxruntime_cxx_api.h:380
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:381
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:314
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 & SetCustomCreateThreadFn(OrtCustomCreateThreadFn ort_custom_create_thread_fn)
Wraps OrtApi::SessionOptionsSetCustomCreateThreadFn.
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:315
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 & SetCustomThreadCreationOptions(void *ort_custom_thread_creation_options)
Wraps OrtApi::SessionOptionsSetCustomThreadCreationOptions.
SessionOptions & AppendExecutionProvider_ROCM(const OrtROCMProviderOptions &provider_options)
Wraps OrtApi::SessionOptionsAppendExecutionProvider_ROCM.
SessionOptions & DisableCpuMemArena()
Wraps OrtApi::DisableCpuMemArena.
SessionOptions & SetCustomJoinThreadFn(OrtCustomJoinThreadFn ort_custom_join_thread_fn)
Wraps OrtApi::SessionOptionsSetCustomJoinThreadFn.
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:317
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:433
TensorTypeAndShapeInfo(std::nullptr_t)
Create an empty TensorTypeAndShapeInfo object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:434
TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo *p)
Used for interop with the C API.
Definition: onnxruntime_cxx_api.h:435
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:468
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:469
TypeInfo(OrtTypeInfo *p)
C API Interop.
Definition: onnxruntime_cxx_api.h:470
Wraps an object that inherits from Ort::Base and stops it from deleting the contained pointer on dest...
Definition: onnxruntime_cxx_api.h:226
Unowned(Unowned &&v)
Definition: onnxruntime_cxx_api.h:228
~Unowned()
Definition: onnxruntime_cxx_api.h:229
Unowned(typename T::contained_type *p)
Definition: onnxruntime_cxx_api.h:227
Definition: onnxruntime_cxx_api.h:488
const char ** str
Definition: onnxruntime_cxx_api.h:493
size_t values_shape_len
Definition: onnxruntime_cxx_api.h:490
const int64_t * values_shape
Definition: onnxruntime_cxx_api.h:489
const void * p_data
Definition: onnxruntime_cxx_api.h:492
union Ort::Value::OrtSparseValuesParam::@0 data
Definition: onnxruntime_cxx_api.h:499
const int64_t * shape
Definition: onnxruntime_cxx_api.h:500
size_t shape_len
Definition: onnxruntime_cxx_api.h:501
Definition: onnxruntime_cxx_api.h:479
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:700
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:701
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
< Return true if OrtValue contains data and returns false if the OrtValue is a None
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)
bool HasValue() const
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:273
const OrtApi *(* GetApi)(uint32_t version)
Get a pointer to the requested version of the OrtApi.
Definition: onnxruntime_c_api.h:522
The C API.
Definition: onnxruntime_c_api.h:563
CUDA Provider Options.
Definition: onnxruntime_c_api.h:349
Definition: onnxruntime_c_api.h:3288
OrtCustomOpInputOutputCharacteristic(* GetOutputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition: onnxruntime_c_api.h:3313
size_t(* GetInputTypeCount)(const struct OrtCustomOp *op)
Definition: onnxruntime_c_api.h:3303
const char *(* GetName)(const struct OrtCustomOp *op)
Definition: onnxruntime_c_api.h:3296
size_t(* GetOutputTypeCount)(const struct OrtCustomOp *op)
Definition: onnxruntime_c_api.h:3305
void(* KernelDestroy)(void *op_kernel)
Definition: onnxruntime_c_api.h:3309
void *(* CreateKernel)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info)
Definition: onnxruntime_c_api.h:3292
uint32_t version
Definition: onnxruntime_c_api.h:3289
ONNXTensorElementDataType(* GetInputType)(const struct OrtCustomOp *op, size_t index)
Definition: onnxruntime_c_api.h:3302
OrtCustomOpInputOutputCharacteristic(* GetInputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition: onnxruntime_c_api.h:3312
const char *(* GetExecutionProviderType)(const struct OrtCustomOp *op)
Definition: onnxruntime_c_api.h:3299
ONNXTensorElementDataType(* GetOutputType)(const struct OrtCustomOp *op, size_t index)
Definition: onnxruntime_c_api.h:3304
void(* KernelCompute)(void *op_kernel, OrtKernelContext *context)
Definition: onnxruntime_c_api.h:3308
OpenVINO Provider Options.
Definition: onnxruntime_c_api.h:491
ROCM Provider Options.
Definition: onnxruntime_c_api.h:408
TensorRT Provider Options.
Definition: onnxruntime_c_api.h:466