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;
1190};
1191} // namespace detail
1192
1197
1200struct EpDevice : detail::EpDeviceImpl<OrtEpDevice> {
1201 explicit EpDevice(std::nullptr_t) {}
1202 explicit EpDevice(OrtEpDevice* p) : EpDeviceImpl<OrtEpDevice>{p} {}
1203
1205 EpDevice(OrtEpFactory& ep_factory, ConstHardwareDevice& hardware_device,
1206 ConstKeyValuePairs ep_metadata = {}, ConstKeyValuePairs ep_options = {});
1207};
1208
1222 const std::vector<ConstEpDevice>& ep_devices,
1223 const char* compatibility_info);
1224
1240AllocatedStringPtr GetCompatibilityInfoFromModelAllocated(const ORTCHAR_T* model_path, const char* ep_type,
1241 OrtAllocator* allocator);
1242
1255AllocatedStringPtr GetCompatibilityInfoFromModelBytesAllocated(const void* model_data, size_t model_data_length,
1256 const char* ep_type, OrtAllocator* allocator);
1257
1258namespace detail {
1259template <typename T>
1262 using B::B;
1263
1264 std::string GetName() const;
1265 std::string GetDomain() const;
1266 std::string GetOperatorType() const;
1267};
1268} // namespace detail
1269
1274
1275namespace detail {
1276template <typename T>
1279 using B::B;
1280
1281 std::string GetEpName() const;
1282 std::vector<ConstEpAssignedNode> GetNodes() const;
1283};
1284} // namespace detail
1285
1290
1291namespace detail {
1292template <typename T>
1295 using B::B;
1296
1298 OrtProfilingEventCategory GetCategory() const;
1299
1302 const char* GetName() const;
1303
1305 int64_t GetTimestampUs() const;
1306
1308 int64_t GetDurationUs() const;
1309
1313 const char* GetArgValue(const char* key) const;
1314};
1315} // namespace detail
1316
1325
1333 explicit ProfilingEvent(std::nullptr_t) {}
1335 : ConstProfilingEventImpl<OrtProfilingEvent>{p} {}
1336
1338 ProfilingEvent(OrtProfilingEventCategory category,
1339 int32_t process_id,
1340 int32_t thread_id,
1341 const char* event_name,
1342 int64_t timestamp_us,
1343 int64_t duration_us,
1344 const std::unordered_map<std::string, std::string>& args = {});
1345
1347 ProfilingEvent(OrtProfilingEventCategory category,
1348 int32_t process_id,
1349 int32_t thread_id,
1350 const char* event_name,
1351 int64_t timestamp_us,
1352 int64_t duration_us,
1353 const char* const* arg_keys,
1354 const char* const* arg_values,
1355 size_t num_args);
1356
1358};
1359
1360namespace detail {
1361template <typename T>
1364 using B::B;
1365
1368 Ort::Status AddEvents(const OrtProfilingEvent* const* events, size_t num_events);
1369 Ort::Status AddEvents(const std::vector<ProfilingEvent>& events);
1370};
1371} // namespace detail
1372
1379
1385struct Env : detail::Base<OrtEnv> {
1386 explicit Env(std::nullptr_t) {}
1387
1389 Env(OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
1390
1392 Env(OrtLoggingLevel logging_level, const char* logid, OrtLoggingFunction logging_function, void* logger_param);
1393
1395 Env(const OrtThreadingOptions* tp_options, OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
1396
1398 Env(const OrtThreadingOptions* tp_options, OrtLoggingFunction logging_function, void* logger_param,
1399 OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
1400
1402 explicit Env(const OrtEnvCreationOptions* options);
1403
1405 explicit Env(OrtEnv* p) : Base<OrtEnv>{p} {}
1406
1409
1411
1412 Env& CreateAndRegisterAllocator(const OrtMemoryInfo* mem_info, const OrtArenaCfg* arena_cfg);
1413
1414 Env& CreateAndRegisterAllocatorV2(const std::string& provider_type, const OrtMemoryInfo* mem_info,
1415 const std::unordered_map<std::string, std::string>& options,
1416 const OrtArenaCfg* arena_cfg);
1417
1419
1421
1423 OrtAllocatorType allocator_type,
1424 const OrtKeyValuePairs* allocator_options);
1425
1426 // Result may be nullptr
1428
1430 OrtDeviceMemoryType mem_type);
1431
1432 Env& RegisterExecutionProviderLibrary(const char* registration_name, const std::basic_string<ORTCHAR_T>& path);
1433 Env& UnregisterExecutionProviderLibrary(const char* registration_name);
1434
1435 std::vector<ConstEpDevice> GetEpDevices() const;
1436
1443 size_t GetNumHardwareDevices() const;
1444
1451 std::vector<ConstHardwareDevice> GetHardwareDevices() const;
1452
1464 const char* ep_name, ConstHardwareDevice hw) const;
1465
1466 Status CopyTensors(const std::vector<Value>& src_tensors,
1467 const std::vector<Value>& dst_tensors,
1468 OrtSyncStream* stream) const;
1469
1472 Status CopyTensor(const OrtValue* src_tensor, OrtValue* dst_tensor, OrtSyncStream* stream) const;
1473
1479};
1480
1484struct CustomOpDomain : detail::Base<OrtCustomOpDomain> {
1486 using Base::Base;
1487
1488 explicit CustomOpDomain(std::nullptr_t) {}
1489
1491 explicit CustomOpDomain(const char* domain);
1492
1493 // This does not take ownership of the op, simply registers it.
1494 void Add(const OrtCustomOp* op);
1495};
1496
1498struct LoraAdapter : detail::Base<OrtLoraAdapter> {
1500 using Base::Base;
1501
1502 explicit LoraAdapter(std::nullptr_t) {}
1510 static LoraAdapter CreateLoraAdapter(const std::basic_string<ORTCHAR_T>& adapter_path,
1511 OrtAllocator* allocator);
1512
1521 static LoraAdapter CreateLoraAdapterFromArray(const void* bytes, size_t num_bytes,
1522 OrtAllocator* allocator);
1523};
1524
1528struct RunOptions : detail::Base<OrtRunOptions> {
1529 explicit RunOptions(std::nullptr_t) {}
1531
1534
1537
1538 RunOptions& SetRunTag(const char* run_tag);
1539 const char* GetRunTag() const;
1540
1541 RunOptions& AddConfigEntry(const char* config_key, const char* config_value);
1542 const char* GetConfigEntry(const char* config_key);
1543
1550
1556
1564
1573
1579 RunOptions& EnableProfiling(const ORTCHAR_T* profile_file_prefix);
1580
1586};
1587
1588namespace detail {
1589// Utility function that returns a SessionOption config entry key for a specific custom operator.
1590// Ex: custom_op.[custom_op_name].[config]
1591std::string MakeCustomOpConfigEntryKey(const char* custom_op_name, const char* config);
1592} // namespace detail
1593
1604 CustomOpConfigs() = default;
1605 ~CustomOpConfigs() = default;
1610
1619 CustomOpConfigs& AddConfig(const char* custom_op_name, const char* config_key, const char* config_value);
1620
1629 const std::unordered_map<std::string, std::string>& GetFlattenedConfigs() const;
1630
1631 private:
1632 std::unordered_map<std::string, std::string> flat_configs_;
1633};
1634
1640namespace detail {
1641// we separate const-only methods because passing const ptr to non-const methods
1642// is only discovered when inline methods are compiled which is counter-intuitive
1643template <typename T>
1644struct ConstSessionOptionsImpl : Base<T> {
1645 using B = Base<T>;
1646 using B::B;
1647
1648 SessionOptions Clone() const;
1649
1650 std::string GetConfigEntry(const char* config_key) const;
1651 bool HasConfigEntry(const char* config_key) const;
1652 std::string GetConfigEntryOrDefault(const char* config_key, const std::string& def) const;
1653
1654 bool GetMemPatternEnabled() const;
1655 ExecutionMode GetExecutionMode() const;
1656};
1657
1658template <typename T>
1659struct SessionOptionsImpl : ConstSessionOptionsImpl<T> {
1660 using B = ConstSessionOptionsImpl<T>;
1661 using B::B;
1662
1663 SessionOptionsImpl& SetIntraOpNumThreads(int intra_op_num_threads);
1664 SessionOptionsImpl& SetInterOpNumThreads(int inter_op_num_threads);
1665 SessionOptionsImpl& SetGraphOptimizationLevel(GraphOptimizationLevel graph_optimization_level);
1666 SessionOptionsImpl& SetDeterministicCompute(bool value);
1667
1668 SessionOptionsImpl& EnableCpuMemArena();
1669 SessionOptionsImpl& DisableCpuMemArena();
1670
1671 SessionOptionsImpl& SetOptimizedModelFilePath(const ORTCHAR_T* optimized_model_file);
1672
1673 SessionOptionsImpl& EnableProfiling(const ORTCHAR_T* profile_file_prefix);
1674 SessionOptionsImpl& DisableProfiling();
1675
1676 SessionOptionsImpl& EnableOrtCustomOps();
1677
1678 SessionOptionsImpl& EnableMemPattern();
1679 SessionOptionsImpl& DisableMemPattern();
1680
1681 SessionOptionsImpl& SetExecutionMode(ExecutionMode execution_mode);
1682
1683 SessionOptionsImpl& SetLoadCancellationFlag(bool value);
1684
1685 SessionOptionsImpl& SetLogId(const char* logid);
1686 SessionOptionsImpl& SetLogSeverityLevel(int level);
1687
1688 SessionOptionsImpl& Add(OrtCustomOpDomain* custom_op_domain);
1689
1690 SessionOptionsImpl& DisablePerSessionThreads();
1691
1692 SessionOptionsImpl& AddConfigEntry(const char* config_key, const char* config_value);
1693
1695 SessionOptionsImpl& SetEpContextDataReadFunc(OrtReadNamedBufferFunc read_func, void* state);
1697 SessionOptionsImpl& ClearEpContextDataReadFunc();
1698
1699 SessionOptionsImpl& AddInitializer(const char* name, const OrtValue* ort_val);
1700 SessionOptionsImpl& AddExternalInitializers(const std::vector<std::string>& names, const std::vector<Value>& ort_values);
1701 SessionOptionsImpl& AddExternalInitializersFromFilesInMemory(const std::vector<std::basic_string<ORTCHAR_T>>& external_initializer_file_names,
1702 const std::vector<char*>& external_initializer_file_buffer_array,
1703 const std::vector<size_t>& external_initializer_file_lengths);
1704
1705 SessionOptionsImpl& AppendExecutionProvider_CPU(int use_arena);
1706 SessionOptionsImpl& AppendExecutionProvider_CUDA(const OrtCUDAProviderOptions& provider_options);
1707 SessionOptionsImpl& AppendExecutionProvider_CUDA_V2(const OrtCUDAProviderOptionsV2& provider_options);
1708 SessionOptionsImpl& AppendExecutionProvider_ROCM(const OrtROCMProviderOptions& provider_options);
1709 SessionOptionsImpl& AppendExecutionProvider_OpenVINO(const OrtOpenVINOProviderOptions& provider_options);
1711 SessionOptionsImpl& AppendExecutionProvider_OpenVINO_V2(const std::unordered_map<std::string, std::string>& provider_options = {});
1712 SessionOptionsImpl& AppendExecutionProvider_TensorRT(const OrtTensorRTProviderOptions& provider_options);
1713 SessionOptionsImpl& AppendExecutionProvider_TensorRT_V2(const OrtTensorRTProviderOptionsV2& provider_options);
1714 SessionOptionsImpl& AppendExecutionProvider_MIGraphX(const OrtMIGraphXProviderOptions& provider_options);
1716 SessionOptionsImpl& AppendExecutionProvider_CANN(const OrtCANNProviderOptions& provider_options);
1718 SessionOptionsImpl& AppendExecutionProvider_Dnnl(const OrtDnnlProviderOptions& provider_options);
1720 SessionOptionsImpl& AppendExecutionProvider(const std::string& provider_name,
1721 const std::unordered_map<std::string, std::string>& provider_options = {});
1722
1725 SessionOptionsImpl& AppendExecutionProvider_V2(Env& env, const std::vector<ConstEpDevice>& ep_devices,
1726 const KeyValuePairs& ep_options);
1729 SessionOptionsImpl& AppendExecutionProvider_V2(Env& env, const std::vector<ConstEpDevice>& ep_devices,
1730 const std::unordered_map<std::string, std::string>& ep_options);
1731
1733 SessionOptionsImpl& SetEpSelectionPolicy(OrtExecutionProviderDevicePolicy policy);
1734
1736 SessionOptionsImpl& SetEpSelectionPolicy(EpSelectionDelegate delegate, void* state = nullptr);
1737
1738 SessionOptionsImpl& SetCustomCreateThreadFn(OrtCustomCreateThreadFn ort_custom_create_thread_fn);
1739 SessionOptionsImpl& SetCustomThreadCreationOptions(void* ort_custom_thread_creation_options);
1740 SessionOptionsImpl& SetCustomJoinThreadFn(OrtCustomJoinThreadFn ort_custom_join_thread_fn);
1741
1745 SessionOptionsImpl& RegisterCustomOpsLibrary(const ORTCHAR_T* library_name, const CustomOpConfigs& custom_op_configs = {});
1746
1747 SessionOptionsImpl& RegisterCustomOpsUsingFunction(const char* function_name);
1748
1750 SessionOptionsImpl& AppendExecutionProvider_VitisAI(const std::unordered_map<std::string, std::string>& provider_options = {});
1751
1753 SessionOptionsImpl& AddFreeDimensionOverride(const char* dim_denotation, int64_t dim_value);
1754
1756 SessionOptionsImpl& AddFreeDimensionOverrideByName(const char* dim_name, int64_t dim_value);
1757};
1758} // namespace detail
1759
1760using UnownedSessionOptions = detail::SessionOptionsImpl<detail::Unowned<OrtSessionOptions>>;
1761using ConstSessionOptions = detail::ConstSessionOptionsImpl<detail::Unowned<const OrtSessionOptions>>;
1762
1766struct SessionOptions : detail::SessionOptionsImpl<OrtSessionOptions> {
1767 explicit SessionOptions(std::nullptr_t) {}
1769 explicit SessionOptions(OrtSessionOptions* p) : SessionOptionsImpl<OrtSessionOptions>{p} {}
1772};
1773
1779struct EpContextConfig : detail::Base<OrtEpContextConfig> {
1781 using Base::Base;
1782
1783 explicit EpContextConfig(std::nullptr_t) noexcept {}
1784 explicit EpContextConfig(const SessionOptions& session_options);
1785 explicit EpContextConfig(ConstSessionOptions session_options);
1786
1788 void GetReadFunc(OrtReadNamedBufferFunc& read_func, void*& state) const;
1789 void GetWriteFunc(OrtWriteNamedBufferFunc& write_func, void*& state) const;
1790};
1791
1796struct ModelCompilationOptions : detail::Base<OrtModelCompilationOptions> {
1798 using Base::Base;
1799
1800 explicit ModelCompilationOptions(std::nullptr_t) {}
1801
1802 ModelCompilationOptions(const Env& env, const SessionOptions& session_options);
1803 ModelCompilationOptions(const Env& env, ConstSessionOptions session_options);
1804
1805 ModelCompilationOptions& SetInputModelPath(const ORTCHAR_T* input_model_path);
1807 size_t input_model_data_size);
1808 ModelCompilationOptions& SetEpContextEmbedMode(bool embed_ep_context_in_model);
1809 ModelCompilationOptions& SetOutputModelPath(const ORTCHAR_T* output_model_path);
1811 size_t initializer_size_threshold);
1813 size_t initializer_size_threshold,
1814 OrtAllocator* allocator,
1815 void** output_buffer_ptr,
1816 size_t* output_buffer_size_ptr);
1818
1821 OrtGetInitializerLocationFunc get_initializer_location_func,
1822 void* state);
1823
1824 ModelCompilationOptions& SetOutputModelBuffer(OrtAllocator* allocator, void** output_model_buffer_ptr,
1825 size_t* output_model_buffer_size_ptr);
1826
1829
1832
1833 ModelCompilationOptions& SetEpContextBinaryInformation(const ORTCHAR_T* output_directory,
1834 const ORTCHAR_T* model_name);
1836
1838
1841};
1842
1849Status CompileModel(const Env& env, const ModelCompilationOptions& model_compilation_options);
1850
1855struct ModelPackageOptions : detail::Base<OrtModelPackageOptions> {
1857 using Base::Base;
1858
1859 explicit ModelPackageOptions(std::nullptr_t) {}
1860 ModelPackageOptions(const Env& env, const SessionOptions& session_options);
1861 ModelPackageOptions(const Env& env, ConstSessionOptions session_options);
1862};
1863
1865struct ModelPackageContext : detail::Base<OrtModelPackageContext> {
1867 using Base::Base;
1868
1869 explicit ModelPackageContext(std::nullptr_t) {}
1870 explicit ModelPackageContext(const ORTCHAR_T* package_root);
1871
1872 int64_t GetSchemaVersion() const;
1873 size_t GetComponentCount() const;
1874 std::vector<std::string> GetComponentNames() const;
1875 size_t GetVariantCount(const char* component_name) const;
1876 std::vector<std::string> GetVariantNames(const char* component_name) const;
1877 const char* GetVariantEpName(const char* component_name, const char* variant_name) const;
1878 std::string ResolveStringRef(const char* base_dir, const char* input, bool must_exist) const;
1880 const ModelPackageOptions& options) const;
1881};
1882
1884struct ModelPackageComponentContext : detail::Base<OrtModelPackageComponentContext> {
1886 using Base::Base;
1887
1888 explicit ModelPackageComponentContext(std::nullptr_t) {}
1889
1890 std::string GetSelectedVariantName() const;
1891 std::basic_string<ORTCHAR_T> GetSelectedVariantFolderPath() const;
1893 Session CreateSession(const Env& env, const SessionOptions& session_options);
1894 Session CreateSession(const Env& env, ConstSessionOptions session_options);
1895};
1896
1900struct ModelMetadata : detail::Base<OrtModelMetadata> {
1902 using Base::Base;
1903
1904 explicit ModelMetadata(std::nullptr_t) {}
1905
1913
1921
1929
1937
1945
1952 std::vector<AllocatedStringPtr> GetCustomMetadataMapKeysAllocated(OrtAllocator* allocator) const;
1953
1964
1965 int64_t GetVersion() const;
1966};
1967
1968struct IoBinding;
1969
1970namespace detail {
1971
1972// we separate const-only methods because passing const ptr to non-const methods
1973// is only discovered when inline methods are compiled which is counter-intuitive
1974template <typename T>
1976 using B = Base<T>;
1977 using B::B;
1978
1979 size_t GetInputCount() const;
1980 size_t GetOutputCount() const;
1982
1983 std::vector<std::string> GetInputNames() const;
1984 std::vector<std::string> GetOutputNames() const;
1985 std::vector<std::string> GetOverridableInitializerNames() const;
1986
1987 std::vector<ConstMemoryInfo> GetMemoryInfoForInputs() const;
1988 std::vector<ConstMemoryInfo> GetMemoryInfoForOutputs() const;
1989 std::vector<ConstEpDevice> GetEpDeviceForInputs() const;
1990 std::vector<ConstEpDevice> GetEpDeviceForOutputs() const;
1991
2000
2009
2018
2019 uint64_t GetProfilingStartTimeNs() const;
2021
2022 TypeInfo GetInputTypeInfo(size_t index) const;
2023 TypeInfo GetOutputTypeInfo(size_t index) const;
2025
2026 int GetOpset(const std::string& domain) const;
2027
2028 std::vector<ValueInfo> GetInputs() const;
2029 std::vector<ValueInfo> GetOutputs() const;
2030
2035 std::vector<ConstEpAssignedSubgraph> GetEpGraphAssignmentInfo() const;
2036};
2037
2038template <typename T>
2041 using B::B;
2042
2060 std::vector<Value> Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
2061 const char* const* output_names, size_t output_count);
2062
2066 void Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
2067 const char* const* output_names, Value* output_values, size_t output_count);
2068
2069 void Run(const RunOptions& run_options, const IoBinding&);
2070
2090 void RunAsync(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
2091 const char* const* output_names, Value* output_values, size_t output_count, RunAsyncCallbackFn callback, void* user_data);
2092
2100
2112 void SetEpDynamicOptions(const char* const* keys, const char* const* values, size_t kv_len);
2113
2114 void FinalizeModelEditorSession(const Model& model, const SessionOptions& options,
2115 OrtPrepackedWeightsContainer* prepacked_weights_container = nullptr);
2116
2123 void ReleaseCapturedGraph(int graph_annotation_id);
2124};
2125
2126} // namespace detail
2127
2130
2134struct Session : detail::SessionImpl<OrtSession> {
2136 explicit Session(std::nullptr_t) {}
2137 explicit Session(OrtSession* p) : SessionImpl{p} {}
2138
2139 Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
2140
2142 Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options,
2143 OrtPrepackedWeightsContainer* prepacked_weights_container);
2144
2146 Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options);
2147
2149 Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options,
2150 OrtPrepackedWeightsContainer* prepacked_weights_container);
2151
2152#if !defined(ORT_MINIMAL_BUILD)
2154 Session(const Env& env, const Model& model, const SessionOptions& options);
2155
2157 static Session CreateModelEditorSession(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
2158
2160 static Session CreateModelEditorSession(const Env& env, const void* model_data, size_t model_data_length,
2161 const SessionOptions& options);
2162#endif // !defined(ORT_MINIMAL_BUILD)
2163
2164 ConstSession GetConst() const { return ConstSession{this->p_}; }
2165 UnownedSession GetUnowned() const { return UnownedSession{this->p_}; }
2166};
2167
2168namespace detail {
2169template <typename T>
2171 using B = Base<T>;
2172 using B::B;
2173
2175
2180 size_t GetElementCount() const;
2181
2182 size_t GetDimensionsCount() const;
2183
2188 [[deprecated("use GetShape()")]] void GetDimensions(int64_t* values, size_t values_count) const;
2189
2190 void GetSymbolicDimensions(const char** values, size_t values_count) const;
2191 std::vector<const char*> GetSymbolicDimensions() const;
2192
2193 bool HasShape() const;
2194 std::vector<int64_t> GetShape() const;
2195};
2196
2197} // namespace detail
2198
2200
2206 using Base::Base;
2207
2209 explicit TensorTypeAndShapeInfo(std::nullptr_t) {}
2211 explicit TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* p) : TensorTypeAndShapeInfoImpl{p} {}
2212
2213 // Create a TensorTypeAndShapeInfo object with the specified element type and dimensions
2214 // symbolic_dims are optional, but should be 1:1 with dims.
2215 // The value in symbolic_dims will be used for all entries in dims that are -1.
2217 const std::vector<int64_t>& dims,
2218 const std::vector<std::string>* symbolic_dims = nullptr);
2219
2221};
2222
2223namespace detail {
2224template <typename T>
2226 using B = Base<T>;
2227 using B::B;
2229};
2230
2231} // namespace detail
2232
2234
2238struct SequenceTypeInfo : detail::SequenceTypeInfoImpl<OrtSequenceTypeInfo> {
2240 using Base::Base;
2241
2242 explicit SequenceTypeInfo(std::nullptr_t) {}
2243 explicit SequenceTypeInfo(OrtSequenceTypeInfo* p) : SequenceTypeInfoImpl<OrtSequenceTypeInfo>{p} {}
2245};
2246
2247namespace detail {
2248template <typename T>
2250 using B = Base<T>;
2251 using B::B;
2253};
2254
2255} // namespace detail
2256
2257// This is always owned by the TypeInfo and can only be obtained from it.
2259
2260namespace detail {
2261template <typename T>
2268
2269} // namespace detail
2270
2272
2276struct MapTypeInfo : detail::MapTypeInfoImpl<OrtMapTypeInfo> {
2278 using Base::Base;
2279
2280 explicit MapTypeInfo(std::nullptr_t) {}
2281 explicit MapTypeInfo(OrtMapTypeInfo* p) : MapTypeInfoImpl<OrtMapTypeInfo>{p} {}
2282 ConstMapTypeInfo GetConst() const { return ConstMapTypeInfo{this->p_}; }
2283};
2284
2285namespace detail {
2286template <typename T>
2298} // namespace detail
2299
2305
2310struct TypeInfo : detail::TypeInfoImpl<OrtTypeInfo> {
2312 using Base::Base;
2313
2315 explicit TypeInfo(std::nullptr_t) {}
2316 explicit TypeInfo(OrtTypeInfo* p) : TypeInfoImpl<OrtTypeInfo>{p} {}
2317
2318#if !defined(ORT_MINIMAL_BUILD)
2324#endif // !defined(ORT_MINIMAL_BUILD)
2325
2326 ConstTypeInfo GetConst() const { return ConstTypeInfo{this->p_}; }
2327};
2328
2329namespace detail {
2330// This structure is used to feed sparse tensor values
2331// information for use with FillSparseTensor<Format>() API
2332// if the data type for the sparse tensor values is numeric
2333// use data.p_data, otherwise, use data.str pointer to feed
2334// values. data.str is an array of const char* that are zero terminated.
2335// number of strings in the array must match shape size.
2336// For fully sparse tensors use shape {0} and set p_data/str
2337// to nullptr.
2339 const int64_t* values_shape;
2341 union {
2342 const void* p_data;
2343 const char** str;
2344 } data;
2345};
2346
2347// Provides a way to pass shape in a single
2348// argument
2349struct Shape {
2350 const int64_t* shape;
2352};
2353
2354template <typename T>
2356 using B = Base<T>;
2357 using B::B;
2358
2362 template <typename R>
2363 void GetOpaqueData(const char* domain, const char* type_name, R&) const;
2364
2365 bool IsTensor() const;
2366 bool HasValue() const;
2367
2368 size_t GetCount() const; // If a non tensor, returns 2 for map and N for sequence, where N is the number of elements
2369 Value GetValue(int index, OrtAllocator* allocator) const;
2370
2378
2393 void GetStringTensorContent(void* buffer, size_t buffer_length, size_t* offsets, size_t offsets_count) const;
2394
2401 template <typename R>
2402 const R* GetTensorData() const;
2403
2408 const void* GetTensorRawData() const;
2409
2417
2425
2431
2440 void GetStringTensorElement(size_t buffer_length, size_t element_index, void* buffer) const;
2441
2448 std::string GetStringTensorElement(size_t element_index) const;
2449
2456 size_t GetStringTensorElementLength(size_t element_index) const;
2457
2468 size_t GetTensorSizeInBytes() const;
2469
2470#if !defined(DISABLE_SPARSE_TENSORS)
2478
2485
2494
2504 template <typename R>
2505 const R* GetSparseTensorIndicesData(OrtSparseIndicesFormat indices_format, size_t& num_indices) const;
2506
2511 bool IsSparseTensor() const;
2512
2521 template <typename R>
2522 const R* GetSparseTensorValues() const;
2523
2524#endif
2525
2538};
2539
2540template <typename T>
2543 using B::B;
2544
2550 template <typename R>
2552
2558
2560 // Obtain a reference to an element of data at the location specified
2566 template <typename R>
2567 R& At(const std::vector<int64_t>& location);
2568
2574 void FillStringTensor(const char* const* s, size_t s_len);
2575
2581 void FillStringTensorElement(const char* s, size_t index);
2582
2595 char* GetResizedStringTensorElementBuffer(size_t index, size_t buffer_length);
2596
2597#if !defined(DISABLE_SPARSE_TENSORS)
2606 void UseCooIndices(int64_t* indices_data, size_t indices_num);
2607
2618 void UseCsrIndices(int64_t* inner_data, size_t inner_num, int64_t* outer_data, size_t outer_num);
2619
2628 void UseBlockSparseIndices(const Shape& indices_shape, int32_t* indices_data);
2629
2639 void FillSparseTensorCoo(const OrtMemoryInfo* data_mem_info, const OrtSparseValuesParam& values_param,
2640 const int64_t* indices_data, size_t indices_num);
2641
2653 void FillSparseTensorCsr(const OrtMemoryInfo* data_mem_info,
2654 const OrtSparseValuesParam& values,
2655 const int64_t* inner_indices_data, size_t inner_indices_num,
2656 const int64_t* outer_indices_data, size_t outer_indices_num);
2657
2668 const OrtSparseValuesParam& values,
2669 const Shape& indices_shape,
2670 const int32_t* indices_data);
2671
2672#endif
2673};
2674
2675} // namespace detail
2676
2679
2683struct Value : detail::ValueImpl<OrtValue> {
2685 using Base::Base;
2688
2689 Value(std::nullptr_t) {}
2690 Value(Value&&) = default;
2691 Value& operator=(Value&&) = default;
2692
2693 ConstValue GetConst() const { return ConstValue{this->p_}; }
2694 UnownedValue GetUnowned() const { return UnownedValue{this->p_}; }
2695
2704 template <typename T>
2705 static Value CreateTensor(const OrtMemoryInfo* info, T* p_data, size_t p_data_element_count,
2706 const int64_t* shape, size_t shape_len);
2707
2717 static Value CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count,
2718 const int64_t* shape, size_t shape_len,
2720
2730 static Value CreateTensor(OrtAllocator* deleter, void* p_data, size_t p_data_byte_count,
2731 const int64_t* shape, size_t shape_len,
2733
2745 template <typename T>
2746 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len);
2747
2759 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len,
2761
2770 static Value CreateMap(const Value& keys, const Value& values);
2771
2779 static Value CreateSequence(const std::vector<Value>& values);
2780
2789 template <typename T>
2790 static Value CreateOpaque(const char* domain, const char* type_name, const T& value);
2791
2792#if !defined(DISABLE_SPARSE_TENSORS)
2803 template <typename T>
2804 static Value CreateSparseTensor(const OrtMemoryInfo* info, T* p_data, const Shape& dense_shape,
2805 const Shape& values_shape);
2806
2823 static Value CreateSparseTensor(const OrtMemoryInfo* info, void* p_data, const Shape& dense_shape,
2824 const Shape& values_shape, ONNXTensorElementDataType type);
2825
2835 template <typename T>
2836 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape);
2837
2849 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape, ONNXTensorElementDataType type);
2850
2851#endif // !defined(DISABLE_SPARSE_TENSORS)
2852};
2853
2854namespace detail {
2855namespace binding_utils {
2856// Bring these out of template
2857std::vector<std::string> GetOutputNamesHelper(const OrtIoBinding* binding, OrtAllocator*);
2858std::vector<Value> GetOutputValuesHelper(const OrtIoBinding* binding, OrtAllocator*);
2859} // namespace binding_utils
2860
2861template <typename T>
2863 using B = Base<T>;
2864 using B::B;
2865
2866 std::vector<std::string> GetOutputNames() const;
2867 std::vector<std::string> GetOutputNames(OrtAllocator*) const;
2868 std::vector<Value> GetOutputValues() const;
2869 std::vector<Value> GetOutputValues(OrtAllocator*) const;
2870};
2871
2872template <typename T>
2875 using B::B;
2876
2877 void BindInput(const char* name, const Value&);
2878 void BindOutput(const char* name, const Value&);
2879 void BindOutput(const char* name, const OrtMemoryInfo*);
2884};
2885
2886} // namespace detail
2887
2890
2894struct IoBinding : detail::IoBindingImpl<OrtIoBinding> {
2895 explicit IoBinding(std::nullptr_t) {}
2896 explicit IoBinding(Session& session);
2897 ConstIoBinding GetConst() const { return ConstIoBinding{this->p_}; }
2898 UnownedIoBinding GetUnowned() const { return UnownedIoBinding{this->p_}; }
2899};
2900
2905struct ArenaCfg : detail::Base<OrtArenaCfg> {
2906 explicit ArenaCfg(std::nullptr_t) {}
2915 ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk);
2916
2921 explicit ArenaCfg(const std::unordered_map<std::string, size_t>& arena_config);
2922};
2923
2924//
2925// Custom OPs (only needed to implement custom OPs)
2926//
2927
2928namespace detail {
2929// Need to define a templated ConstOpAttr with const members
2930template <typename T>
2933 using B::B;
2934
2935 // Wraps OrtApi::OpAttr_GetName
2936 std::string GetName() const;
2937 // Wraps OrtApi::OpAttr_GetType
2939
2940 // Wraps OrtApi::ReadAttr for a single value
2941 // This does not support Tensor Attribute
2942 // Call GetTensorAttributeAsOrtValue() instead.
2943 template <typename R>
2944 Status GetValue(R& out) const;
2945
2946 // Wraps OrtApi::ReadAttr for an array of values
2947 template <typename R>
2948 Status GetValueArray(std::vector<R>& out) const;
2949 // Wraps OrtApi::OpAttr_GetTensorAttributeAsOrtValue
2951};
2952} // namespace detail
2953
2955
2959struct OpAttr : detail::ConstOpAttrImpl<OrtOpAttr> {
2961 using Base::Base;
2962
2963 OpAttr() = default; // Enable storing it in the container for resize()
2964 explicit OpAttr(std::nullptr_t) {}
2965 OpAttr(const char* name, const void* data, int len, OrtOpAttrType type);
2966
2967 ConstOpAttr GetConst() const { return ConstOpAttr{this->p_}; }
2968};
2969
2978#define ORT_CXX_LOG(logger, message_severity, message) \
2979 do { \
2980 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2981 Ort::ThrowOnError(logger.LogMessage(message_severity, ORT_FILE, __LINE__, \
2982 static_cast<const char*>(__FUNCTION__), message)); \
2983 } \
2984 } while (false)
2985
2994#define ORT_CXX_LOG_NOEXCEPT(logger, message_severity, message) \
2995 do { \
2996 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2997 static_cast<void>(logger.LogMessage(message_severity, ORT_FILE, __LINE__, \
2998 static_cast<const char*>(__FUNCTION__), message)); \
2999 } \
3000 } while (false)
3001
3013#define ORT_CXX_LOGF(logger, message_severity, /*format,*/...) \
3014 do { \
3015 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
3016 Ort::ThrowOnError(logger.LogFormattedMessage(message_severity, ORT_FILE, __LINE__, \
3017 static_cast<const char*>(__FUNCTION__), __VA_ARGS__)); \
3018 } \
3019 } while (false)
3020
3032#define ORT_CXX_LOGF_NOEXCEPT(logger, message_severity, /*format,*/...) \
3033 do { \
3034 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
3035 static_cast<void>(logger.LogFormattedMessage(message_severity, ORT_FILE, __LINE__, \
3036 static_cast<const char*>(__FUNCTION__), __VA_ARGS__)); \
3037 } \
3038 } while (false)
3039
3050struct Logger {
3054 Logger() = default;
3055
3059 explicit Logger(std::nullptr_t) {}
3060
3067 explicit Logger(const OrtLogger* logger);
3068
3069 ~Logger() = default;
3070
3071 Logger(const Logger&) = default;
3072 Logger& operator=(const Logger&) = default;
3073
3074 Logger(Logger&& v) noexcept = default;
3075 Logger& operator=(Logger&& v) noexcept = default;
3076
3083
3096 Status LogMessage(OrtLoggingLevel log_severity_level, const ORTCHAR_T* file_path, int line_number,
3097 const char* func_name, const char* message) const noexcept;
3098
3113 template <typename... Args>
3114 Status LogFormattedMessage(OrtLoggingLevel log_severity_level, const ORTCHAR_T* file_path, int line_number,
3115 const char* func_name, const char* format, Args&&... args) const noexcept;
3116
3117 private:
3118 const OrtLogger* logger_{};
3119 OrtLoggingLevel cached_severity_level_{};
3120};
3121
3130 size_t GetInputCount() const;
3131 size_t GetOutputCount() const;
3132 // If input is optional and is not present, the method returns an empty ConstValue
3133 // which can be compared to nullptr.
3134 ConstValue GetInput(size_t index) const;
3135 // If output is optional and is not present, the method returns an empty UnownedValue
3136 // which can be compared to nullptr.
3137 UnownedValue GetOutput(size_t index, const int64_t* dim_values, size_t dim_count) const;
3138 UnownedValue GetOutput(size_t index, const std::vector<int64_t>& dims) const;
3140 void* GetGPUComputeStream() const;
3143 Ort::Allocator GetAllocator(const OrtMemoryInfo& memory_info) const;
3144 OrtKernelContext* GetOrtKernelContext() const { return ctx_; }
3145 void ParallelFor(void (*fn)(void*, size_t), size_t total, size_t num_batch, void* usr_data) const;
3146
3147 private:
3148 OrtKernelContext* ctx_;
3149};
3150
3151struct KernelInfo;
3152
3153namespace detail {
3154namespace attr_utils {
3155void GetAttr(const OrtKernelInfo* p, const char* name, float&);
3156void GetAttr(const OrtKernelInfo* p, const char* name, int64_t&);
3157void GetAttr(const OrtKernelInfo* p, const char* name, std::string&);
3158void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<float>&);
3159void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<int64_t>&);
3160void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<std::string>&);
3161} // namespace attr_utils
3162
3163template <typename T>
3164struct KernelInfoImpl : Base<T> {
3165 using B = Base<T>;
3166 using B::B;
3167
3168 KernelInfo Copy() const;
3169
3170 template <typename R> // R is only implemented for float, int64_t, and string
3171 R GetAttribute(const char* name) const {
3172 R val;
3173 attr_utils::GetAttr(this->p_, name, val);
3174 return val;
3175 }
3176
3177 template <typename R> // R is only implemented for float, int64_t, and string
3178 std::vector<R> GetAttributes(const char* name) const {
3179 std::vector<R> result;
3180 attr_utils::GetAttrs(this->p_, name, result);
3181 return result;
3182 }
3183
3184 Value GetTensorAttribute(const char* name, OrtAllocator* allocator) const;
3185
3186 size_t GetInputCount() const;
3187 size_t GetOutputCount() const;
3188
3189 std::string GetInputName(size_t index) const;
3190 std::string GetOutputName(size_t index) const;
3191
3192 TypeInfo GetInputTypeInfo(size_t index) const;
3193 TypeInfo GetOutputTypeInfo(size_t index) const;
3194
3195 ConstValue GetTensorConstantInput(size_t index, int* is_constant) const;
3196
3197 std::string GetNodeName() const;
3198 Logger GetLogger() const;
3199
3200 KeyValuePairs GetConfigEntries() const;
3201
3202 std::string GetOperatorDomain() const;
3203 std::string GetOperatorType() const;
3204 int GetOperatorSinceVersion() const;
3205 const OrtEp* GetEp() const;
3206};
3207
3208} // namespace detail
3209
3210using ConstKernelInfo = detail::KernelInfoImpl<detail::Unowned<const OrtKernelInfo>>;
3211
3218struct KernelInfo : detail::KernelInfoImpl<OrtKernelInfo> {
3219 using Base = detail::KernelInfoImpl<OrtKernelInfo>;
3220 using Base::Base;
3221 explicit KernelInfo(std::nullptr_t) {}
3222 explicit KernelInfo(OrtKernelInfo* info);
3223 ConstKernelInfo GetConst() const { return ConstKernelInfo{this->p_}; }
3224};
3225
3229struct Op : detail::Base<OrtOp> {
3231 using Base::Base;
3232
3233 explicit Op(std::nullptr_t) {}
3234
3235 explicit Op(OrtOp*);
3236
3237 static Op Create(const OrtKernelInfo* info, const char* op_name, const char* domain,
3238 int version, const char** type_constraint_names,
3239 const ONNXTensorElementDataType* type_constraint_values,
3240 size_t type_constraint_count,
3241 const OpAttr* attr_values,
3242 size_t attr_count,
3243 size_t input_count, size_t output_count);
3244
3245 void Invoke(const OrtKernelContext* context,
3246 const Value* input_values,
3247 size_t input_count,
3248 Value* output_values,
3249 size_t output_count);
3250
3251 // For easier refactoring
3252 void Invoke(const OrtKernelContext* context,
3253 const OrtValue* const* input_values,
3254 size_t input_count,
3255 OrtValue* const* output_values,
3256 size_t output_count);
3257};
3258
3264 SymbolicInteger(int64_t i) : i_(i), is_int_(true) {};
3265 SymbolicInteger(const char* s) : s_(s), is_int_(false) {};
3268
3271
3272 bool operator==(const SymbolicInteger& dim) const {
3273 if (is_int_ == dim.is_int_) {
3274 if (is_int_) {
3275 return i_ == dim.i_;
3276 } else {
3277 return std::string{s_} == std::string{dim.s_};
3278 }
3279 }
3280 return false;
3281 }
3282
3283 bool IsInt() const { return is_int_; }
3284 int64_t AsInt() const { return i_; }
3285 const char* AsSym() const { return s_; }
3286
3287 static constexpr int INVALID_INT_DIM = -2;
3288
3289 private:
3290 union {
3291 int64_t i_;
3292 const char* s_;
3293 };
3294 bool is_int_;
3295 };
3296
3297 using Shape = std::vector<SymbolicInteger>;
3298
3300
3301 const Shape& GetInputShape(size_t indice) const { return input_shapes_.at(indice); }
3302
3303 size_t GetInputCount() const { return input_shapes_.size(); }
3304
3306
3307 int64_t GetAttrInt(const char* attr_name);
3308
3309 using Ints = std::vector<int64_t>;
3310 Ints GetAttrInts(const char* attr_name);
3311
3312 float GetAttrFloat(const char* attr_name);
3313
3314 using Floats = std::vector<float>;
3315 Floats GetAttrFloats(const char* attr_name);
3316
3317 std::string GetAttrString(const char* attr_name);
3318
3319 using Strings = std::vector<std::string>;
3320 Strings GetAttrStrings(const char* attr_name);
3321
3322 private:
3323 ConstOpAttr GetAttrHdl(const char* attr_name) const;
3324 const OrtApi* ort_api_;
3326 std::vector<Shape> input_shapes_;
3327};
3328
3330
3331#define MAX_CUSTOM_OP_END_VER (1UL << 31) - 1
3332
3333template <typename TOp, typename TKernel, bool WithStatus = false>
3337 OrtCustomOp::GetName = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetName(); };
3338
3339 OrtCustomOp::GetExecutionProviderType = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetExecutionProviderType(); };
3340
3341 OrtCustomOp::GetInputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetInputTypeCount(); };
3342 OrtCustomOp::GetInputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputType(index); };
3343 OrtCustomOp::GetInputMemoryType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputMemoryType(index); };
3344
3345 OrtCustomOp::GetOutputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetOutputTypeCount(); };
3346 OrtCustomOp::GetOutputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputType(index); };
3347
3348#if defined(_MSC_VER) && !defined(__clang__)
3349#pragma warning(push)
3350#pragma warning(disable : 26409)
3351#endif
3352 OrtCustomOp::KernelDestroy = [](void* op_kernel) { delete static_cast<TKernel*>(op_kernel); };
3353#if defined(_MSC_VER) && !defined(__clang__)
3354#pragma warning(pop)
3355#endif
3356 OrtCustomOp::GetInputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputCharacteristic(index); };
3357 OrtCustomOp::GetOutputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputCharacteristic(index); };
3358
3359 OrtCustomOp::GetVariadicInputMinArity = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetVariadicInputMinArity(); };
3360 OrtCustomOp::GetVariadicInputHomogeneity = [](const OrtCustomOp* this_) { return static_cast<int>(static_cast<const TOp*>(this_)->GetVariadicInputHomogeneity()); };
3361 OrtCustomOp::GetVariadicOutputMinArity = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetVariadicOutputMinArity(); };
3362 OrtCustomOp::GetVariadicOutputHomogeneity = [](const OrtCustomOp* this_) { return static_cast<int>(static_cast<const TOp*>(this_)->GetVariadicOutputHomogeneity()); };
3363#ifdef __cpp_if_constexpr
3364 if constexpr (WithStatus) {
3365#else
3366 if (WithStatus) {
3367#endif
3368 OrtCustomOp::CreateKernelV2 = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info, void** op_kernel) -> OrtStatusPtr {
3369 return static_cast<const TOp*>(this_)->CreateKernelV2(*api, info, op_kernel);
3370 };
3371 OrtCustomOp::KernelComputeV2 = [](void* op_kernel, OrtKernelContext* context) -> OrtStatusPtr {
3372 return static_cast<TKernel*>(op_kernel)->ComputeV2(context);
3373 };
3374 } else {
3377
3378 OrtCustomOp::CreateKernel = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info) { return static_cast<const TOp*>(this_)->CreateKernel(*api, info); };
3379 OrtCustomOp::KernelCompute = [](void* op_kernel, OrtKernelContext* context) {
3380 static_cast<TKernel*>(op_kernel)->Compute(context);
3381 };
3382 }
3383
3384 SetShapeInferFn<TOp>(0);
3385
3386 OrtCustomOp::GetStartVersion = [](const OrtCustomOp* this_) {
3387 return static_cast<const TOp*>(this_)->start_ver_;
3388 };
3389
3390 OrtCustomOp::GetEndVersion = [](const OrtCustomOp* this_) {
3391 return static_cast<const TOp*>(this_)->end_ver_;
3392 };
3393
3396 OrtCustomOp::GetAliasMap = nullptr;
3398 }
3399
3400 // Default implementation of GetExecutionProviderType that returns nullptr to default to the CPU provider
3401 const char* GetExecutionProviderType() const { return nullptr; }
3402
3403 // Default implementations of GetInputCharacteristic() and GetOutputCharacteristic() below
3404 // (inputs and outputs are required by default)
3406 return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED;
3407 }
3408
3410 return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED;
3411 }
3412
3413 // Default implementation of GetInputMemoryType() that returns OrtMemTypeDefault
3414 OrtMemType GetInputMemoryType(size_t /*index*/) const {
3415 return OrtMemTypeDefault;
3416 }
3417
3418 // Default implementation of GetVariadicInputMinArity() returns 1 to specify that a variadic input
3419 // should expect at least 1 argument.
3421 return 1;
3422 }
3423
3424 // Default implementation of GetVariadicInputHomegeneity() returns true to specify that all arguments
3425 // to a variadic input should be of the same type.
3427 return true;
3428 }
3429
3430 // Default implementation of GetVariadicOutputMinArity() returns 1 to specify that a variadic output
3431 // should produce at least 1 output value.
3433 return 1;
3434 }
3435
3436 // Default implementation of GetVariadicOutputHomegeneity() returns true to specify that all output values
3437 // produced by a variadic output should be of the same type.
3439 return true;
3440 }
3441
3442 // Declare list of session config entries used by this Custom Op.
3443 // Implement this function in order to get configs from CustomOpBase::GetSessionConfigs().
3444 // This default implementation returns an empty vector of config entries.
3445 std::vector<std::string> GetSessionConfigKeys() const {
3446 return std::vector<std::string>{};
3447 }
3448
3449 // Ort::CustomOpBase derived class should provide the following static method with the type/shape inferencing
3450 // implementation if needed:
3451 // static OrtStatusPtr InferOutputShape(Ort::ShapeInferContext& context)
3452 template <typename C>
3453 decltype(&C::InferOutputShape) SetShapeInferFn(decltype(&C::InferOutputShape)) {
3455 ShapeInferContext ctx(&GetApi(), ort_ctx);
3456 return C::InferOutputShape(ctx);
3457 };
3458 return {};
3459 }
3460
3461 template <typename C>
3465
3466 protected:
3467 // Helper function that returns a map of session config entries specified by CustomOpBase::GetSessionConfigKeys.
3468 void GetSessionConfigs(std::unordered_map<std::string, std::string>& out, ConstSessionOptions options) const;
3469
3470 int start_ver_ = 1;
3471 int end_ver_ = MAX_CUSTOM_OP_END_VER;
3472};
3473
3474// Forward declaration to resolve circular dependency
3475// on ConstNode
3477
3478namespace detail {
3479template <typename T>
3481 using B = Base<T>;
3482 using B::B;
3483
3485 std::string GetName() const;
3491 std::vector<ValueInfoConsumerProducerInfo> GetConsumers() const;
3501 bool IsGraphOutput() const;
3505 bool IsFromOuterScope() const;
3506};
3507} // namespace detail
3508
3509// Const object holder that does not own the underlying object
3511
3516 ValueInfo() = default; // Same thing as with nullptr
3517 explicit ValueInfo(std::nullptr_t) {}
3519 explicit ValueInfo(OrtValueInfo* p) : ConstValueInfoImpl<OrtValueInfo>{p} {}
3520
3521#if !defined(ORT_MINIMAL_BUILD)
3522 // Create ValueInfo for a tensor
3523 explicit ValueInfo(const std::string& name, const ConstTypeInfo& type_info);
3524#endif
3525 ConstValueInfo GetConst() const { return ConstValueInfo{this->p_}; }
3526};
3527
3528// Forward declaration
3529struct AttrNameSubgraph;
3530
3531namespace detail {
3532// Forward decl
3533template <typename T>
3534struct ConstGraphImpl;
3535
3536template <typename T>
3537struct ConstNodeImpl : Base<T> {
3538 using B = Base<T>;
3539 using B::B;
3540
3541 // <Wraps OrtApi::Node_GetId
3542 size_t GetId() const;
3543 // <Wraps OrtApi::Node_GetName
3544 std::string GetName() const;
3545 // <Wraps OrtApi::Node_GetOperatorType
3546 std::string GetOperatorType() const;
3547 // <Wraps OrtApi::Node_GetDomain
3548 std::string GetDomain() const;
3549 // <Wraps OrtApi::Node_GetSinceVersion
3550 int GetSinceVersion() const;
3551
3552 // <Wraps OrtApi::Node_Inputs
3553 std::vector<ConstValueInfo> GetInputs() const;
3554 // <Wraps OrtApi::Node_Outputs
3555 std::vector<ConstValueInfo> GetOutputs() const;
3556 // <Wraps OrtApi::Node_ImplicitInputs
3557 std::vector<ConstValueInfo> GetImplicitInputs() const;
3558 // <Wraps OrtApi::Node_GetAttributes
3559 std::vector<ConstOpAttr> GetAttributes() const;
3560 // <Wraps OrtApi::Node_GetAttributeByName
3561 // Please, read C API doc for details
3562 Status GetAttributeByName(const std::string& name, ConstOpAttr& attr) const;
3563 // <Wraps OrtApi::Node_GetSubgraphs
3564 std::vector<AttrNameSubgraph> GetSubgraphs() const;
3565 // <Wraps OrtApi::Node_GetGraph
3566 // ConstGraph is not available yet
3568 // <Wraps OrtApi::Node_GetEpName
3569 std::string GetEpName() const;
3570};
3571} // namespace detail
3572
3574
3578struct Node : detail::ConstNodeImpl<OrtNode> {
3579 Node() = default; // Same thing as with nullptr
3580 explicit Node(std::nullptr_t) {}
3581 explicit Node(OrtNode* p) : ConstNodeImpl<OrtNode>{p} {}
3582
3583#if !defined(ORT_MINIMAL_BUILD)
3584 Node(const std::string& operator_name, const std::string& operator_domain,
3585 const std::string& node_name,
3586 const std::vector<std::string>& input_names,
3587 const std::vector<std::string>& output_names);
3588
3592 Node(const std::string& operator_name, const std::string& operator_domain,
3593 const std::string& node_name,
3594 const std::vector<std::string>& input_names,
3595 const std::vector<std::string>& output_names,
3596 std::vector<OpAttr>& attributes);
3597
3598 private:
3599 static void Init(const std::string& operator_name, const std::string& operator_domain,
3600 const std::string& node_name,
3601 const std::vector<std::string>& input_names,
3602 const std::vector<std::string>& output_names,
3603 std::vector<OpAttr>& attributes,
3604 OrtNode*& node);
3605#endif // !defined(ORT_MINIMAL_BUILD)
3606};
3607
3608// Return struct for some of ValueInfo APIs.
3609// Must be declared after ConstNode is available.
3612 // either producer output or consumer output index
3613 // producer is unsigned only, output can be -1
3614 int64_t index;
3615};
3616
3617// Represents a return value for Graph::GetOperatorSets()
3619 std::string domain;
3620 int64_t version;
3621};
3622
3623namespace detail {
3624template <typename T>
3626 using B = Base<T>;
3627 using B::B;
3628
3629 // <Wraps OrtApi::Graph_GetName
3630 std::string GetName() const;
3631 // <Wraps OrtApi::Graph_GetModelPath
3632 std::basic_string<ORTCHAR_T> GetModelPath() const;
3633 // <Wraps OrtApi::Graph_GetOnnxIRVersion
3634 int64_t GetOnnxIRVersion() const;
3635 // <Wraps OrtApi::Graph_GetOperatorSets
3636 std::vector<OperatorSet> GetOperatorSets() const;
3637 // <Wraps OrtApi::Graph_Inputs
3638 std::vector<ConstValueInfo> GetInputs() const;
3639 // <Wraps OrtApi::Graph_Outputs
3640 std::vector<ConstValueInfo> GetOutputs() const;
3641 // <Wraps OrtApi::Graph_Initializers
3642 std::vector<ConstValueInfo> GetInitializers() const;
3643 // <Wraps OrtApi::Graph_GetNodes
3644 std::vector<ConstNode> GetNodes() const;
3645 // <Wraps OrtApi::Graph_GetParentGraph
3647 // <Wraps OrtApi::Graph_GetGraphView
3648 Graph GetGraphView(const std::vector<ConstNode>& nodes) const;
3649 // <Wraps OrtApi::Graph_GetModelMetadata
3651};
3652
3653template <typename T>
3656 using B::B;
3657
3658#if !defined(ORT_MINIMAL_BUILD)
3662 void SetInputs(std::vector<ValueInfo>& inputs);
3666 void SetOutputs(std::vector<ValueInfo>& outputs);
3670 void AddInitializer(const std::string& name, Value& initializer, bool data_is_external); // Graph takes ownership of Value
3674 void AddNode(Node& node); // Graph takes ownership of Node
3675#endif // !defined(ORT_MINIMAL_BUILD)
3676};
3677} // namespace detail
3678
3680
3681// Return value for Node API
3682// Must be declared after ConstGraph
3687
3691struct Graph : detail::GraphImpl<OrtGraph> {
3692 explicit Graph(std::nullptr_t) {}
3693 explicit Graph(OrtGraph* p) : GraphImpl<OrtGraph>{p} {}
3694#if !defined(ORT_MINIMAL_BUILD)
3695 // <Wraps GetModelEditorApi().CreateGraph()
3697#endif
3698};
3699
3700namespace detail {
3701template <typename T>
3704 using B::B;
3705
3706#if !defined(ORT_MINIMAL_BUILD)
3710 void AddGraph(Graph& graph);
3711#endif
3712};
3713} // namespace detail
3714
3715// Const object holder that does not own the underlying object
3717
3721struct Model : detail::ModelImpl<OrtModel> {
3722 using DomainOpsetPair = std::pair<std::string, int>;
3723
3724 explicit Model(std::nullptr_t) {}
3725 explicit Model(OrtModel* p) : ModelImpl<OrtModel>{p} {}
3726
3727#if !defined(ORT_MINIMAL_BUILD)
3728 //< Wraps GetModelEditorApi().CreateModel()
3729 explicit Model(const std::vector<DomainOpsetPair>& opsets);
3730#endif
3731};
3732
3733namespace detail {
3734template <typename T>
3736 using B = Base<T>;
3737 using B::B;
3738
3740 const char* GetOperatorType() const;
3741
3743 const char* GetDomain() const;
3744
3746 std::pair<int, int> GetSinceVersion() const;
3747
3749 const char* GetExecutionProvider() const;
3750
3752 OrtMemType GetInputMemType(size_t input_index) const;
3753
3755 OrtMemType GetOutputMemType(size_t output_index) const;
3756};
3757} // namespace detail
3758
3760
3763 using Base::Base;
3764
3765 explicit KernelDef(std::nullptr_t) {}
3766 explicit KernelDef(OrtKernelDef* p) : detail::ConstKernelDefImpl<OrtKernelDef>{p} {}
3767
3768 ConstKernelDef GetConst() const { return ConstKernelDef{this->p_}; }
3769};
3770
3775struct KernelDefBuilder : detail::Base<OrtKernelDefBuilder> {
3777 explicit KernelDefBuilder(std::nullptr_t) {}
3778 explicit KernelDefBuilder(OrtKernelDefBuilder* ort_kernel_def_builder);
3779
3780 KernelDefBuilder& SetOperatorType(const char* op_type);
3781 KernelDefBuilder& SetDomain(const char* domain);
3782 KernelDefBuilder& SetSinceVersion(int since_version_start, int since_version_end);
3784 KernelDefBuilder& SetInputMemType(size_t input_index, OrtMemType mem_type);
3785 KernelDefBuilder& SetOutputMemType(size_t output_index, OrtMemType mem_type);
3786 KernelDefBuilder& AddTypeConstraint(const char* arg_name, const OrtDataType* data_type);
3787 KernelDefBuilder& AddTypeConstraint(const char* arg_name, const std::vector<const OrtDataType*>& data_types);
3788 KernelDefBuilder& AddInputOutputAlias(int input_index, int output_index);
3789 KernelDefBuilder& AddInputOutputAliases(const std::vector<int>& input_indices,
3790 const std::vector<int>& output_indices);
3791 KernelDefBuilder& AddInputOutputMutableAlias(int input_index, int output_index);
3792 KernelDefBuilder& AddInputOutputMutableAliases(const std::vector<int>& input_indices,
3793 const std::vector<int>& output_indices);
3794
3796};
3797
3802struct KernelRegistry : detail::Base<OrtKernelRegistry> {
3805
3807 explicit KernelRegistry(std::nullptr_t) {}
3808
3810 explicit KernelRegistry(OrtKernelRegistry* ort_kernel_registry);
3811
3813 Status AddKernel(const OrtKernelDef* kernel_def, OrtKernelCreateFunc kernel_create_func,
3814 void* kernel_create_func_state);
3815};
3816
3817namespace detail {
3818template <typename T>
3820 using B = Base<T>;
3821 using B::B;
3822
3824 std::string GetTypeParamName() const;
3825
3827 std::vector<std::string> GetAllowedTypes() const;
3828
3830 std::vector<size_t> GetInputIndices() const;
3831
3833 std::vector<size_t> GetOutputIndices() const;
3834};
3835} // namespace detail
3836
3841
3842namespace detail {
3843template <typename T>
3844struct OpSchemaImpl : Base<T> {
3845 using B = Base<T>;
3846 using B::B;
3847
3849 int GetSinceVersion() const;
3850
3852 size_t GetNumInputs() const;
3853
3855 std::string GetInputName(size_t index) const;
3856
3860
3862 size_t GetNumOutputs() const;
3863
3865 std::string GetOutputName(size_t index) const;
3866
3870
3873
3876};
3877} // namespace detail
3878
3884
3890OpSchema GetOpSchema(const char* name, int max_inclusive_version, const char* domain);
3891
3892namespace detail {
3893template <typename T>
3896 using B::B;
3897
3898 //< Wraps SharedPrePackedWeightCache_StoreWeightData
3899 Status StoreWeightData(void** buffer_data_ptrs, size_t* buffer_sizes, size_t num_buffers);
3900};
3901} // namespace detail
3902
3920
3923
3924} // namespace Ort
3925#include "onnxruntime_cxx_inline.h"
struct OrtMemoryInfo OrtMemoryInfo
Definition onnxruntime_c_api.h:298
struct OrtKernelInfo OrtKernelInfo
Definition onnxruntime_c_api.h:488
struct OrtNode OrtNode
Definition onnxruntime_c_api.h:326
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:523
struct OrtShapeInferContext OrtShapeInferContext
Definition onnxruntime_c_api.h:323
void(* OrtLoggingFunction)(void *param, OrtLoggingLevel severity, const char *category, const char *logid, const char *code_location, const char *message)
Definition onnxruntime_c_api.h:452
void(* OrtCustomJoinThreadFn)(OrtCustomThreadHandle ort_custom_thread_handle)
Custom thread join function.
Definition onnxruntime_c_api.h:1047
OrtCustomOpInputOutputCharacteristic
Definition onnxruntime_c_api.h:7726
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:325
struct OrtDnnlProviderOptions OrtDnnlProviderOptions
Definition onnxruntime_c_api.h:319
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:1273
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:577
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:335
OrtAllocatorType
Definition onnxruntime_c_api.h:494
struct OrtOp OrtOp
Definition onnxruntime_c_api.h:320
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:614
struct OrtTensorTypeAndShapeInfo OrtTensorTypeAndShapeInfo
Definition onnxruntime_c_api.h:304
struct OrtCUDAProviderOptionsV2 OrtCUDAProviderOptionsV2
Definition onnxruntime_c_api.h:317
struct OrtProfilingEvent OrtProfilingEvent
Definition onnxruntime_ep_c_api.h:35
struct OrtKernelContext OrtKernelContext
Definition onnxruntime_c_api.h:490
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:634
struct OrtCANNProviderOptions OrtCANNProviderOptions
Definition onnxruntime_c_api.h:318
struct OrtEpDevice OrtEpDevice
Definition onnxruntime_c_api.h:332
void(* RunAsyncCallbackFn)(void *user_data, OrtValue **outputs, size_t num_outputs, OrtStatusPtr status)
Callback function for RunAsync.
Definition onnxruntime_c_api.h:1121
OrtHardwareDeviceType
Definition onnxruntime_c_api.h:530
struct OrtModel OrtModel
Definition onnxruntime_c_api.h:328
struct OrtGraph OrtGraph
Definition onnxruntime_c_api.h:327
struct OrtSyncStream OrtSyncStream
Definition onnxruntime_c_api.h:334
struct OrtSessionOptions OrtSessionOptions
Definition onnxruntime_c_api.h:308
OrtDeviceMemoryType
This matches OrtDevice::MemoryType values.
Definition onnxruntime_c_api.h:516
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:596
GraphOptimizationLevel
Graph optimization level.
Definition onnxruntime_c_api.h:461
struct OrtKeyValuePairs OrtKeyValuePairs
Definition onnxruntime_c_api.h:333
OrtStatus * OrtStatusPtr
Definition onnxruntime_c_api.h:349
OrtMemType
Memory types for allocated memory, execution provider specific types should be extended in each provi...
Definition onnxruntime_c_api.h:504
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:339
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:685
#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:322
struct OrtMapTypeInfo OrtMapTypeInfo
Definition onnxruntime_c_api.h:305
struct OrtArenaCfg OrtArenaCfg
Definition onnxruntime_c_api.h:313
ExecutionMode
Definition onnxruntime_c_api.h:469
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:1040
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:538
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
@ OrtMemTypeDefault
The default allocator for execution provider.
Definition onnxruntime_c_api.h:512
@ 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:1761
detail::KernelInfoImpl< detail::Unowned< const OrtKernelInfo > > ConstKernelInfo
Definition onnxruntime_cxx_api.h:3210
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:1760
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:3329
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:2905
ArenaCfg(std::nullptr_t)
Create an empty ArenaCfg object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:2906
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:3683
ConstGraph sub_graph
Definition onnxruntime_cxx_api.h:3685
std::string attr_name
Definition onnxruntime_cxx_api.h:3684
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:3334
OrtCustomOpInputOutputCharacteristic GetOutputCharacteristic(size_t) const
Definition onnxruntime_cxx_api.h:3409
OrtCustomOpInputOutputCharacteristic GetInputCharacteristic(size_t) const
Definition onnxruntime_cxx_api.h:3405
OrtMemType GetInputMemoryType(size_t) const
Definition onnxruntime_cxx_api.h:3414
std::vector< std::string > GetSessionConfigKeys() const
Definition onnxruntime_cxx_api.h:3445
bool GetVariadicInputHomogeneity() const
Definition onnxruntime_cxx_api.h:3426
int GetVariadicInputMinArity() const
Definition onnxruntime_cxx_api.h:3420
void SetShapeInferFn(...)
Definition onnxruntime_cxx_api.h:3462
CustomOpBase()
Definition onnxruntime_cxx_api.h:3335
bool GetVariadicOutputHomogeneity() const
Definition onnxruntime_cxx_api.h:3438
int GetVariadicOutputMinArity() const
Definition onnxruntime_cxx_api.h:3432
decltype(&C::InferOutputShape) SetShapeInferFn(decltype(&C::InferOutputShape))
Definition onnxruntime_cxx_api.h:3453
const char * GetExecutionProviderType() const
Definition onnxruntime_cxx_api.h:3401
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:1603
~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:1484
CustomOpDomain(std::nullptr_t)
Create an empty CustomOpDomain object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1488
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:1385
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:1405
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:1386
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:1779
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:1783
void GetReadFunc(OrtReadNamedBufferFunc &read_func, void *&state) const
Wraps OrtEpApi::EpContextConfigGetEpContextDataReadFunc.
Mutable EpDevice that is created by EpApi users.
Definition onnxruntime_cxx_api.h:1200
EpDevice(OrtEpDevice *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:1202
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:1201
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:3691
Graph(OrtGraph *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:3693
Graph(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:3692
Wrapper around OrtIoBinding.
Definition onnxruntime_cxx_api.h:2894
UnownedIoBinding GetUnowned() const
Definition onnxruntime_cxx_api.h:2898
ConstIoBinding GetConst() const
Definition onnxruntime_cxx_api.h:2897
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:2895
This class wraps a raw pointer OrtKernelContext* that is being passed to the custom kernel Compute() ...
Definition onnxruntime_cxx_api.h:3128
KernelContext(OrtKernelContext *context)
OrtSyncStream * GetSyncStream() const
Logger GetLogger() const
ConstValue GetInput(size_t index) const
OrtKernelContext * GetOrtKernelContext() const
Definition onnxruntime_cxx_api.h:3144
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:3775
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:3777
KernelDefBuilder(OrtKernelDefBuilder *ort_kernel_def_builder)
KernelDefBuilder & SetSinceVersion(int since_version_start, int since_version_end)
Definition onnxruntime_cxx_api.h:3761
KernelDef(OrtKernelDef *p)
Definition onnxruntime_cxx_api.h:3766
KernelDef(std::nullptr_t)
Definition onnxruntime_cxx_api.h:3765
ConstKernelDef GetConst() const
Definition onnxruntime_cxx_api.h:3768
This struct owns the OrtKernInfo* pointer when a copy is made. For convenient wrapping of OrtKernelIn...
Definition onnxruntime_cxx_api.h:3218
KernelInfo(OrtKernelInfo *info)
Take ownership of the instance.
ConstKernelInfo GetConst() const
Definition onnxruntime_cxx_api.h:3223
detail::KernelInfoImpl< OrtKernelInfo > Base
Definition onnxruntime_cxx_api.h:3219
KernelInfo(std::nullptr_t)
Create an empty instance to initialize later.
Definition onnxruntime_cxx_api.h:3221
Registry for kernels supported by an EP.
Definition onnxruntime_cxx_api.h:3802
KernelRegistry()
< Wrapper around OrtEpApi::CreateKernelRegistry
KernelRegistry(std::nullptr_t)
Take ownership of a pointer created with the C API.
Definition onnxruntime_cxx_api.h:3807
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:3050
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:3059
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:1498
static LoraAdapter CreateLoraAdapter(const std::basic_string< char > &adapter_path, OrtAllocator *allocator)
Wraps OrtApi::CreateLoraAdapter.
LoraAdapter(std::nullptr_t)
Definition onnxruntime_cxx_api.h:1502
static LoraAdapter CreateLoraAdapterFromArray(const void *bytes, size_t num_bytes, OrtAllocator *allocator)
Wraps OrtApi::CreateLoraAdapterFromArray.
Wrapper around OrtMapTypeInfo.
Definition onnxruntime_cxx_api.h:2276
ConstMapTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:2282
MapTypeInfo(OrtMapTypeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:2281
MapTypeInfo(std::nullptr_t)
Create an empty MapTypeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:2280
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:1796
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:1800
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 & 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)
Wraps OrtCompileApi::ModelCompilationOptions_SetInputModel.
ModelCompilationOptions & SetWeightlessEnabled(bool use_weightless)
Wraps OrtCompileApi::ModelCompilationOptions_SetWeightlessEnabled.
Wrapper around OrtModel.
Definition onnxruntime_cxx_api.h:3721
Model(const std::vector< DomainOpsetPair > &opsets)
Model(OrtModel *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:3725
std::pair< std::string, int > DomainOpsetPair
Definition onnxruntime_cxx_api.h:3722
Model(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:3724
Wrapper around OrtModelMetadata.
Definition onnxruntime_cxx_api.h:1900
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:1904
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:1884
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:1888
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:1865
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:1869
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:1855
ModelPackageOptions(const Env &env, ConstSessionOptions session_options)
ModelPackageOptions(std::nullptr_t)
Definition onnxruntime_cxx_api.h:1859
ModelPackageOptions(const Env &env, const SessionOptions &session_options)
Wrapper around OrtNode.
Definition onnxruntime_cxx_api.h:3578
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:3580
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:3581
This struct provides life time management for custom op attribute.
Definition onnxruntime_cxx_api.h:2959
OpAttr(const char *name, const void *data, int len, OrtOpAttrType type)
OpAttr()=default
OpAttr(std::nullptr_t)
Definition onnxruntime_cxx_api.h:2964
ConstOpAttr GetConst() const
Definition onnxruntime_cxx_api.h:2967
Create and own custom defined operation.
Definition onnxruntime_cxx_api.h:3229
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:3233
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:3618
std::string domain
Definition onnxruntime_cxx_api.h:3619
int64_t version
Definition onnxruntime_cxx_api.h:3620
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:1332
ProfilingEvent(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:1333
ConstProfilingEvent GetConst() const
Definition onnxruntime_cxx_api.h:1357
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:1334
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:1528
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:1529
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:2238
SequenceTypeInfo(std::nullptr_t)
Create an empty SequenceTypeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:2242
ConstSequenceTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:2244
SequenceTypeInfo(OrtSequenceTypeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:2243
Wrapper around OrtSession.
Definition onnxruntime_cxx_api.h:2134
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:2136
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:2165
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:2137
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:2164
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:1766
SessionOptions(std::nullptr_t)
Create an empty SessionOptions object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1767
UnownedSessionOptions GetUnowned() const
Definition onnxruntime_cxx_api.h:1770
SessionOptions()
Wraps OrtApi::CreateSessionOptions.
ConstSessionOptions GetConst() const
Definition onnxruntime_cxx_api.h:1771
SessionOptions(OrtSessionOptions *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1769
Definition onnxruntime_cxx_api.h:3263
SymbolicInteger & operator=(const SymbolicInteger &)=default
SymbolicInteger(const SymbolicInteger &)=default
int64_t AsInt() const
Definition onnxruntime_cxx_api.h:3284
int64_t i_
Definition onnxruntime_cxx_api.h:3291
const char * s_
Definition onnxruntime_cxx_api.h:3292
bool operator==(const SymbolicInteger &dim) const
Definition onnxruntime_cxx_api.h:3272
SymbolicInteger & operator=(SymbolicInteger &&)=default
SymbolicInteger(SymbolicInteger &&)=default
const char * AsSym() const
Definition onnxruntime_cxx_api.h:3285
SymbolicInteger(int64_t i)
Definition onnxruntime_cxx_api.h:3264
SymbolicInteger(const char *s)
Definition onnxruntime_cxx_api.h:3265
bool IsInt() const
Definition onnxruntime_cxx_api.h:3283
Provide access to per-node attributes and input shapes, so one could compute and set output shapes.
Definition onnxruntime_cxx_api.h:3262
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:3297
std::vector< float > Floats
Definition onnxruntime_cxx_api.h:3314
std::string GetAttrString(const char *attr_name)
std::vector< int64_t > Ints
Definition onnxruntime_cxx_api.h:3309
ShapeInferContext(const OrtApi *ort_api, OrtShapeInferContext *ctx)
int64_t GetAttrInt(const char *attr_name)
size_t GetInputCount() const
Definition onnxruntime_cxx_api.h:3303
std::vector< std::string > Strings
Definition onnxruntime_cxx_api.h:3319
Floats GetAttrFloats(const char *attr_name)
const Shape & GetInputShape(size_t indice) const
Definition onnxruntime_cxx_api.h:3301
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:2204
TensorTypeAndShapeInfo(std::nullptr_t)
Create an empty TensorTypeAndShapeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:2209
ConstTensorTypeAndShapeInfo GetConst() const
Definition onnxruntime_cxx_api.h:2220
TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:2211
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:2310
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:2315
static TypeInfo CreateMapTypeInfo(ONNXTensorElementDataType key_type, ConstTypeInfo value_type)
ConstTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:2326
TypeInfo(OrtTypeInfo *p)
C API Interop.
Definition onnxruntime_cxx_api.h:2316
Wrapper around OrtValue.
Definition onnxruntime_cxx_api.h:2683
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:2689
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:2694
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:2693
Definition onnxruntime_cxx_api.h:3610
int64_t index
Definition onnxruntime_cxx_api.h:3614
ConstNode node
Definition onnxruntime_cxx_api.h:3611
Wrapper around OrtValueInfo.
Definition onnxruntime_cxx_api.h:3515
ConstValueInfo GetConst() const
Definition onnxruntime_cxx_api.h:3525
ValueInfo(std::nullptr_t)
Definition onnxruntime_cxx_api.h:3517
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:3519
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:3625
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:2862
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:3735
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:3537
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:2931
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:1293
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:1975
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:2355
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:3480
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:1260
std::string GetDomain() const
std::string GetOperatorType() const
std::string GetName() const
Definition onnxruntime_cxx_api.h:1277
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.
SyncStream CreateSyncStream(ConstKeyValuePairs stream_options={}) const
ConstKeyValuePairs EpMetadata() const
Definition onnxruntime_cxx_api.h:3654
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:2873
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:2262
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:3702
void AddGraph(Graph &graph)
Definition onnxruntime_cxx_api.h:3844
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:3819
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:2249
TypeInfo GetOptionalElementType() const
Wraps OrtApi::CastOptionalTypeToContainedTypeInfo.
Definition onnxruntime_cxx_api.h:2338
const char ** str
Definition onnxruntime_cxx_api.h:2343
const int64_t * values_shape
Definition onnxruntime_cxx_api.h:2339
size_t values_shape_len
Definition onnxruntime_cxx_api.h:2340
const void * p_data
Definition onnxruntime_cxx_api.h:2342
Definition onnxruntime_cxx_api.h:1362
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:2225
TypeInfo GetSequenceElementType() const
Wraps OrtApi::GetSequenceElementType.
Definition onnxruntime_cxx_api.h:2039
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:2349
const int64_t * shape
Definition onnxruntime_cxx_api.h:2350
size_t shape_len
Definition onnxruntime_cxx_api.h:2351
Definition onnxruntime_cxx_api.h:3894
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:2170
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:2287
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:2541
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:368
void(* Free)(struct OrtAllocator *this_, void *p)
Free a block of memory previously allocated with OrtAllocator::Alloc.
Definition onnxruntime_c_api.h:375
const OrtApi *(* GetApi)(uint32_t version)
Get a pointer to the requested version of the OrtApi.
Definition onnxruntime_c_api.h:1007
The C API.
Definition onnxruntime_c_api.h:1375
const OrtModelPackageApi *(* GetModelPackageApi)(void)
Get the stable model package API table.
Definition onnxruntime_c_api.h:7708
const OrtEpApi *(* GetEpApi)(void)
Get the OrtEpApi instance for implementing an execution provider.
Definition onnxruntime_c_api.h:5855
const OrtInteropApi *(* GetInteropApi)(void)
Get the EP Interop API instance.
Definition onnxruntime_c_api.h:7112
const OrtCompileApi *(* GetCompileApi)(void)
Get the Compile API instance.
Definition onnxruntime_c_api.h:5587
void(* ReleaseTensorRTProviderOptions)(OrtTensorRTProviderOptionsV2 *input)
Release an OrtTensorRTProviderOptionsV2.
Definition onnxruntime_c_api.h:3634
const OrtModelEditorApi *(* GetModelEditorApi)(void)
Get the Model Editor API instance.
Definition onnxruntime_c_api.h:5529
void(* ReleaseCUDAProviderOptions)(OrtCUDAProviderOptionsV2 *input)
Release an OrtCUDAProviderOptionsV2.
Definition onnxruntime_c_api.h:4137
CUDA Provider Options.
Definition onnxruntime_c_api.h:704
The OrtCompileApi struct provides functions to compile ONNX models.
Definition onnxruntime_c_api.h:8290
Definition onnxruntime_c_api.h:7736
int(* GetVariadicInputHomogeneity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7785
OrtCustomOpInputOutputCharacteristic(* GetOutputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7769
size_t(* GetInputTypeCount)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7757
int(* GetVariadicOutputMinArity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7789
size_t(* GetAliasMap)(int **input_index, int **output_index)
Definition onnxruntime_c_api.h:7822
int(* GetStartVersion)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7807
void(* ReleaseMayInplace)(int *input_index, int *output_index)
Definition onnxruntime_c_api.h:7819
const char *(* GetName)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7750
size_t(* GetOutputTypeCount)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7759
void(* KernelDestroy)(void *op_kernel)
Definition onnxruntime_c_api.h:7765
int(* GetVariadicOutputHomogeneity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7794
OrtMemType(* GetInputMemoryType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7776
void *(* CreateKernel)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info)
Definition onnxruntime_c_api.h:7746
uint32_t version
Definition onnxruntime_c_api.h:7737
ONNXTensorElementDataType(* GetInputType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7756
void(* ReleaseAliasMap)(int *input_index, int *output_index)
Definition onnxruntime_c_api.h:7823
OrtCustomOpInputOutputCharacteristic(* GetInputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7768
const char *(* GetExecutionProviderType)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7753
ONNXTensorElementDataType(* GetOutputType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7758
int(* GetVariadicInputMinArity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7780
OrtStatusPtr(* InferOutputShapeFn)(const struct OrtCustomOp *op, OrtShapeInferContext *)
Definition onnxruntime_c_api.h:7804
int(* GetEndVersion)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7808
OrtStatusPtr(* CreateKernelV2)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info, void **kernel)
Definition onnxruntime_c_api.h:7797
size_t(* GetMayInplace)(int **input_index, int **output_index)
Definition onnxruntime_c_api.h:7815
OrtStatusPtr(* KernelComputeV2)(void *op_kernel, OrtKernelContext *context)
Definition onnxruntime_c_api.h:7802
void(* KernelCompute)(void *op_kernel, OrtKernelContext *context)
Definition onnxruntime_c_api.h:7764
Configuration options for creating an OrtEnv.
Definition onnxruntime_c_api.h:1287
The OrtEpApi struct provides functions that are relevant to the implementation of an execution provid...
Definition onnxruntime_ep_c_api.h:1021
The OrtEpFactory provides functions to create and manage execution providers.
Definition onnxruntime_ep_c_api.h:2842
The OrtEp struct provides functions to implement for an execution provider.
Definition onnxruntime_ep_c_api.h:2220
The OrtInteropApi struct provides functions for external resource interop with execution providers.
Definition onnxruntime_c_api.h:8686
MIGraphX Provider Options.
Definition onnxruntime_c_api.h:908
The OrtModelEditorApi struct provides functions to create or edit an ONNX model.
Definition onnxruntime_c_api.h:7837
Stable API table for model package workflows.
Definition onnxruntime_c_api.h:8931
OpenVINO Provider Options.
Definition onnxruntime_c_api.h:947
ROCM Provider Options.
Definition onnxruntime_c_api.h:791
TensorRT Provider Options.
Definition onnxruntime_c_api.h:880
Configuration for thread pool work callbacks.
Definition onnxruntime_c_api.h:1100