ONNX Runtime
Loading...
Searching...
No Matches
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. The primary purpose of C++ API is exception safety so
8// all the resources follow RAII and do not leak memory.
9//
10// Each of the C++ wrapper classes holds only a pointer to the C internal object. Treat them like smart pointers.
11// To create an empty object, pass 'nullptr' to the constructor (for example, Env e{nullptr};). However, you can't use them
12// until you assign an instance that actually holds an underlying object.
13//
14// For Ort objects only move assignment between objects is allowed, there are no copy constructors.
15// Some objects have explicit 'Clone' methods for this purpose.
16//
17// ConstXXXX types are copyable since they do not own the underlying C object, so you can pass them to functions as arguments
18// by value or by reference. ConstXXXX types are restricted to const only interfaces.
19//
20// UnownedXXXX are similar to ConstXXXX but also allow non-const interfaces.
21//
22// The lifetime of the corresponding owning object must eclipse the lifetimes of the ConstXXXX/UnownedXXXX types. They exists so you do not
23// have to fallback to C types and the API with the usual pitfalls. In general, do not use C API from your C++ code.
24
25#pragma once
26#include "onnxruntime_c_api.h"
27#include "onnxruntime_float16.h"
28
29#include <array>
30#include <cstddef>
31#include <cstdio>
32#include <memory>
33#include <stdexcept>
34#include <string>
35#include <type_traits>
36#include <unordered_map>
37#include <utility>
38#include <variant>
39#include <vector>
40
41#ifdef ORT_NO_EXCEPTIONS
42#include <iostream>
43#endif
44
48namespace Ort {
49
54struct Exception : std::exception {
55 Exception(const std::string& string, OrtErrorCode code) : message_{string}, code_{code} {}
56 Exception(std::string&& string, OrtErrorCode code) : message_{std::move(string)}, code_{code} {}
57
58 OrtErrorCode GetOrtErrorCode() const { return code_; }
59 const char* what() const noexcept override { return message_.c_str(); }
60
61 private:
62 std::string message_;
63 OrtErrorCode code_;
64};
65
66#ifdef ORT_NO_EXCEPTIONS
67// The #ifndef is for the very special case where the user of this library wants to define their own way of handling errors.
68// NOTE: This header expects control flow to not continue after calling ORT_CXX_API_THROW
69#ifndef ORT_CXX_API_THROW
70#define ORT_CXX_API_THROW(string, code) \
71 do { \
72 std::cerr << Ort::Exception(string, code) \
73 .what() \
74 << std::endl; \
75 abort(); \
76 } while (false)
77#endif
78#else
79#define ORT_CXX_API_THROW(string, code) \
80 throw Ort::Exception(string, code)
81#endif
82
83#ifdef ORT_API_MANUAL_INIT
84// If the macro ORT_API_MANUAL_INIT is defined, no static initialization
85// will be performed. Instead, users must call InitApi() before using the
86// ORT C++ APIs..
87//
88// InitApi() sets the global API object using the default initialization
89// logic. Users call this to initialize the ORT C++ APIs at a time that
90// makes sense in their program.
91inline void InitApi() noexcept;
92
93// InitApi(const OrtApi*) is used by custom operator libraries that are not
94// linked to onnxruntime. It sets the global API object, which is required
95// by the ORT C++ APIs.
96//
97// Example mycustomop.cc:
98//
99// #define ORT_API_MANUAL_INIT
100// #include <onnxruntime_cxx_api.h>
101// #undef ORT_API_MANUAL_INIT
102//
103// OrtStatus* ORT_API_CALL RegisterCustomOps(OrtSessionOptions* options, const OrtApiBase* api_base) {
104// Ort::InitApi(api_base->GetApi(ORT_API_VERSION));
105// // ...
106// }
107//
108inline void InitApi(const OrtApi* api) noexcept;
109#endif
110
111namespace detail {
112// This is used internally by the C++ API. This class holds the global
113// variable that points to the OrtApi.
114struct Global {
115 static const OrtApi* Api(const OrtApi* newValue = nullptr) noexcept {
116 // This block-level static will be initialized once when this function is
117 // first executed, delaying the call to DefaultInit() until it is first needed.
118 //
119 // When ORT_API_MANUAL_INIT is not defined, DefaultInit() calls
120 // OrtGetApiBase()->GetApi(), which may result in a shared library being
121 // loaded.
122 //
123 // Using a block-level static instead of a class-level static helps
124 // avoid issues with static initialization order and dynamic libraries
125 // loading other dynamic libraries.
126 //
127 // This makes it safe to include the C++ API headers in a shared library
128 // that is delay loaded or delay loads its dependencies.
129 //
130 // This DOES NOT make it safe to _use_ arbitrary ORT C++ APIs when
131 // initializing static members, however.
132 static const OrtApi* api = DefaultInit();
133
134 if (newValue) {
135 api = newValue;
136 }
137
138 return api;
139 }
140
141 private:
142 // Has different definitions based on ORT_API_MANUAL_INIT
143 static const OrtApi* DefaultInit() noexcept;
144
145#ifdef ORT_API_MANUAL_INIT
146 // Public APIs to set the OrtApi* to use.
147 friend void ::Ort::InitApi() noexcept;
148 friend void ::Ort::InitApi(const OrtApi*) noexcept;
149#endif
150};
151} // namespace detail
152
153#ifdef ORT_API_MANUAL_INIT
154
155// See comments on declaration above for usage.
156inline void InitApi(const OrtApi* api) noexcept { detail::Global::Api(api); }
157inline void InitApi() noexcept { InitApi(OrtGetApiBase()->GetApi(ORT_API_VERSION)); }
158
159#ifdef _MSC_VER
160// If you get a linker error about a mismatch here, you are trying to
161// link two compilation units that have different definitions for
162// ORT_API_MANUAL_INIT together. All compilation units must agree on the
163// definition of ORT_API_MANUAL_INIT.
164#pragma detect_mismatch("ORT_API_MANUAL_INIT", "enabled")
165#endif
166
167inline const OrtApi* detail::Global::DefaultInit() noexcept {
168 // When ORT_API_MANUAL_INIT is defined, there's no default init that can
169 // be done.
170 return nullptr;
171}
172
173#else // ORT_API_MANUAL_INIT
174
175#ifdef _MSC_VER
176// If you get a linker error about a mismatch here, you are trying to link
177// two compilation units that have different definitions for
178// ORT_API_MANUAL_INIT together. All compilation units must agree on the
179// definition of ORT_API_MANUAL_INIT.
180#pragma detect_mismatch("ORT_API_MANUAL_INIT", "disabled")
181#endif
182
183inline const OrtApi* detail::Global::DefaultInit() noexcept {
185}
186#endif // ORT_API_MANUAL_INIT
187
189inline const OrtApi& GetApi() noexcept { return *detail::Global::Api(); }
190
195std::string GetVersionString();
196
202std::string GetBuildInfoString();
203
209std::vector<std::string> GetAvailableProviders();
210
216 auto* api = GetApi().GetModelEditorApi();
217 if (api == nullptr) {
218 // minimal build
219 ORT_CXX_API_THROW("Model Editor API is not available in this build", ORT_FAIL);
220 }
221
222 return *api;
223}
224
230 auto* api = GetApi().GetCompileApi();
231 if (api == nullptr) {
232 // minimal build
233 ORT_CXX_API_THROW("Compile API is not available in this build", ORT_FAIL);
234 }
235
236 return *api;
237}
238
244 auto* api = GetApi().GetInteropApi();
245 if (api == nullptr) {
246 // minimal build
247 ORT_CXX_API_THROW("Interop API is not available in this build", ORT_FAIL);
248 }
249
250 return *api;
251}
252
258 auto* api = GetApi().GetModelPackageApi();
259 if (api == nullptr) {
260 ORT_CXX_API_THROW("Model Package API is not available in this build", ORT_FAIL);
261 }
262
263 return *api;
264}
265
270inline const OrtEpApi& GetEpApi() {
271 auto* api = GetApi().GetEpApi();
272 if (api == nullptr) {
273 // minimal build
274 ORT_CXX_API_THROW("EP API is not available in this build", ORT_FAIL);
275 }
276
277 return *api;
278}
279
298struct Float16_t : onnxruntime_float16::Float16Impl<Float16_t> {
299 private:
305 constexpr explicit Float16_t(uint16_t v) noexcept { val = v; }
306
307 public:
308 using Base = onnxruntime_float16::Float16Impl<Float16_t>;
309
313 Float16_t() = default;
314
320 constexpr static Float16_t FromBits(uint16_t v) noexcept { return Float16_t(v); }
321
326 explicit Float16_t(float v) noexcept { val = Base::ToUint16Impl(v); }
327
332 float ToFloat() const noexcept { return Base::ToFloatImpl(); }
333
338 using Base::IsNegative;
339
344 using Base::IsNaN;
345
350 using Base::IsFinite;
351
356 using Base::IsPositiveInfinity;
357
362 using Base::IsNegativeInfinity;
363
368 using Base::IsInfinity;
369
374 using Base::IsNaNOrZero;
375
380 using Base::IsNormal;
381
386 using Base::IsSubnormal;
387
392 using Base::Abs;
393
398 using Base::Negate;
399
408 using Base::AreZero;
409
413 explicit operator float() const noexcept { return ToFloat(); }
414
415 using Base::operator==;
416 using Base::operator!=;
417 using Base::operator<;
418};
419
420static_assert(sizeof(Float16_t) == sizeof(uint16_t), "Sizes must match");
421
440struct BFloat16_t : onnxruntime_float16::BFloat16Impl<BFloat16_t> {
441 private:
449 constexpr explicit BFloat16_t(uint16_t v) noexcept { val = v; }
450
451 public:
452 using Base = onnxruntime_float16::BFloat16Impl<BFloat16_t>;
453
454 BFloat16_t() = default;
455
461 static constexpr BFloat16_t FromBits(uint16_t v) noexcept { return BFloat16_t(v); }
462
467 explicit BFloat16_t(float v) noexcept { val = Base::ToUint16Impl(v); }
468
473 float ToFloat() const noexcept { return Base::ToFloatImpl(); }
474
479 using Base::IsNegative;
480
485 using Base::IsNaN;
486
491 using Base::IsFinite;
492
497 using Base::IsPositiveInfinity;
498
503 using Base::IsNegativeInfinity;
504
509 using Base::IsInfinity;
510
515 using Base::IsNaNOrZero;
516
521 using Base::IsNormal;
522
527 using Base::IsSubnormal;
528
533 using Base::Abs;
534
539 using Base::Negate;
540
549 using Base::AreZero;
550
554 explicit operator float() const noexcept { return ToFloat(); }
555
556 // We do not have an inherited impl for the below operators
557 // as the internal class implements them a little differently
558 bool operator==(const BFloat16_t& rhs) const noexcept;
559 bool operator!=(const BFloat16_t& rhs) const noexcept { return !(*this == rhs); }
560 bool operator<(const BFloat16_t& rhs) const noexcept;
561};
562
563static_assert(sizeof(BFloat16_t) == sizeof(uint16_t), "Sizes must match");
564
571 uint8_t value;
572 constexpr Float8E4M3FN_t() noexcept : value(0) {}
573 constexpr Float8E4M3FN_t(uint8_t v) noexcept : value(v) {}
574 constexpr operator uint8_t() const noexcept { return value; }
575 // nan values are treated like any other value for operator ==, !=
576 constexpr bool operator==(const Float8E4M3FN_t& rhs) const noexcept { return value == rhs.value; };
577 constexpr bool operator!=(const Float8E4M3FN_t& rhs) const noexcept { return value != rhs.value; };
578};
579
580static_assert(sizeof(Float8E4M3FN_t) == sizeof(uint8_t), "Sizes must match");
581
588 uint8_t value;
589 constexpr Float8E4M3FNUZ_t() noexcept : value(0) {}
590 constexpr Float8E4M3FNUZ_t(uint8_t v) noexcept : value(v) {}
591 constexpr operator uint8_t() const noexcept { return value; }
592 // nan values are treated like any other value for operator ==, !=
593 constexpr bool operator==(const Float8E4M3FNUZ_t& rhs) const noexcept { return value == rhs.value; };
594 constexpr bool operator!=(const Float8E4M3FNUZ_t& rhs) const noexcept { return value != rhs.value; };
595};
596
597static_assert(sizeof(Float8E4M3FNUZ_t) == sizeof(uint8_t), "Sizes must match");
598
605 uint8_t value;
606 constexpr Float8E5M2_t() noexcept : value(0) {}
607 constexpr Float8E5M2_t(uint8_t v) noexcept : value(v) {}
608 constexpr operator uint8_t() const noexcept { return value; }
609 // nan values are treated like any other value for operator ==, !=
610 constexpr bool operator==(const Float8E5M2_t& rhs) const noexcept { return value == rhs.value; };
611 constexpr bool operator!=(const Float8E5M2_t& rhs) const noexcept { return value != rhs.value; };
612};
613
614static_assert(sizeof(Float8E5M2_t) == sizeof(uint8_t), "Sizes must match");
615
622 uint8_t value;
623 constexpr Float8E5M2FNUZ_t() noexcept : value(0) {}
624 constexpr Float8E5M2FNUZ_t(uint8_t v) noexcept : value(v) {}
625 constexpr operator uint8_t() const noexcept { return value; }
626 // nan values are treated like any other value for operator ==, !=
627 constexpr bool operator==(const Float8E5M2FNUZ_t& rhs) const noexcept { return value == rhs.value; };
628 constexpr bool operator!=(const Float8E5M2FNUZ_t& rhs) const noexcept { return value != rhs.value; };
629};
630
631static_assert(sizeof(Float8E5M2FNUZ_t) == sizeof(uint8_t), "Sizes must match");
632
633namespace detail {
634// 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
635// This can't be done in the C API since C doesn't have function overloading.
636#define ORT_DEFINE_RELEASE(NAME) \
637 inline void OrtRelease(Ort##NAME* ptr) { GetApi().Release##NAME(ptr); }
638
639#define ORT_DEFINE_RELEASE_FROM_API_STRUCT(NAME, API_GETTER) \
640 inline void OrtRelease(Ort##NAME* ptr) { API_GETTER().Release##NAME(ptr); }
641
642ORT_DEFINE_RELEASE(Allocator);
643ORT_DEFINE_RELEASE(ArenaCfg);
644ORT_DEFINE_RELEASE(CustomOpDomain);
646ORT_DEFINE_RELEASE(Env);
647ORT_DEFINE_RELEASE(ExternalInitializerInfo);
648ORT_DEFINE_RELEASE(Graph);
649ORT_DEFINE_RELEASE(IoBinding);
650ORT_DEFINE_RELEASE(KernelInfo);
651ORT_DEFINE_RELEASE(KeyValuePairs);
652ORT_DEFINE_RELEASE(LoraAdapter);
653ORT_DEFINE_RELEASE(MemoryInfo);
654ORT_DEFINE_RELEASE(MapTypeInfo);
655ORT_DEFINE_RELEASE(Model);
656ORT_DEFINE_RELEASE(ModelMetadata);
657ORT_DEFINE_RELEASE(Node);
658ORT_DEFINE_RELEASE(Op);
659ORT_DEFINE_RELEASE(OpAttr);
660ORT_DEFINE_RELEASE(PrepackedWeightsContainer);
661ORT_DEFINE_RELEASE(RunOptions);
662ORT_DEFINE_RELEASE(Session);
663ORT_DEFINE_RELEASE(SessionOptions);
664ORT_DEFINE_RELEASE(SequenceTypeInfo);
665ORT_DEFINE_RELEASE(Status);
666ORT_DEFINE_RELEASE(SyncStream);
667ORT_DEFINE_RELEASE(TensorTypeAndShapeInfo);
668ORT_DEFINE_RELEASE(ThreadingOptions);
669ORT_DEFINE_RELEASE(TypeInfo);
670ORT_DEFINE_RELEASE(Value);
671ORT_DEFINE_RELEASE(ValueInfo);
672
673ORT_DEFINE_RELEASE_FROM_API_STRUCT(ModelCompilationOptions, GetCompileApi);
674ORT_DEFINE_RELEASE_FROM_API_STRUCT(ModelPackageOptions, GetModelPackageApi);
675ORT_DEFINE_RELEASE_FROM_API_STRUCT(ModelPackageContext, GetModelPackageApi);
676ORT_DEFINE_RELEASE_FROM_API_STRUCT(ModelPackageComponentContext, GetModelPackageApi);
677ORT_DEFINE_RELEASE_FROM_API_STRUCT(EpContextConfig, GetEpApi);
678ORT_DEFINE_RELEASE_FROM_API_STRUCT(EpDevice, GetEpApi);
679ORT_DEFINE_RELEASE_FROM_API_STRUCT(KernelDef, GetEpApi);
680ORT_DEFINE_RELEASE_FROM_API_STRUCT(KernelDefBuilder, GetEpApi);
681ORT_DEFINE_RELEASE_FROM_API_STRUCT(KernelRegistry, GetEpApi);
682ORT_DEFINE_RELEASE_FROM_API_STRUCT(OpSchema, GetEpApi);
683ORT_DEFINE_RELEASE_FROM_API_STRUCT(ProfilingEvent, GetEpApi);
684
685// This is defined explicitly since OrtTensorRTProviderOptionsV2 is not a C API type,
686// but the struct has V2 in its name to indicate that it is the second version of the options.
689
690#undef ORT_DEFINE_RELEASE
691#undef ORT_DEFINE_RELEASE_FROM_API_STRUCT
692
696template <typename T>
697struct Unowned {
698 using Type = T;
699};
700
720template <typename T>
721struct Base {
722 using contained_type = T;
723
724 constexpr Base() = default;
725 constexpr explicit Base(contained_type* p) noexcept : p_{p} {}
727 OrtRelease(p_);
728 }
729
730 Base(const Base&) = delete;
731 Base& operator=(const Base&) = delete;
732
733 Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }
734 Base& operator=(Base&& v) noexcept {
735 OrtRelease(p_);
736 p_ = v.release();
737 return *this;
738 }
739
740 constexpr operator contained_type*() const noexcept { return p_; }
741 constexpr contained_type& operator*() const noexcept { return *p_; }
742
746 T* p = p_;
747 p_ = nullptr;
748 return p;
749 }
750
751 protected:
753};
754
755// Undefined. For const types use Base<Unowned<const T>>
756template <typename T>
757struct Base<const T>;
758
766template <typename T>
767struct Base<Unowned<T>> {
769
770 constexpr Base() = default;
771 constexpr explicit Base(contained_type* p) noexcept : p_{p} {}
772
773 ~Base() = default;
774
775 Base(const Base&) = default;
776 Base& operator=(const Base&) = default;
777
778 Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }
779 Base& operator=(Base&& v) noexcept {
780 p_ = nullptr;
781 std::swap(p_, v.p_);
782 return *this;
783 }
784
785 constexpr operator contained_type*() const noexcept { return p_; }
786 constexpr contained_type& operator*() const noexcept { return *p_; }
787
788 protected:
790};
791
792// Light functor to release memory with OrtAllocator
795 explicit AllocatedFree(OrtAllocator* allocator)
796 : allocator_(allocator) {}
797 void operator()(void* ptr) const {
798 if (ptr) allocator_->Free(allocator_, ptr);
799 }
800};
801
802} // namespace detail
803
804struct AllocatorWithDefaultOptions;
805struct Env;
806struct EpContextConfig;
807struct EpDevice;
808struct ExternalInitializerInfo;
809struct Graph;
810struct Model;
811struct ModelPackageOptions;
812struct ModelPackageContext;
813struct ModelPackageComponentContext;
814struct Node;
815struct ModelMetadata;
816struct TypeInfo;
817struct PrepackedWeightsContainer;
818struct Session;
819struct SessionOptions;
820struct SyncStream;
821struct TensorRTProviderOptions;
822struct Value;
823struct ValueInfo;
824
829using AllocatedStringPtr = std::unique_ptr<char, detail::AllocatedFree>;
830
835struct Status : detail::Base<OrtStatus> {
836 Status() = default; // Same as with std::nullptr_t. But can be used in re-sizable containers and represent success.
837 explicit Status(std::nullptr_t) noexcept {}
838 explicit Status(OrtStatus* status) noexcept;
839 explicit Status(const Exception&);
840 explicit Status(const std::exception&);
841 Status(const char* message, OrtErrorCode code);
842 std::string GetErrorMessage() const;
844 bool IsOK() const noexcept;
845};
846
876
881struct TensorRTProviderOptions : detail::Base<OrtTensorRTProviderOptionsV2> {
882 TensorRTProviderOptions(std::nullptr_t) {}
886 void Update(const std::unordered_map<std::string, std::string>& options);
888 void UpdateWithValue(const char* key, void* value);
889
891 void* GetOptionByName(const char* name) const;
894};
895
900struct CUDAProviderOptions : detail::Base<OrtCUDAProviderOptionsV2> {
901 CUDAProviderOptions(std::nullptr_t) {}
905 void Update(const std::unordered_map<std::string, std::string>& options);
909 void UpdateWithValue(const char* key, void* value);
911 void* GetOptionByName(const char* name) const;
912};
913
928
929namespace detail {
930template <typename T>
932 using B = Base<T>;
933 using B::B;
934
935 // Wraps OrtApi::ExternalInitializerInfo_GetFilePath
936 const std::basic_string<ORTCHAR_T> GetFilePath() const;
937 // Wraps OrtApi::ExternalInitializerInfo_GetFileOffset
938 int64_t GetFileOffset() const;
939 // Wraps OrtApi::ExternalInitializerInfo_GetByteSize
940 size_t GetByteSize() const;
941};
942} // namespace detail
943
944// Const object holder that does not own the underlying object
947
953 using Base::Base;
954
955 explicit ExternalInitializerInfo(std::nullptr_t) {}
957 : detail::ConstExternalInitializerInfoImpl<OrtExternalInitializerInfo>{p} {}
958
960
962 ExternalInitializerInfo(const ORTCHAR_T* filepath, int64_t file_offset, size_t byte_size);
963
965 static Status Create(const ORTCHAR_T* filepath, int64_t file_offset, size_t byte_size,
966 /*out*/ ExternalInitializerInfo& out);
967};
968
969namespace detail {
970template <typename T>
973 using B::B;
974
975 const char* GetValue(const char* key) const;
976
977 // get the pairs in unordered_map. needs to copy to std::string so the hash works as expected
978 std::unordered_map<std::string, std::string> GetKeyValuePairs() const;
979 // get the pairs in two vectors. entries will be 1:1 between keys and values. avoids copying to std::string
980 void GetKeyValuePairs(std::vector<const char*>& keys, std::vector<const char*>& values) const;
981};
982} // namespace detail
983
984// Const object holder that does not own the underlying object
986
988struct KeyValuePairs : detail::KeyValuePairsImpl<OrtKeyValuePairs> {
989 explicit KeyValuePairs(std::nullptr_t) {}
991 explicit KeyValuePairs(OrtKeyValuePairs* p) : KeyValuePairsImpl<OrtKeyValuePairs>{p} {}
992
994 explicit KeyValuePairs();
995
997 explicit KeyValuePairs(const std::unordered_map<std::string, std::string>& kv_pairs);
998
1000 void Add(const char* key, const char* value);
1001
1003 void Remove(const char* key);
1004
1005 ConstKeyValuePairs GetConst() const { return ConstKeyValuePairs{this->p_}; }
1006};
1007
1008namespace detail {
1009template <typename T>
1011 using B = Base<T>;
1012 using B::B;
1013
1014 std::string GetAllocatorName() const;
1016 int GetDeviceId() const;
1020 uint32_t GetVendorId() const;
1021
1022 template <typename U>
1023 bool operator==(const MemoryInfoImpl<U>& o) const;
1024};
1025} // namespace detail
1026
1027// Const object holder that does not own the underlying object
1029
1033struct MemoryInfo : detail::MemoryInfoImpl<OrtMemoryInfo> {
1035 explicit MemoryInfo(std::nullptr_t) {}
1036 explicit MemoryInfo(OrtMemoryInfo* p) : MemoryInfoImpl<OrtMemoryInfo>{p} {}
1037 MemoryInfo(const char* name, OrtAllocatorType type, int id, OrtMemType mem_type);
1038 MemoryInfo(const char* name, OrtMemoryInfoDeviceType device_type, uint32_t vendor_id, uint32_t device_id,
1039 OrtDeviceMemoryType mem_type, size_t alignment, OrtAllocatorType allocator_type);
1040 ConstMemoryInfo GetConst() const { return ConstMemoryInfo{this->p_}; }
1041};
1042
1050 MemoryAllocation(OrtAllocator* allocator, void* p, size_t size);
1055 MemoryAllocation& operator=(MemoryAllocation&&) noexcept;
1056
1057 void* get() { return p_; }
1058 size_t size() const { return size_; }
1059
1060 private:
1061 OrtAllocator* allocator_;
1062 void* p_;
1063 size_t size_;
1064};
1065
1066namespace detail {
1067template <typename T>
1068struct AllocatorImpl : Base<T> {
1069 using B = Base<T>;
1070 using B::B;
1071
1072 void* Alloc(size_t size);
1073 void* Reserve(size_t size);
1074 MemoryAllocation GetAllocation(size_t size);
1075 void Free(void* p);
1076 ConstMemoryInfo GetInfo() const;
1077
1082 KeyValuePairs GetStats() const;
1083
1088 void Shrink();
1089};
1090} // namespace detail
1091
1095struct AllocatorWithDefaultOptions : detail::AllocatorImpl<detail::Unowned<OrtAllocator>> {
1096 explicit AllocatorWithDefaultOptions(std::nullptr_t) {}
1098};
1099
1104struct Allocator : detail::AllocatorImpl<OrtAllocator> {
1105 explicit Allocator(std::nullptr_t) {}
1106 Allocator(const Session& session, const OrtMemoryInfo*);
1107
1109 explicit Allocator(OrtAllocator* p) : AllocatorImpl<OrtAllocator>{p} {}
1110};
1111
1112using UnownedAllocator = detail::AllocatorImpl<detail::Unowned<OrtAllocator>>;
1113
1118namespace detail {
1119template <typename T>
1121 using B = Base<T>;
1122 using B::B;
1123 // For some reason this is not a const method on the stream
1124 void* GetHandle();
1125};
1126} // namespace detail
1127
1128struct SyncStream : detail::SyncStreamImpl<OrtSyncStream> {
1130 explicit SyncStream(std::nullptr_t) {}
1132 explicit SyncStream(OrtSyncStream* p) : SyncStreamImpl<OrtSyncStream>{p} {}
1133};
1134
1136
1137namespace detail {
1138template <typename T>
1141 using B::B;
1142
1144 uint32_t VendorId() const;
1145 uint32_t DeviceId() const;
1146 const char* Vendor() const;
1148};
1149} // namespace detail
1150
1155
1156namespace detail {
1157template <typename T>
1160 using B::B;
1161
1162 uint32_t GetReasonsBitmask() const;
1163 const char* GetNotes() const;
1164 int32_t GetErrorCode() const;
1165};
1166} // namespace detail
1167
1172 explicit DeviceEpIncompatibilityDetails(std::nullptr_t) {}
1174 : DeviceEpIncompatibilityDetailsImpl<OrtDeviceEpIncompatibilityDetails>{p} {}
1175};
1176
1177namespace detail {
1178template <typename T>
1181 using B::B;
1182
1183 const char* EpName() const;
1184 const char* EpVendor() const;
1194 std::pair<uint64_t, uint64_t> GetMemoryCapacity(
1198};
1199} // namespace detail
1200
1205
1208struct EpDevice : detail::EpDeviceImpl<OrtEpDevice> {
1209 explicit EpDevice(std::nullptr_t) {}
1210 explicit EpDevice(OrtEpDevice* p) : EpDeviceImpl<OrtEpDevice>{p} {}
1211
1213 EpDevice(OrtEpFactory& ep_factory, ConstHardwareDevice& hardware_device,
1214 ConstKeyValuePairs ep_metadata = {}, ConstKeyValuePairs ep_options = {});
1215};
1216
1230 const std::vector<ConstEpDevice>& ep_devices,
1231 const char* compatibility_info);
1232
1248AllocatedStringPtr GetCompatibilityInfoFromModelAllocated(const ORTCHAR_T* model_path, const char* ep_type,
1249 OrtAllocator* allocator);
1250
1263AllocatedStringPtr GetCompatibilityInfoFromModelBytesAllocated(const void* model_data, size_t model_data_length,
1264 const char* ep_type, OrtAllocator* allocator);
1265
1266namespace detail {
1267template <typename T>
1270 using B::B;
1271
1272 std::string GetName() const;
1273 std::string GetDomain() const;
1274 std::string GetOperatorType() const;
1275};
1276} // namespace detail
1277
1282
1283namespace detail {
1284template <typename T>
1287 using B::B;
1288
1289 std::string GetEpName() const;
1290 std::vector<ConstEpAssignedNode> GetNodes() const;
1291};
1292} // namespace detail
1293
1298
1299namespace detail {
1300template <typename T>
1303 using B::B;
1304
1306 OrtProfilingEventCategory GetCategory() const;
1307
1310 const char* GetName() const;
1311
1313 int64_t GetTimestampUs() const;
1314
1316 int64_t GetDurationUs() const;
1317
1321 const char* GetArgValue(const char* key) const;
1322};
1323} // namespace detail
1324
1333
1341 explicit ProfilingEvent(std::nullptr_t) {}
1343 : ConstProfilingEventImpl<OrtProfilingEvent>{p} {}
1344
1346 ProfilingEvent(OrtProfilingEventCategory category,
1347 int32_t process_id,
1348 int32_t thread_id,
1349 const char* event_name,
1350 int64_t timestamp_us,
1351 int64_t duration_us,
1352 const std::unordered_map<std::string, std::string>& args = {});
1353
1355 ProfilingEvent(OrtProfilingEventCategory category,
1356 int32_t process_id,
1357 int32_t thread_id,
1358 const char* event_name,
1359 int64_t timestamp_us,
1360 int64_t duration_us,
1361 const char* const* arg_keys,
1362 const char* const* arg_values,
1363 size_t num_args);
1364
1366};
1367
1368namespace detail {
1369template <typename T>
1372 using B::B;
1373
1376 Ort::Status AddEvents(const OrtProfilingEvent* const* events, size_t num_events);
1377 Ort::Status AddEvents(const std::vector<ProfilingEvent>& events);
1378};
1379} // namespace detail
1380
1387
1393struct Env : detail::Base<OrtEnv> {
1394 explicit Env(std::nullptr_t) {}
1395
1397 Env(OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
1398
1400 Env(OrtLoggingLevel logging_level, const char* logid, OrtLoggingFunction logging_function, void* logger_param);
1401
1403 Env(const OrtThreadingOptions* tp_options, OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
1404
1406 Env(const OrtThreadingOptions* tp_options, OrtLoggingFunction logging_function, void* logger_param,
1407 OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
1408
1410 explicit Env(const OrtEnvCreationOptions* options);
1411
1413 explicit Env(OrtEnv* p) : Base<OrtEnv>{p} {}
1414
1417
1419
1420 Env& CreateAndRegisterAllocator(const OrtMemoryInfo* mem_info, const OrtArenaCfg* arena_cfg);
1421
1422 Env& CreateAndRegisterAllocatorV2(const std::string& provider_type, const OrtMemoryInfo* mem_info,
1423 const std::unordered_map<std::string, std::string>& options,
1424 const OrtArenaCfg* arena_cfg);
1425
1427
1429
1431 OrtAllocatorType allocator_type,
1432 const OrtKeyValuePairs* allocator_options);
1433
1434 // Result may be nullptr
1436
1438 OrtDeviceMemoryType mem_type);
1439
1440 Env& RegisterExecutionProviderLibrary(const char* registration_name, const std::basic_string<ORTCHAR_T>& path);
1441 Env& UnregisterExecutionProviderLibrary(const char* registration_name);
1442
1443 std::vector<ConstEpDevice> GetEpDevices() const;
1444
1451 size_t GetNumHardwareDevices() const;
1452
1459 std::vector<ConstHardwareDevice> GetHardwareDevices() const;
1460
1472 const char* ep_name, ConstHardwareDevice hw) const;
1473
1474 Status CopyTensors(const std::vector<Value>& src_tensors,
1475 const std::vector<Value>& dst_tensors,
1476 OrtSyncStream* stream) const;
1477
1480 Status CopyTensor(const OrtValue* src_tensor, OrtValue* dst_tensor, OrtSyncStream* stream) const;
1481
1487};
1488
1492struct CustomOpDomain : detail::Base<OrtCustomOpDomain> {
1494 using Base::Base;
1495
1496 explicit CustomOpDomain(std::nullptr_t) {}
1497
1499 explicit CustomOpDomain(const char* domain);
1500
1501 // This does not take ownership of the op, simply registers it.
1502 void Add(const OrtCustomOp* op);
1503};
1504
1506struct LoraAdapter : detail::Base<OrtLoraAdapter> {
1508 using Base::Base;
1509
1510 explicit LoraAdapter(std::nullptr_t) {}
1518 static LoraAdapter CreateLoraAdapter(const std::basic_string<ORTCHAR_T>& adapter_path,
1519 OrtAllocator* allocator);
1520
1529 static LoraAdapter CreateLoraAdapterFromArray(const void* bytes, size_t num_bytes,
1530 OrtAllocator* allocator);
1531};
1532
1536struct RunOptions : detail::Base<OrtRunOptions> {
1537 explicit RunOptions(std::nullptr_t) {}
1539
1542
1545
1546 RunOptions& SetRunTag(const char* run_tag);
1547 const char* GetRunTag() const;
1548
1549 RunOptions& AddConfigEntry(const char* config_key, const char* config_value);
1550 const char* GetConfigEntry(const char* config_key);
1551
1558
1564
1572
1581
1587 RunOptions& EnableProfiling(const ORTCHAR_T* profile_file_prefix);
1588
1594};
1595
1596namespace detail {
1597// Utility function that returns a SessionOption config entry key for a specific custom operator.
1598// Ex: custom_op.[custom_op_name].[config]
1599std::string MakeCustomOpConfigEntryKey(const char* custom_op_name, const char* config);
1600} // namespace detail
1601
1612 CustomOpConfigs() = default;
1613 ~CustomOpConfigs() = default;
1618
1627 CustomOpConfigs& AddConfig(const char* custom_op_name, const char* config_key, const char* config_value);
1628
1637 const std::unordered_map<std::string, std::string>& GetFlattenedConfigs() const;
1638
1639 private:
1640 std::unordered_map<std::string, std::string> flat_configs_;
1641};
1642
1648namespace detail {
1649// we separate const-only methods because passing const ptr to non-const methods
1650// is only discovered when inline methods are compiled which is counter-intuitive
1651template <typename T>
1652struct ConstSessionOptionsImpl : Base<T> {
1653 using B = Base<T>;
1654 using B::B;
1655
1656 SessionOptions Clone() const;
1657
1658 std::string GetConfigEntry(const char* config_key) const;
1659 bool HasConfigEntry(const char* config_key) const;
1660 std::string GetConfigEntryOrDefault(const char* config_key, const std::string& def) const;
1661
1662 bool GetMemPatternEnabled() const;
1663 ExecutionMode GetExecutionMode() const;
1664};
1665
1666template <typename T>
1667struct SessionOptionsImpl : ConstSessionOptionsImpl<T> {
1668 using B = ConstSessionOptionsImpl<T>;
1669 using B::B;
1670
1671 SessionOptionsImpl& SetIntraOpNumThreads(int intra_op_num_threads);
1672 SessionOptionsImpl& SetInterOpNumThreads(int inter_op_num_threads);
1673 SessionOptionsImpl& SetGraphOptimizationLevel(GraphOptimizationLevel graph_optimization_level);
1674 SessionOptionsImpl& SetDeterministicCompute(bool value);
1675
1676 SessionOptionsImpl& EnableCpuMemArena();
1677 SessionOptionsImpl& DisableCpuMemArena();
1678
1679 SessionOptionsImpl& SetOptimizedModelFilePath(const ORTCHAR_T* optimized_model_file);
1680
1681 SessionOptionsImpl& EnableProfiling(const ORTCHAR_T* profile_file_prefix);
1682 SessionOptionsImpl& DisableProfiling();
1683
1684 SessionOptionsImpl& EnableOrtCustomOps();
1685
1686 SessionOptionsImpl& EnableMemPattern();
1687 SessionOptionsImpl& DisableMemPattern();
1688
1689 SessionOptionsImpl& SetExecutionMode(ExecutionMode execution_mode);
1690
1691 SessionOptionsImpl& SetLoadCancellationFlag(bool value);
1692
1693 SessionOptionsImpl& SetLogId(const char* logid);
1694 SessionOptionsImpl& SetLogSeverityLevel(int level);
1695
1696 SessionOptionsImpl& Add(OrtCustomOpDomain* custom_op_domain);
1697
1698 SessionOptionsImpl& DisablePerSessionThreads();
1699
1700 SessionOptionsImpl& AddConfigEntry(const char* config_key, const char* config_value);
1701
1703 SessionOptionsImpl& SetEpContextDataReadFunc(OrtReadNamedBufferFunc read_func, void* state);
1705 SessionOptionsImpl& ClearEpContextDataReadFunc();
1706
1707 SessionOptionsImpl& AddInitializer(const char* name, const OrtValue* ort_val);
1708 SessionOptionsImpl& AddExternalInitializers(const std::vector<std::string>& names, const std::vector<Value>& ort_values);
1709 SessionOptionsImpl& AddExternalInitializersFromFilesInMemory(const std::vector<std::basic_string<ORTCHAR_T>>& external_initializer_file_names,
1710 const std::vector<char*>& external_initializer_file_buffer_array,
1711 const std::vector<size_t>& external_initializer_file_lengths);
1712
1713 SessionOptionsImpl& AppendExecutionProvider_CPU(int use_arena);
1714 SessionOptionsImpl& AppendExecutionProvider_CUDA(const OrtCUDAProviderOptions& provider_options);
1715 SessionOptionsImpl& AppendExecutionProvider_CUDA_V2(const OrtCUDAProviderOptionsV2& provider_options);
1716 SessionOptionsImpl& AppendExecutionProvider_ROCM(const OrtROCMProviderOptions& provider_options);
1717 SessionOptionsImpl& AppendExecutionProvider_OpenVINO(const OrtOpenVINOProviderOptions& provider_options);
1719 SessionOptionsImpl& AppendExecutionProvider_OpenVINO_V2(const std::unordered_map<std::string, std::string>& provider_options = {});
1720 SessionOptionsImpl& AppendExecutionProvider_TensorRT(const OrtTensorRTProviderOptions& provider_options);
1721 SessionOptionsImpl& AppendExecutionProvider_TensorRT_V2(const OrtTensorRTProviderOptionsV2& provider_options);
1722 SessionOptionsImpl& AppendExecutionProvider_MIGraphX(const OrtMIGraphXProviderOptions& provider_options);
1724 SessionOptionsImpl& AppendExecutionProvider_CANN(const OrtCANNProviderOptions& provider_options);
1726 SessionOptionsImpl& AppendExecutionProvider_Dnnl(const OrtDnnlProviderOptions& provider_options);
1728 SessionOptionsImpl& AppendExecutionProvider(const std::string& provider_name,
1729 const std::unordered_map<std::string, std::string>& provider_options = {});
1730
1733 SessionOptionsImpl& AppendExecutionProvider_V2(Env& env, const std::vector<ConstEpDevice>& ep_devices,
1734 const KeyValuePairs& ep_options);
1737 SessionOptionsImpl& AppendExecutionProvider_V2(Env& env, const std::vector<ConstEpDevice>& ep_devices,
1738 const std::unordered_map<std::string, std::string>& ep_options);
1739
1741 SessionOptionsImpl& SetEpSelectionPolicy(OrtExecutionProviderDevicePolicy policy);
1742
1744 SessionOptionsImpl& SetEpSelectionPolicy(EpSelectionDelegate delegate, void* state = nullptr);
1745
1746 SessionOptionsImpl& SetCustomCreateThreadFn(OrtCustomCreateThreadFn ort_custom_create_thread_fn);
1747 SessionOptionsImpl& SetCustomThreadCreationOptions(void* ort_custom_thread_creation_options);
1748 SessionOptionsImpl& SetCustomJoinThreadFn(OrtCustomJoinThreadFn ort_custom_join_thread_fn);
1749
1753 SessionOptionsImpl& RegisterCustomOpsLibrary(const ORTCHAR_T* library_name, const CustomOpConfigs& custom_op_configs = {});
1754
1755 SessionOptionsImpl& RegisterCustomOpsUsingFunction(const char* function_name);
1756
1758 SessionOptionsImpl& AppendExecutionProvider_VitisAI(const std::unordered_map<std::string, std::string>& provider_options = {});
1759
1761 SessionOptionsImpl& AddFreeDimensionOverride(const char* dim_denotation, int64_t dim_value);
1762
1764 SessionOptionsImpl& AddFreeDimensionOverrideByName(const char* dim_name, int64_t dim_value);
1765};
1766} // namespace detail
1767
1768using UnownedSessionOptions = detail::SessionOptionsImpl<detail::Unowned<OrtSessionOptions>>;
1769using ConstSessionOptions = detail::ConstSessionOptionsImpl<detail::Unowned<const OrtSessionOptions>>;
1770
1774struct SessionOptions : detail::SessionOptionsImpl<OrtSessionOptions> {
1775 explicit SessionOptions(std::nullptr_t) {}
1777 explicit SessionOptions(OrtSessionOptions* p) : SessionOptionsImpl<OrtSessionOptions>{p} {}
1780};
1781
1787struct EpContextConfig : detail::Base<OrtEpContextConfig> {
1789 using Base::Base;
1790
1791 explicit EpContextConfig(std::nullptr_t) noexcept {}
1792 explicit EpContextConfig(const SessionOptions& session_options);
1793 explicit EpContextConfig(ConstSessionOptions session_options);
1794
1796 void GetReadFunc(OrtReadNamedBufferFunc& read_func, void*& state) const;
1797 void GetWriteFunc(OrtWriteNamedBufferFunc& write_func, void*& state) const;
1798};
1799
1804struct ModelCompilationOptions : detail::Base<OrtModelCompilationOptions> {
1806 using Base::Base;
1807
1808 explicit ModelCompilationOptions(std::nullptr_t) {}
1809
1810 ModelCompilationOptions(const Env& env, const SessionOptions& session_options);
1811 ModelCompilationOptions(const Env& env, ConstSessionOptions session_options);
1812
1813 ModelCompilationOptions& SetInputModelPath(const ORTCHAR_T* input_model_path);
1815 size_t input_model_data_size);
1816 ModelCompilationOptions& SetEpContextEmbedMode(bool embed_ep_context_in_model);
1817 ModelCompilationOptions& SetOutputModelPath(const ORTCHAR_T* output_model_path);
1819 size_t initializer_size_threshold);
1821 size_t initializer_size_threshold,
1822 OrtAllocator* allocator,
1823 void** output_buffer_ptr,
1824 size_t* output_buffer_size_ptr);
1826
1829 OrtGetInitializerLocationFunc get_initializer_location_func,
1830 void* state);
1831
1832 ModelCompilationOptions& SetOutputModelBuffer(OrtAllocator* allocator, void** output_model_buffer_ptr,
1833 size_t* output_model_buffer_size_ptr);
1834
1837
1840
1841 ModelCompilationOptions& SetEpContextBinaryInformation(const ORTCHAR_T* output_directory,
1842 const ORTCHAR_T* model_name);
1844
1846
1851};
1852
1859Status CompileModel(const Env& env, const ModelCompilationOptions& model_compilation_options);
1860
1865struct ModelPackageOptions : detail::Base<OrtModelPackageOptions> {
1867 using Base::Base;
1868
1869 explicit ModelPackageOptions(std::nullptr_t) {}
1870 ModelPackageOptions(const Env& env, const SessionOptions& session_options);
1871 ModelPackageOptions(const Env& env, ConstSessionOptions session_options);
1872};
1873
1875struct ModelPackageContext : detail::Base<OrtModelPackageContext> {
1877 using Base::Base;
1878
1879 explicit ModelPackageContext(std::nullptr_t) {}
1880 explicit ModelPackageContext(const ORTCHAR_T* package_root);
1881
1882 int64_t GetSchemaVersion() const;
1883 size_t GetComponentCount() const;
1884 std::vector<std::string> GetComponentNames() const;
1885 size_t GetVariantCount(const char* component_name) const;
1886 std::vector<std::string> GetVariantNames(const char* component_name) const;
1887 const char* GetVariantEpName(const char* component_name, const char* variant_name) const;
1888 std::string ResolveStringRef(const char* base_dir, const char* input, bool must_exist) const;
1890 const ModelPackageOptions& options) const;
1891};
1892
1894struct ModelPackageComponentContext : detail::Base<OrtModelPackageComponentContext> {
1896 using Base::Base;
1897
1898 explicit ModelPackageComponentContext(std::nullptr_t) {}
1899
1900 std::string GetSelectedVariantName() const;
1901 std::basic_string<ORTCHAR_T> GetSelectedVariantFolderPath() const;
1903 Session CreateSession(const Env& env, const SessionOptions& session_options);
1904 Session CreateSession(const Env& env, ConstSessionOptions session_options);
1905};
1906
1910struct ModelMetadata : detail::Base<OrtModelMetadata> {
1912 using Base::Base;
1913
1914 explicit ModelMetadata(std::nullptr_t) {}
1915
1923
1931
1939
1947
1955
1962 std::vector<AllocatedStringPtr> GetCustomMetadataMapKeysAllocated(OrtAllocator* allocator) const;
1963
1974
1975 int64_t GetVersion() const;
1976};
1977
1978struct IoBinding;
1979
1980namespace detail {
1981
1982// we separate const-only methods because passing const ptr to non-const methods
1983// is only discovered when inline methods are compiled which is counter-intuitive
1984template <typename T>
1986 using B = Base<T>;
1987 using B::B;
1988
1989 size_t GetInputCount() const;
1990 size_t GetOutputCount() const;
1992
1993 std::vector<std::string> GetInputNames() const;
1994 std::vector<std::string> GetOutputNames() const;
1995 std::vector<std::string> GetOverridableInitializerNames() const;
1996
1997 std::vector<ConstMemoryInfo> GetMemoryInfoForInputs() const;
1998 std::vector<ConstMemoryInfo> GetMemoryInfoForOutputs() const;
1999 std::vector<ConstEpDevice> GetEpDeviceForInputs() const;
2000 std::vector<ConstEpDevice> GetEpDeviceForOutputs() const;
2001
2010
2019
2028
2029 uint64_t GetProfilingStartTimeNs() const;
2031
2032 TypeInfo GetInputTypeInfo(size_t index) const;
2033 TypeInfo GetOutputTypeInfo(size_t index) const;
2035
2036 int GetOpset(const std::string& domain) const;
2037
2038 std::vector<ValueInfo> GetInputs() const;
2039 std::vector<ValueInfo> GetOutputs() const;
2040
2045 std::vector<ConstEpAssignedSubgraph> GetEpGraphAssignmentInfo() const;
2046};
2047
2048template <typename T>
2051 using B::B;
2052
2070 std::vector<Value> Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
2071 const char* const* output_names, size_t output_count);
2072
2076 void Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
2077 const char* const* output_names, Value* output_values, size_t output_count);
2078
2079 void Run(const RunOptions& run_options, const IoBinding&);
2080
2100 void RunAsync(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
2101 const char* const* output_names, Value* output_values, size_t output_count, RunAsyncCallbackFn callback, void* user_data);
2102
2110
2122 void SetEpDynamicOptions(const char* const* keys, const char* const* values, size_t kv_len);
2123
2124 void FinalizeModelEditorSession(const Model& model, const SessionOptions& options,
2125 OrtPrepackedWeightsContainer* prepacked_weights_container = nullptr);
2126
2133 void ReleaseCapturedGraph(int graph_annotation_id);
2134};
2135
2136} // namespace detail
2137
2140
2144struct Session : detail::SessionImpl<OrtSession> {
2146 explicit Session(std::nullptr_t) {}
2147 explicit Session(OrtSession* p) : SessionImpl{p} {}
2148
2149 Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
2150
2152 Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options,
2153 OrtPrepackedWeightsContainer* prepacked_weights_container);
2154
2156 Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options);
2157
2159 Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options,
2160 OrtPrepackedWeightsContainer* prepacked_weights_container);
2161
2162#if !defined(ORT_MINIMAL_BUILD)
2164 Session(const Env& env, const Model& model, const SessionOptions& options);
2165
2167 static Session CreateModelEditorSession(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
2168
2170 static Session CreateModelEditorSession(const Env& env, const void* model_data, size_t model_data_length,
2171 const SessionOptions& options);
2172#endif // !defined(ORT_MINIMAL_BUILD)
2173
2174 ConstSession GetConst() const { return ConstSession{this->p_}; }
2175 UnownedSession GetUnowned() const { return UnownedSession{this->p_}; }
2176};
2177
2178namespace detail {
2179template <typename T>
2181 using B = Base<T>;
2182 using B::B;
2183
2185
2190 size_t GetElementCount() const;
2191
2192 size_t GetDimensionsCount() const;
2193
2198 [[deprecated("use GetShape()")]] void GetDimensions(int64_t* values, size_t values_count) const;
2199
2200 void GetSymbolicDimensions(const char** values, size_t values_count) const;
2201 std::vector<const char*> GetSymbolicDimensions() const;
2202
2203 bool HasShape() const;
2204 std::vector<int64_t> GetShape() const;
2205};
2206
2207} // namespace detail
2208
2210
2216 using Base::Base;
2217
2219 explicit TensorTypeAndShapeInfo(std::nullptr_t) {}
2221 explicit TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* p) : TensorTypeAndShapeInfoImpl{p} {}
2222
2223 // Create a TensorTypeAndShapeInfo object with the specified element type and dimensions
2224 // symbolic_dims are optional, but should be 1:1 with dims.
2225 // The value in symbolic_dims will be used for all entries in dims that are -1.
2227 const std::vector<int64_t>& dims,
2228 const std::vector<std::string>* symbolic_dims = nullptr);
2229
2231};
2232
2233namespace detail {
2234template <typename T>
2236 using B = Base<T>;
2237 using B::B;
2239};
2240
2241} // namespace detail
2242
2244
2248struct SequenceTypeInfo : detail::SequenceTypeInfoImpl<OrtSequenceTypeInfo> {
2250 using Base::Base;
2251
2252 explicit SequenceTypeInfo(std::nullptr_t) {}
2253 explicit SequenceTypeInfo(OrtSequenceTypeInfo* p) : SequenceTypeInfoImpl<OrtSequenceTypeInfo>{p} {}
2255};
2256
2257namespace detail {
2258template <typename T>
2260 using B = Base<T>;
2261 using B::B;
2263};
2264
2265} // namespace detail
2266
2267// This is always owned by the TypeInfo and can only be obtained from it.
2269
2270namespace detail {
2271template <typename T>
2278
2279} // namespace detail
2280
2282
2286struct MapTypeInfo : detail::MapTypeInfoImpl<OrtMapTypeInfo> {
2288 using Base::Base;
2289
2290 explicit MapTypeInfo(std::nullptr_t) {}
2291 explicit MapTypeInfo(OrtMapTypeInfo* p) : MapTypeInfoImpl<OrtMapTypeInfo>{p} {}
2292 ConstMapTypeInfo GetConst() const { return ConstMapTypeInfo{this->p_}; }
2293};
2294
2295namespace detail {
2296template <typename T>
2308} // namespace detail
2309
2315
2320struct TypeInfo : detail::TypeInfoImpl<OrtTypeInfo> {
2322 using Base::Base;
2323
2325 explicit TypeInfo(std::nullptr_t) {}
2326 explicit TypeInfo(OrtTypeInfo* p) : TypeInfoImpl<OrtTypeInfo>{p} {}
2327
2328#if !defined(ORT_MINIMAL_BUILD)
2334#endif // !defined(ORT_MINIMAL_BUILD)
2335
2336 ConstTypeInfo GetConst() const { return ConstTypeInfo{this->p_}; }
2337};
2338
2339namespace detail {
2340// This structure is used to feed sparse tensor values
2341// information for use with FillSparseTensor<Format>() API
2342// if the data type for the sparse tensor values is numeric
2343// use data.p_data, otherwise, use data.str pointer to feed
2344// values. data.str is an array of const char* that are zero terminated.
2345// number of strings in the array must match shape size.
2346// For fully sparse tensors use shape {0} and set p_data/str
2347// to nullptr.
2349 const int64_t* values_shape;
2351 union {
2352 const void* p_data;
2353 const char** str;
2354 } data;
2355};
2356
2357// Provides a way to pass shape in a single
2358// argument
2359struct Shape {
2360 const int64_t* shape;
2362};
2363
2364template <typename T>
2366 using B = Base<T>;
2367 using B::B;
2368
2372 template <typename R>
2373 void GetOpaqueData(const char* domain, const char* type_name, R&) const;
2374
2375 bool IsTensor() const;
2376 bool HasValue() const;
2377
2378 size_t GetCount() const; // If a non tensor, returns 2 for map and N for sequence, where N is the number of elements
2379 Value GetValue(int index, OrtAllocator* allocator) const;
2380
2388
2403 void GetStringTensorContent(void* buffer, size_t buffer_length, size_t* offsets, size_t offsets_count) const;
2404
2411 template <typename R>
2412 const R* GetTensorData() const;
2413
2418 const void* GetTensorRawData() const;
2419
2427
2435
2441
2450 void GetStringTensorElement(size_t buffer_length, size_t element_index, void* buffer) const;
2451
2458 std::string GetStringTensorElement(size_t element_index) const;
2459
2466 size_t GetStringTensorElementLength(size_t element_index) const;
2467
2478 size_t GetTensorSizeInBytes() const;
2479
2480#if !defined(DISABLE_SPARSE_TENSORS)
2488
2495
2504
2514 template <typename R>
2515 const R* GetSparseTensorIndicesData(OrtSparseIndicesFormat indices_format, size_t& num_indices) const;
2516
2521 bool IsSparseTensor() const;
2522
2531 template <typename R>
2532 const R* GetSparseTensorValues() const;
2533
2534#endif
2535
2548};
2549
2550template <typename T>
2553 using B::B;
2554
2560 template <typename R>
2562
2568
2570 // Obtain a reference to an element of data at the location specified
2576 template <typename R>
2577 R& At(const std::vector<int64_t>& location);
2578
2584 void FillStringTensor(const char* const* s, size_t s_len);
2585
2591 void FillStringTensorElement(const char* s, size_t index);
2592
2605 char* GetResizedStringTensorElementBuffer(size_t index, size_t buffer_length);
2606
2607#if !defined(DISABLE_SPARSE_TENSORS)
2616 void UseCooIndices(int64_t* indices_data, size_t indices_num);
2617
2628 void UseCsrIndices(int64_t* inner_data, size_t inner_num, int64_t* outer_data, size_t outer_num);
2629
2638 void UseBlockSparseIndices(const Shape& indices_shape, int32_t* indices_data);
2639
2649 void FillSparseTensorCoo(const OrtMemoryInfo* data_mem_info, const OrtSparseValuesParam& values_param,
2650 const int64_t* indices_data, size_t indices_num);
2651
2663 void FillSparseTensorCsr(const OrtMemoryInfo* data_mem_info,
2664 const OrtSparseValuesParam& values,
2665 const int64_t* inner_indices_data, size_t inner_indices_num,
2666 const int64_t* outer_indices_data, size_t outer_indices_num);
2667
2678 const OrtSparseValuesParam& values,
2679 const Shape& indices_shape,
2680 const int32_t* indices_data);
2681
2682#endif
2683};
2684
2685} // namespace detail
2686
2689
2693struct Value : detail::ValueImpl<OrtValue> {
2695 using Base::Base;
2698
2699 Value(std::nullptr_t) {}
2700 Value(Value&&) = default;
2701 Value& operator=(Value&&) = default;
2702
2703 ConstValue GetConst() const { return ConstValue{this->p_}; }
2704 UnownedValue GetUnowned() const { return UnownedValue{this->p_}; }
2705
2714 template <typename T>
2715 static Value CreateTensor(const OrtMemoryInfo* info, T* p_data, size_t p_data_element_count,
2716 const int64_t* shape, size_t shape_len);
2717
2727 static Value CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count,
2728 const int64_t* shape, size_t shape_len,
2730
2740 static Value CreateTensor(OrtAllocator* deleter, void* p_data, size_t p_data_byte_count,
2741 const int64_t* shape, size_t shape_len,
2743
2755 template <typename T>
2756 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len);
2757
2769 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len,
2771
2780 static Value CreateMap(const Value& keys, const Value& values);
2781
2789 static Value CreateSequence(const std::vector<Value>& values);
2790
2799 template <typename T>
2800 static Value CreateOpaque(const char* domain, const char* type_name, const T& value);
2801
2802#if !defined(DISABLE_SPARSE_TENSORS)
2813 template <typename T>
2814 static Value CreateSparseTensor(const OrtMemoryInfo* info, T* p_data, const Shape& dense_shape,
2815 const Shape& values_shape);
2816
2833 static Value CreateSparseTensor(const OrtMemoryInfo* info, void* p_data, const Shape& dense_shape,
2834 const Shape& values_shape, ONNXTensorElementDataType type);
2835
2845 template <typename T>
2846 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape);
2847
2859 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape, ONNXTensorElementDataType type);
2860
2861#endif // !defined(DISABLE_SPARSE_TENSORS)
2862};
2863
2864namespace detail {
2865namespace binding_utils {
2866// Bring these out of template
2867std::vector<std::string> GetOutputNamesHelper(const OrtIoBinding* binding, OrtAllocator*);
2868std::vector<Value> GetOutputValuesHelper(const OrtIoBinding* binding, OrtAllocator*);
2869} // namespace binding_utils
2870
2871template <typename T>
2873 using B = Base<T>;
2874 using B::B;
2875
2876 std::vector<std::string> GetOutputNames() const;
2877 std::vector<std::string> GetOutputNames(OrtAllocator*) const;
2878 std::vector<Value> GetOutputValues() const;
2879 std::vector<Value> GetOutputValues(OrtAllocator*) const;
2880};
2881
2882template <typename T>
2885 using B::B;
2886
2887 void BindInput(const char* name, const Value&);
2888 void BindOutput(const char* name, const Value&);
2889 void BindOutput(const char* name, const OrtMemoryInfo*);
2894};
2895
2896} // namespace detail
2897
2900
2904struct IoBinding : detail::IoBindingImpl<OrtIoBinding> {
2905 explicit IoBinding(std::nullptr_t) {}
2906 explicit IoBinding(Session& session);
2907 ConstIoBinding GetConst() const { return ConstIoBinding{this->p_}; }
2908 UnownedIoBinding GetUnowned() const { return UnownedIoBinding{this->p_}; }
2909};
2910
2915struct ArenaCfg : detail::Base<OrtArenaCfg> {
2916 explicit ArenaCfg(std::nullptr_t) {}
2925 ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk);
2926
2931 explicit ArenaCfg(const std::unordered_map<std::string, size_t>& arena_config);
2932};
2933
2934//
2935// Custom OPs (only needed to implement custom OPs)
2936//
2937
2938namespace detail {
2939// Need to define a templated ConstOpAttr with const members
2940template <typename T>
2943 using B::B;
2944
2945 // Wraps OrtApi::OpAttr_GetName
2946 std::string GetName() const;
2947 // Wraps OrtApi::OpAttr_GetType
2949
2950 // Wraps OrtApi::ReadAttr for a single value
2951 // This does not support Tensor Attribute
2952 // Call GetTensorAttributeAsOrtValue() instead.
2953 template <typename R>
2954 Status GetValue(R& out) const;
2955
2956 // Wraps OrtApi::ReadAttr for an array of values
2957 template <typename R>
2958 Status GetValueArray(std::vector<R>& out) const;
2959 // Wraps OrtApi::OpAttr_GetTensorAttributeAsOrtValue
2961};
2962} // namespace detail
2963
2965
2969struct OpAttr : detail::ConstOpAttrImpl<OrtOpAttr> {
2971 using Base::Base;
2972
2973 OpAttr() = default; // Enable storing it in the container for resize()
2974 explicit OpAttr(std::nullptr_t) {}
2975 OpAttr(const char* name, const void* data, int len, OrtOpAttrType type);
2976
2977 ConstOpAttr GetConst() const { return ConstOpAttr{this->p_}; }
2978};
2979
2988#define ORT_CXX_LOG(logger, message_severity, message) \
2989 do { \
2990 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2991 Ort::ThrowOnError(logger.LogMessage(message_severity, ORT_FILE, __LINE__, \
2992 static_cast<const char*>(__FUNCTION__), message)); \
2993 } \
2994 } while (false)
2995
3004#define ORT_CXX_LOG_NOEXCEPT(logger, message_severity, message) \
3005 do { \
3006 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
3007 static_cast<void>(logger.LogMessage(message_severity, ORT_FILE, __LINE__, \
3008 static_cast<const char*>(__FUNCTION__), message)); \
3009 } \
3010 } while (false)
3011
3023#define ORT_CXX_LOGF(logger, message_severity, /*format,*/...) \
3024 do { \
3025 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
3026 Ort::ThrowOnError(logger.LogFormattedMessage(message_severity, ORT_FILE, __LINE__, \
3027 static_cast<const char*>(__FUNCTION__), __VA_ARGS__)); \
3028 } \
3029 } while (false)
3030
3042#define ORT_CXX_LOGF_NOEXCEPT(logger, message_severity, /*format,*/...) \
3043 do { \
3044 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
3045 static_cast<void>(logger.LogFormattedMessage(message_severity, ORT_FILE, __LINE__, \
3046 static_cast<const char*>(__FUNCTION__), __VA_ARGS__)); \
3047 } \
3048 } while (false)
3049
3060struct Logger {
3064 Logger() = default;
3065
3069 explicit Logger(std::nullptr_t) {}
3070
3077 explicit Logger(const OrtLogger* logger);
3078
3079 ~Logger() = default;
3080
3081 Logger(const Logger&) = default;
3082 Logger& operator=(const Logger&) = default;
3083
3084 Logger(Logger&& v) noexcept = default;
3085 Logger& operator=(Logger&& v) noexcept = default;
3086
3093
3106 Status LogMessage(OrtLoggingLevel log_severity_level, const ORTCHAR_T* file_path, int line_number,
3107 const char* func_name, const char* message) const noexcept;
3108
3123 template <typename... Args>
3124 Status LogFormattedMessage(OrtLoggingLevel log_severity_level, const ORTCHAR_T* file_path, int line_number,
3125 const char* func_name, const char* format, Args&&... args) const noexcept;
3126
3127 private:
3128 const OrtLogger* logger_{};
3129 OrtLoggingLevel cached_severity_level_{};
3130};
3131
3140 size_t GetInputCount() const;
3141 size_t GetOutputCount() const;
3142 // If input is optional and is not present, the method returns an empty ConstValue
3143 // which can be compared to nullptr.
3144 ConstValue GetInput(size_t index) const;
3145 // If output is optional and is not present, the method returns an empty UnownedValue
3146 // which can be compared to nullptr.
3147 UnownedValue GetOutput(size_t index, const int64_t* dim_values, size_t dim_count) const;
3148 UnownedValue GetOutput(size_t index, const std::vector<int64_t>& dims) const;
3150 void* GetGPUComputeStream() const;
3153 Ort::Allocator GetAllocator(const OrtMemoryInfo& memory_info) const;
3154 OrtKernelContext* GetOrtKernelContext() const { return ctx_; }
3155 void ParallelFor(void (*fn)(void*, size_t), size_t total, size_t num_batch, void* usr_data) const;
3156
3157 private:
3158 OrtKernelContext* ctx_;
3159};
3160
3161struct KernelInfo;
3162
3163namespace detail {
3164namespace attr_utils {
3165void GetAttr(const OrtKernelInfo* p, const char* name, float&);
3166void GetAttr(const OrtKernelInfo* p, const char* name, int64_t&);
3167void GetAttr(const OrtKernelInfo* p, const char* name, std::string&);
3168void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<float>&);
3169void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<int64_t>&);
3170void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<std::string>&);
3171} // namespace attr_utils
3172
3173template <typename T>
3174struct KernelInfoImpl : Base<T> {
3175 using B = Base<T>;
3176 using B::B;
3177
3178 KernelInfo Copy() const;
3179
3180 template <typename R> // R is only implemented for float, int64_t, and string
3181 R GetAttribute(const char* name) const {
3182 R val;
3183 attr_utils::GetAttr(this->p_, name, val);
3184 return val;
3185 }
3186
3187 template <typename R> // R is only implemented for float, int64_t, and string
3188 std::vector<R> GetAttributes(const char* name) const {
3189 std::vector<R> result;
3190 attr_utils::GetAttrs(this->p_, name, result);
3191 return result;
3192 }
3193
3194 Value GetTensorAttribute(const char* name, OrtAllocator* allocator) const;
3195
3196 size_t GetInputCount() const;
3197 size_t GetOutputCount() const;
3198
3199 std::string GetInputName(size_t index) const;
3200 std::string GetOutputName(size_t index) const;
3201
3202 TypeInfo GetInputTypeInfo(size_t index) const;
3203 TypeInfo GetOutputTypeInfo(size_t index) const;
3204
3205 ConstValue GetTensorConstantInput(size_t index, int* is_constant) const;
3206
3207 std::string GetNodeName() const;
3208 Logger GetLogger() const;
3209
3210 KeyValuePairs GetConfigEntries() const;
3211
3212 std::string GetOperatorDomain() const;
3213 std::string GetOperatorType() const;
3214 int GetOperatorSinceVersion() const;
3215 const OrtEp* GetEp() const;
3216};
3217
3218} // namespace detail
3219
3220using ConstKernelInfo = detail::KernelInfoImpl<detail::Unowned<const OrtKernelInfo>>;
3221
3228struct KernelInfo : detail::KernelInfoImpl<OrtKernelInfo> {
3229 using Base = detail::KernelInfoImpl<OrtKernelInfo>;
3230 using Base::Base;
3231 explicit KernelInfo(std::nullptr_t) {}
3232 explicit KernelInfo(OrtKernelInfo* info);
3233 ConstKernelInfo GetConst() const { return ConstKernelInfo{this->p_}; }
3234};
3235
3239struct Op : detail::Base<OrtOp> {
3241 using Base::Base;
3242
3243 explicit Op(std::nullptr_t) {}
3244
3245 explicit Op(OrtOp*);
3246
3247 static Op Create(const OrtKernelInfo* info, const char* op_name, const char* domain,
3248 int version, const char** type_constraint_names,
3249 const ONNXTensorElementDataType* type_constraint_values,
3250 size_t type_constraint_count,
3251 const OpAttr* attr_values,
3252 size_t attr_count,
3253 size_t input_count, size_t output_count);
3254
3255 void Invoke(const OrtKernelContext* context,
3256 const Value* input_values,
3257 size_t input_count,
3258 Value* output_values,
3259 size_t output_count);
3260
3261 // For easier refactoring
3262 void Invoke(const OrtKernelContext* context,
3263 const OrtValue* const* input_values,
3264 size_t input_count,
3265 OrtValue* const* output_values,
3266 size_t output_count);
3267};
3268
3274 SymbolicInteger(int64_t i) : i_(i), is_int_(true) {};
3275 SymbolicInteger(const char* s) : s_(s), is_int_(false) {};
3278
3281
3282 bool operator==(const SymbolicInteger& dim) const {
3283 if (is_int_ == dim.is_int_) {
3284 if (is_int_) {
3285 return i_ == dim.i_;
3286 } else {
3287 return std::string{s_} == std::string{dim.s_};
3288 }
3289 }
3290 return false;
3291 }
3292
3293 bool IsInt() const { return is_int_; }
3294 int64_t AsInt() const { return i_; }
3295 const char* AsSym() const { return s_; }
3296
3297 static constexpr int INVALID_INT_DIM = -2;
3298
3299 private:
3300 union {
3301 int64_t i_;
3302 const char* s_;
3303 };
3304 bool is_int_;
3305 };
3306
3307 using Shape = std::vector<SymbolicInteger>;
3308
3310
3311 const Shape& GetInputShape(size_t indice) const { return input_shapes_.at(indice); }
3312
3313 size_t GetInputCount() const { return input_shapes_.size(); }
3314
3316
3317 int64_t GetAttrInt(const char* attr_name);
3318
3319 using Ints = std::vector<int64_t>;
3320 Ints GetAttrInts(const char* attr_name);
3321
3322 float GetAttrFloat(const char* attr_name);
3323
3324 using Floats = std::vector<float>;
3325 Floats GetAttrFloats(const char* attr_name);
3326
3327 std::string GetAttrString(const char* attr_name);
3328
3329 using Strings = std::vector<std::string>;
3330 Strings GetAttrStrings(const char* attr_name);
3331
3332 private:
3333 ConstOpAttr GetAttrHdl(const char* attr_name) const;
3334 const OrtApi* ort_api_;
3336 std::vector<Shape> input_shapes_;
3337};
3338
3340
3341#define MAX_CUSTOM_OP_END_VER (1UL << 31) - 1
3342
3343template <typename TOp, typename TKernel, bool WithStatus = false>
3347 OrtCustomOp::GetName = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetName(); };
3348
3349 OrtCustomOp::GetExecutionProviderType = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetExecutionProviderType(); };
3350
3351 OrtCustomOp::GetInputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetInputTypeCount(); };
3352 OrtCustomOp::GetInputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputType(index); };
3353 OrtCustomOp::GetInputMemoryType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputMemoryType(index); };
3354
3355 OrtCustomOp::GetOutputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetOutputTypeCount(); };
3356 OrtCustomOp::GetOutputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputType(index); };
3357
3358#if defined(_MSC_VER) && !defined(__clang__)
3359#pragma warning(push)
3360#pragma warning(disable : 26409)
3361#endif
3362 OrtCustomOp::KernelDestroy = [](void* op_kernel) { delete static_cast<TKernel*>(op_kernel); };
3363#if defined(_MSC_VER) && !defined(__clang__)
3364#pragma warning(pop)
3365#endif
3366 OrtCustomOp::GetInputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputCharacteristic(index); };
3367 OrtCustomOp::GetOutputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputCharacteristic(index); };
3368
3369 OrtCustomOp::GetVariadicInputMinArity = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetVariadicInputMinArity(); };
3370 OrtCustomOp::GetVariadicInputHomogeneity = [](const OrtCustomOp* this_) { return static_cast<int>(static_cast<const TOp*>(this_)->GetVariadicInputHomogeneity()); };
3371 OrtCustomOp::GetVariadicOutputMinArity = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetVariadicOutputMinArity(); };
3372 OrtCustomOp::GetVariadicOutputHomogeneity = [](const OrtCustomOp* this_) { return static_cast<int>(static_cast<const TOp*>(this_)->GetVariadicOutputHomogeneity()); };
3373#ifdef __cpp_if_constexpr
3374 if constexpr (WithStatus) {
3375#else
3376 if (WithStatus) {
3377#endif
3378 OrtCustomOp::CreateKernelV2 = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info, void** op_kernel) -> OrtStatusPtr {
3379 return static_cast<const TOp*>(this_)->CreateKernelV2(*api, info, op_kernel);
3380 };
3381 OrtCustomOp::KernelComputeV2 = [](void* op_kernel, OrtKernelContext* context) -> OrtStatusPtr {
3382 return static_cast<TKernel*>(op_kernel)->ComputeV2(context);
3383 };
3384 } else {
3387
3388 OrtCustomOp::CreateKernel = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info) { return static_cast<const TOp*>(this_)->CreateKernel(*api, info); };
3389 OrtCustomOp::KernelCompute = [](void* op_kernel, OrtKernelContext* context) {
3390 static_cast<TKernel*>(op_kernel)->Compute(context);
3391 };
3392 }
3393
3394 SetShapeInferFn<TOp>(0);
3395
3396 OrtCustomOp::GetStartVersion = [](const OrtCustomOp* this_) {
3397 return static_cast<const TOp*>(this_)->start_ver_;
3398 };
3399
3400 OrtCustomOp::GetEndVersion = [](const OrtCustomOp* this_) {
3401 return static_cast<const TOp*>(this_)->end_ver_;
3402 };
3403
3406 OrtCustomOp::GetAliasMap = nullptr;
3408 }
3409
3410 // Default implementation of GetExecutionProviderType that returns nullptr to default to the CPU provider
3411 const char* GetExecutionProviderType() const { return nullptr; }
3412
3413 // Default implementations of GetInputCharacteristic() and GetOutputCharacteristic() below
3414 // (inputs and outputs are required by default)
3416 return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED;
3417 }
3418
3420 return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED;
3421 }
3422
3423 // Default implementation of GetInputMemoryType() that returns OrtMemTypeDefault
3424 OrtMemType GetInputMemoryType(size_t /*index*/) const {
3425 return OrtMemTypeDefault;
3426 }
3427
3428 // Default implementation of GetVariadicInputMinArity() returns 1 to specify that a variadic input
3429 // should expect at least 1 argument.
3431 return 1;
3432 }
3433
3434 // Default implementation of GetVariadicInputHomegeneity() returns true to specify that all arguments
3435 // to a variadic input should be of the same type.
3437 return true;
3438 }
3439
3440 // Default implementation of GetVariadicOutputMinArity() returns 1 to specify that a variadic output
3441 // should produce at least 1 output value.
3443 return 1;
3444 }
3445
3446 // Default implementation of GetVariadicOutputHomegeneity() returns true to specify that all output values
3447 // produced by a variadic output should be of the same type.
3449 return true;
3450 }
3451
3452 // Declare list of session config entries used by this Custom Op.
3453 // Implement this function in order to get configs from CustomOpBase::GetSessionConfigs().
3454 // This default implementation returns an empty vector of config entries.
3455 std::vector<std::string> GetSessionConfigKeys() const {
3456 return std::vector<std::string>{};
3457 }
3458
3459 // Ort::CustomOpBase derived class should provide the following static method with the type/shape inferencing
3460 // implementation if needed:
3461 // static OrtStatusPtr InferOutputShape(Ort::ShapeInferContext& context)
3462 template <typename C>
3463 decltype(&C::InferOutputShape) SetShapeInferFn(decltype(&C::InferOutputShape)) {
3465 ShapeInferContext ctx(&GetApi(), ort_ctx);
3466 return C::InferOutputShape(ctx);
3467 };
3468 return {};
3469 }
3470
3471 template <typename C>
3475
3476 protected:
3477 // Helper function that returns a map of session config entries specified by CustomOpBase::GetSessionConfigKeys.
3478 void GetSessionConfigs(std::unordered_map<std::string, std::string>& out, ConstSessionOptions options) const;
3479
3480 int start_ver_ = 1;
3481 int end_ver_ = MAX_CUSTOM_OP_END_VER;
3482};
3483
3484// Forward declaration to resolve circular dependency
3485// on ConstNode
3487
3488namespace detail {
3489template <typename T>
3491 using B = Base<T>;
3492 using B::B;
3493
3495 std::string GetName() const;
3501 std::vector<ValueInfoConsumerProducerInfo> GetConsumers() const;
3511 bool IsGraphOutput() const;
3515 bool IsFromOuterScope() const;
3516};
3517} // namespace detail
3518
3519// Const object holder that does not own the underlying object
3521
3526 ValueInfo() = default; // Same thing as with nullptr
3527 explicit ValueInfo(std::nullptr_t) {}
3529 explicit ValueInfo(OrtValueInfo* p) : ConstValueInfoImpl<OrtValueInfo>{p} {}
3530
3531#if !defined(ORT_MINIMAL_BUILD)
3532 // Create ValueInfo for a tensor
3533 explicit ValueInfo(const std::string& name, const ConstTypeInfo& type_info);
3534#endif
3535 ConstValueInfo GetConst() const { return ConstValueInfo{this->p_}; }
3536};
3537
3538// Forward declaration
3539struct AttrNameSubgraph;
3540
3541namespace detail {
3542// Forward decl
3543template <typename T>
3544struct ConstGraphImpl;
3545
3546template <typename T>
3547struct ConstNodeImpl : Base<T> {
3548 using B = Base<T>;
3549 using B::B;
3550
3551 // <Wraps OrtApi::Node_GetId
3552 size_t GetId() const;
3553 // <Wraps OrtApi::Node_GetName
3554 std::string GetName() const;
3555 // <Wraps OrtApi::Node_GetOperatorType
3556 std::string GetOperatorType() const;
3557 // <Wraps OrtApi::Node_GetDomain
3558 std::string GetDomain() const;
3559 // <Wraps OrtApi::Node_GetSinceVersion
3560 int GetSinceVersion() const;
3561
3562 // <Wraps OrtApi::Node_Inputs
3563 std::vector<ConstValueInfo> GetInputs() const;
3564 // <Wraps OrtApi::Node_Outputs
3565 std::vector<ConstValueInfo> GetOutputs() const;
3566 // <Wraps OrtApi::Node_ImplicitInputs
3567 std::vector<ConstValueInfo> GetImplicitInputs() const;
3568 // <Wraps OrtApi::Node_GetAttributes
3569 std::vector<ConstOpAttr> GetAttributes() const;
3570 // <Wraps OrtApi::Node_GetAttributeByName
3571 // Please, read C API doc for details
3572 Status GetAttributeByName(const std::string& name, ConstOpAttr& attr) const;
3573 // <Wraps OrtApi::Node_GetSubgraphs
3574 std::vector<AttrNameSubgraph> GetSubgraphs() const;
3575 // <Wraps OrtApi::Node_GetGraph
3576 // ConstGraph is not available yet
3578 // <Wraps OrtApi::Node_GetEpName
3579 std::string GetEpName() const;
3580};
3581} // namespace detail
3582
3584
3588struct Node : detail::ConstNodeImpl<OrtNode> {
3589 Node() = default; // Same thing as with nullptr
3590 explicit Node(std::nullptr_t) {}
3591 explicit Node(OrtNode* p) : ConstNodeImpl<OrtNode>{p} {}
3592
3593#if !defined(ORT_MINIMAL_BUILD)
3594 Node(const std::string& operator_name, const std::string& operator_domain,
3595 const std::string& node_name,
3596 const std::vector<std::string>& input_names,
3597 const std::vector<std::string>& output_names);
3598
3602 Node(const std::string& operator_name, const std::string& operator_domain,
3603 const std::string& node_name,
3604 const std::vector<std::string>& input_names,
3605 const std::vector<std::string>& output_names,
3606 std::vector<OpAttr>& attributes);
3607
3608 private:
3609 static void Init(const std::string& operator_name, const std::string& operator_domain,
3610 const std::string& node_name,
3611 const std::vector<std::string>& input_names,
3612 const std::vector<std::string>& output_names,
3613 std::vector<OpAttr>& attributes,
3614 OrtNode*& node);
3615#endif // !defined(ORT_MINIMAL_BUILD)
3616};
3617
3618// Return struct for some of ValueInfo APIs.
3619// Must be declared after ConstNode is available.
3622 // either producer output or consumer output index
3623 // producer is unsigned only, output can be -1
3624 int64_t index;
3625};
3626
3627// Represents a return value for Graph::GetOperatorSets()
3629 std::string domain;
3630 int64_t version;
3631};
3632
3633namespace detail {
3634template <typename T>
3636 using B = Base<T>;
3637 using B::B;
3638
3639 // <Wraps OrtApi::Graph_GetName
3640 std::string GetName() const;
3641 // <Wraps OrtApi::Graph_GetModelPath
3642 std::basic_string<ORTCHAR_T> GetModelPath() const;
3643 // <Wraps OrtApi::Graph_GetOnnxIRVersion
3644 int64_t GetOnnxIRVersion() const;
3645 // <Wraps OrtApi::Graph_GetOperatorSets
3646 std::vector<OperatorSet> GetOperatorSets() const;
3647 // <Wraps OrtApi::Graph_Inputs
3648 std::vector<ConstValueInfo> GetInputs() const;
3649 // <Wraps OrtApi::Graph_Outputs
3650 std::vector<ConstValueInfo> GetOutputs() const;
3651 // <Wraps OrtApi::Graph_Initializers
3652 std::vector<ConstValueInfo> GetInitializers() const;
3653 // <Wraps OrtApi::Graph_GetNodes
3654 std::vector<ConstNode> GetNodes() const;
3655 // <Wraps OrtApi::Graph_GetParentGraph
3657 // <Wraps OrtApi::Graph_GetGraphView
3658 Graph GetGraphView(const std::vector<ConstNode>& nodes) const;
3659 // <Wraps OrtApi::Graph_GetModelMetadata
3661};
3662
3663template <typename T>
3666 using B::B;
3667
3668#if !defined(ORT_MINIMAL_BUILD)
3672 void SetInputs(std::vector<ValueInfo>& inputs);
3676 void SetOutputs(std::vector<ValueInfo>& outputs);
3680 void AddInitializer(const std::string& name, Value& initializer, bool data_is_external); // Graph takes ownership of Value
3684 void AddNode(Node& node); // Graph takes ownership of Node
3685#endif // !defined(ORT_MINIMAL_BUILD)
3686};
3687} // namespace detail
3688
3690
3691// Return value for Node API
3692// Must be declared after ConstGraph
3697
3701struct Graph : detail::GraphImpl<OrtGraph> {
3702 explicit Graph(std::nullptr_t) {}
3703 explicit Graph(OrtGraph* p) : GraphImpl<OrtGraph>{p} {}
3704#if !defined(ORT_MINIMAL_BUILD)
3705 // <Wraps GetModelEditorApi().CreateGraph()
3707#endif
3708};
3709
3710namespace detail {
3711template <typename T>
3714 using B::B;
3715
3716#if !defined(ORT_MINIMAL_BUILD)
3720 void AddGraph(Graph& graph);
3721#endif
3722};
3723} // namespace detail
3724
3725// Const object holder that does not own the underlying object
3727
3731struct Model : detail::ModelImpl<OrtModel> {
3732 using DomainOpsetPair = std::pair<std::string, int>;
3733
3734 explicit Model(std::nullptr_t) {}
3735 explicit Model(OrtModel* p) : ModelImpl<OrtModel>{p} {}
3736
3737#if !defined(ORT_MINIMAL_BUILD)
3738 //< Wraps GetModelEditorApi().CreateModel()
3739 explicit Model(const std::vector<DomainOpsetPair>& opsets);
3740#endif
3741};
3742
3743namespace detail {
3744template <typename T>
3746 using B = Base<T>;
3747 using B::B;
3748
3750 const char* GetOperatorType() const;
3751
3753 const char* GetDomain() const;
3754
3756 std::pair<int, int> GetSinceVersion() const;
3757
3759 const char* GetExecutionProvider() const;
3760
3762 OrtMemType GetInputMemType(size_t input_index) const;
3763
3765 OrtMemType GetOutputMemType(size_t output_index) const;
3766};
3767} // namespace detail
3768
3770
3773 using Base::Base;
3774
3775 explicit KernelDef(std::nullptr_t) {}
3776 explicit KernelDef(OrtKernelDef* p) : detail::ConstKernelDefImpl<OrtKernelDef>{p} {}
3777
3778 ConstKernelDef GetConst() const { return ConstKernelDef{this->p_}; }
3779};
3780
3785struct KernelDefBuilder : detail::Base<OrtKernelDefBuilder> {
3787 explicit KernelDefBuilder(std::nullptr_t) {}
3788 explicit KernelDefBuilder(OrtKernelDefBuilder* ort_kernel_def_builder);
3789
3790 KernelDefBuilder& SetOperatorType(const char* op_type);
3791 KernelDefBuilder& SetDomain(const char* domain);
3792 KernelDefBuilder& SetSinceVersion(int since_version_start, int since_version_end);
3794 KernelDefBuilder& SetInputMemType(size_t input_index, OrtMemType mem_type);
3795 KernelDefBuilder& SetOutputMemType(size_t output_index, OrtMemType mem_type);
3796 KernelDefBuilder& AddTypeConstraint(const char* arg_name, const OrtDataType* data_type);
3797 KernelDefBuilder& AddTypeConstraint(const char* arg_name, const std::vector<const OrtDataType*>& data_types);
3798 KernelDefBuilder& AddInputOutputAlias(int input_index, int output_index);
3799 KernelDefBuilder& AddInputOutputAliases(const std::vector<int>& input_indices,
3800 const std::vector<int>& output_indices);
3801 KernelDefBuilder& AddInputOutputMutableAlias(int input_index, int output_index);
3802 KernelDefBuilder& AddInputOutputMutableAliases(const std::vector<int>& input_indices,
3803 const std::vector<int>& output_indices);
3804
3806};
3807
3812struct KernelRegistry : detail::Base<OrtKernelRegistry> {
3815
3817 explicit KernelRegistry(std::nullptr_t) {}
3818
3820 explicit KernelRegistry(OrtKernelRegistry* ort_kernel_registry);
3821
3823 Status AddKernel(const OrtKernelDef* kernel_def, OrtKernelCreateFunc kernel_create_func,
3824 void* kernel_create_func_state);
3825};
3826
3827namespace detail {
3828template <typename T>
3830 using B = Base<T>;
3831 using B::B;
3832
3834 std::string GetTypeParamName() const;
3835
3837 std::vector<std::string> GetAllowedTypes() const;
3838
3840 std::vector<size_t> GetInputIndices() const;
3841
3843 std::vector<size_t> GetOutputIndices() const;
3844};
3845} // namespace detail
3846
3851
3852namespace detail {
3853template <typename T>
3854struct OpSchemaImpl : Base<T> {
3855 using B = Base<T>;
3856 using B::B;
3857
3859 int GetSinceVersion() const;
3860
3862 size_t GetNumInputs() const;
3863
3865 std::string GetInputName(size_t index) const;
3866
3870
3872 size_t GetNumOutputs() const;
3873
3875 std::string GetOutputName(size_t index) const;
3876
3880
3883
3886};
3887} // namespace detail
3888
3894
3900OpSchema GetOpSchema(const char* name, int max_inclusive_version, const char* domain);
3901
3902namespace detail {
3903template <typename T>
3906 using B::B;
3907
3908 //< Wraps SharedPrePackedWeightCache_StoreWeightData
3909 Status StoreWeightData(void** buffer_data_ptrs, size_t* buffer_sizes, size_t num_buffers);
3910};
3911} // namespace detail
3912
3930
3933
3934} // namespace Ort
3935#include "onnxruntime_cxx_inline.h"
struct OrtMemoryInfo OrtMemoryInfo
Definition onnxruntime_c_api.h:298
struct OrtKernelInfo OrtKernelInfo
Definition onnxruntime_c_api.h:491
struct OrtNode OrtNode
Definition onnxruntime_c_api.h:329
OrtLoggingLevel
Logging severity levels.
Definition onnxruntime_c_api.h:266
OrtMemoryInfoDeviceType
This mimics OrtDevice type constants so they can be returned in the API.
Definition onnxruntime_c_api.h:526
struct OrtShapeInferContext OrtShapeInferContext
Definition onnxruntime_c_api.h:326
void(* OrtLoggingFunction)(void *param, OrtLoggingLevel severity, const char *category, const char *logid, const char *code_location, const char *message)
Definition onnxruntime_c_api.h:455
void(* OrtCustomJoinThreadFn)(OrtCustomThreadHandle ort_custom_thread_handle)
Custom thread join function.
Definition onnxruntime_c_api.h:1050
OrtCustomOpInputOutputCharacteristic
Definition onnxruntime_c_api.h:7788
struct OrtTensorRTProviderOptionsV2 OrtTensorRTProviderOptionsV2
Definition onnxruntime_c_api.h:315
struct OrtThreadingOptions OrtThreadingOptions
Definition onnxruntime_c_api.h:312
struct OrtSequenceTypeInfo OrtSequenceTypeInfo
Definition onnxruntime_c_api.h:306
struct OrtValueInfo OrtValueInfo
Definition onnxruntime_c_api.h:328
struct OrtDnnlProviderOptions OrtDnnlProviderOptions
Definition onnxruntime_c_api.h:322
OrtSparseIndicesFormat
Definition onnxruntime_c_api.h:255
struct OrtPrepackedWeightsContainer OrtPrepackedWeightsContainer
Definition onnxruntime_c_api.h:314
struct OrtSession OrtSession
Definition onnxruntime_c_api.h:300
OrtCompiledModelCompatibility
Definition onnxruntime_c_api.h:1276
OrtStatus *(* EpSelectionDelegate)(const OrtEpDevice **ep_devices, size_t num_devices, const OrtKeyValuePairs *model_metadata, const OrtKeyValuePairs *runtime_metadata, const OrtEpDevice **selected, size_t max_selected, size_t *num_selected, void *state)
Delegate to allow providing custom OrtEpDevice selection logic.
Definition onnxruntime_c_api.h:580
struct OrtCustomOpDomain OrtCustomOpDomain
Definition onnxruntime_c_api.h:309
struct OrtIoBinding OrtIoBinding
Definition onnxruntime_c_api.h:299
struct OrtExternalInitializerInfo OrtExternalInitializerInfo
Definition onnxruntime_c_api.h:338
OrtAllocatorType
Definition onnxruntime_c_api.h:497
struct OrtOp OrtOp
Definition onnxruntime_c_api.h:323
struct OrtTypeInfo OrtTypeInfo
Definition onnxruntime_c_api.h:303
OrtStatus *(* OrtWriteNamedBufferFunc)(void *state, const char *name, const void *buffer, size_t buffer_num_bytes)
Function called to write named binary data.
Definition onnxruntime_c_api.h:617
struct OrtTensorTypeAndShapeInfo OrtTensorTypeAndShapeInfo
Definition onnxruntime_c_api.h:304
struct OrtCUDAProviderOptionsV2 OrtCUDAProviderOptionsV2
Definition onnxruntime_c_api.h:320
struct OrtProfilingEvent OrtProfilingEvent
Definition onnxruntime_ep_c_api.h:35
struct OrtKernelContext OrtKernelContext
Definition onnxruntime_c_api.h:493
OrtStatus *(* OrtReadNamedBufferFunc)(void *state, const char *name, OrtAllocator *allocator, void **buffer, size_t *data_size)
Function called to read named binary data.
Definition onnxruntime_c_api.h:637
struct OrtCANNProviderOptions OrtCANNProviderOptions
Definition onnxruntime_c_api.h:321
struct OrtEpDevice OrtEpDevice
Definition onnxruntime_c_api.h:335
void(* RunAsyncCallbackFn)(void *user_data, OrtValue **outputs, size_t num_outputs, OrtStatusPtr status)
Callback function for RunAsync.
Definition onnxruntime_c_api.h:1124
OrtHardwareDeviceType
Definition onnxruntime_c_api.h:533
struct OrtModel OrtModel
Definition onnxruntime_c_api.h:331
struct OrtGraph OrtGraph
Definition onnxruntime_c_api.h:330
struct OrtSyncStream OrtSyncStream
Definition onnxruntime_c_api.h:337
OrtWeightlessSupport
Describes the weightless modes.
Definition onnxruntime_c_api.h:8357
struct OrtSessionOptions OrtSessionOptions
Definition onnxruntime_c_api.h:308
OrtDeviceMemoryType
This matches OrtDevice::MemoryType values.
Definition onnxruntime_c_api.h:519
struct OrtValue OrtValue
Definition onnxruntime_c_api.h:301
OrtStatus *(* OrtWriteBufferFunc)(void *state, const void *buffer, size_t buffer_num_bytes)
Function called by ORT to write a buffer to a custom destination (e.g., file, stream,...
Definition onnxruntime_c_api.h:599
GraphOptimizationLevel
Graph optimization level.
Definition onnxruntime_c_api.h:464
struct OrtKeyValuePairs OrtKeyValuePairs
Definition onnxruntime_c_api.h:336
OrtStatus * OrtStatusPtr
Definition onnxruntime_c_api.h:352
OrtMemType
Memory types for allocated memory, execution provider specific types should be extended in each provi...
Definition onnxruntime_c_api.h:507
OrtSparseFormat
Definition onnxruntime_c_api.h:247
ONNXType
Definition onnxruntime_c_api.h:235
struct OrtEnv OrtEnv
Definition onnxruntime_c_api.h:296
OrtErrorCode
Error codes reported by ONNX Runtime.
Definition onnxruntime_error_code.h:19
struct OrtStatus OrtStatus
Definition onnxruntime_c_api.h:297
struct OrtDeviceEpIncompatibilityDetails OrtDeviceEpIncompatibilityDetails
Definition onnxruntime_c_api.h:342
OrtStatus *(* OrtGetInitializerLocationFunc)(void *state, const char *initializer_name, const OrtValue *initializer_value, const OrtExternalInitializerInfo *external_info, OrtExternalInitializerInfo **new_external_info)
Function called by ORT to allow user to specify how an initializer should be saved,...
Definition onnxruntime_c_api.h:688
#define ORT_API_VERSION
The API version defined in this header.
Definition onnxruntime_c_api.h:43
struct OrtLogger OrtLogger
Definition onnxruntime_c_api.h:325
struct OrtMapTypeInfo OrtMapTypeInfo
Definition onnxruntime_c_api.h:305
struct OrtArenaCfg OrtArenaCfg
Definition onnxruntime_c_api.h:313
ExecutionMode
Definition onnxruntime_c_api.h:472
OrtOpAttrType
Definition onnxruntime_c_api.h:274
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:1043
ONNXTensorElementDataType
Definition onnxruntime_c_api.h:194
OrtExecutionProviderDevicePolicy
These are the default EP selection policies used by ORT when doing automatic EP selection.
Definition onnxruntime_c_api.h:541
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:269
@ OrtDeviceMemoryType_DEFAULT
Device memory.
Definition onnxruntime_c_api.h:520
@ OrtMemTypeDefault
The default allocator for execution provider.
Definition onnxruntime_c_api.h:515
@ ORT_FAIL
Definition onnxruntime_error_code.h:27
@ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT
Definition onnxruntime_c_api.h:196
std::vector< Value > GetOutputValuesHelper(const OrtIoBinding *binding, OrtAllocator *)
std::vector< std::string > GetOutputNamesHelper(const OrtIoBinding *binding, OrtAllocator *)
void OrtRelease(OrtAllocator *ptr)
Definition onnxruntime_cxx_api.h:642
std::string MakeCustomOpConfigEntryKey(const char *custom_op_name, const char *config)
All C++ Onnxruntime APIs are defined inside this namespace.
Definition onnxruntime_cxx_api.h:48
Ort::KeyValuePairs GetEnvConfigEntries()
const OrtModelEditorApi & GetModelEditorApi()
This returns a reference to the ORT C Model Editor API. Used if building or augmenting a model at run...
Definition onnxruntime_cxx_api.h:215
std::unique_ptr< char, detail::AllocatedFree > AllocatedStringPtr
unique_ptr typedef used to own strings allocated by OrtAllocators and release them at the end of the ...
Definition onnxruntime_cxx_api.h:829
detail::ConstSessionOptionsImpl< detail::Unowned< const OrtSessionOptions > > ConstSessionOptions
Definition onnxruntime_cxx_api.h:1769
detail::KernelInfoImpl< detail::Unowned< const OrtKernelInfo > > ConstKernelInfo
Definition onnxruntime_cxx_api.h:3220
const OrtApi & GetApi() noexcept
This returns a reference to the ORT C API.
Definition onnxruntime_cxx_api.h:189
const OrtCompileApi & GetCompileApi()
This returns a reference to the ORT C Compile API. Used if compiling a model at runtime.
Definition onnxruntime_cxx_api.h:229
AllocatedStringPtr GetCompatibilityInfoFromModelAllocated(const char *model_path, const char *ep_type, OrtAllocator *allocator)
Extract EP compatibility info from a precompiled model file.
AllocatedStringPtr GetCompatibilityInfoFromModelBytesAllocated(const void *model_data, size_t model_data_length, const char *ep_type, OrtAllocator *allocator)
Extract EP compatibility info from precompiled model bytes in memory.
detail::AllocatorImpl< detail::Unowned< OrtAllocator > > UnownedAllocator
Definition onnxruntime_cxx_api.h:1112
OrtCompiledModelCompatibility GetModelCompatibilityForEpDevices(const std::vector< ConstEpDevice > &ep_devices, const char *compatibility_info)
Validate a compiled model's compatibility for one or more EP devices.
const OrtInteropApi & GetInteropApi()
This returns a reference to the ORT C Interop API. Used for external resource import with EPs.
Definition onnxruntime_cxx_api.h:243
OpSchema GetOpSchema(const char *name, int max_inclusive_version, const char *domain)
Get an operator schema from the global schema registry.
detail::SessionOptionsImpl< detail::Unowned< OrtSessionOptions > > UnownedSessionOptions
Definition onnxruntime_cxx_api.h:1768
std::string GetBuildInfoString()
This function returns the onnxruntime build information: including git branch, git commit id,...
const OrtEpApi & GetEpApi()
This returns a reference to the ORT C EP API. Used if authoring a plugin execution provider.
Definition onnxruntime_cxx_api.h:270
std::string GetVersionString()
This function returns the onnxruntime version string.
std::vector< std::string > GetAvailableProviders()
This is a C++ wrapper for OrtApi::GetAvailableProviders() and returns a vector of strings representin...
Ort::Status(*)(Ort::ShapeInferContext &) ShapeInferFn
Definition onnxruntime_cxx_api.h:3339
const OrtModelPackageApi & GetModelPackageApi()
This returns a reference to the stable ORT Model Package API.
Definition onnxruntime_cxx_api.h:257
Status CompileModel(const Env &env, const ModelCompilationOptions &model_compilation_options)
Compiles an input model to generate a model with EPContext nodes that execute EP-specific kernels....
Wrapper around OrtAllocator.
Definition onnxruntime_cxx_api.h:1104
Allocator(const Session &session, const OrtMemoryInfo *)
Take ownership of a pointer created by C API.
Allocator(std::nullptr_t)
Convenience to create a class member and then replace with an instance.
Definition onnxruntime_cxx_api.h:1105
Allocator(OrtAllocator *p)
Definition onnxruntime_cxx_api.h:1109
Wrapper around OrtAllocator default instance that is owned by Onnxruntime.
Definition onnxruntime_cxx_api.h:1095
AllocatorWithDefaultOptions(std::nullptr_t)
Convenience to create a class member and then replace with an instance.
Definition onnxruntime_cxx_api.h:1096
it is a structure that represents the configuration of an arena based allocator
Definition onnxruntime_cxx_api.h:2915
ArenaCfg(std::nullptr_t)
Create an empty ArenaCfg object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:2916
ArenaCfg(const std::unordered_map< std::string, size_t > &arena_config)
ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk)
Definition onnxruntime_cxx_api.h:3693
ConstGraph sub_graph
Definition onnxruntime_cxx_api.h:3695
std::string attr_name
Definition onnxruntime_cxx_api.h:3694
bfloat16 (Brain Floating Point) data type
Definition onnxruntime_cxx_api.h:440
bool operator==(const BFloat16_t &rhs) const noexcept
onnxruntime_float16::BFloat16Impl< BFloat16_t > Base
Definition onnxruntime_cxx_api.h:452
BFloat16_t()=default
static constexpr BFloat16_t FromBits(uint16_t v) noexcept
Explicit conversion to uint16_t representation of bfloat16.
Definition onnxruntime_cxx_api.h:461
bool operator!=(const BFloat16_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:559
BFloat16_t(float v) noexcept
__ctor from float. Float is converted into bfloat16 16-bit representation.
Definition onnxruntime_cxx_api.h:467
float ToFloat() const noexcept
Converts bfloat16 to float.
Definition onnxruntime_cxx_api.h:473
bool operator<(const BFloat16_t &rhs) const noexcept
The CUDAProviderOptions (V2)
Definition onnxruntime_cxx_api.h:900
CUDAProviderOptions()
Wraps OrtApi::CreateCUDAProviderOptions.
CUDAProviderOptions(std::nullptr_t)
Definition onnxruntime_cxx_api.h:901
void UpdateWithValue(const char *key, void *value)
Wrapper around OrtApi::GetCUDAProviderOptionsByName.
std::string GetCUDAProviderOptionsAsString() const
Wrapper around OrtApi::UpdateCUDAProviderOptionsWithValue.
void Update(const std::unordered_map< std::string, std::string > &options)
Wrapper around OrtApi::GetCUDAProviderOptionsAsString.
void * GetOptionByName(const char *name) const
Definition onnxruntime_cxx_api.h:3344
OrtCustomOpInputOutputCharacteristic GetOutputCharacteristic(size_t) const
Definition onnxruntime_cxx_api.h:3419
OrtCustomOpInputOutputCharacteristic GetInputCharacteristic(size_t) const
Definition onnxruntime_cxx_api.h:3415
OrtMemType GetInputMemoryType(size_t) const
Definition onnxruntime_cxx_api.h:3424
std::vector< std::string > GetSessionConfigKeys() const
Definition onnxruntime_cxx_api.h:3455
bool GetVariadicInputHomogeneity() const
Definition onnxruntime_cxx_api.h:3436
int GetVariadicInputMinArity() const
Definition onnxruntime_cxx_api.h:3430
void SetShapeInferFn(...)
Definition onnxruntime_cxx_api.h:3472
CustomOpBase()
Definition onnxruntime_cxx_api.h:3345
bool GetVariadicOutputHomogeneity() const
Definition onnxruntime_cxx_api.h:3448
int GetVariadicOutputMinArity() const
Definition onnxruntime_cxx_api.h:3442
decltype(&C::InferOutputShape) SetShapeInferFn(decltype(&C::InferOutputShape))
Definition onnxruntime_cxx_api.h:3463
const char * GetExecutionProviderType() const
Definition onnxruntime_cxx_api.h:3411
void GetSessionConfigs(std::unordered_map< std::string, std::string > &out, ConstSessionOptions options) const
Class that represents session configuration entries for one or more custom operators.
Definition onnxruntime_cxx_api.h:1611
~CustomOpConfigs()=default
CustomOpConfigs & AddConfig(const char *custom_op_name, const char *config_key, const char *config_value)
Adds a session configuration entry/value for a specific custom operator.
CustomOpConfigs & operator=(CustomOpConfigs &&o)=default
CustomOpConfigs(CustomOpConfigs &&o)=default
CustomOpConfigs()=default
const std::unordered_map< std::string, std::string > & GetFlattenedConfigs() const
Returns a flattened map of custom operator configuration entries and their values.
CustomOpConfigs(const CustomOpConfigs &)=default
CustomOpConfigs & operator=(const CustomOpConfigs &)=default
Custom Op Domain.
Definition onnxruntime_cxx_api.h:1492
CustomOpDomain(std::nullptr_t)
Create an empty CustomOpDomain object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1496
CustomOpDomain(const char *domain)
Wraps OrtApi::CreateCustomOpDomain.
void Add(const OrtCustomOp *op)
Wraps CustomOpDomain_Add.
Wrapper around OrtDeviceEpIncompatibilityDetails.
Definition onnxruntime_cxx_api.h:1171
DeviceEpIncompatibilityDetails(OrtDeviceEpIncompatibilityDetails *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:1173
DeviceEpIncompatibilityDetails(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:1172
The Env (Environment)
Definition onnxruntime_cxx_api.h:1393
std::vector< ConstHardwareDevice > GetHardwareDevices() const
Get the list of available hardware devices.
Env & EnableTelemetryEvents()
Wraps OrtApi::EnableTelemetryEvents.
Env(OrtEnv *p)
C Interop Helper.
Definition onnxruntime_cxx_api.h:1413
Env & CreateAndRegisterAllocatorV2(const std::string &provider_type, const OrtMemoryInfo *mem_info, const std::unordered_map< std::string, std::string > &options, const OrtArenaCfg *arena_cfg)
Wraps OrtApi::CreateAndRegisterAllocatorV2.
Env & UnregisterExecutionProviderLibrary(const char *registration_name)
Wraps OrtApi::UnregisterExecutionProviderLibrary.
Env & SetPerSessionThreadPoolCallbacks(const OrtThreadPoolCallbacksConfig &config)
Wraps OrtApi::SetPerSessionThreadPoolCallbacks Stores work callbacks on the Env for per-session threa...
std::vector< ConstEpDevice > GetEpDevices() const
DeviceEpIncompatibilityDetails GetHardwareDeviceEpIncompatibilityDetails(const char *ep_name, ConstHardwareDevice hw) const
Check for known incompatibility issues between hardware device and a specific execution provider.
Env & UnregisterAllocator(const OrtMemoryInfo *mem_info)
Wraps OrtApi::UnregisterAllocator.
Env(std::nullptr_t)
Create an empty Env object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1394
Status CopyTensor(const OrtValue *src_tensor, OrtValue *dst_tensor, OrtSyncStream *stream) const
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 & RegisterAllocator(OrtAllocator *allocator)
Wraps OrtApi::RegisterAllocator.
UnownedAllocator CreateSharedAllocator(const OrtEpDevice *ep_device, OrtDeviceMemoryType mem_type, OrtAllocatorType allocator_type, const OrtKeyValuePairs *allocator_options)
Wraps OrtApi::CreateSharedAllocator.
size_t GetNumHardwareDevices() const
Get the number of available hardware devices.
Env(OrtLoggingLevel logging_level, const char *logid, OrtLoggingFunction logging_function, void *logger_param)
Wraps OrtApi::CreateEnvWithCustomLogger.
Env(const OrtEnvCreationOptions *options)
Wraps OrtApi::CreateEnvWithOptions.
Env & CreateAndRegisterAllocator(const OrtMemoryInfo *mem_info, const OrtArenaCfg *arena_cfg)
Wraps OrtApi::CreateAndRegisterAllocator.
UnownedAllocator GetSharedAllocator(const OrtMemoryInfo *mem_info)
Wraps OrtApi::GetSharedAllocator.
Env & RegisterExecutionProviderLibrary(const char *registration_name, const std::basic_string< char > &path)
Wraps OrtApi::RegisterExecutionProviderLibrary.
Env & UpdateEnvWithCustomLogLevel(OrtLoggingLevel log_severity_level)
Wraps OrtApi::UpdateEnvWithCustomLogLevel.
Status CopyTensors(const std::vector< Value > &src_tensors, const std::vector< Value > &dst_tensors, OrtSyncStream *stream) const
Wraps OrtApi::CopyTensors.
void ReleaseSharedAllocator(const OrtEpDevice *ep_device, OrtDeviceMemoryType mem_type)
Wraps OrtApi::ReleaseSharedAllocator.
Env & DisableTelemetryEvents()
Wraps OrtApi::DisableTelemetryEvents.
Move-only owner for the EPContext callback configuration used by plugin EPs.
Definition onnxruntime_cxx_api.h:1787
EpContextConfig(const SessionOptions &session_options)
Wraps OrtEpApi::SessionOptionsGetEpContextConfig.
EpContextConfig(ConstSessionOptions session_options)
Wraps OrtEpApi::SessionOptionsGetEpContextConfig.
void GetWriteFunc(OrtWriteNamedBufferFunc &write_func, void *&state) const
Wraps OrtEpApi::EpContextConfigGetEpContextDataWriteFunc.
EpContextConfig(std::nullptr_t) noexcept
Definition onnxruntime_cxx_api.h:1791
void GetReadFunc(OrtReadNamedBufferFunc &read_func, void *&state) const
Wraps OrtEpApi::EpContextConfigGetEpContextDataReadFunc.
Mutable EpDevice that is created by EpApi users.
Definition onnxruntime_cxx_api.h:1208
EpDevice(OrtEpDevice *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:1210
EpDevice(OrtEpFactory &ep_factory, ConstHardwareDevice &hardware_device, ConstKeyValuePairs ep_metadata={}, ConstKeyValuePairs ep_options={})
Wraps OrtEpApi::CreateEpDevice.
EpDevice(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:1209
All C++ methods that can fail will throw an exception of this type.
Definition onnxruntime_cxx_api.h:54
const char * what() const noexcept override
Definition onnxruntime_cxx_api.h:59
Exception(const std::string &string, OrtErrorCode code)
Definition onnxruntime_cxx_api.h:55
OrtErrorCode GetOrtErrorCode() const
Definition onnxruntime_cxx_api.h:58
Exception(std::string &&string, OrtErrorCode code)
Definition onnxruntime_cxx_api.h:56
Wrapper around OrtExternalInitializerInfo.
Definition onnxruntime_cxx_api.h:951
ConstExternalInitializerInfo GetConst() const
Wraps OrtApi::CreateExternalInitializerInfo.
Definition onnxruntime_cxx_api.h:959
ExternalInitializerInfo(const char *filepath, int64_t file_offset, size_t byte_size)
Wrapper around CreateExternalInitializerInfo that does not throw an exception.
ExternalInitializerInfo(std::nullptr_t)
Definition onnxruntime_cxx_api.h:955
ExternalInitializerInfo(OrtExternalInitializerInfo *p)
Definition onnxruntime_cxx_api.h:956
static Status Create(const char *filepath, int64_t file_offset, size_t byte_size, ExternalInitializerInfo &out)
IEEE 754 half-precision floating point data type.
Definition onnxruntime_cxx_api.h:298
Float16_t()=default
Default constructor.
Float16_t(float v) noexcept
__ctor from float. Float is converted into float16 16-bit representation.
Definition onnxruntime_cxx_api.h:326
onnxruntime_float16::Float16Impl< Float16_t > Base
Definition onnxruntime_cxx_api.h:308
float ToFloat() const noexcept
Converts float16 to float.
Definition onnxruntime_cxx_api.h:332
static constexpr Float16_t FromBits(uint16_t v) noexcept
Explicit conversion to uint16_t representation of float16.
Definition onnxruntime_cxx_api.h:320
float8e4m3fn (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:570
uint8_t value
Definition onnxruntime_cxx_api.h:571
constexpr Float8E4M3FN_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:573
constexpr bool operator==(const Float8E4M3FN_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:576
constexpr Float8E4M3FN_t() noexcept
Definition onnxruntime_cxx_api.h:572
constexpr bool operator!=(const Float8E4M3FN_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:577
float8e4m3fnuz (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:587
constexpr bool operator==(const Float8E4M3FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:593
uint8_t value
Definition onnxruntime_cxx_api.h:588
constexpr Float8E4M3FNUZ_t() noexcept
Definition onnxruntime_cxx_api.h:589
constexpr bool operator!=(const Float8E4M3FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:594
constexpr Float8E4M3FNUZ_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:590
float8e5m2 (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:604
constexpr Float8E5M2_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:607
uint8_t value
Definition onnxruntime_cxx_api.h:605
constexpr bool operator!=(const Float8E5M2_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:611
constexpr Float8E5M2_t() noexcept
Definition onnxruntime_cxx_api.h:606
constexpr bool operator==(const Float8E5M2_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:610
float8e5m2fnuz (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:621
constexpr Float8E5M2FNUZ_t() noexcept
Definition onnxruntime_cxx_api.h:623
constexpr Float8E5M2FNUZ_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:624
constexpr bool operator!=(const Float8E5M2FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:628
constexpr bool operator==(const Float8E5M2FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:627
uint8_t value
Definition onnxruntime_cxx_api.h:622
Wrapper around OrtGraph.
Definition onnxruntime_cxx_api.h:3701
Graph(OrtGraph *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:3703
Graph(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:3702
Wrapper around OrtIoBinding.
Definition onnxruntime_cxx_api.h:2904
UnownedIoBinding GetUnowned() const
Definition onnxruntime_cxx_api.h:2908
ConstIoBinding GetConst() const
Definition onnxruntime_cxx_api.h:2907
IoBinding(Session &session)
IoBinding(std::nullptr_t)
Create an empty object for convenience. Sometimes, we want to initialize members later.
Definition onnxruntime_cxx_api.h:2905
This class wraps a raw pointer OrtKernelContext* that is being passed to the custom kernel Compute() ...
Definition onnxruntime_cxx_api.h:3138
KernelContext(OrtKernelContext *context)
OrtSyncStream * GetSyncStream() const
Logger GetLogger() const
ConstValue GetInput(size_t index) const
OrtKernelContext * GetOrtKernelContext() const
Definition onnxruntime_cxx_api.h:3154
void ParallelFor(void(*fn)(void *, size_t), size_t total, size_t num_batch, void *usr_data) const
UnownedValue GetPreallocatedOutput(size_t index) const
void * GetGPUComputeStream() const
size_t GetInputCount() const
Ort::Allocator GetAllocator(const OrtMemoryInfo &memory_info) const
size_t GetOutputCount() const
UnownedValue GetOutput(size_t index, const std::vector< int64_t > &dims) const
UnownedValue GetOutput(size_t index, const int64_t *dim_values, size_t dim_count) const
Builder for OrtKernelDef.
Definition onnxruntime_cxx_api.h:3785
KernelDefBuilder & AddTypeConstraint(const char *arg_name, const OrtDataType *data_type)
KernelDefBuilder & SetOutputMemType(size_t output_index, OrtMemType mem_type)
KernelDefBuilder & AddInputOutputMutableAliases(const std::vector< int > &input_indices, const std::vector< int > &output_indices)
KernelDefBuilder & SetInputMemType(size_t input_index, OrtMemType mem_type)
KernelDefBuilder & SetDomain(const char *domain)
KernelDefBuilder & AddInputOutputAliases(const std::vector< int > &input_indices, const std::vector< int > &output_indices)
KernelDefBuilder & AddInputOutputAlias(int input_index, int output_index)
KernelDefBuilder & SetExecutionProvider(const char *ep_name)
KernelDefBuilder & SetOperatorType(const char *op_type)
KernelDefBuilder & AddInputOutputMutableAlias(int input_index, int output_index)
KernelDefBuilder()
Wraps OrtEpApi::CreateKernelDefBuilder.
KernelDefBuilder & AddTypeConstraint(const char *arg_name, const std::vector< const OrtDataType * > &data_types)
KernelDefBuilder(std::nullptr_t)
Create an empty object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:3787
KernelDefBuilder(OrtKernelDefBuilder *ort_kernel_def_builder)
KernelDefBuilder & SetSinceVersion(int since_version_start, int since_version_end)
Definition onnxruntime_cxx_api.h:3771
KernelDef(OrtKernelDef *p)
Definition onnxruntime_cxx_api.h:3776
KernelDef(std::nullptr_t)
Definition onnxruntime_cxx_api.h:3775
ConstKernelDef GetConst() const
Definition onnxruntime_cxx_api.h:3778
This struct owns the OrtKernInfo* pointer when a copy is made. For convenient wrapping of OrtKernelIn...
Definition onnxruntime_cxx_api.h:3228
KernelInfo(OrtKernelInfo *info)
Take ownership of the instance.
ConstKernelInfo GetConst() const
Definition onnxruntime_cxx_api.h:3233
detail::KernelInfoImpl< OrtKernelInfo > Base
Definition onnxruntime_cxx_api.h:3229
KernelInfo(std::nullptr_t)
Create an empty instance to initialize later.
Definition onnxruntime_cxx_api.h:3231
Registry for kernels supported by an EP.
Definition onnxruntime_cxx_api.h:3812
KernelRegistry()
< Wrapper around OrtEpApi::CreateKernelRegistry
KernelRegistry(std::nullptr_t)
Take ownership of a pointer created with the C API.
Definition onnxruntime_cxx_api.h:3817
Status AddKernel(const OrtKernelDef *kernel_def, OrtKernelCreateFunc kernel_create_func, void *kernel_create_func_state)
KernelRegistry(OrtKernelRegistry *ort_kernel_registry)
Wraps KernelRegistry_AddKernel.
Wrapper around OrtKeyValuePairs.
Definition onnxruntime_cxx_api.h:988
KeyValuePairs()
Wraps OrtApi::CreateKeyValuePairs.
void Add(const char *key, const char *value)
Wraps OrtApi::AddKeyValuePair.
KeyValuePairs(const std::unordered_map< std::string, std::string > &kv_pairs)
Wraps OrtApi::CreateKeyValuePairs and OrtApi::AddKeyValuePair.
void Remove(const char *key)
Wraps OrtApi::RemoveKeyValuePair.
KeyValuePairs(std::nullptr_t)
Definition onnxruntime_cxx_api.h:989
ConstKeyValuePairs GetConst() const
Definition onnxruntime_cxx_api.h:1005
KeyValuePairs(OrtKeyValuePairs *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:991
This class represents an ONNX Runtime logger that can be used to log information with an associated s...
Definition onnxruntime_cxx_api.h:3060
Logger(Logger &&v) noexcept=default
Logger & operator=(Logger &&v) noexcept=default
Logger & operator=(const Logger &)=default
~Logger()=default
Logger(const Logger &)=default
Logger()=default
Logger(std::nullptr_t)
Definition onnxruntime_cxx_api.h:3069
Logger(const OrtLogger *logger)
OrtLoggingLevel GetLoggingSeverityLevel() const noexcept
LoraAdapter holds a set of Lora Parameters loaded from a single file.
Definition onnxruntime_cxx_api.h:1506
static LoraAdapter CreateLoraAdapter(const std::basic_string< char > &adapter_path, OrtAllocator *allocator)
Wraps OrtApi::CreateLoraAdapter.
LoraAdapter(std::nullptr_t)
Definition onnxruntime_cxx_api.h:1510
static LoraAdapter CreateLoraAdapterFromArray(const void *bytes, size_t num_bytes, OrtAllocator *allocator)
Wraps OrtApi::CreateLoraAdapterFromArray.
Wrapper around OrtMapTypeInfo.
Definition onnxruntime_cxx_api.h:2286
ConstMapTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:2292
MapTypeInfo(OrtMapTypeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:2291
MapTypeInfo(std::nullptr_t)
Create an empty MapTypeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:2290
Represents native memory allocation coming from one of the OrtAllocators registered with OnnxRuntime....
Definition onnxruntime_cxx_api.h:1049
MemoryAllocation(MemoryAllocation &&) noexcept
MemoryAllocation & operator=(const MemoryAllocation &)=delete
MemoryAllocation(const MemoryAllocation &)=delete
MemoryAllocation(OrtAllocator *allocator, void *p, size_t size)
size_t size() const
Definition onnxruntime_cxx_api.h:1058
Wrapper around OrtMemoryInfo.
Definition onnxruntime_cxx_api.h:1033
MemoryInfo(const char *name, OrtAllocatorType type, int id, OrtMemType mem_type)
MemoryInfo(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:1035
MemoryInfo(OrtMemoryInfo *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:1036
static MemoryInfo CreateCpu(OrtAllocatorType type, OrtMemType mem_type1)
ConstMemoryInfo GetConst() const
Definition onnxruntime_cxx_api.h:1040
MemoryInfo(const char *name, OrtMemoryInfoDeviceType device_type, uint32_t vendor_id, uint32_t device_id, OrtDeviceMemoryType mem_type, size_t alignment, OrtAllocatorType allocator_type)
Wrapper around CreateMemoryInfo_V2.
Options object used when compiling a model.
Definition onnxruntime_cxx_api.h:1804
ModelCompilationOptions & SetOutputModelWriteFunc(OrtWriteBufferFunc write_func, void *state)
ModelCompilationOptions & SetEpContextEmbedMode(bool embed_ep_context_in_model)
Wraps OrtApi::ModelCompilationOptions_SetEpContextEmbedMode.
ModelCompilationOptions & SetInputModelFromBuffer(const void *input_model_data, size_t input_model_data_size)
Wraps OrtApi::ModelCompilationOptions_SetInputModelFromBuffer.
ModelCompilationOptions & SetOutputModelBuffer(OrtAllocator *allocator, void **output_model_buffer_ptr, size_t *output_model_buffer_size_ptr)
Wraps OrtApi::ModelCompilationOptions_SetOutputModelBuffer.
ModelCompilationOptions & SetFlags(uint32_t flags)
Wraps OrtApi::ModelCompilationOptions_SetFlags.
ModelCompilationOptions & SetOutputModelExternalInitializersFile(const char *file_path, size_t initializer_size_threshold)
Wraps OrtApi::ModelCompilationOptions_SetOutputModelExternalInitializersFile.
ModelCompilationOptions(std::nullptr_t)
Create an empty ModelCompilationOptions object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1808
ModelCompilationOptions & SetEpContextDataWriteFunc(OrtWriteNamedBufferFunc write_func, void *state=nullptr)
Register or clear the external EPContext write callback. Wraps OrtCompileApi::ModelCompilationOptions...
ModelCompilationOptions(const Env &env, ConstSessionOptions session_options)
Wraps OrtApi::CreateModelCompilationOptionsFromSessionOptions.
ModelCompilationOptions & SetOutputModelPath(const char *output_model_path)
Wraps OrtApi::ModelCompilationOptions_SetOutputModelPath.
ModelCompilationOptions & SetOutputModelExternalInitializersBuffer(const char *logical_file_name, size_t initializer_size_threshold, OrtAllocator *allocator, void **output_buffer_ptr, size_t *output_buffer_size_ptr)
ModelCompilationOptions & SetInputModelPath(const char *input_model_path)
Wraps OrtApi::ModelCompilationOptions_SetInputModelPath.
ModelCompilationOptions & SetOutputModelGetInitializerLocationFunc(OrtGetInitializerLocationFunc get_initializer_location_func, void *state)
ModelCompilationOptions & SetEpContextBinaryInformation(const char *output_directory, const char *model_name)
Wraps OrtApi::ModelCompilationOptions_SetEpContextBinaryInformation.
ModelCompilationOptions & SetOutputModelExternalInitializersAlignment(size_t alignment, size_t minimum_size)
Wraps OrtApi::ModelCompilationOptions_SetOutputModelGetInitializerLocationFunc.
ModelCompilationOptions & SetWeightlessMode(OrtWeightlessSupport weightless_mode)
Wraps OrtCompileApi::ModelCompilationOptions_SetWeightlessMode.
ModelCompilationOptions & SetGraphOptimizationLevel(GraphOptimizationLevel graph_optimization_level)
Wraps OrtApi::ModelCompilationOptions_SetGraphOptimizationLevel.
ModelCompilationOptions(const Env &env, const SessionOptions &session_options)
Wraps OrtApi::CreateModelCompilationOptionsFromSessionOptions.
ModelCompilationOptions & SetInputModel(const OrtModel *model)
ModelCompilationOptions & SetWeightlessEnabled(bool use_weightless)
Wraps OrtCompileApi::ModelCompilationOptions_SetWeightlessEnabled.
Wrapper around OrtModel.
Definition onnxruntime_cxx_api.h:3731
Model(const std::vector< DomainOpsetPair > &opsets)
Model(OrtModel *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:3735
std::pair< std::string, int > DomainOpsetPair
Definition onnxruntime_cxx_api.h:3732
Model(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:3734
Wrapper around OrtModelMetadata.
Definition onnxruntime_cxx_api.h:1910
AllocatedStringPtr GetDescriptionAllocated(OrtAllocator *allocator) const
Returns a copy of the description.
std::vector< AllocatedStringPtr > GetCustomMetadataMapKeysAllocated(OrtAllocator *allocator) const
Returns a vector of copies of the custom metadata keys.
ModelMetadata(std::nullptr_t)
Create an empty ModelMetadata object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1914
AllocatedStringPtr GetGraphDescriptionAllocated(OrtAllocator *allocator) const
Returns a copy of the graph description.
AllocatedStringPtr GetProducerNameAllocated(OrtAllocator *allocator) const
Returns a copy of the producer name.
AllocatedStringPtr GetGraphNameAllocated(OrtAllocator *allocator) const
Returns a copy of the graph name.
AllocatedStringPtr LookupCustomMetadataMapAllocated(const char *key, OrtAllocator *allocator) const
Looks up a value by a key in the Custom Metadata map.
AllocatedStringPtr GetDomainAllocated(OrtAllocator *allocator) const
Returns a copy of the domain name.
int64_t GetVersion() const
Wraps OrtApi::ModelMetadataGetVersion.
Context for a selected model package component and variant.
Definition onnxruntime_cxx_api.h:1894
Session CreateSession(const Env &env, ConstSessionOptions session_options)
Session CreateSession(const Env &env, const SessionOptions &session_options)
ModelPackageComponentContext(std::nullptr_t)
Definition onnxruntime_cxx_api.h:1898
Session CreateSession(const Env &env)
std::string GetSelectedVariantName() const
std::basic_string< char > GetSelectedVariantFolderPath() const
Context used to inspect a model package and select one of its components.
Definition onnxruntime_cxx_api.h:1875
ModelPackageContext(const char *package_root)
std::vector< std::string > GetComponentNames() const
int64_t GetSchemaVersion() const
const char * GetVariantEpName(const char *component_name, const char *variant_name) const
std::string ResolveStringRef(const char *base_dir, const char *input, bool must_exist) const
size_t GetVariantCount(const char *component_name) const
size_t GetComponentCount() const
std::vector< std::string > GetVariantNames(const char *component_name) const
ModelPackageContext(std::nullptr_t)
Definition onnxruntime_cxx_api.h:1879
ModelPackageComponentContext SelectComponent(const char *component_name, const ModelPackageOptions &options) const
Options used to select a component variant from a model package.
Definition onnxruntime_cxx_api.h:1865
ModelPackageOptions(const Env &env, ConstSessionOptions session_options)
ModelPackageOptions(std::nullptr_t)
Definition onnxruntime_cxx_api.h:1869
ModelPackageOptions(const Env &env, const SessionOptions &session_options)
Wrapper around OrtNode.
Definition onnxruntime_cxx_api.h:3588
Node(const std::string &operator_name, const std::string &operator_domain, const std::string &node_name, const std::vector< std::string > &input_names, const std::vector< std::string > &output_names)
Node()=default
Node(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:3590
Node(const std::string &operator_name, const std::string &operator_domain, const std::string &node_name, const std::vector< std::string > &input_names, const std::vector< std::string > &output_names, std::vector< OpAttr > &attributes)
Wraps CreateNode. Node takes ownership of attributes on success and updates the OpAttr in attributes ...
Node(OrtNode *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:3591
This struct provides life time management for custom op attribute.
Definition onnxruntime_cxx_api.h:2969
OpAttr(const char *name, const void *data, int len, OrtOpAttrType type)
OpAttr()=default
OpAttr(std::nullptr_t)
Definition onnxruntime_cxx_api.h:2974
ConstOpAttr GetConst() const
Definition onnxruntime_cxx_api.h:2977
Create and own custom defined operation.
Definition onnxruntime_cxx_api.h:3239
Op(OrtOp *)
Take ownership of the OrtOp.
static Op Create(const OrtKernelInfo *info, const char *op_name, const char *domain, int version, const char **type_constraint_names, const ONNXTensorElementDataType *type_constraint_values, size_t type_constraint_count, const OpAttr *attr_values, size_t attr_count, size_t input_count, size_t output_count)
Op(std::nullptr_t)
Create an empty Operator object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:3243
void Invoke(const OrtKernelContext *context, const OrtValue *const *input_values, size_t input_count, OrtValue *const *output_values, size_t output_count)
void Invoke(const OrtKernelContext *context, const Value *input_values, size_t input_count, Value *output_values, size_t output_count)
Definition onnxruntime_cxx_api.h:3628
std::string domain
Definition onnxruntime_cxx_api.h:3629
int64_t version
Definition onnxruntime_cxx_api.h:3630
The PrepackedWeightsContainer.
Definition onnxruntime_cxx_api.h:919
PrepackedWeightsContainer()
Wraps OrtApi::CreatePrepackedWeightsContainer.
PrepackedWeightsContainer(OrtPrepackedWeightsContainer *p)
Definition onnxruntime_cxx_api.h:924
PrepackedWeightsContainer(std::nullptr_t)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:922
Owning wrapper around OrtProfilingEvent.
Definition onnxruntime_cxx_api.h:1340
ProfilingEvent(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:1341
ConstProfilingEvent GetConst() const
Definition onnxruntime_cxx_api.h:1365
ProfilingEvent(OrtProfilingEventCategory category, int32_t process_id, int32_t thread_id, const char *event_name, int64_t timestamp_us, int64_t duration_us, const std::unordered_map< std::string, std::string > &args={})
Wraps OrtEpApi::CreateProfilingEvent.
ProfilingEvent(OrtProfilingEvent *p)
Take ownership.
Definition onnxruntime_cxx_api.h:1342
ProfilingEvent(OrtProfilingEventCategory category, int32_t process_id, int32_t thread_id, const char *event_name, int64_t timestamp_us, int64_t duration_us, const char *const *arg_keys, const char *const *arg_values, size_t num_args)
Wraps OrtEpApi::CreateProfilingEvent.
RunOptions.
Definition onnxruntime_cxx_api.h:1536
int GetRunLogSeverityLevel() const
Wraps OrtApi::RunOptionsGetRunLogSeverityLevel.
RunOptions & SetTerminate()
Terminates all currently executing Session::Run calls that were made using this RunOptions instance.
RunOptions & DisableProfiling()
Disable profiling for this run.
RunOptions & SetSyncStream(OrtSyncStream *stream)
Associate a sync stream with the run options.
RunOptions & SetRunTag(const char *run_tag)
wraps OrtApi::RunOptionsSetRunTag
RunOptions & AddActiveLoraAdapter(const LoraAdapter &adapter)
Add the LoraAdapter to the list of active adapters. The setting does not affect RunWithBinding() call...
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:1537
RunOptions & SetRunLogVerbosityLevel(int)
Wraps OrtApi::RunOptionsSetRunLogVerbosityLevel.
RunOptions & SetRunLogSeverityLevel(int)
Wraps OrtApi::RunOptionsSetRunLogSeverityLevel.
RunOptions & EnableProfiling(const char *profile_file_prefix)
Enable profiling for this run.
RunOptions & AddConfigEntry(const char *config_key, const char *config_value)
Wraps OrtApi::AddRunConfigEntry.
const char * GetRunTag() const
Wraps OrtApi::RunOptionsGetRunTag.
RunOptions()
Wraps OrtApi::CreateRunOptions.
const char * GetConfigEntry(const char *config_key)
Wraps OrtApi::GetRunConfigEntry.
Wrapper around OrtSequenceTypeInfo.
Definition onnxruntime_cxx_api.h:2248
SequenceTypeInfo(std::nullptr_t)
Create an empty SequenceTypeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:2252
ConstSequenceTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:2254
SequenceTypeInfo(OrtSequenceTypeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:2253
Wrapper around OrtSession.
Definition onnxruntime_cxx_api.h:2144
Session(std::nullptr_t)
Create an empty Session object, must be assigned a valid one to be used. Wraps OrtApi::CreateSession.
Definition onnxruntime_cxx_api.h:2146
static Session CreateModelEditorSession(const Env &env, const void *model_data, size_t model_data_length, const SessionOptions &options)
Wraps OrtModelEditorApi::CreateModelEditorSession.
UnownedSession GetUnowned() const
Definition onnxruntime_cxx_api.h:2175
Session(const Env &env, const char *model_path, const SessionOptions &options, OrtPrepackedWeightsContainer *prepacked_weights_container)
Wraps OrtApi::CreateSessionWithPrepackedWeightsContainer.
Session(const Env &env, const void *model_data, size_t model_data_length, const SessionOptions &options, OrtPrepackedWeightsContainer *prepacked_weights_container)
Wraps OrtApi::CreateSessionFromArrayWithPrepackedWeightsContainer.
Session(const Env &env, const Model &model, const SessionOptions &options)
Wraps OrtModelEditorApi::CreateSessionFromModel.
Session(OrtSession *p)
C API Interop.
Definition onnxruntime_cxx_api.h:2147
static Session CreateModelEditorSession(const Env &env, const char *model_path, const SessionOptions &options)
Wraps OrtModelEditorApi::CreateModelEditorSession.
Session(const Env &env, const char *model_path, const SessionOptions &options)
ConstSession GetConst() const
Definition onnxruntime_cxx_api.h:2174
Session(const Env &env, const void *model_data, size_t model_data_length, const SessionOptions &options)
Wraps OrtApi::CreateSessionFromArray.
Wrapper around OrtSessionOptions.
Definition onnxruntime_cxx_api.h:1774
SessionOptions(std::nullptr_t)
Create an empty SessionOptions object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1775
UnownedSessionOptions GetUnowned() const
Definition onnxruntime_cxx_api.h:1778
SessionOptions()
Wraps OrtApi::CreateSessionOptions.
ConstSessionOptions GetConst() const
Definition onnxruntime_cxx_api.h:1779
SessionOptions(OrtSessionOptions *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1777
Definition onnxruntime_cxx_api.h:3273
SymbolicInteger & operator=(const SymbolicInteger &)=default
SymbolicInteger(const SymbolicInteger &)=default
int64_t AsInt() const
Definition onnxruntime_cxx_api.h:3294
int64_t i_
Definition onnxruntime_cxx_api.h:3301
const char * s_
Definition onnxruntime_cxx_api.h:3302
bool operator==(const SymbolicInteger &dim) const
Definition onnxruntime_cxx_api.h:3282
SymbolicInteger & operator=(SymbolicInteger &&)=default
SymbolicInteger(SymbolicInteger &&)=default
const char * AsSym() const
Definition onnxruntime_cxx_api.h:3295
SymbolicInteger(int64_t i)
Definition onnxruntime_cxx_api.h:3274
SymbolicInteger(const char *s)
Definition onnxruntime_cxx_api.h:3275
bool IsInt() const
Definition onnxruntime_cxx_api.h:3293
Provide access to per-node attributes and input shapes, so one could compute and set output shapes.
Definition onnxruntime_cxx_api.h:3272
Ints GetAttrInts(const char *attr_name)
Strings GetAttrStrings(const char *attr_name)
Status SetOutputShape(size_t indice, const Shape &shape, ONNXTensorElementDataType type=ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT)
std::vector< SymbolicInteger > Shape
Definition onnxruntime_cxx_api.h:3307
std::vector< float > Floats
Definition onnxruntime_cxx_api.h:3324
std::string GetAttrString(const char *attr_name)
std::vector< int64_t > Ints
Definition onnxruntime_cxx_api.h:3319
ShapeInferContext(const OrtApi *ort_api, OrtShapeInferContext *ctx)
int64_t GetAttrInt(const char *attr_name)
size_t GetInputCount() const
Definition onnxruntime_cxx_api.h:3313
std::vector< std::string > Strings
Definition onnxruntime_cxx_api.h:3329
Floats GetAttrFloats(const char *attr_name)
const Shape & GetInputShape(size_t indice) const
Definition onnxruntime_cxx_api.h:3311
float GetAttrFloat(const char *attr_name)
The Status that holds ownership of OrtStatus received from C API Use it to safely destroy OrtStatus* ...
Definition onnxruntime_cxx_api.h:835
OrtErrorCode GetErrorCode() const
Status(const Exception &)
Creates status instance out of exception.
bool IsOK() const noexcept
Returns true if instance represents an OK (non-error) status.
Status(OrtStatus *status) noexcept
Takes ownership of OrtStatus instance returned from the C API.
std::string GetErrorMessage() const
Status()=default
Status(const std::exception &)
Creates status instance out of exception.
Status(const char *message, OrtErrorCode code)
Creates status instance out of null-terminated string message.
Status(std::nullptr_t) noexcept
Create an empty object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:837
Definition onnxruntime_cxx_api.h:1128
SyncStream(OrtSyncStream *p)
Definition onnxruntime_cxx_api.h:1132
SyncStream(std::nullptr_t)
< Create an empty SyncStream object, must be assigned a valid one to be used
Definition onnxruntime_cxx_api.h:1130
The TensorRTOptions (V2)
Definition onnxruntime_cxx_api.h:881
void Update(const std::unordered_map< std::string, std::string > &options)
Wrapper around OrtApi::UpdateTensorRTProviderOptions.
void UpdateWithValue(const char *key, void *value)
Wrapper around OrtApi::GetTensorRTProviderOptionsByName.
std::string GetTensorRTProviderOptionsAsString() const
void * GetOptionByName(const char *name) const
Wrapper around OrtApi::GetTensorRTProviderOptionsAsString.
TensorRTProviderOptions(std::nullptr_t)
Definition onnxruntime_cxx_api.h:882
TensorRTProviderOptions()
Wraps OrtApi::CreateTensorRTProviderOptionsV2.
Wrapper around OrtTensorTypeAndShapeInfo.
Definition onnxruntime_cxx_api.h:2214
TensorTypeAndShapeInfo(std::nullptr_t)
Create an empty TensorTypeAndShapeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:2219
ConstTensorTypeAndShapeInfo GetConst() const
Definition onnxruntime_cxx_api.h:2230
TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:2221
TensorTypeAndShapeInfo(ONNXTensorElementDataType element_type, const std::vector< int64_t > &dims, const std::vector< std::string > *symbolic_dims=nullptr)
The ThreadingOptions.
Definition onnxruntime_cxx_api.h:851
ThreadingOptions & SetGlobalCustomThreadCreationOptions(void *ort_custom_thread_creation_options)
Wraps OrtApi::SetGlobalCustomThreadCreationOptions.
ThreadingOptions()
Wraps OrtApi::CreateThreadingOptions.
ThreadingOptions & SetGlobalInterOpNumThreads(int inter_op_num_threads)
Wraps OrtApi::SetGlobalInterOpNumThreads.
ThreadingOptions & SetGlobalCustomCreateThreadFn(OrtCustomCreateThreadFn ort_custom_create_thread_fn)
Wraps OrtApi::SetGlobalCustomCreateThreadFn.
ThreadingOptions & SetGlobalCustomJoinThreadFn(OrtCustomJoinThreadFn ort_custom_join_thread_fn)
Wraps OrtApi::SetGlobalCustomJoinThreadFn.
ThreadingOptions & SetGlobalSpinControl(int allow_spinning)
Wraps OrtApi::SetGlobalSpinControl.
ThreadingOptions & SetGlobalDenormalAsZero()
Wraps OrtApi::SetGlobalDenormalAsZero.
ThreadingOptions & SetGlobalIntraOpNumThreads(int intra_op_num_threads)
Wraps OrtApi::SetGlobalIntraOpNumThreads.
Type information that may contain either TensorTypeAndShapeInfo or the information about contained se...
Definition onnxruntime_cxx_api.h:2320
static TypeInfo CreateOptionalTypeInfo(ConstTypeInfo contained_type)
static TypeInfo CreateSequenceTypeInfo(ConstTypeInfo sequence_type)
static TypeInfo CreateTensorInfo(ConstTensorTypeAndShapeInfo tensor_info)
static TypeInfo CreateSparseTensorInfo(ConstTensorTypeAndShapeInfo sparse_tensor_info)
TypeInfo(std::nullptr_t)
Create an empty TypeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:2325
static TypeInfo CreateMapTypeInfo(ONNXTensorElementDataType key_type, ConstTypeInfo value_type)
ConstTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:2336
TypeInfo(OrtTypeInfo *p)
C API Interop.
Definition onnxruntime_cxx_api.h:2326
Wrapper around OrtValue.
Definition onnxruntime_cxx_api.h:2693
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...
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....
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:2699
static Value CreateTensor(const OrtMemoryInfo *info, T *p_data, size_t p_data_element_count, const int64_t *shape, size_t shape_len)
Creates a tensor with a user supplied buffer. Wraps OrtApi::CreateTensorWithDataAsOrtValue.
static Value CreateSparseTensor(OrtAllocator *allocator, const Shape &dense_shape)
This is a simple forwarding method to the below CreateSparseTensor. This helps to specify data type e...
static Value CreateTensor(OrtAllocator *allocator, const int64_t *shape, size_t shape_len, ONNXTensorElementDataType type)
Creates an OrtValue with a tensor using the supplied OrtAllocator. Wraps OrtApi::CreateTensorAsOrtVal...
UnownedValue GetUnowned() const
Definition onnxruntime_cxx_api.h:2704
static Value CreateSequence(const std::vector< Value > &values)
Creates an OrtValue with a Sequence Onnx type representation. The API would ref-count the supplied Or...
static Value CreateMap(const Value &keys, const Value &values)
Creates an OrtValue with a Map Onnx type representation. The API would ref-count the supplied OrtValu...
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)
Creates a tensor with a user supplied buffer. Wraps OrtApi::CreateTensorWithDataAsOrtValue.
static Value CreateTensor(OrtAllocator *allocator, const int64_t *shape, size_t shape_len)
Creates an OrtValue with a tensor using a supplied OrtAllocator. Wraps OrtApi::CreateTensorAsOrtValue...
static Value CreateOpaque(const char *domain, const char *type_name, const T &value)
Creates an OrtValue wrapping an Opaque type. This is used for experimental support of non-tensor type...
static Value CreateTensor(OrtAllocator *deleter, void *p_data, size_t p_data_byte_count, const int64_t *shape, size_t shape_len, ONNXTensorElementDataType type)
Creates a tensor with a user supplied buffer. Wraps OrtApi::CreateTensorWithDataAndDeleterAsOrtValue.
ConstValue GetConst() const
Definition onnxruntime_cxx_api.h:2703
Definition onnxruntime_cxx_api.h:3620
int64_t index
Definition onnxruntime_cxx_api.h:3624
ConstNode node
Definition onnxruntime_cxx_api.h:3621
Wrapper around OrtValueInfo.
Definition onnxruntime_cxx_api.h:3525
ConstValueInfo GetConst() const
Definition onnxruntime_cxx_api.h:3535
ValueInfo(std::nullptr_t)
Definition onnxruntime_cxx_api.h:3527
ValueInfo(const std::string &name, const ConstTypeInfo &type_info)
ValueInfo(OrtValueInfo *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:3529
ValueInfo()=default
Definition onnxruntime_cxx_api.h:793
AllocatedFree(OrtAllocator *allocator)
Definition onnxruntime_cxx_api.h:795
OrtAllocator * allocator_
Definition onnxruntime_cxx_api.h:794
void operator()(void *ptr) const
Definition onnxruntime_cxx_api.h:797
Base & operator=(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:779
constexpr contained_type & operator*() const noexcept
Definition onnxruntime_cxx_api.h:786
typename Unowned< T >::Type contained_type
Definition onnxruntime_cxx_api.h:768
Base(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:778
Base(const Base &)=default
constexpr Base(contained_type *p) noexcept
Definition onnxruntime_cxx_api.h:771
Base & operator=(const Base &)=default
Used internally by the C++ API. C++ wrapper types inherit from this. This is a zero cost abstraction ...
Definition onnxruntime_cxx_api.h:721
Base(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:733
constexpr Base()=default
constexpr contained_type & operator*() const noexcept
Definition onnxruntime_cxx_api.h:741
contained_type * release()
Relinquishes ownership of the contained C object pointer The underlying object is not destroyed.
Definition onnxruntime_cxx_api.h:745
Base(const Base &)=delete
constexpr Base(contained_type *p) noexcept
Definition onnxruntime_cxx_api.h:725
Base & operator=(const Base &)=delete
Base & operator=(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:734
contained_type * p_
Definition onnxruntime_cxx_api.h:752
~Base()
Definition onnxruntime_cxx_api.h:726
T contained_type
Definition onnxruntime_cxx_api.h:722
Definition onnxruntime_cxx_api.h:931
const std::basic_string< char > GetFilePath() const
Definition onnxruntime_cxx_api.h:3635
std::vector< ConstNode > GetNodes() const
std::vector< ConstValueInfo > GetInputs() const
ConstNode GetParentNode() const
int64_t GetOnnxIRVersion() const
std::basic_string< char > GetModelPath() const
Graph GetGraphView(const std::vector< ConstNode > &nodes) const
ModelMetadata GetModelMetadata() const
Wraps OrtApi::Graph_GetModelMetadata.
std::vector< ConstValueInfo > GetInitializers() const
std::string GetName() const
std::vector< ConstValueInfo > GetOutputs() const
std::vector< OperatorSet > GetOperatorSets() const
Definition onnxruntime_cxx_api.h:2872
std::vector< Value > GetOutputValues(OrtAllocator *) const
std::vector< std::string > GetOutputNames(OrtAllocator *) const
std::vector< Value > GetOutputValues() const
std::vector< std::string > GetOutputNames() const
Definition onnxruntime_cxx_api.h:3745
std::pair< int, int > GetSinceVersion() const
Wraps OrtEpApi::KernelDef_GetExecutionProvider.
const char * GetDomain() const
Wraps OrtEpApi::KernelDef_GetSinceVersion.
OrtMemType GetOutputMemType(size_t output_index) const
const char * GetExecutionProvider() const
Wraps OrtEpApi::KernelDef_GetInputMemType.
OrtMemType GetInputMemType(size_t input_index) const
Wraps OrtEpApi::KernelDef_GetOutputMemType.
const char * GetOperatorType() const
< Wraps OrtEpApi::KernelDef_GetOperatorType
Definition onnxruntime_cxx_api.h:3547
std::vector< ConstValueInfo > GetOutputs() const
std::vector< ConstValueInfo > GetImplicitInputs() const
std::string GetName() const
std::string GetDomain() const
std::vector< AttrNameSubgraph > GetSubgraphs() const
ConstGraphImpl< detail::Unowned< const OrtGraph > > GetGraph() const
std::string GetOperatorType() const
std::vector< ConstOpAttr > GetAttributes() const
std::vector< ConstValueInfo > GetInputs() const
Status GetAttributeByName(const std::string &name, ConstOpAttr &attr) const
std::string GetEpName() const
Definition onnxruntime_cxx_api.h:2941
std::string GetName() const
Status GetValue(R &out) const
Status GetTensorAttributeAsOrtValue(Value &) const
Status GetValueArray(std::vector< R > &out) const
OrtOpAttrType GetType() const
Definition onnxruntime_cxx_api.h:1301
int64_t GetTimestampUs() const
Get the start timestamp in microseconds. Wraps OrtEpApi::ProfilingEvent_GetTimestampUs.
const char * GetName() const
Get the event name. Wraps OrtEpApi::ProfilingEvent_GetName.
const char * GetArgValue(const char *key) const
Get the value of an event argument by key. Wraps OrtEpApi::ProfilingEvent_GetArgValue.
int64_t GetDurationUs() const
Get the duration in microseconds. Wraps OrtEpApi::ProfilingEvent_GetDurationUs.
OrtProfilingEventCategory GetCategory() const
Get the event category. Wraps OrtEpApi::ProfilingEvent_GetCategory.
Definition onnxruntime_cxx_api.h:1985
std::vector< std::string > GetOutputNames() const
TypeInfo GetInputTypeInfo(size_t index) const
Wraps OrtApi::SessionGetInputTypeInfo.
std::vector< ConstEpAssignedSubgraph > GetEpGraphAssignmentInfo() const
Returns information on the subgraph/nodes assigned to execution providers in the session.
size_t GetOutputCount() const
Returns the number of model outputs.
std::vector< ValueInfo > GetOutputs() const
int GetOpset(const std::string &domain) const
Wraps OrtApi::SessionGetOpsetForDomain.
uint64_t GetProfilingStartTimeNs() const
Wraps OrtApi::SessionGetProfilingStartTimeNs.
std::vector< ConstEpDevice > GetEpDeviceForOutputs() const
Wrapper for OrtApi::SessionGetEpDeviceForOutputs.
std::vector< std::string > GetOverridableInitializerNames() const
ModelMetadata GetModelMetadata() const
Wraps OrtApi::SessionGetModelMetadata.
size_t GetInputCount() const
Returns the number of model inputs.
TypeInfo GetOutputTypeInfo(size_t index) const
Wraps OrtApi::SessionGetOutputTypeInfo.
std::vector< std::string > GetInputNames() const
AllocatedStringPtr GetOverridableInitializerNameAllocated(size_t index, OrtAllocator *allocator) const
Returns a copy of the overridable initializer name at then specified index.
std::vector< ConstEpDevice > GetEpDeviceForInputs() const
Wrapper for OrtApi::SessionGetEpDeviceForInputs.
AllocatedStringPtr GetOutputNameAllocated(size_t index, OrtAllocator *allocator) const
Returns a copy of output name at then specified index.
size_t GetOverridableInitializerCount() const
Returns the number of inputs that have defaults that can be overridden.
std::vector< ConstMemoryInfo > GetMemoryInfoForOutputs() const
Wrapper for OrtApi::SessionGetMemoryInfoForOutputs.
AllocatedStringPtr GetInputNameAllocated(size_t index, OrtAllocator *allocator) const
Returns a copy of input name at the specified index.
std::vector< ConstMemoryInfo > GetMemoryInfoForInputs() const
Wrapper for OrtApi::SessionGetMemoryInfoForInputs.
std::vector< ValueInfo > GetInputs() const
TypeInfo GetOverridableInitializerTypeInfo(size_t index) const
Wraps OrtApi::SessionGetOverridableInitializerTypeInfo.
Definition onnxruntime_cxx_api.h:2365
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...
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...
TensorTypeAndShapeInfo GetSparseTensorIndicesTypeShapeInfo(OrtSparseIndicesFormat format) const
The API returns type and shape information for the specified indices. Each supported indices have the...
const void * GetTensorRawData() const
Returns a non-typed pointer to a tensor contained data.
std::string GetStringTensorElement(size_t element_index) const
Returns string tensor UTF-8 encoded string element. Use of this API is recommended over GetStringTens...
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...
size_t GetStringTensorDataLength() const
This API returns a full length of string data contained within either a tensor or a sparse Tensor....
bool IsSparseTensor() const
Returns true if the OrtValue contains a sparse tensor.
TypeInfo GetTypeInfo() const
The API returns type information for data contained in a tensor. For sparse tensors it returns type i...
const R * 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...
bool IsTensor() const
Returns true if Value is a tensor, false for other types like map/sequence/etc.
ConstMemoryInfo GetTensorMemoryInfo() const
This API returns information about the memory allocation used to hold data.
size_t GetTensorSizeInBytes() const
Returns the total size of the tensor data in bytes. Throws an exception if the OrtValue does not cont...
const R * GetSparseTensorValues() const
The API returns a pointer to an internal buffer of the sparse tensor containing non-zero values....
TensorTypeAndShapeInfo GetTensorTypeAndShapeInfo() const
The API returns type information for data contained in a tensor. For sparse tensors it returns type i...
Value GetValue(int index, OrtAllocator *allocator) const
size_t GetCount() const
< Return true if OrtValue contains data and returns false if the OrtValue is a None
void GetOpaqueData(const char *domain, const char *type_name, R &) const
Obtains a pointer to a user defined data for experimental purposes.
TensorTypeAndShapeInfo GetSparseTensorValuesTypeAndShapeInfo() const
The API returns type and shape information for stored non-zero values of the sparse tensor....
void GetTensorElementTypeAndShapeDataReference(ONNXTensorElementDataType &elem_type, Shape &shape) const
Returns the tensor's element type and a reference to the tensor's internal shape data....
const R * GetTensorData() const
Returns a const typed pointer to the tensor contained data. No type checking is performed,...
OrtSparseFormat GetSparseFormat() const
The API returns the sparse data format this OrtValue holds in a sparse tensor. If the sparse tensor w...
Definition onnxruntime_cxx_api.h:3490
Status GetInitializer(ConstValue &value) const
< A wrapper around OrtApi::ValueInfo_GetInitializerValue
std::string GetName() const
< A wrapper around OrtApi::GetValueInfoName
bool IsFromOuterScope() const
< A wrapper around OrtApi::ValueInfo_IsFromOuterScope
Status GetExternalInitializerInfo(ExternalInitializerInfo &info) const
< A wrapper around OrtApi::ValueInfo_GetExternalInitializerInfo
bool IsConstantInitializer() const
< A wrapper around OrtApi::ValueInfo_IsConstantInitializer
std::vector< ValueInfoConsumerProducerInfo > GetConsumers() const
< A wrapper around OrtApi::ValueInfo_GetValueConsumers
bool IsGraphOutput() const
< A wrapper around OrtApi::ValueInfo_IsGraphOutput
bool IsRequiredGraphInput() const
< A wrapper around OrtApi::ValueInfo_IsRequiredGraphInput
ConstTypeInfo TypeInfo() const
< A wrapper around OrtApi::GetValueInfoTypeInfo
ValueInfoConsumerProducerInfo GetProducerNode() const
bool IsOptionalGraphInput() const
< A wrapper around OrtApi::ValueInfo_IsOptionalGraphInput
Definition onnxruntime_cxx_api.h:1158
uint32_t GetReasonsBitmask() const
Wraps DeviceEpIncompatibilityDetails_GetReasonsBitmask.
const char * GetNotes() const
Wraps DeviceEpIncompatibilityDetails_GetNotes.
int32_t GetErrorCode() const
Wraps DeviceEpIncompatibilityDetails_GetErrorCode.
Definition onnxruntime_cxx_api.h:1268
std::string GetDomain() const
std::string GetOperatorType() const
std::string GetName() const
Definition onnxruntime_cxx_api.h:1285
std::vector< ConstEpAssignedNode > GetNodes() const
Definition onnxruntime_cxx_api.h:1179
const char * EpName() const
const char * EpVendor() const
ConstKeyValuePairs EpOptions() const
ConstHardwareDevice Device() const
ConstMemoryInfo GetMemoryInfo(OrtDeviceMemoryType memory_type) const
Wraps EpDevice_MemoryInfo.
uint64_t GetTotalMemoryCapacity(OrtDeviceMemoryType memory_type=OrtDeviceMemoryType_DEFAULT) const
Total memory in bytes without querying available memory. Throws if unsupported.
SyncStream CreateSyncStream(ConstKeyValuePairs stream_options={}) const
ConstKeyValuePairs EpMetadata() const
std::pair< uint64_t, uint64_t > GetMemoryCapacity(OrtDeviceMemoryType memory_type=OrtDeviceMemoryType_DEFAULT) const
Definition onnxruntime_cxx_api.h:3664
void SetInputs(std::vector< ValueInfo > &inputs)
void SetOutputs(std::vector< ValueInfo > &outputs)
void AddNode(Node &node)
void AddInitializer(const std::string &name, Value &initializer, bool data_is_external)
Definition onnxruntime_cxx_api.h:1139
OrtHardwareDeviceType Type() const
const char * Vendor() const
ConstKeyValuePairs Metadata() const
Definition onnxruntime_cxx_api.h:2883
void BindOutput(const char *name, const Value &)
void BindInput(const char *name, const Value &)
void BindOutput(const char *name, const OrtMemoryInfo *)
Definition onnxruntime_cxx_api.h:971
void GetKeyValuePairs(std::vector< const char * > &keys, std::vector< const char * > &values) const
std::unordered_map< std::string, std::string > GetKeyValuePairs() const
const char * GetValue(const char *key) const
Definition onnxruntime_cxx_api.h:2272
ONNXTensorElementDataType GetMapKeyType() const
Wraps OrtApi::GetMapKeyType.
TypeInfo GetMapValueType() const
Wraps OrtApi::GetMapValueType.
Definition onnxruntime_cxx_api.h:1010
std::string GetAllocatorName() const
Wrapper MemoryInfoGetName.
int GetDeviceId() const
Wrapper MemoryInfoGetId.
OrtMemType GetMemoryType() const
Wrapper MemoryInfoGetMemType.
OrtDeviceMemoryType GetDeviceMemoryType() const
Wrapper MemoryInfoGetDeviceMemType.
OrtMemoryInfoDeviceType GetDeviceType() const
Wrapper MemoryInfoGetDeviceType.
OrtAllocatorType GetAllocatorType() const
Wrapper MemoryInfoGetType.
uint32_t GetVendorId() const
Wrapper MemoryInfoGetVendorId.
bool operator==(const MemoryInfoImpl< U > &o) const
Definition onnxruntime_cxx_api.h:3712
void AddGraph(Graph &graph)
Definition onnxruntime_cxx_api.h:3854
std::string GetInputName(size_t index) const
int GetSinceVersion() const
< Wraps OrtEpApi::OpSchema_GetSinceVersion
size_t GetNumOutputs() const
Wraps OrtEpApi::OpSchema_GetOutputName.
ConstOpSchemaTypeConstraint GetOutputTypeConstraint(size_t index) const
Wraps OrtEpApi::OpSchema_GetTypeConstraintCount.
size_t GetTypeConstraintCount() const
Wraps OrtEpApi::OpSchema_GetTypeConstraint. Returns the i-th type constraint.
ConstOpSchemaTypeConstraint GetInputTypeConstraint(size_t index) const
Wraps OrtEpApi::OpSchema_GetNumOutputs.
size_t GetNumInputs() const
Wraps OrtEpApi::OpSchema_GetInputName.
std::string GetOutputName(size_t index) const
ConstOpSchemaTypeConstraint GetTypeConstraint(size_t index) const
Definition onnxruntime_cxx_api.h:3829
std::vector< size_t > GetOutputIndices() const
std::vector< size_t > GetInputIndices() const
Wraps OrtEpApi::OpSchemaTypeConstraint_GetOutputIndices.
std::vector< std::string > GetAllowedTypes() const
Wraps OrtEpApi::OpSchemaTypeConstraint_GetInputIndices.
std::string GetTypeParamName() const
< Wraps OrtEpApi::OpSchemaTypeConstraint_GetTypeParamName
Definition onnxruntime_cxx_api.h:2259
TypeInfo GetOptionalElementType() const
Wraps OrtApi::CastOptionalTypeToContainedTypeInfo.
Definition onnxruntime_cxx_api.h:2348
const char ** str
Definition onnxruntime_cxx_api.h:2353
const int64_t * values_shape
Definition onnxruntime_cxx_api.h:2349
size_t values_shape_len
Definition onnxruntime_cxx_api.h:2350
const void * p_data
Definition onnxruntime_cxx_api.h:2352
Definition onnxruntime_cxx_api.h:1370
Ort::Status AddEvents(const std::vector< ProfilingEvent > &events)
Ort::Status AddEvents(const OrtProfilingEvent *const *events, size_t num_events)
Adds profiling events to this container. Events are copied. Wraps OrtEpApi::ProfilingEventsContainer_...
Definition onnxruntime_cxx_api.h:2235
TypeInfo GetSequenceElementType() const
Wraps OrtApi::GetSequenceElementType.
Definition onnxruntime_cxx_api.h:2049
void SetEpDynamicOptions(const char *const *keys, const char *const *values, size_t kv_len)
Set DynamicOptions for EPs (Execution Providers)
AllocatedStringPtr EndProfilingAllocated(OrtAllocator *allocator)
End profiling and return a copy of the profiling file name.
void ReleaseCapturedGraph(int graph_annotation_id)
Release a previously captured graph.
void FinalizeModelEditorSession(const Model &model, const SessionOptions &options, OrtPrepackedWeightsContainer *prepacked_weights_container=nullptr)
void Run(const RunOptions &run_options, const IoBinding &)
Wraps OrtApi::RunWithBinding.
void RunAsync(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, RunAsyncCallbackFn callback, void *user_data)
Run the model asynchronously in a thread owned by intra op thread pool.
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.
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&,...
Definition onnxruntime_cxx_api.h:2359
const int64_t * shape
Definition onnxruntime_cxx_api.h:2360
size_t shape_len
Definition onnxruntime_cxx_api.h:2361
Definition onnxruntime_cxx_api.h:3904
Status StoreWeightData(void **buffer_data_ptrs, size_t *buffer_sizes, size_t num_buffers)
Definition onnxruntime_cxx_api.h:1120
void * GetHandle()
Wraps SyncStream_GetHandle.
Definition onnxruntime_cxx_api.h:2180
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.
std::vector< const char * > GetSymbolicDimensions() const
void GetSymbolicDimensions(const char **values, size_t values_count) const
Wraps OrtApi::GetSymbolicDimensions.
size_t GetDimensionsCount() const
Wraps OrtApi::GetDimensionsCount.
ONNXTensorElementDataType GetElementType() const
Wraps OrtApi::GetTensorElementType.
bool HasShape() const
Wraps OrtApi::TensorTypeAndShape_HasShape.
Definition onnxruntime_cxx_api.h:2297
ONNXType GetONNXType() const
ConstSequenceTypeInfo GetSequenceTypeInfo() const
Wraps OrtApi::CastTypeInfoToSequenceTypeInfo.
ConstMapTypeInfo GetMapTypeInfo() const
Wraps OrtApi::CastTypeInfoToMapTypeInfo.
ConstOptionalTypeInfo GetOptionalTypeInfo() const
wraps OrtApi::CastTypeInfoToOptionalTypeInfo
ConstTensorTypeAndShapeInfo GetTensorTypeAndShapeInfo() const
Wraps OrtApi::CastTypeInfoToTensorInfo.
This is a tagging template type. Use it with Base<T> to indicate that the C++ interface object has no...
Definition onnxruntime_cxx_api.h:697
T Type
Definition onnxruntime_cxx_api.h:698
Definition onnxruntime_cxx_api.h:2551
void FillStringTensorElement(const char *s, size_t index)
Set a single string in a string tensor.
R * GetTensorMutableData()
Returns a non-const typed pointer to an OrtValue/Tensor contained buffer No type checking is performe...
R & At(const std::vector< int64_t > &location)
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 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...
void * GetTensorMutableRawData()
Returns a non-typed non-const pointer to a tensor contained 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...
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...
void FillStringTensor(const char *const *s, size_t s_len)
Set all strings at once in a string tensor.
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...
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...
char * GetResizedStringTensorElementBuffer(size_t index, size_t buffer_length)
Allocate if necessary and obtain a pointer to a UTF-8 encoded string element buffer indexed by the fl...
Memory allocation interface.
Definition onnxruntime_c_api.h:371
void(* Free)(struct OrtAllocator *this_, void *p)
Free a block of memory previously allocated with OrtAllocator::Alloc.
Definition onnxruntime_c_api.h:378
const OrtApi *(* GetApi)(uint32_t version)
Get a pointer to the requested version of the OrtApi.
Definition onnxruntime_c_api.h:1010
The C API.
Definition onnxruntime_c_api.h:1378
const OrtModelPackageApi *(* GetModelPackageApi)(void)
Get the stable model package API table.
Definition onnxruntime_c_api.h:7727
const OrtEpApi *(* GetEpApi)(void)
Get the OrtEpApi instance for implementing an execution provider.
Definition onnxruntime_c_api.h:5865
const OrtInteropApi *(* GetInteropApi)(void)
Get the EP Interop API instance.
Definition onnxruntime_c_api.h:7129
const OrtCompileApi *(* GetCompileApi)(void)
Get the Compile API instance.
Definition onnxruntime_c_api.h:5597
void(* ReleaseTensorRTProviderOptions)(OrtTensorRTProviderOptionsV2 *input)
Release an OrtTensorRTProviderOptionsV2.
Definition onnxruntime_c_api.h:3637
const OrtModelEditorApi *(* GetModelEditorApi)(void)
Get the Model Editor API instance.
Definition onnxruntime_c_api.h:5539
void(* ReleaseCUDAProviderOptions)(OrtCUDAProviderOptionsV2 *input)
Release an OrtCUDAProviderOptionsV2.
Definition onnxruntime_c_api.h:4140
CUDA Provider Options.
Definition onnxruntime_c_api.h:707
The OrtCompileApi struct provides functions to compile ONNX models.
Definition onnxruntime_c_api.h:8405
Definition onnxruntime_c_api.h:7798
int(* GetVariadicInputHomogeneity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7847
OrtCustomOpInputOutputCharacteristic(* GetOutputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7831
size_t(* GetInputTypeCount)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7819
int(* GetVariadicOutputMinArity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7851
size_t(* GetAliasMap)(int **input_index, int **output_index)
Definition onnxruntime_c_api.h:7884
int(* GetStartVersion)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7869
void(* ReleaseMayInplace)(int *input_index, int *output_index)
Definition onnxruntime_c_api.h:7881
const char *(* GetName)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7812
size_t(* GetOutputTypeCount)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7821
void(* KernelDestroy)(void *op_kernel)
Definition onnxruntime_c_api.h:7827
int(* GetVariadicOutputHomogeneity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7856
OrtMemType(* GetInputMemoryType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7838
void *(* CreateKernel)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info)
Definition onnxruntime_c_api.h:7808
uint32_t version
Definition onnxruntime_c_api.h:7799
ONNXTensorElementDataType(* GetInputType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7818
void(* ReleaseAliasMap)(int *input_index, int *output_index)
Definition onnxruntime_c_api.h:7885
OrtCustomOpInputOutputCharacteristic(* GetInputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7830
const char *(* GetExecutionProviderType)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7815
ONNXTensorElementDataType(* GetOutputType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7820
int(* GetVariadicInputMinArity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7842
OrtStatusPtr(* InferOutputShapeFn)(const struct OrtCustomOp *op, OrtShapeInferContext *)
Definition onnxruntime_c_api.h:7866
int(* GetEndVersion)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7870
OrtStatusPtr(* CreateKernelV2)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info, void **kernel)
Definition onnxruntime_c_api.h:7859
size_t(* GetMayInplace)(int **input_index, int **output_index)
Definition onnxruntime_c_api.h:7877
OrtStatusPtr(* KernelComputeV2)(void *op_kernel, OrtKernelContext *context)
Definition onnxruntime_c_api.h:7864
void(* KernelCompute)(void *op_kernel, OrtKernelContext *context)
Definition onnxruntime_c_api.h:7826
Configuration options for creating an OrtEnv.
Definition onnxruntime_c_api.h:1290
The OrtEpApi struct provides functions that are relevant to the implementation of an execution provid...
Definition onnxruntime_ep_c_api.h:1026
The OrtEpFactory provides functions to create and manage execution providers.
Definition onnxruntime_ep_c_api.h:2860
The OrtEp struct provides functions to implement for an execution provider.
Definition onnxruntime_ep_c_api.h:2208
The OrtInteropApi struct provides functions for external resource interop with execution providers.
Definition onnxruntime_c_api.h:8835
MIGraphX Provider Options.
Definition onnxruntime_c_api.h:911
The OrtModelEditorApi struct provides functions to create or edit an ONNX model.
Definition onnxruntime_c_api.h:7899
Stable API table for model package workflows.
Definition onnxruntime_c_api.h:9080
OpenVINO Provider Options.
Definition onnxruntime_c_api.h:950
ROCM Provider Options.
Definition onnxruntime_c_api.h:794
TensorRT Provider Options.
Definition onnxruntime_c_api.h:883
Configuration for thread pool work callbacks.
Definition onnxruntime_c_api.h:1103