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
257inline const OrtEpApi& GetEpApi() {
258 auto* api = GetApi().GetEpApi();
259 if (api == nullptr) {
260 // minimal build
261 ORT_CXX_API_THROW("EP API is not available in this build", ORT_FAIL);
262 }
263
264 return *api;
265}
266
285struct Float16_t : onnxruntime_float16::Float16Impl<Float16_t> {
286 private:
292 constexpr explicit Float16_t(uint16_t v) noexcept { val = v; }
293
294 public:
295 using Base = onnxruntime_float16::Float16Impl<Float16_t>;
296
300 Float16_t() = default;
301
307 constexpr static Float16_t FromBits(uint16_t v) noexcept { return Float16_t(v); }
308
313 explicit Float16_t(float v) noexcept { val = Base::ToUint16Impl(v); }
314
319 float ToFloat() const noexcept { return Base::ToFloatImpl(); }
320
325 using Base::IsNegative;
326
331 using Base::IsNaN;
332
337 using Base::IsFinite;
338
343 using Base::IsPositiveInfinity;
344
349 using Base::IsNegativeInfinity;
350
355 using Base::IsInfinity;
356
361 using Base::IsNaNOrZero;
362
367 using Base::IsNormal;
368
373 using Base::IsSubnormal;
374
379 using Base::Abs;
380
385 using Base::Negate;
386
395 using Base::AreZero;
396
400 explicit operator float() const noexcept { return ToFloat(); }
401
402 using Base::operator==;
403 using Base::operator!=;
404 using Base::operator<;
405};
406
407static_assert(sizeof(Float16_t) == sizeof(uint16_t), "Sizes must match");
408
427struct BFloat16_t : onnxruntime_float16::BFloat16Impl<BFloat16_t> {
428 private:
436 constexpr explicit BFloat16_t(uint16_t v) noexcept { val = v; }
437
438 public:
439 using Base = onnxruntime_float16::BFloat16Impl<BFloat16_t>;
440
441 BFloat16_t() = default;
442
448 static constexpr BFloat16_t FromBits(uint16_t v) noexcept { return BFloat16_t(v); }
449
454 explicit BFloat16_t(float v) noexcept { val = Base::ToUint16Impl(v); }
455
460 float ToFloat() const noexcept { return Base::ToFloatImpl(); }
461
466 using Base::IsNegative;
467
472 using Base::IsNaN;
473
478 using Base::IsFinite;
479
484 using Base::IsPositiveInfinity;
485
490 using Base::IsNegativeInfinity;
491
496 using Base::IsInfinity;
497
502 using Base::IsNaNOrZero;
503
508 using Base::IsNormal;
509
514 using Base::IsSubnormal;
515
520 using Base::Abs;
521
526 using Base::Negate;
527
536 using Base::AreZero;
537
541 explicit operator float() const noexcept { return ToFloat(); }
542
543 // We do not have an inherited impl for the below operators
544 // as the internal class implements them a little differently
545 bool operator==(const BFloat16_t& rhs) const noexcept;
546 bool operator!=(const BFloat16_t& rhs) const noexcept { return !(*this == rhs); }
547 bool operator<(const BFloat16_t& rhs) const noexcept;
548};
549
550static_assert(sizeof(BFloat16_t) == sizeof(uint16_t), "Sizes must match");
551
558 uint8_t value;
559 constexpr Float8E4M3FN_t() noexcept : value(0) {}
560 constexpr Float8E4M3FN_t(uint8_t v) noexcept : value(v) {}
561 constexpr operator uint8_t() const noexcept { return value; }
562 // nan values are treated like any other value for operator ==, !=
563 constexpr bool operator==(const Float8E4M3FN_t& rhs) const noexcept { return value == rhs.value; };
564 constexpr bool operator!=(const Float8E4M3FN_t& rhs) const noexcept { return value != rhs.value; };
565};
566
567static_assert(sizeof(Float8E4M3FN_t) == sizeof(uint8_t), "Sizes must match");
568
575 uint8_t value;
576 constexpr Float8E4M3FNUZ_t() noexcept : value(0) {}
577 constexpr Float8E4M3FNUZ_t(uint8_t v) noexcept : value(v) {}
578 constexpr operator uint8_t() const noexcept { return value; }
579 // nan values are treated like any other value for operator ==, !=
580 constexpr bool operator==(const Float8E4M3FNUZ_t& rhs) const noexcept { return value == rhs.value; };
581 constexpr bool operator!=(const Float8E4M3FNUZ_t& rhs) const noexcept { return value != rhs.value; };
582};
583
584static_assert(sizeof(Float8E4M3FNUZ_t) == sizeof(uint8_t), "Sizes must match");
585
592 uint8_t value;
593 constexpr Float8E5M2_t() noexcept : value(0) {}
594 constexpr Float8E5M2_t(uint8_t v) noexcept : value(v) {}
595 constexpr operator uint8_t() const noexcept { return value; }
596 // nan values are treated like any other value for operator ==, !=
597 constexpr bool operator==(const Float8E5M2_t& rhs) const noexcept { return value == rhs.value; };
598 constexpr bool operator!=(const Float8E5M2_t& rhs) const noexcept { return value != rhs.value; };
599};
600
601static_assert(sizeof(Float8E5M2_t) == sizeof(uint8_t), "Sizes must match");
602
609 uint8_t value;
610 constexpr Float8E5M2FNUZ_t() noexcept : value(0) {}
611 constexpr Float8E5M2FNUZ_t(uint8_t v) noexcept : value(v) {}
612 constexpr operator uint8_t() const noexcept { return value; }
613 // nan values are treated like any other value for operator ==, !=
614 constexpr bool operator==(const Float8E5M2FNUZ_t& rhs) const noexcept { return value == rhs.value; };
615 constexpr bool operator!=(const Float8E5M2FNUZ_t& rhs) const noexcept { return value != rhs.value; };
616};
617
618static_assert(sizeof(Float8E5M2FNUZ_t) == sizeof(uint8_t), "Sizes must match");
619
620namespace detail {
621// 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
622// This can't be done in the C API since C doesn't have function overloading.
623#define ORT_DEFINE_RELEASE(NAME) \
624 inline void OrtRelease(Ort##NAME* ptr) { GetApi().Release##NAME(ptr); }
625
626#define ORT_DEFINE_RELEASE_FROM_API_STRUCT(NAME, API_GETTER) \
627 inline void OrtRelease(Ort##NAME* ptr) { API_GETTER().Release##NAME(ptr); }
628
629ORT_DEFINE_RELEASE(Allocator);
630ORT_DEFINE_RELEASE(ArenaCfg);
631ORT_DEFINE_RELEASE(CustomOpDomain);
633ORT_DEFINE_RELEASE(Env);
634ORT_DEFINE_RELEASE(ExternalInitializerInfo);
635ORT_DEFINE_RELEASE(Graph);
636ORT_DEFINE_RELEASE(IoBinding);
637ORT_DEFINE_RELEASE(KernelInfo);
638ORT_DEFINE_RELEASE(KeyValuePairs);
639ORT_DEFINE_RELEASE(LoraAdapter);
640ORT_DEFINE_RELEASE(MemoryInfo);
641ORT_DEFINE_RELEASE(MapTypeInfo);
642ORT_DEFINE_RELEASE(Model);
643ORT_DEFINE_RELEASE(ModelMetadata);
644ORT_DEFINE_RELEASE(Node);
645ORT_DEFINE_RELEASE(Op);
646ORT_DEFINE_RELEASE(OpAttr);
647ORT_DEFINE_RELEASE(PrepackedWeightsContainer);
648ORT_DEFINE_RELEASE(RunOptions);
649ORT_DEFINE_RELEASE(Session);
650ORT_DEFINE_RELEASE(SessionOptions);
651ORT_DEFINE_RELEASE(SequenceTypeInfo);
652ORT_DEFINE_RELEASE(Status);
653ORT_DEFINE_RELEASE(SyncStream);
654ORT_DEFINE_RELEASE(TensorTypeAndShapeInfo);
655ORT_DEFINE_RELEASE(ThreadingOptions);
656ORT_DEFINE_RELEASE(TypeInfo);
657ORT_DEFINE_RELEASE(Value);
658ORT_DEFINE_RELEASE(ValueInfo);
659
660ORT_DEFINE_RELEASE_FROM_API_STRUCT(ModelCompilationOptions, GetCompileApi);
661ORT_DEFINE_RELEASE_FROM_API_STRUCT(EpDevice, GetEpApi);
662ORT_DEFINE_RELEASE_FROM_API_STRUCT(KernelDef, GetEpApi);
663ORT_DEFINE_RELEASE_FROM_API_STRUCT(KernelDefBuilder, GetEpApi);
664ORT_DEFINE_RELEASE_FROM_API_STRUCT(KernelRegistry, GetEpApi);
665ORT_DEFINE_RELEASE_FROM_API_STRUCT(OpSchema, GetEpApi);
666ORT_DEFINE_RELEASE_FROM_API_STRUCT(ProfilingEvent, GetEpApi);
667
668// This is defined explicitly since OrtTensorRTProviderOptionsV2 is not a C API type,
669// but the struct has V2 in its name to indicate that it is the second version of the options.
672
673#undef ORT_DEFINE_RELEASE
674#undef ORT_DEFINE_RELEASE_FROM_API_STRUCT
675
679template <typename T>
680struct Unowned {
681 using Type = T;
682};
683
703template <typename T>
704struct Base {
705 using contained_type = T;
706
707 constexpr Base() = default;
708 constexpr explicit Base(contained_type* p) noexcept : p_{p} {}
710 OrtRelease(p_);
711 }
712
713 Base(const Base&) = delete;
714 Base& operator=(const Base&) = delete;
715
716 Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }
717 Base& operator=(Base&& v) noexcept {
718 OrtRelease(p_);
719 p_ = v.release();
720 return *this;
721 }
722
723 constexpr operator contained_type*() const noexcept { return p_; }
724 constexpr contained_type& operator*() const noexcept { return *p_; }
725
729 T* p = p_;
730 p_ = nullptr;
731 return p;
732 }
733
734 protected:
736};
737
738// Undefined. For const types use Base<Unowned<const T>>
739template <typename T>
740struct Base<const T>;
741
749template <typename T>
750struct Base<Unowned<T>> {
752
753 constexpr Base() = default;
754 constexpr explicit Base(contained_type* p) noexcept : p_{p} {}
755
756 ~Base() = default;
757
758 Base(const Base&) = default;
759 Base& operator=(const Base&) = default;
760
761 Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }
762 Base& operator=(Base&& v) noexcept {
763 p_ = nullptr;
764 std::swap(p_, v.p_);
765 return *this;
766 }
767
768 constexpr operator contained_type*() const noexcept { return p_; }
769 constexpr contained_type& operator*() const noexcept { return *p_; }
770
771 protected:
773};
774
775// Light functor to release memory with OrtAllocator
778 explicit AllocatedFree(OrtAllocator* allocator)
779 : allocator_(allocator) {}
780 void operator()(void* ptr) const {
781 if (ptr) allocator_->Free(allocator_, ptr);
782 }
783};
784
785} // namespace detail
786
787struct AllocatorWithDefaultOptions;
788struct Env;
789struct EpDevice;
790struct ExternalInitializerInfo;
791struct Graph;
792struct Model;
793struct Node;
794struct ModelMetadata;
795struct TypeInfo;
796struct PrepackedWeightsContainer;
797struct Session;
798struct SessionOptions;
799struct SyncStream;
800struct TensorRTProviderOptions;
801struct Value;
802struct ValueInfo;
803
808using AllocatedStringPtr = std::unique_ptr<char, detail::AllocatedFree>;
809
814struct Status : detail::Base<OrtStatus> {
815 Status() = default; // Same as with std::nullptr_t. But can be used in re-sizable containers and represent success.
816 explicit Status(std::nullptr_t) noexcept {}
817 explicit Status(OrtStatus* status) noexcept;
818 explicit Status(const Exception&);
819 explicit Status(const std::exception&);
820 Status(const char* message, OrtErrorCode code);
821 std::string GetErrorMessage() const;
823 bool IsOK() const noexcept;
824};
825
855
860struct TensorRTProviderOptions : detail::Base<OrtTensorRTProviderOptionsV2> {
861 TensorRTProviderOptions(std::nullptr_t) {}
865 void Update(const std::unordered_map<std::string, std::string>& options);
867 void UpdateWithValue(const char* key, void* value);
868
870 void* GetOptionByName(const char* name) const;
873};
874
879struct CUDAProviderOptions : detail::Base<OrtCUDAProviderOptionsV2> {
880 CUDAProviderOptions(std::nullptr_t) {}
884 void Update(const std::unordered_map<std::string, std::string>& options);
888 void UpdateWithValue(const char* key, void* value);
890 void* GetOptionByName(const char* name) const;
891};
892
907
908namespace detail {
909template <typename T>
911 using B = Base<T>;
912 using B::B;
913
914 // Wraps OrtApi::ExternalInitializerInfo_GetFilePath
915 const std::basic_string<ORTCHAR_T> GetFilePath() const;
916 // Wraps OrtApi::ExternalInitializerInfo_GetFileOffset
917 int64_t GetFileOffset() const;
918 // Wraps OrtApi::ExternalInitializerInfo_GetByteSize
919 size_t GetByteSize() const;
920};
921} // namespace detail
922
923// Const object holder that does not own the underlying object
926
932 using Base::Base;
933
934 explicit ExternalInitializerInfo(std::nullptr_t) {}
936 : detail::ConstExternalInitializerInfoImpl<OrtExternalInitializerInfo>{p} {}
937
939
941 ExternalInitializerInfo(const ORTCHAR_T* filepath, int64_t file_offset, size_t byte_size);
942
944 static Status Create(const ORTCHAR_T* filepath, int64_t file_offset, size_t byte_size,
945 /*out*/ ExternalInitializerInfo& out);
946};
947
948namespace detail {
949template <typename T>
952 using B::B;
953
954 const char* GetValue(const char* key) const;
955
956 // get the pairs in unordered_map. needs to copy to std::string so the hash works as expected
957 std::unordered_map<std::string, std::string> GetKeyValuePairs() const;
958 // get the pairs in two vectors. entries will be 1:1 between keys and values. avoids copying to std::string
959 void GetKeyValuePairs(std::vector<const char*>& keys, std::vector<const char*>& values) const;
960};
961} // namespace detail
962
963// Const object holder that does not own the underlying object
965
967struct KeyValuePairs : detail::KeyValuePairsImpl<OrtKeyValuePairs> {
968 explicit KeyValuePairs(std::nullptr_t) {}
970 explicit KeyValuePairs(OrtKeyValuePairs* p) : KeyValuePairsImpl<OrtKeyValuePairs>{p} {}
971
973 explicit KeyValuePairs();
974
976 explicit KeyValuePairs(const std::unordered_map<std::string, std::string>& kv_pairs);
977
979 void Add(const char* key, const char* value);
980
982 void Remove(const char* key);
983
984 ConstKeyValuePairs GetConst() const { return ConstKeyValuePairs{this->p_}; }
985};
986
987namespace detail {
988template <typename T>
989struct MemoryInfoImpl : Base<T> {
990 using B = Base<T>;
991 using B::B;
992
993 std::string GetAllocatorName() const;
995 int GetDeviceId() const;
999 uint32_t GetVendorId() const;
1000
1001 template <typename U>
1002 bool operator==(const MemoryInfoImpl<U>& o) const;
1003};
1004} // namespace detail
1005
1006// Const object holder that does not own the underlying object
1008
1012struct MemoryInfo : detail::MemoryInfoImpl<OrtMemoryInfo> {
1014 explicit MemoryInfo(std::nullptr_t) {}
1015 explicit MemoryInfo(OrtMemoryInfo* p) : MemoryInfoImpl<OrtMemoryInfo>{p} {}
1016 MemoryInfo(const char* name, OrtAllocatorType type, int id, OrtMemType mem_type);
1017 MemoryInfo(const char* name, OrtMemoryInfoDeviceType device_type, uint32_t vendor_id, uint32_t device_id,
1018 OrtDeviceMemoryType mem_type, size_t alignment, OrtAllocatorType allocator_type);
1019 ConstMemoryInfo GetConst() const { return ConstMemoryInfo{this->p_}; }
1020};
1021
1029 MemoryAllocation(OrtAllocator* allocator, void* p, size_t size);
1034 MemoryAllocation& operator=(MemoryAllocation&&) noexcept;
1035
1036 void* get() { return p_; }
1037 size_t size() const { return size_; }
1038
1039 private:
1040 OrtAllocator* allocator_;
1041 void* p_;
1042 size_t size_;
1043};
1044
1045namespace detail {
1046template <typename T>
1047struct AllocatorImpl : Base<T> {
1048 using B = Base<T>;
1049 using B::B;
1050
1051 void* Alloc(size_t size);
1052 void* Reserve(size_t size);
1053 MemoryAllocation GetAllocation(size_t size);
1054 void Free(void* p);
1055 ConstMemoryInfo GetInfo() const;
1056
1061 KeyValuePairs GetStats() const;
1062
1067 void Shrink();
1068};
1069} // namespace detail
1070
1074struct AllocatorWithDefaultOptions : detail::AllocatorImpl<detail::Unowned<OrtAllocator>> {
1075 explicit AllocatorWithDefaultOptions(std::nullptr_t) {}
1077};
1078
1083struct Allocator : detail::AllocatorImpl<OrtAllocator> {
1084 explicit Allocator(std::nullptr_t) {}
1085 Allocator(const Session& session, const OrtMemoryInfo*);
1086
1088 explicit Allocator(OrtAllocator* p) : AllocatorImpl<OrtAllocator>{p} {}
1089};
1090
1091using UnownedAllocator = detail::AllocatorImpl<detail::Unowned<OrtAllocator>>;
1092
1097namespace detail {
1098template <typename T>
1100 using B = Base<T>;
1101 using B::B;
1102 // For some reason this is not a const method on the stream
1103 void* GetHandle();
1104};
1105} // namespace detail
1106
1107struct SyncStream : detail::SyncStreamImpl<OrtSyncStream> {
1109 explicit SyncStream(std::nullptr_t) {}
1111 explicit SyncStream(OrtSyncStream* p) : SyncStreamImpl<OrtSyncStream>{p} {}
1112};
1113
1115
1116namespace detail {
1117template <typename T>
1120 using B::B;
1121
1123 uint32_t VendorId() const;
1124 uint32_t DeviceId() const;
1125 const char* Vendor() const;
1127};
1128} // namespace detail
1129
1134
1135namespace detail {
1136template <typename T>
1139 using B::B;
1140
1141 uint32_t GetReasonsBitmask() const;
1142 const char* GetNotes() const;
1143 int32_t GetErrorCode() const;
1144};
1145} // namespace detail
1146
1151 explicit DeviceEpIncompatibilityDetails(std::nullptr_t) {}
1153 : DeviceEpIncompatibilityDetailsImpl<OrtDeviceEpIncompatibilityDetails>{p} {}
1154};
1155
1156namespace detail {
1157template <typename T>
1160 using B::B;
1161
1162 const char* EpName() const;
1163 const char* EpVendor() const;
1169};
1170} // namespace detail
1171
1176
1179struct EpDevice : detail::EpDeviceImpl<OrtEpDevice> {
1180 explicit EpDevice(std::nullptr_t) {}
1181 explicit EpDevice(OrtEpDevice* p) : EpDeviceImpl<OrtEpDevice>{p} {}
1182
1184 EpDevice(OrtEpFactory& ep_factory, ConstHardwareDevice& hardware_device,
1185 ConstKeyValuePairs ep_metadata = {}, ConstKeyValuePairs ep_options = {});
1186};
1187
1195 const std::vector<ConstEpDevice>& ep_devices,
1196 const char* compatibility_info);
1197
1213AllocatedStringPtr GetCompatibilityInfoFromModelAllocated(const ORTCHAR_T* model_path, const char* ep_type,
1214 OrtAllocator* allocator);
1215
1228AllocatedStringPtr GetCompatibilityInfoFromModelBytesAllocated(const void* model_data, size_t model_data_length,
1229 const char* ep_type, OrtAllocator* allocator);
1230
1231namespace detail {
1232template <typename T>
1235 using B::B;
1236
1237 std::string GetName() const;
1238 std::string GetDomain() const;
1239 std::string GetOperatorType() const;
1240};
1241} // namespace detail
1242
1247
1248namespace detail {
1249template <typename T>
1252 using B::B;
1253
1254 std::string GetEpName() const;
1255 std::vector<ConstEpAssignedNode> GetNodes() const;
1256};
1257} // namespace detail
1258
1263
1264namespace detail {
1265template <typename T>
1268 using B::B;
1269
1271 OrtProfilingEventCategory GetCategory() const;
1272
1275 const char* GetName() const;
1276
1278 int64_t GetTimestampUs() const;
1279
1281 int64_t GetDurationUs() const;
1282
1286 const char* GetArgValue(const char* key) const;
1287};
1288} // namespace detail
1289
1298
1306 explicit ProfilingEvent(std::nullptr_t) {}
1308 : ConstProfilingEventImpl<OrtProfilingEvent>{p} {}
1309
1311 ProfilingEvent(OrtProfilingEventCategory category,
1312 int32_t process_id,
1313 int32_t thread_id,
1314 const char* event_name,
1315 int64_t timestamp_us,
1316 int64_t duration_us,
1317 const std::unordered_map<std::string, std::string>& args = {});
1318
1320 ProfilingEvent(OrtProfilingEventCategory category,
1321 int32_t process_id,
1322 int32_t thread_id,
1323 const char* event_name,
1324 int64_t timestamp_us,
1325 int64_t duration_us,
1326 const char* const* arg_keys,
1327 const char* const* arg_values,
1328 size_t num_args);
1329
1331};
1332
1333namespace detail {
1334template <typename T>
1337 using B::B;
1338
1341 Ort::Status AddEvents(const OrtProfilingEvent* const* events, size_t num_events);
1342 Ort::Status AddEvents(const std::vector<ProfilingEvent>& events);
1343};
1344} // namespace detail
1345
1352
1358struct Env : detail::Base<OrtEnv> {
1359 explicit Env(std::nullptr_t) {}
1360
1362 Env(OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
1363
1365 Env(OrtLoggingLevel logging_level, const char* logid, OrtLoggingFunction logging_function, void* logger_param);
1366
1368 Env(const OrtThreadingOptions* tp_options, OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
1369
1371 Env(const OrtThreadingOptions* tp_options, OrtLoggingFunction logging_function, void* logger_param,
1372 OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
1373
1375 explicit Env(const OrtEnvCreationOptions* options);
1376
1378 explicit Env(OrtEnv* p) : Base<OrtEnv>{p} {}
1379
1382
1384
1385 Env& CreateAndRegisterAllocator(const OrtMemoryInfo* mem_info, const OrtArenaCfg* arena_cfg);
1386
1387 Env& CreateAndRegisterAllocatorV2(const std::string& provider_type, const OrtMemoryInfo* mem_info,
1388 const std::unordered_map<std::string, std::string>& options,
1389 const OrtArenaCfg* arena_cfg);
1390
1392
1394
1396 OrtAllocatorType allocator_type,
1397 const OrtKeyValuePairs* allocator_options);
1398
1399 // Result may be nullptr
1401
1403 OrtDeviceMemoryType mem_type);
1404
1405 Env& RegisterExecutionProviderLibrary(const char* registration_name, const std::basic_string<ORTCHAR_T>& path);
1406 Env& UnregisterExecutionProviderLibrary(const char* registration_name);
1407
1408 std::vector<ConstEpDevice> GetEpDevices() const;
1409
1416 size_t GetNumHardwareDevices() const;
1417
1424 std::vector<ConstHardwareDevice> GetHardwareDevices() const;
1425
1437 const char* ep_name, ConstHardwareDevice hw) const;
1438
1439 Status CopyTensors(const std::vector<Value>& src_tensors,
1440 const std::vector<Value>& dst_tensors,
1441 OrtSyncStream* stream) const;
1442
1445 Status CopyTensor(const OrtValue* src_tensor, OrtValue* dst_tensor, OrtSyncStream* stream) const;
1446
1452};
1453
1457struct CustomOpDomain : detail::Base<OrtCustomOpDomain> {
1459 using Base::Base;
1460
1461 explicit CustomOpDomain(std::nullptr_t) {}
1462
1464 explicit CustomOpDomain(const char* domain);
1465
1466 // This does not take ownership of the op, simply registers it.
1467 void Add(const OrtCustomOp* op);
1468};
1469
1471struct LoraAdapter : detail::Base<OrtLoraAdapter> {
1473 using Base::Base;
1474
1475 explicit LoraAdapter(std::nullptr_t) {}
1482 static LoraAdapter CreateLoraAdapter(const std::basic_string<ORTCHAR_T>& adapter_path,
1483 OrtAllocator* allocator);
1484
1492 static LoraAdapter CreateLoraAdapterFromArray(const void* bytes, size_t num_bytes,
1493 OrtAllocator* allocator);
1494};
1495
1499struct RunOptions : detail::Base<OrtRunOptions> {
1500 explicit RunOptions(std::nullptr_t) {}
1502
1505
1508
1509 RunOptions& SetRunTag(const char* run_tag);
1510 const char* GetRunTag() const;
1511
1512 RunOptions& AddConfigEntry(const char* config_key, const char* config_value);
1513 const char* GetConfigEntry(const char* config_key);
1514
1521
1527
1535
1544
1550 RunOptions& EnableProfiling(const ORTCHAR_T* profile_file_prefix);
1551
1557};
1558
1559namespace detail {
1560// Utility function that returns a SessionOption config entry key for a specific custom operator.
1561// Ex: custom_op.[custom_op_name].[config]
1562std::string MakeCustomOpConfigEntryKey(const char* custom_op_name, const char* config);
1563} // namespace detail
1564
1575 CustomOpConfigs() = default;
1576 ~CustomOpConfigs() = default;
1581
1590 CustomOpConfigs& AddConfig(const char* custom_op_name, const char* config_key, const char* config_value);
1591
1600 const std::unordered_map<std::string, std::string>& GetFlattenedConfigs() const;
1601
1602 private:
1603 std::unordered_map<std::string, std::string> flat_configs_;
1604};
1605
1611namespace detail {
1612// we separate const-only methods because passing const ptr to non-const methods
1613// is only discovered when inline methods are compiled which is counter-intuitive
1614template <typename T>
1615struct ConstSessionOptionsImpl : Base<T> {
1616 using B = Base<T>;
1617 using B::B;
1618
1619 SessionOptions Clone() const;
1620
1621 std::string GetConfigEntry(const char* config_key) const;
1622 bool HasConfigEntry(const char* config_key) const;
1623 std::string GetConfigEntryOrDefault(const char* config_key, const std::string& def) const;
1624
1625 bool GetMemPatternEnabled() const;
1626 ExecutionMode GetExecutionMode() const;
1627};
1628
1629template <typename T>
1630struct SessionOptionsImpl : ConstSessionOptionsImpl<T> {
1631 using B = ConstSessionOptionsImpl<T>;
1632 using B::B;
1633
1634 SessionOptionsImpl& SetIntraOpNumThreads(int intra_op_num_threads);
1635 SessionOptionsImpl& SetInterOpNumThreads(int inter_op_num_threads);
1636 SessionOptionsImpl& SetGraphOptimizationLevel(GraphOptimizationLevel graph_optimization_level);
1637 SessionOptionsImpl& SetDeterministicCompute(bool value);
1638
1639 SessionOptionsImpl& EnableCpuMemArena();
1640 SessionOptionsImpl& DisableCpuMemArena();
1641
1642 SessionOptionsImpl& SetOptimizedModelFilePath(const ORTCHAR_T* optimized_model_file);
1643
1644 SessionOptionsImpl& EnableProfiling(const ORTCHAR_T* profile_file_prefix);
1645 SessionOptionsImpl& DisableProfiling();
1646
1647 SessionOptionsImpl& EnableOrtCustomOps();
1648
1649 SessionOptionsImpl& EnableMemPattern();
1650 SessionOptionsImpl& DisableMemPattern();
1651
1652 SessionOptionsImpl& SetExecutionMode(ExecutionMode execution_mode);
1653
1654 SessionOptionsImpl& SetLoadCancellationFlag(bool value);
1655
1656 SessionOptionsImpl& SetLogId(const char* logid);
1657 SessionOptionsImpl& SetLogSeverityLevel(int level);
1658
1659 SessionOptionsImpl& Add(OrtCustomOpDomain* custom_op_domain);
1660
1661 SessionOptionsImpl& DisablePerSessionThreads();
1662
1663 SessionOptionsImpl& AddConfigEntry(const char* config_key, const char* config_value);
1664
1665 SessionOptionsImpl& AddInitializer(const char* name, const OrtValue* ort_val);
1666 SessionOptionsImpl& AddExternalInitializers(const std::vector<std::string>& names, const std::vector<Value>& ort_values);
1667 SessionOptionsImpl& AddExternalInitializersFromFilesInMemory(const std::vector<std::basic_string<ORTCHAR_T>>& external_initializer_file_names,
1668 const std::vector<char*>& external_initializer_file_buffer_array,
1669 const std::vector<size_t>& external_initializer_file_lengths);
1670
1671 SessionOptionsImpl& AppendExecutionProvider_CPU(int use_arena);
1672 SessionOptionsImpl& AppendExecutionProvider_CUDA(const OrtCUDAProviderOptions& provider_options);
1673 SessionOptionsImpl& AppendExecutionProvider_CUDA_V2(const OrtCUDAProviderOptionsV2& provider_options);
1674 SessionOptionsImpl& AppendExecutionProvider_ROCM(const OrtROCMProviderOptions& provider_options);
1675 SessionOptionsImpl& AppendExecutionProvider_OpenVINO(const OrtOpenVINOProviderOptions& provider_options);
1677 SessionOptionsImpl& AppendExecutionProvider_OpenVINO_V2(const std::unordered_map<std::string, std::string>& provider_options = {});
1678 SessionOptionsImpl& AppendExecutionProvider_TensorRT(const OrtTensorRTProviderOptions& provider_options);
1679 SessionOptionsImpl& AppendExecutionProvider_TensorRT_V2(const OrtTensorRTProviderOptionsV2& provider_options);
1680 SessionOptionsImpl& AppendExecutionProvider_MIGraphX(const OrtMIGraphXProviderOptions& provider_options);
1682 SessionOptionsImpl& AppendExecutionProvider_CANN(const OrtCANNProviderOptions& provider_options);
1684 SessionOptionsImpl& AppendExecutionProvider_Dnnl(const OrtDnnlProviderOptions& provider_options);
1686 SessionOptionsImpl& AppendExecutionProvider(const std::string& provider_name,
1687 const std::unordered_map<std::string, std::string>& provider_options = {});
1688
1691 SessionOptionsImpl& AppendExecutionProvider_V2(Env& env, const std::vector<ConstEpDevice>& ep_devices,
1692 const KeyValuePairs& ep_options);
1695 SessionOptionsImpl& AppendExecutionProvider_V2(Env& env, const std::vector<ConstEpDevice>& ep_devices,
1696 const std::unordered_map<std::string, std::string>& ep_options);
1697
1699 SessionOptionsImpl& SetEpSelectionPolicy(OrtExecutionProviderDevicePolicy policy);
1700
1702 SessionOptionsImpl& SetEpSelectionPolicy(EpSelectionDelegate delegate, void* state = nullptr);
1703
1704 SessionOptionsImpl& SetCustomCreateThreadFn(OrtCustomCreateThreadFn ort_custom_create_thread_fn);
1705 SessionOptionsImpl& SetCustomThreadCreationOptions(void* ort_custom_thread_creation_options);
1706 SessionOptionsImpl& SetCustomJoinThreadFn(OrtCustomJoinThreadFn ort_custom_join_thread_fn);
1707
1711 SessionOptionsImpl& RegisterCustomOpsLibrary(const ORTCHAR_T* library_name, const CustomOpConfigs& custom_op_configs = {});
1712
1713 SessionOptionsImpl& RegisterCustomOpsUsingFunction(const char* function_name);
1714
1716 SessionOptionsImpl& AppendExecutionProvider_VitisAI(const std::unordered_map<std::string, std::string>& provider_options = {});
1717
1719 SessionOptionsImpl& AddFreeDimensionOverride(const char* dim_denotation, int64_t dim_value);
1720
1722 SessionOptionsImpl& AddFreeDimensionOverrideByName(const char* dim_name, int64_t dim_value);
1723};
1724} // namespace detail
1725
1726using UnownedSessionOptions = detail::SessionOptionsImpl<detail::Unowned<OrtSessionOptions>>;
1727using ConstSessionOptions = detail::ConstSessionOptionsImpl<detail::Unowned<const OrtSessionOptions>>;
1728
1732struct SessionOptions : detail::SessionOptionsImpl<OrtSessionOptions> {
1733 explicit SessionOptions(std::nullptr_t) {}
1735 explicit SessionOptions(OrtSessionOptions* p) : SessionOptionsImpl<OrtSessionOptions>{p} {}
1738};
1739
1744struct ModelCompilationOptions : detail::Base<OrtModelCompilationOptions> {
1746 using Base::Base;
1747
1748 explicit ModelCompilationOptions(std::nullptr_t) {}
1749
1750 ModelCompilationOptions(const Env& env, const SessionOptions& session_options);
1751 ModelCompilationOptions(const Env& env, ConstSessionOptions session_options);
1752
1753 ModelCompilationOptions& SetInputModelPath(const ORTCHAR_T* input_model_path);
1755 size_t input_model_data_size);
1756 ModelCompilationOptions& SetEpContextEmbedMode(bool embed_ep_context_in_model);
1757 ModelCompilationOptions& SetOutputModelPath(const ORTCHAR_T* output_model_path);
1759 size_t initializer_size_threshold);
1760
1763 OrtGetInitializerLocationFunc get_initializer_location_func,
1764 void* state);
1765
1766 ModelCompilationOptions& SetOutputModelBuffer(OrtAllocator* allocator, void** output_model_buffer_ptr,
1767 size_t* output_model_buffer_size_ptr);
1768
1771
1772 ModelCompilationOptions& SetEpContextBinaryInformation(const ORTCHAR_T* output_directory,
1773 const ORTCHAR_T* model_name);
1775
1777
1779};
1780
1787Status CompileModel(const Env& env, const ModelCompilationOptions& model_compilation_options);
1788
1792struct ModelMetadata : detail::Base<OrtModelMetadata> {
1794 using Base::Base;
1795
1796 explicit ModelMetadata(std::nullptr_t) {}
1797
1805
1813
1821
1829
1837
1844 std::vector<AllocatedStringPtr> GetCustomMetadataMapKeysAllocated(OrtAllocator* allocator) const;
1845
1856
1857 int64_t GetVersion() const;
1858};
1859
1860struct IoBinding;
1861
1862namespace detail {
1863
1864// we separate const-only methods because passing const ptr to non-const methods
1865// is only discovered when inline methods are compiled which is counter-intuitive
1866template <typename T>
1868 using B = Base<T>;
1869 using B::B;
1870
1871 size_t GetInputCount() const;
1872 size_t GetOutputCount() const;
1874
1875 std::vector<std::string> GetInputNames() const;
1876 std::vector<std::string> GetOutputNames() const;
1877 std::vector<std::string> GetOverridableInitializerNames() const;
1878
1879 std::vector<ConstMemoryInfo> GetMemoryInfoForInputs() const;
1880 std::vector<ConstMemoryInfo> GetMemoryInfoForOutputs() const;
1881 std::vector<ConstEpDevice> GetEpDeviceForInputs() const;
1882 std::vector<ConstEpDevice> GetEpDeviceForOutputs() const;
1883
1892
1901
1910
1911 uint64_t GetProfilingStartTimeNs() const;
1913
1914 TypeInfo GetInputTypeInfo(size_t index) const;
1915 TypeInfo GetOutputTypeInfo(size_t index) const;
1917
1918 int GetOpset(const std::string& domain) const;
1919
1920 std::vector<ValueInfo> GetInputs() const;
1921 std::vector<ValueInfo> GetOutputs() const;
1922
1927 std::vector<ConstEpAssignedSubgraph> GetEpGraphAssignmentInfo() const;
1928};
1929
1930template <typename T>
1933 using B::B;
1934
1952 std::vector<Value> Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
1953 const char* const* output_names, size_t output_count);
1954
1958 void Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
1959 const char* const* output_names, Value* output_values, size_t output_count);
1960
1961 void Run(const RunOptions& run_options, const IoBinding&);
1962
1982 void RunAsync(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
1983 const char* const* output_names, Value* output_values, size_t output_count, RunAsyncCallbackFn callback, void* user_data);
1984
1992
2004 void SetEpDynamicOptions(const char* const* keys, const char* const* values, size_t kv_len);
2005
2006 void FinalizeModelEditorSession(const Model& model, const SessionOptions& options,
2007 OrtPrepackedWeightsContainer* prepacked_weights_container = nullptr);
2008
2015 void ReleaseCapturedGraph(int graph_annotation_id);
2016};
2017
2018} // namespace detail
2019
2022
2026struct Session : detail::SessionImpl<OrtSession> {
2028 explicit Session(std::nullptr_t) {}
2029 explicit Session(OrtSession* p) : SessionImpl{p} {}
2030
2031 Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
2032
2034 Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options,
2035 OrtPrepackedWeightsContainer* prepacked_weights_container);
2036
2038 Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options);
2039
2041 Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options,
2042 OrtPrepackedWeightsContainer* prepacked_weights_container);
2043
2044#if !defined(ORT_MINIMAL_BUILD)
2046 Session(const Env& env, const Model& model, const SessionOptions& options);
2047
2049 static Session CreateModelEditorSession(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
2050
2052 static Session CreateModelEditorSession(const Env& env, const void* model_data, size_t model_data_length,
2053 const SessionOptions& options);
2054#endif // !defined(ORT_MINIMAL_BUILD)
2055
2056 ConstSession GetConst() const { return ConstSession{this->p_}; }
2057 UnownedSession GetUnowned() const { return UnownedSession{this->p_}; }
2058};
2059
2060namespace detail {
2061template <typename T>
2063 using B = Base<T>;
2064 using B::B;
2065
2067
2072 size_t GetElementCount() const;
2073
2074 size_t GetDimensionsCount() const;
2075
2080 [[deprecated("use GetShape()")]] void GetDimensions(int64_t* values, size_t values_count) const;
2081
2082 void GetSymbolicDimensions(const char** values, size_t values_count) const;
2083 std::vector<const char*> GetSymbolicDimensions() const;
2084
2085 bool HasShape() const;
2086 std::vector<int64_t> GetShape() const;
2087};
2088
2089} // namespace detail
2090
2092
2098 using Base::Base;
2099
2101 explicit TensorTypeAndShapeInfo(std::nullptr_t) {}
2103 explicit TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* p) : TensorTypeAndShapeInfoImpl{p} {}
2104
2105 // Create a TensorTypeAndShapeInfo object with the specified element type and dimensions
2106 // symbolic_dims are optional, but should be 1:1 with dims.
2107 // The value in symbolic_dims will be used for all entries in dims that are -1.
2109 const std::vector<int64_t>& dims,
2110 const std::vector<std::string>* symbolic_dims = nullptr);
2111
2113};
2114
2115namespace detail {
2116template <typename T>
2118 using B = Base<T>;
2119 using B::B;
2121};
2122
2123} // namespace detail
2124
2126
2130struct SequenceTypeInfo : detail::SequenceTypeInfoImpl<OrtSequenceTypeInfo> {
2132 using Base::Base;
2133
2134 explicit SequenceTypeInfo(std::nullptr_t) {}
2135 explicit SequenceTypeInfo(OrtSequenceTypeInfo* p) : SequenceTypeInfoImpl<OrtSequenceTypeInfo>{p} {}
2137};
2138
2139namespace detail {
2140template <typename T>
2142 using B = Base<T>;
2143 using B::B;
2145};
2146
2147} // namespace detail
2148
2149// This is always owned by the TypeInfo and can only be obtained from it.
2151
2152namespace detail {
2153template <typename T>
2160
2161} // namespace detail
2162
2164
2168struct MapTypeInfo : detail::MapTypeInfoImpl<OrtMapTypeInfo> {
2170 using Base::Base;
2171
2172 explicit MapTypeInfo(std::nullptr_t) {}
2173 explicit MapTypeInfo(OrtMapTypeInfo* p) : MapTypeInfoImpl<OrtMapTypeInfo>{p} {}
2174 ConstMapTypeInfo GetConst() const { return ConstMapTypeInfo{this->p_}; }
2175};
2176
2177namespace detail {
2178template <typename T>
2190} // namespace detail
2191
2197
2202struct TypeInfo : detail::TypeInfoImpl<OrtTypeInfo> {
2204 using Base::Base;
2205
2207 explicit TypeInfo(std::nullptr_t) {}
2208 explicit TypeInfo(OrtTypeInfo* p) : TypeInfoImpl<OrtTypeInfo>{p} {}
2209
2210#if !defined(ORT_MINIMAL_BUILD)
2216#endif // !defined(ORT_MINIMAL_BUILD)
2217
2218 ConstTypeInfo GetConst() const { return ConstTypeInfo{this->p_}; }
2219};
2220
2221namespace detail {
2222// This structure is used to feed sparse tensor values
2223// information for use with FillSparseTensor<Format>() API
2224// if the data type for the sparse tensor values is numeric
2225// use data.p_data, otherwise, use data.str pointer to feed
2226// values. data.str is an array of const char* that are zero terminated.
2227// number of strings in the array must match shape size.
2228// For fully sparse tensors use shape {0} and set p_data/str
2229// to nullptr.
2231 const int64_t* values_shape;
2233 union {
2234 const void* p_data;
2235 const char** str;
2236 } data;
2237};
2238
2239// Provides a way to pass shape in a single
2240// argument
2241struct Shape {
2242 const int64_t* shape;
2244};
2245
2246template <typename T>
2248 using B = Base<T>;
2249 using B::B;
2250
2254 template <typename R>
2255 void GetOpaqueData(const char* domain, const char* type_name, R&) const;
2256
2257 bool IsTensor() const;
2258 bool HasValue() const;
2259
2260 size_t GetCount() const; // If a non tensor, returns 2 for map and N for sequence, where N is the number of elements
2261 Value GetValue(int index, OrtAllocator* allocator) const;
2262
2270
2285 void GetStringTensorContent(void* buffer, size_t buffer_length, size_t* offsets, size_t offsets_count) const;
2286
2293 template <typename R>
2294 const R* GetTensorData() const;
2295
2300 const void* GetTensorRawData() const;
2301
2309
2317
2323
2332 void GetStringTensorElement(size_t buffer_length, size_t element_index, void* buffer) const;
2333
2340 std::string GetStringTensorElement(size_t element_index) const;
2341
2348 size_t GetStringTensorElementLength(size_t element_index) const;
2349
2360 size_t GetTensorSizeInBytes() const;
2361
2362#if !defined(DISABLE_SPARSE_TENSORS)
2370
2377
2386
2396 template <typename R>
2397 const R* GetSparseTensorIndicesData(OrtSparseIndicesFormat indices_format, size_t& num_indices) const;
2398
2403 bool IsSparseTensor() const;
2404
2413 template <typename R>
2414 const R* GetSparseTensorValues() const;
2415
2416#endif
2417
2430};
2431
2432template <typename T>
2435 using B::B;
2436
2442 template <typename R>
2444
2450
2452 // Obtain a reference to an element of data at the location specified
2458 template <typename R>
2459 R& At(const std::vector<int64_t>& location);
2460
2466 void FillStringTensor(const char* const* s, size_t s_len);
2467
2473 void FillStringTensorElement(const char* s, size_t index);
2474
2487 char* GetResizedStringTensorElementBuffer(size_t index, size_t buffer_length);
2488
2489#if !defined(DISABLE_SPARSE_TENSORS)
2498 void UseCooIndices(int64_t* indices_data, size_t indices_num);
2499
2510 void UseCsrIndices(int64_t* inner_data, size_t inner_num, int64_t* outer_data, size_t outer_num);
2511
2520 void UseBlockSparseIndices(const Shape& indices_shape, int32_t* indices_data);
2521
2531 void FillSparseTensorCoo(const OrtMemoryInfo* data_mem_info, const OrtSparseValuesParam& values_param,
2532 const int64_t* indices_data, size_t indices_num);
2533
2545 void FillSparseTensorCsr(const OrtMemoryInfo* data_mem_info,
2546 const OrtSparseValuesParam& values,
2547 const int64_t* inner_indices_data, size_t inner_indices_num,
2548 const int64_t* outer_indices_data, size_t outer_indices_num);
2549
2560 const OrtSparseValuesParam& values,
2561 const Shape& indices_shape,
2562 const int32_t* indices_data);
2563
2564#endif
2565};
2566
2567} // namespace detail
2568
2571
2575struct Value : detail::ValueImpl<OrtValue> {
2577 using Base::Base;
2580
2581 Value(std::nullptr_t) {}
2582 Value(Value&&) = default;
2583 Value& operator=(Value&&) = default;
2584
2585 ConstValue GetConst() const { return ConstValue{this->p_}; }
2586 UnownedValue GetUnowned() const { return UnownedValue{this->p_}; }
2587
2596 template <typename T>
2597 static Value CreateTensor(const OrtMemoryInfo* info, T* p_data, size_t p_data_element_count,
2598 const int64_t* shape, size_t shape_len);
2599
2609 static Value CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count,
2610 const int64_t* shape, size_t shape_len,
2612
2622 static Value CreateTensor(OrtAllocator* deleter, void* p_data, size_t p_data_byte_count,
2623 const int64_t* shape, size_t shape_len,
2625
2637 template <typename T>
2638 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len);
2639
2651 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len,
2653
2662 static Value CreateMap(const Value& keys, const Value& values);
2663
2671 static Value CreateSequence(const std::vector<Value>& values);
2672
2681 template <typename T>
2682 static Value CreateOpaque(const char* domain, const char* type_name, const T& value);
2683
2684#if !defined(DISABLE_SPARSE_TENSORS)
2695 template <typename T>
2696 static Value CreateSparseTensor(const OrtMemoryInfo* info, T* p_data, const Shape& dense_shape,
2697 const Shape& values_shape);
2698
2715 static Value CreateSparseTensor(const OrtMemoryInfo* info, void* p_data, const Shape& dense_shape,
2716 const Shape& values_shape, ONNXTensorElementDataType type);
2717
2727 template <typename T>
2728 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape);
2729
2741 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape, ONNXTensorElementDataType type);
2742
2743#endif // !defined(DISABLE_SPARSE_TENSORS)
2744};
2745
2746namespace detail {
2747namespace binding_utils {
2748// Bring these out of template
2749std::vector<std::string> GetOutputNamesHelper(const OrtIoBinding* binding, OrtAllocator*);
2750std::vector<Value> GetOutputValuesHelper(const OrtIoBinding* binding, OrtAllocator*);
2751} // namespace binding_utils
2752
2753template <typename T>
2755 using B = Base<T>;
2756 using B::B;
2757
2758 std::vector<std::string> GetOutputNames() const;
2759 std::vector<std::string> GetOutputNames(OrtAllocator*) const;
2760 std::vector<Value> GetOutputValues() const;
2761 std::vector<Value> GetOutputValues(OrtAllocator*) const;
2762};
2763
2764template <typename T>
2767 using B::B;
2768
2769 void BindInput(const char* name, const Value&);
2770 void BindOutput(const char* name, const Value&);
2771 void BindOutput(const char* name, const OrtMemoryInfo*);
2776};
2777
2778} // namespace detail
2779
2782
2786struct IoBinding : detail::IoBindingImpl<OrtIoBinding> {
2787 explicit IoBinding(std::nullptr_t) {}
2788 explicit IoBinding(Session& session);
2789 ConstIoBinding GetConst() const { return ConstIoBinding{this->p_}; }
2790 UnownedIoBinding GetUnowned() const { return UnownedIoBinding{this->p_}; }
2791};
2792
2797struct ArenaCfg : detail::Base<OrtArenaCfg> {
2798 explicit ArenaCfg(std::nullptr_t) {}
2807 ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk);
2808
2813 explicit ArenaCfg(const std::unordered_map<std::string, size_t>& arena_config);
2814};
2815
2816//
2817// Custom OPs (only needed to implement custom OPs)
2818//
2819
2820namespace detail {
2821// Need to define a templated ConstOpAttr with const members
2822template <typename T>
2825 using B::B;
2826
2827 // Wraps OrtApi::OpAttr_GetName
2828 std::string GetName() const;
2829 // Wraps OrtApi::OpAttr_GetType
2831
2832 // Wraps OrtApi::ReadAttr for a single value
2833 // This does not support Tensor Attribute
2834 // Call GetTensorAttributeAsOrtValue() instead.
2835 template <typename R>
2836 Status GetValue(R& out) const;
2837
2838 // Wraps OrtApi::ReadAttr for an array of values
2839 template <typename R>
2840 Status GetValueArray(std::vector<R>& out) const;
2841 // Wraps OrtApi::OpAttr_GetTensorAttributeAsOrtValue
2843};
2844} // namespace detail
2845
2847
2851struct OpAttr : detail::ConstOpAttrImpl<OrtOpAttr> {
2853 using Base::Base;
2854
2855 OpAttr() = default; // Enable storing it in the container for resize()
2856 explicit OpAttr(std::nullptr_t) {}
2857 OpAttr(const char* name, const void* data, int len, OrtOpAttrType type);
2858
2859 ConstOpAttr GetConst() const { return ConstOpAttr{this->p_}; }
2860};
2861
2870#define ORT_CXX_LOG(logger, message_severity, message) \
2871 do { \
2872 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2873 Ort::ThrowOnError(logger.LogMessage(message_severity, ORT_FILE, __LINE__, \
2874 static_cast<const char*>(__FUNCTION__), message)); \
2875 } \
2876 } while (false)
2877
2886#define ORT_CXX_LOG_NOEXCEPT(logger, message_severity, message) \
2887 do { \
2888 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2889 static_cast<void>(logger.LogMessage(message_severity, ORT_FILE, __LINE__, \
2890 static_cast<const char*>(__FUNCTION__), message)); \
2891 } \
2892 } while (false)
2893
2905#define ORT_CXX_LOGF(logger, message_severity, /*format,*/...) \
2906 do { \
2907 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2908 Ort::ThrowOnError(logger.LogFormattedMessage(message_severity, ORT_FILE, __LINE__, \
2909 static_cast<const char*>(__FUNCTION__), __VA_ARGS__)); \
2910 } \
2911 } while (false)
2912
2924#define ORT_CXX_LOGF_NOEXCEPT(logger, message_severity, /*format,*/...) \
2925 do { \
2926 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2927 static_cast<void>(logger.LogFormattedMessage(message_severity, ORT_FILE, __LINE__, \
2928 static_cast<const char*>(__FUNCTION__), __VA_ARGS__)); \
2929 } \
2930 } while (false)
2931
2942struct Logger {
2946 Logger() = default;
2947
2951 explicit Logger(std::nullptr_t) {}
2952
2959 explicit Logger(const OrtLogger* logger);
2960
2961 ~Logger() = default;
2962
2963 Logger(const Logger&) = default;
2964 Logger& operator=(const Logger&) = default;
2965
2966 Logger(Logger&& v) noexcept = default;
2967 Logger& operator=(Logger&& v) noexcept = default;
2968
2975
2988 Status LogMessage(OrtLoggingLevel log_severity_level, const ORTCHAR_T* file_path, int line_number,
2989 const char* func_name, const char* message) const noexcept;
2990
3005 template <typename... Args>
3006 Status LogFormattedMessage(OrtLoggingLevel log_severity_level, const ORTCHAR_T* file_path, int line_number,
3007 const char* func_name, const char* format, Args&&... args) const noexcept;
3008
3009 private:
3010 const OrtLogger* logger_{};
3011 OrtLoggingLevel cached_severity_level_{};
3012};
3013
3022 size_t GetInputCount() const;
3023 size_t GetOutputCount() const;
3024 // If input is optional and is not present, the method returns an empty ConstValue
3025 // which can be compared to nullptr.
3026 ConstValue GetInput(size_t index) const;
3027 // If output is optional and is not present, the method returns an empty UnownedValue
3028 // which can be compared to nullptr.
3029 UnownedValue GetOutput(size_t index, const int64_t* dim_values, size_t dim_count) const;
3030 UnownedValue GetOutput(size_t index, const std::vector<int64_t>& dims) const;
3031 void* GetGPUComputeStream() const;
3034 Ort::Allocator GetAllocator(const OrtMemoryInfo& memory_info) const;
3035 OrtKernelContext* GetOrtKernelContext() const { return ctx_; }
3036 void ParallelFor(void (*fn)(void*, size_t), size_t total, size_t num_batch, void* usr_data) const;
3037
3038 private:
3039 OrtKernelContext* ctx_;
3040};
3041
3042struct KernelInfo;
3043
3044namespace detail {
3045namespace attr_utils {
3046void GetAttr(const OrtKernelInfo* p, const char* name, float&);
3047void GetAttr(const OrtKernelInfo* p, const char* name, int64_t&);
3048void GetAttr(const OrtKernelInfo* p, const char* name, std::string&);
3049void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<float>&);
3050void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<int64_t>&);
3051void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<std::string>&);
3052} // namespace attr_utils
3053
3054template <typename T>
3055struct KernelInfoImpl : Base<T> {
3056 using B = Base<T>;
3057 using B::B;
3058
3059 KernelInfo Copy() const;
3060
3061 template <typename R> // R is only implemented for float, int64_t, and string
3062 R GetAttribute(const char* name) const {
3063 R val;
3064 attr_utils::GetAttr(this->p_, name, val);
3065 return val;
3066 }
3067
3068 template <typename R> // R is only implemented for float, int64_t, and string
3069 std::vector<R> GetAttributes(const char* name) const {
3070 std::vector<R> result;
3071 attr_utils::GetAttrs(this->p_, name, result);
3072 return result;
3073 }
3074
3075 Value GetTensorAttribute(const char* name, OrtAllocator* allocator) const;
3076
3077 size_t GetInputCount() const;
3078 size_t GetOutputCount() const;
3079
3080 std::string GetInputName(size_t index) const;
3081 std::string GetOutputName(size_t index) const;
3082
3083 TypeInfo GetInputTypeInfo(size_t index) const;
3084 TypeInfo GetOutputTypeInfo(size_t index) const;
3085
3086 ConstValue GetTensorConstantInput(size_t index, int* is_constant) const;
3087
3088 std::string GetNodeName() const;
3089 Logger GetLogger() const;
3090
3091 KeyValuePairs GetConfigEntries() const;
3092
3093 std::string GetOperatorDomain() const;
3094 std::string GetOperatorType() const;
3095 int GetOperatorSinceVersion() const;
3096 const OrtEp* GetEp() const;
3097};
3098
3099} // namespace detail
3100
3101using ConstKernelInfo = detail::KernelInfoImpl<detail::Unowned<const OrtKernelInfo>>;
3102
3109struct KernelInfo : detail::KernelInfoImpl<OrtKernelInfo> {
3110 using Base = detail::KernelInfoImpl<OrtKernelInfo>;
3111 using Base::Base;
3112 explicit KernelInfo(std::nullptr_t) {}
3113 explicit KernelInfo(OrtKernelInfo* info);
3114 ConstKernelInfo GetConst() const { return ConstKernelInfo{this->p_}; }
3115};
3116
3120struct Op : detail::Base<OrtOp> {
3122 using Base::Base;
3123
3124 explicit Op(std::nullptr_t) {}
3125
3126 explicit Op(OrtOp*);
3127
3128 static Op Create(const OrtKernelInfo* info, const char* op_name, const char* domain,
3129 int version, const char** type_constraint_names,
3130 const ONNXTensorElementDataType* type_constraint_values,
3131 size_t type_constraint_count,
3132 const OpAttr* attr_values,
3133 size_t attr_count,
3134 size_t input_count, size_t output_count);
3135
3136 void Invoke(const OrtKernelContext* context,
3137 const Value* input_values,
3138 size_t input_count,
3139 Value* output_values,
3140 size_t output_count);
3141
3142 // For easier refactoring
3143 void Invoke(const OrtKernelContext* context,
3144 const OrtValue* const* input_values,
3145 size_t input_count,
3146 OrtValue* const* output_values,
3147 size_t output_count);
3148};
3149
3155 SymbolicInteger(int64_t i) : i_(i), is_int_(true) {};
3156 SymbolicInteger(const char* s) : s_(s), is_int_(false) {};
3159
3162
3163 bool operator==(const SymbolicInteger& dim) const {
3164 if (is_int_ == dim.is_int_) {
3165 if (is_int_) {
3166 return i_ == dim.i_;
3167 } else {
3168 return std::string{s_} == std::string{dim.s_};
3169 }
3170 }
3171 return false;
3172 }
3173
3174 bool IsInt() const { return is_int_; }
3175 int64_t AsInt() const { return i_; }
3176 const char* AsSym() const { return s_; }
3177
3178 static constexpr int INVALID_INT_DIM = -2;
3179
3180 private:
3181 union {
3182 int64_t i_;
3183 const char* s_;
3184 };
3185 bool is_int_;
3186 };
3187
3188 using Shape = std::vector<SymbolicInteger>;
3189
3191
3192 const Shape& GetInputShape(size_t indice) const { return input_shapes_.at(indice); }
3193
3194 size_t GetInputCount() const { return input_shapes_.size(); }
3195
3197
3198 int64_t GetAttrInt(const char* attr_name);
3199
3200 using Ints = std::vector<int64_t>;
3201 Ints GetAttrInts(const char* attr_name);
3202
3203 float GetAttrFloat(const char* attr_name);
3204
3205 using Floats = std::vector<float>;
3206 Floats GetAttrFloats(const char* attr_name);
3207
3208 std::string GetAttrString(const char* attr_name);
3209
3210 using Strings = std::vector<std::string>;
3211 Strings GetAttrStrings(const char* attr_name);
3212
3213 private:
3214 ConstOpAttr GetAttrHdl(const char* attr_name) const;
3215 const OrtApi* ort_api_;
3217 std::vector<Shape> input_shapes_;
3218};
3219
3221
3222#define MAX_CUSTOM_OP_END_VER (1UL << 31) - 1
3223
3224template <typename TOp, typename TKernel, bool WithStatus = false>
3228 OrtCustomOp::GetName = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetName(); };
3229
3230 OrtCustomOp::GetExecutionProviderType = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetExecutionProviderType(); };
3231
3232 OrtCustomOp::GetInputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetInputTypeCount(); };
3233 OrtCustomOp::GetInputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputType(index); };
3234 OrtCustomOp::GetInputMemoryType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputMemoryType(index); };
3235
3236 OrtCustomOp::GetOutputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetOutputTypeCount(); };
3237 OrtCustomOp::GetOutputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputType(index); };
3238
3239#if defined(_MSC_VER) && !defined(__clang__)
3240#pragma warning(push)
3241#pragma warning(disable : 26409)
3242#endif
3243 OrtCustomOp::KernelDestroy = [](void* op_kernel) { delete static_cast<TKernel*>(op_kernel); };
3244#if defined(_MSC_VER) && !defined(__clang__)
3245#pragma warning(pop)
3246#endif
3247 OrtCustomOp::GetInputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputCharacteristic(index); };
3248 OrtCustomOp::GetOutputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputCharacteristic(index); };
3249
3250 OrtCustomOp::GetVariadicInputMinArity = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetVariadicInputMinArity(); };
3251 OrtCustomOp::GetVariadicInputHomogeneity = [](const OrtCustomOp* this_) { return static_cast<int>(static_cast<const TOp*>(this_)->GetVariadicInputHomogeneity()); };
3252 OrtCustomOp::GetVariadicOutputMinArity = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetVariadicOutputMinArity(); };
3253 OrtCustomOp::GetVariadicOutputHomogeneity = [](const OrtCustomOp* this_) { return static_cast<int>(static_cast<const TOp*>(this_)->GetVariadicOutputHomogeneity()); };
3254#ifdef __cpp_if_constexpr
3255 if constexpr (WithStatus) {
3256#else
3257 if (WithStatus) {
3258#endif
3259 OrtCustomOp::CreateKernelV2 = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info, void** op_kernel) -> OrtStatusPtr {
3260 return static_cast<const TOp*>(this_)->CreateKernelV2(*api, info, op_kernel);
3261 };
3262 OrtCustomOp::KernelComputeV2 = [](void* op_kernel, OrtKernelContext* context) -> OrtStatusPtr {
3263 return static_cast<TKernel*>(op_kernel)->ComputeV2(context);
3264 };
3265 } else {
3268
3269 OrtCustomOp::CreateKernel = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info) { return static_cast<const TOp*>(this_)->CreateKernel(*api, info); };
3270 OrtCustomOp::KernelCompute = [](void* op_kernel, OrtKernelContext* context) {
3271 static_cast<TKernel*>(op_kernel)->Compute(context);
3272 };
3273 }
3274
3275 SetShapeInferFn<TOp>(0);
3276
3277 OrtCustomOp::GetStartVersion = [](const OrtCustomOp* this_) {
3278 return static_cast<const TOp*>(this_)->start_ver_;
3279 };
3280
3281 OrtCustomOp::GetEndVersion = [](const OrtCustomOp* this_) {
3282 return static_cast<const TOp*>(this_)->end_ver_;
3283 };
3284
3287 OrtCustomOp::GetAliasMap = nullptr;
3289 }
3290
3291 // Default implementation of GetExecutionProviderType that returns nullptr to default to the CPU provider
3292 const char* GetExecutionProviderType() const { return nullptr; }
3293
3294 // Default implementations of GetInputCharacteristic() and GetOutputCharacteristic() below
3295 // (inputs and outputs are required by default)
3297 return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED;
3298 }
3299
3301 return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED;
3302 }
3303
3304 // Default implementation of GetInputMemoryType() that returns OrtMemTypeDefault
3305 OrtMemType GetInputMemoryType(size_t /*index*/) const {
3306 return OrtMemTypeDefault;
3307 }
3308
3309 // Default implementation of GetVariadicInputMinArity() returns 1 to specify that a variadic input
3310 // should expect at least 1 argument.
3312 return 1;
3313 }
3314
3315 // Default implementation of GetVariadicInputHomegeneity() returns true to specify that all arguments
3316 // to a variadic input should be of the same type.
3318 return true;
3319 }
3320
3321 // Default implementation of GetVariadicOutputMinArity() returns 1 to specify that a variadic output
3322 // should produce at least 1 output value.
3324 return 1;
3325 }
3326
3327 // Default implementation of GetVariadicOutputHomegeneity() returns true to specify that all output values
3328 // produced by a variadic output should be of the same type.
3330 return true;
3331 }
3332
3333 // Declare list of session config entries used by this Custom Op.
3334 // Implement this function in order to get configs from CustomOpBase::GetSessionConfigs().
3335 // This default implementation returns an empty vector of config entries.
3336 std::vector<std::string> GetSessionConfigKeys() const {
3337 return std::vector<std::string>{};
3338 }
3339
3340 // Ort::CustomOpBase derived class should provide the following static method with the type/shape inferencing
3341 // implementation if needed:
3342 // static OrtStatusPtr InferOutputShape(Ort::ShapeInferContext& context)
3343 template <typename C>
3344 decltype(&C::InferOutputShape) SetShapeInferFn(decltype(&C::InferOutputShape)) {
3346 ShapeInferContext ctx(&GetApi(), ort_ctx);
3347 return C::InferOutputShape(ctx);
3348 };
3349 return {};
3350 }
3351
3352 template <typename C>
3356
3357 protected:
3358 // Helper function that returns a map of session config entries specified by CustomOpBase::GetSessionConfigKeys.
3359 void GetSessionConfigs(std::unordered_map<std::string, std::string>& out, ConstSessionOptions options) const;
3360
3361 int start_ver_ = 1;
3362 int end_ver_ = MAX_CUSTOM_OP_END_VER;
3363};
3364
3365// Forward declaration to resolve circular dependency
3366// on ConstNode
3368
3369namespace detail {
3370template <typename T>
3372 using B = Base<T>;
3373 using B::B;
3374
3376 std::string GetName() const;
3382 std::vector<ValueInfoConsumerProducerInfo> GetConsumers() const;
3392 bool IsGraphOutput() const;
3396 bool IsFromOuterScope() const;
3397};
3398} // namespace detail
3399
3400// Const object holder that does not own the underlying object
3402
3407 ValueInfo() = default; // Same thing as with nullptr
3408 explicit ValueInfo(std::nullptr_t) {}
3410 explicit ValueInfo(OrtValueInfo* p) : ConstValueInfoImpl<OrtValueInfo>{p} {}
3411
3412#if !defined(ORT_MINIMAL_BUILD)
3413 // Create ValueInfo for a tensor
3414 explicit ValueInfo(const std::string& name, const ConstTypeInfo& type_info);
3415#endif
3416 ConstValueInfo GetConst() const { return ConstValueInfo{this->p_}; }
3417};
3418
3419// Forward declaration
3420struct AttrNameSubgraph;
3421
3422namespace detail {
3423// Forward decl
3424template <typename T>
3425struct ConstGraphImpl;
3426
3427template <typename T>
3428struct ConstNodeImpl : Base<T> {
3429 using B = Base<T>;
3430 using B::B;
3431
3432 // <Wraps OrtApi::Node_GetId
3433 size_t GetId() const;
3434 // <Wraps OrtApi::Node_GetName
3435 std::string GetName() const;
3436 // <Wraps OrtApi::Node_GetOperatorType
3437 std::string GetOperatorType() const;
3438 // <Wraps OrtApi::Node_GetDomain
3439 std::string GetDomain() const;
3440 // <Wraps OrtApi::Node_GetSinceVersion
3441 int GetSinceVersion() const;
3442
3443 // <Wraps OrtApi::Node_Inputs
3444 std::vector<ConstValueInfo> GetInputs() const;
3445 // <Wraps OrtApi::Node_Outputs
3446 std::vector<ConstValueInfo> GetOutputs() const;
3447 // <Wraps OrtApi::Node_ImplicitInputs
3448 std::vector<ConstValueInfo> GetImplicitInputs() const;
3449 // <Wraps OrtApi::Node_GetAttributes
3450 std::vector<ConstOpAttr> GetAttributes() const;
3451 // <Wraps OrtApi::Node_GetAttributeByName
3452 // Please, read C API doc for details
3453 Status GetAttributeByName(const std::string& name, ConstOpAttr& attr) const;
3454 // <Wraps OrtApi::Node_GetSubgraphs
3455 std::vector<AttrNameSubgraph> GetSubgraphs() const;
3456 // <Wraps OrtApi::Node_GetGraph
3457 // ConstGraph is not available yet
3459 // <Wraps OrtApi::Node_GetEpName
3460 std::string GetEpName() const;
3461};
3462} // namespace detail
3463
3465
3469struct Node : detail::ConstNodeImpl<OrtNode> {
3470 Node() = default; // Same thing as with nullptr
3471 explicit Node(std::nullptr_t) {}
3472 explicit Node(OrtNode* p) : ConstNodeImpl<OrtNode>{p} {}
3473
3474#if !defined(ORT_MINIMAL_BUILD)
3475 Node(const std::string& operator_name, const std::string& operator_domain,
3476 const std::string& node_name,
3477 const std::vector<std::string>& input_names,
3478 const std::vector<std::string>& output_names);
3479
3483 Node(const std::string& operator_name, const std::string& operator_domain,
3484 const std::string& node_name,
3485 const std::vector<std::string>& input_names,
3486 const std::vector<std::string>& output_names,
3487 std::vector<OpAttr>& attributes);
3488
3489 private:
3490 static void Init(const std::string& operator_name, const std::string& operator_domain,
3491 const std::string& node_name,
3492 const std::vector<std::string>& input_names,
3493 const std::vector<std::string>& output_names,
3494 std::vector<OpAttr>& attributes,
3495 OrtNode*& node);
3496#endif // !defined(ORT_MINIMAL_BUILD)
3497};
3498
3499// Return struct for some of ValueInfo APIs.
3500// Must be declared after ConstNode is available.
3503 // either producer output or consumer output index
3504 // producer is unsigned only, output can be -1
3505 int64_t index;
3506};
3507
3508// Represents a return value for Graph::GetOperatorSets()
3510 std::string domain;
3511 int64_t version;
3512};
3513
3514namespace detail {
3515template <typename T>
3517 using B = Base<T>;
3518 using B::B;
3519
3520 // <Wraps OrtApi::Graph_GetName
3521 std::string GetName() const;
3522 // <Wraps OrtApi::Graph_GetModelPath
3523 std::basic_string<ORTCHAR_T> GetModelPath() const;
3524 // <Wraps OrtApi::Graph_GetOnnxIRVersion
3525 int64_t GetOnnxIRVersion() const;
3526 // <Wraps OrtApi::Graph_GetOperatorSets
3527 std::vector<OperatorSet> GetOperatorSets() const;
3528 // <Wraps OrtApi::Graph_Inputs
3529 std::vector<ConstValueInfo> GetInputs() const;
3530 // <Wraps OrtApi::Graph_Outputs
3531 std::vector<ConstValueInfo> GetOutputs() const;
3532 // <Wraps OrtApi::Graph_Initializers
3533 std::vector<ConstValueInfo> GetInitializers() const;
3534 // <Wraps OrtApi::Graph_GetNodes
3535 std::vector<ConstNode> GetNodes() const;
3536 // <Wraps OrtApi::Graph_GetParentGraph
3538 // <Wraps OrtApi::Graph_GetGraphView
3539 Graph GetGraphView(const std::vector<ConstNode>& nodes) const;
3540 // <Wraps OrtApi::Graph_GetModelMetadata
3542};
3543
3544template <typename T>
3547 using B::B;
3548
3549#if !defined(ORT_MINIMAL_BUILD)
3553 void SetInputs(std::vector<ValueInfo>& inputs);
3557 void SetOutputs(std::vector<ValueInfo>& outputs);
3561 void AddInitializer(const std::string& name, Value& initializer, bool data_is_external); // Graph takes ownership of Value
3565 void AddNode(Node& node); // Graph takes ownership of Node
3566#endif // !defined(ORT_MINIMAL_BUILD)
3567};
3568} // namespace detail
3569
3571
3572// Return value for Node API
3573// Must be declared after ConstGraph
3578
3582struct Graph : detail::GraphImpl<OrtGraph> {
3583 explicit Graph(std::nullptr_t) {}
3584 explicit Graph(OrtGraph* p) : GraphImpl<OrtGraph>{p} {}
3585#if !defined(ORT_MINIMAL_BUILD)
3586 // <Wraps GetModelEditorApi().CreateGraph()
3588#endif
3589};
3590
3591namespace detail {
3592template <typename T>
3595 using B::B;
3596
3597#if !defined(ORT_MINIMAL_BUILD)
3601 void AddGraph(Graph& graph);
3602#endif
3603};
3604} // namespace detail
3605
3606// Const object holder that does not own the underlying object
3608
3612struct Model : detail::ModelImpl<OrtModel> {
3613 using DomainOpsetPair = std::pair<std::string, int>;
3614
3615 explicit Model(std::nullptr_t) {}
3616 explicit Model(OrtModel* p) : ModelImpl<OrtModel>{p} {}
3617
3618#if !defined(ORT_MINIMAL_BUILD)
3619 //< Wraps GetModelEditorApi().CreateModel()
3620 explicit Model(const std::vector<DomainOpsetPair>& opsets);
3621#endif
3622};
3623
3624namespace detail {
3625template <typename T>
3627 using B = Base<T>;
3628 using B::B;
3629
3631 const char* GetOperatorType() const;
3632
3634 const char* GetDomain() const;
3635
3637 std::pair<int, int> GetSinceVersion() const;
3638
3640 const char* GetExecutionProvider() const;
3641
3643 OrtMemType GetInputMemType(size_t input_index) const;
3644
3646 OrtMemType GetOutputMemType(size_t output_index) const;
3647};
3648} // namespace detail
3649
3651
3654 using Base::Base;
3655
3656 explicit KernelDef(std::nullptr_t) {}
3657 explicit KernelDef(OrtKernelDef* p) : detail::ConstKernelDefImpl<OrtKernelDef>{p} {}
3658
3659 ConstKernelDef GetConst() const { return ConstKernelDef{this->p_}; }
3660};
3661
3666struct KernelDefBuilder : detail::Base<OrtKernelDefBuilder> {
3668 explicit KernelDefBuilder(std::nullptr_t) {}
3669 explicit KernelDefBuilder(OrtKernelDefBuilder* ort_kernel_def_builder);
3670
3671 KernelDefBuilder& SetOperatorType(const char* op_type);
3672 KernelDefBuilder& SetDomain(const char* domain);
3673 KernelDefBuilder& SetSinceVersion(int since_version_start, int since_version_end);
3675 KernelDefBuilder& SetInputMemType(size_t input_index, OrtMemType mem_type);
3676 KernelDefBuilder& SetOutputMemType(size_t output_index, OrtMemType mem_type);
3677 KernelDefBuilder& AddTypeConstraint(const char* arg_name, const OrtDataType* data_type);
3678 KernelDefBuilder& AddTypeConstraint(const char* arg_name, const std::vector<const OrtDataType*>& data_types);
3679 KernelDefBuilder& AddInputOutputAlias(int input_index, int output_index);
3680 KernelDefBuilder& AddInputOutputAliases(const std::vector<int>& input_indices,
3681 const std::vector<int>& output_indices);
3682 KernelDefBuilder& AddInputOutputMutableAlias(int input_index, int output_index);
3683 KernelDefBuilder& AddInputOutputMutableAliases(const std::vector<int>& input_indices,
3684 const std::vector<int>& output_indices);
3685
3687};
3688
3693struct KernelRegistry : detail::Base<OrtKernelRegistry> {
3696
3698 explicit KernelRegistry(std::nullptr_t) {}
3699
3701 explicit KernelRegistry(OrtKernelRegistry* ort_kernel_registry);
3702
3704 Status AddKernel(const OrtKernelDef* kernel_def, OrtKernelCreateFunc kernel_create_func,
3705 void* kernel_create_func_state);
3706};
3707
3708namespace detail {
3709template <typename T>
3711 using B = Base<T>;
3712 using B::B;
3713
3715 std::string GetTypeParamName() const;
3716
3718 std::vector<std::string> GetAllowedTypes() const;
3719
3721 std::vector<size_t> GetInputIndices() const;
3722
3724 std::vector<size_t> GetOutputIndices() const;
3725};
3726} // namespace detail
3727
3732
3733namespace detail {
3734template <typename T>
3735struct OpSchemaImpl : Base<T> {
3736 using B = Base<T>;
3737 using B::B;
3738
3740 int GetSinceVersion() const;
3741
3743 size_t GetNumInputs() const;
3744
3746 std::string GetInputName(size_t index) const;
3747
3751
3753 size_t GetNumOutputs() const;
3754
3756 std::string GetOutputName(size_t index) const;
3757
3761
3764
3767};
3768} // namespace detail
3769
3775
3781OpSchema GetOpSchema(const char* name, int max_inclusive_version, const char* domain);
3782
3783namespace detail {
3784template <typename T>
3787 using B::B;
3788
3789 //< Wraps SharedPrePackedWeightCache_StoreWeightData
3790 Status StoreWeightData(void** buffer_data_ptrs, size_t* buffer_sizes, size_t num_buffers);
3791};
3792} // namespace detail
3793
3811
3814
3815} // namespace Ort
3816#include "onnxruntime_cxx_inline.h"
struct OrtMemoryInfo OrtMemoryInfo
Definition onnxruntime_c_api.h:292
struct OrtKernelInfo OrtKernelInfo
Definition onnxruntime_c_api.h:478
struct OrtNode OrtNode
Definition onnxruntime_c_api.h:320
OrtLoggingLevel
Logging severity levels.
Definition onnxruntime_c_api.h:260
OrtMemoryInfoDeviceType
This mimics OrtDevice type constants so they can be returned in the API.
Definition onnxruntime_c_api.h:513
struct OrtShapeInferContext OrtShapeInferContext
Definition onnxruntime_c_api.h:317
void(* OrtLoggingFunction)(void *param, OrtLoggingLevel severity, const char *category, const char *logid, const char *code_location, const char *message)
Definition onnxruntime_c_api.h:442
void(* OrtCustomJoinThreadFn)(OrtCustomThreadHandle ort_custom_thread_handle)
Custom thread join function.
Definition onnxruntime_c_api.h:979
OrtCustomOpInputOutputCharacteristic
Definition onnxruntime_c_api.h:7541
struct OrtTensorRTProviderOptionsV2 OrtTensorRTProviderOptionsV2
Definition onnxruntime_c_api.h:309
struct OrtThreadingOptions OrtThreadingOptions
Definition onnxruntime_c_api.h:306
struct OrtSequenceTypeInfo OrtSequenceTypeInfo
Definition onnxruntime_c_api.h:300
struct OrtValueInfo OrtValueInfo
Definition onnxruntime_c_api.h:319
struct OrtDnnlProviderOptions OrtDnnlProviderOptions
Definition onnxruntime_c_api.h:313
OrtSparseIndicesFormat
Definition onnxruntime_c_api.h:249
struct OrtPrepackedWeightsContainer OrtPrepackedWeightsContainer
Definition onnxruntime_c_api.h:308
struct OrtSession OrtSession
Definition onnxruntime_c_api.h:294
OrtCompiledModelCompatibility
Definition onnxruntime_c_api.h:1192
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:567
struct OrtCustomOpDomain OrtCustomOpDomain
Definition onnxruntime_c_api.h:303
struct OrtIoBinding OrtIoBinding
Definition onnxruntime_c_api.h:293
struct OrtExternalInitializerInfo OrtExternalInitializerInfo
Definition onnxruntime_c_api.h:328
OrtAllocatorType
Definition onnxruntime_c_api.h:484
struct OrtOp OrtOp
Definition onnxruntime_c_api.h:314
struct OrtTypeInfo OrtTypeInfo
Definition onnxruntime_c_api.h:297
struct OrtTensorTypeAndShapeInfo OrtTensorTypeAndShapeInfo
Definition onnxruntime_c_api.h:298
struct OrtCUDAProviderOptionsV2 OrtCUDAProviderOptionsV2
Definition onnxruntime_c_api.h:311
struct OrtProfilingEvent OrtProfilingEvent
Definition onnxruntime_ep_c_api.h:35
struct OrtKernelContext OrtKernelContext
Definition onnxruntime_c_api.h:480
struct OrtCANNProviderOptions OrtCANNProviderOptions
Definition onnxruntime_c_api.h:312
struct OrtEpDevice OrtEpDevice
Definition onnxruntime_c_api.h:325
void(* RunAsyncCallbackFn)(void *user_data, OrtValue **outputs, size_t num_outputs, OrtStatusPtr status)
Callback function for RunAsync.
Definition onnxruntime_c_api.h:1053
OrtHardwareDeviceType
Definition onnxruntime_c_api.h:520
struct OrtModel OrtModel
Definition onnxruntime_c_api.h:322
struct OrtGraph OrtGraph
Definition onnxruntime_c_api.h:321
struct OrtSyncStream OrtSyncStream
Definition onnxruntime_c_api.h:327
struct OrtSessionOptions OrtSessionOptions
Definition onnxruntime_c_api.h:302
OrtDeviceMemoryType
This matches OrtDevice::MemoryType values.
Definition onnxruntime_c_api.h:506
struct OrtValue OrtValue
Definition onnxruntime_c_api.h:295
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:586
GraphOptimizationLevel
Graph optimization level.
Definition onnxruntime_c_api.h:451
struct OrtKeyValuePairs OrtKeyValuePairs
Definition onnxruntime_c_api.h:326
OrtStatus * OrtStatusPtr
Definition onnxruntime_c_api.h:339
OrtMemType
Memory types for allocated memory, execution provider specific types should be extended in each provi...
Definition onnxruntime_c_api.h:494
OrtSparseFormat
Definition onnxruntime_c_api.h:241
ONNXType
Definition onnxruntime_c_api.h:229
struct OrtEnv OrtEnv
Definition onnxruntime_c_api.h:290
OrtErrorCode
Error codes reported by ONNX Runtime.
Definition onnxruntime_error_code.h:19
struct OrtStatus OrtStatus
Definition onnxruntime_c_api.h:291
struct OrtDeviceEpIncompatibilityDetails OrtDeviceEpIncompatibilityDetails
Definition onnxruntime_c_api.h:332
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:620
#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:316
struct OrtMapTypeInfo OrtMapTypeInfo
Definition onnxruntime_c_api.h:299
struct OrtArenaCfg OrtArenaCfg
Definition onnxruntime_c_api.h:307
ExecutionMode
Definition onnxruntime_c_api.h:459
OrtOpAttrType
Definition onnxruntime_c_api.h:268
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:972
ONNXTensorElementDataType
Definition onnxruntime_c_api.h:193
OrtExecutionProviderDevicePolicy
These are the default EP selection policies used by ORT when doing automatic EP selection.
Definition onnxruntime_c_api.h:528
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:263
@ OrtMemTypeDefault
The default allocator for execution provider.
Definition onnxruntime_c_api.h:502
@ ORT_FAIL
Definition onnxruntime_error_code.h:27
@ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT
Definition onnxruntime_c_api.h:195
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:629
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:808
detail::ConstSessionOptionsImpl< detail::Unowned< const OrtSessionOptions > > ConstSessionOptions
Definition onnxruntime_cxx_api.h:1727
detail::KernelInfoImpl< detail::Unowned< const OrtKernelInfo > > ConstKernelInfo
Definition onnxruntime_cxx_api.h:3101
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:1091
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:1726
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:257
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:3220
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:1083
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:1084
Allocator(OrtAllocator *p)
Definition onnxruntime_cxx_api.h:1088
Wrapper around OrtAllocator default instance that is owned by Onnxruntime.
Definition onnxruntime_cxx_api.h:1074
AllocatorWithDefaultOptions(std::nullptr_t)
Convenience to create a class member and then replace with an instance.
Definition onnxruntime_cxx_api.h:1075
it is a structure that represents the configuration of an arena based allocator
Definition onnxruntime_cxx_api.h:2797
ArenaCfg(std::nullptr_t)
Create an empty ArenaCfg object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:2798
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:3574
ConstGraph sub_graph
Definition onnxruntime_cxx_api.h:3576
std::string attr_name
Definition onnxruntime_cxx_api.h:3575
bfloat16 (Brain Floating Point) data type
Definition onnxruntime_cxx_api.h:427
bool operator==(const BFloat16_t &rhs) const noexcept
onnxruntime_float16::BFloat16Impl< BFloat16_t > Base
Definition onnxruntime_cxx_api.h:439
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:448
bool operator!=(const BFloat16_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:546
BFloat16_t(float v) noexcept
__ctor from float. Float is converted into bfloat16 16-bit representation.
Definition onnxruntime_cxx_api.h:454
float ToFloat() const noexcept
Converts bfloat16 to float.
Definition onnxruntime_cxx_api.h:460
bool operator<(const BFloat16_t &rhs) const noexcept
The CUDAProviderOptions (V2)
Definition onnxruntime_cxx_api.h:879
CUDAProviderOptions()
Wraps OrtApi::CreateCUDAProviderOptions.
CUDAProviderOptions(std::nullptr_t)
Definition onnxruntime_cxx_api.h:880
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:3225
OrtCustomOpInputOutputCharacteristic GetOutputCharacteristic(size_t) const
Definition onnxruntime_cxx_api.h:3300
OrtCustomOpInputOutputCharacteristic GetInputCharacteristic(size_t) const
Definition onnxruntime_cxx_api.h:3296
OrtMemType GetInputMemoryType(size_t) const
Definition onnxruntime_cxx_api.h:3305
std::vector< std::string > GetSessionConfigKeys() const
Definition onnxruntime_cxx_api.h:3336
bool GetVariadicInputHomogeneity() const
Definition onnxruntime_cxx_api.h:3317
int GetVariadicInputMinArity() const
Definition onnxruntime_cxx_api.h:3311
void SetShapeInferFn(...)
Definition onnxruntime_cxx_api.h:3353
CustomOpBase()
Definition onnxruntime_cxx_api.h:3226
bool GetVariadicOutputHomogeneity() const
Definition onnxruntime_cxx_api.h:3329
int GetVariadicOutputMinArity() const
Definition onnxruntime_cxx_api.h:3323
decltype(&C::InferOutputShape) SetShapeInferFn(decltype(&C::InferOutputShape))
Definition onnxruntime_cxx_api.h:3344
const char * GetExecutionProviderType() const
Definition onnxruntime_cxx_api.h:3292
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:1574
~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:1457
CustomOpDomain(std::nullptr_t)
Create an empty CustomOpDomain object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1461
CustomOpDomain(const char *domain)
Wraps OrtApi::CreateCustomOpDomain.
void Add(const OrtCustomOp *op)
Wraps CustomOpDomain_Add.
Wrapper around OrtDeviceEpIncompatibilityDetails.
Definition onnxruntime_cxx_api.h:1150
DeviceEpIncompatibilityDetails(OrtDeviceEpIncompatibilityDetails *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:1152
DeviceEpIncompatibilityDetails(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:1151
The Env (Environment)
Definition onnxruntime_cxx_api.h:1358
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:1378
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:1359
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.
Mutable EpDevice that is created by EpApi users.
Definition onnxruntime_cxx_api.h:1179
EpDevice(OrtEpDevice *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:1181
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:1180
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:930
ConstExternalInitializerInfo GetConst() const
Wraps OrtApi::CreateExternalInitializerInfo.
Definition onnxruntime_cxx_api.h:938
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:934
ExternalInitializerInfo(OrtExternalInitializerInfo *p)
Definition onnxruntime_cxx_api.h:935
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:285
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:313
onnxruntime_float16::Float16Impl< Float16_t > Base
Definition onnxruntime_cxx_api.h:295
float ToFloat() const noexcept
Converts float16 to float.
Definition onnxruntime_cxx_api.h:319
static constexpr Float16_t FromBits(uint16_t v) noexcept
Explicit conversion to uint16_t representation of float16.
Definition onnxruntime_cxx_api.h:307
float8e4m3fn (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:557
uint8_t value
Definition onnxruntime_cxx_api.h:558
constexpr Float8E4M3FN_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:560
constexpr bool operator==(const Float8E4M3FN_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:563
constexpr Float8E4M3FN_t() noexcept
Definition onnxruntime_cxx_api.h:559
constexpr bool operator!=(const Float8E4M3FN_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:564
float8e4m3fnuz (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:574
constexpr bool operator==(const Float8E4M3FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:580
uint8_t value
Definition onnxruntime_cxx_api.h:575
constexpr Float8E4M3FNUZ_t() noexcept
Definition onnxruntime_cxx_api.h:576
constexpr bool operator!=(const Float8E4M3FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:581
constexpr Float8E4M3FNUZ_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:577
float8e5m2 (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:591
constexpr Float8E5M2_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:594
uint8_t value
Definition onnxruntime_cxx_api.h:592
constexpr bool operator!=(const Float8E5M2_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:598
constexpr Float8E5M2_t() noexcept
Definition onnxruntime_cxx_api.h:593
constexpr bool operator==(const Float8E5M2_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:597
float8e5m2fnuz (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:608
constexpr Float8E5M2FNUZ_t() noexcept
Definition onnxruntime_cxx_api.h:610
constexpr Float8E5M2FNUZ_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:611
constexpr bool operator!=(const Float8E5M2FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:615
constexpr bool operator==(const Float8E5M2FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:614
uint8_t value
Definition onnxruntime_cxx_api.h:609
Wrapper around OrtGraph.
Definition onnxruntime_cxx_api.h:3582
Graph(OrtGraph *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:3584
Graph(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:3583
Wrapper around OrtIoBinding.
Definition onnxruntime_cxx_api.h:2786
UnownedIoBinding GetUnowned() const
Definition onnxruntime_cxx_api.h:2790
ConstIoBinding GetConst() const
Definition onnxruntime_cxx_api.h:2789
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:2787
This class wraps a raw pointer OrtKernelContext* that is being passed to the custom kernel Compute() ...
Definition onnxruntime_cxx_api.h:3020
KernelContext(OrtKernelContext *context)
OrtSyncStream * GetSyncStream() const
Logger GetLogger() const
ConstValue GetInput(size_t index) const
OrtKernelContext * GetOrtKernelContext() const
Definition onnxruntime_cxx_api.h:3035
void ParallelFor(void(*fn)(void *, size_t), size_t total, size_t num_batch, void *usr_data) 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:3666
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:3668
KernelDefBuilder(OrtKernelDefBuilder *ort_kernel_def_builder)
KernelDefBuilder & SetSinceVersion(int since_version_start, int since_version_end)
Definition onnxruntime_cxx_api.h:3652
KernelDef(OrtKernelDef *p)
Definition onnxruntime_cxx_api.h:3657
KernelDef(std::nullptr_t)
Definition onnxruntime_cxx_api.h:3656
ConstKernelDef GetConst() const
Definition onnxruntime_cxx_api.h:3659
This struct owns the OrtKernInfo* pointer when a copy is made. For convenient wrapping of OrtKernelIn...
Definition onnxruntime_cxx_api.h:3109
KernelInfo(OrtKernelInfo *info)
Take ownership of the instance.
ConstKernelInfo GetConst() const
Definition onnxruntime_cxx_api.h:3114
detail::KernelInfoImpl< OrtKernelInfo > Base
Definition onnxruntime_cxx_api.h:3110
KernelInfo(std::nullptr_t)
Create an empty instance to initialize later.
Definition onnxruntime_cxx_api.h:3112
Registry for kernels supported by an EP.
Definition onnxruntime_cxx_api.h:3693
KernelRegistry()
< Wrapper around OrtEpApi::CreateKernelRegistry
KernelRegistry(std::nullptr_t)
Take ownership of a pointer created with the C API.
Definition onnxruntime_cxx_api.h:3698
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:967
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:968
ConstKeyValuePairs GetConst() const
Definition onnxruntime_cxx_api.h:984
KeyValuePairs(OrtKeyValuePairs *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:970
This class represents an ONNX Runtime logger that can be used to log information with an associated s...
Definition onnxruntime_cxx_api.h:2942
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:2951
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:1471
static LoraAdapter CreateLoraAdapter(const std::basic_string< char > &adapter_path, OrtAllocator *allocator)
Wraps OrtApi::CreateLoraAdapter.
LoraAdapter(std::nullptr_t)
Definition onnxruntime_cxx_api.h:1475
static LoraAdapter CreateLoraAdapterFromArray(const void *bytes, size_t num_bytes, OrtAllocator *allocator)
Wraps OrtApi::CreateLoraAdapterFromArray.
Wrapper around OrtMapTypeInfo.
Definition onnxruntime_cxx_api.h:2168
ConstMapTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:2174
MapTypeInfo(OrtMapTypeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:2173
MapTypeInfo(std::nullptr_t)
Create an empty MapTypeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:2172
Represents native memory allocation coming from one of the OrtAllocators registered with OnnxRuntime....
Definition onnxruntime_cxx_api.h:1028
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:1037
Wrapper around OrtMemoryInfo.
Definition onnxruntime_cxx_api.h:1012
MemoryInfo(const char *name, OrtAllocatorType type, int id, OrtMemType mem_type)
MemoryInfo(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:1014
MemoryInfo(OrtMemoryInfo *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:1015
static MemoryInfo CreateCpu(OrtAllocatorType type, OrtMemType mem_type1)
ConstMemoryInfo GetConst() const
Definition onnxruntime_cxx_api.h:1019
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:1744
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:1748
ModelCompilationOptions(const Env &env, ConstSessionOptions session_options)
Wraps OrtApi::CreateModelCompilationOptionsFromSessionOptions.
ModelCompilationOptions & SetOutputModelPath(const char *output_model_path)
Wraps OrtApi::ModelCompilationOptions_SetOutputModelPath.
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 & 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.
Wrapper around OrtModel.
Definition onnxruntime_cxx_api.h:3612
Model(const std::vector< DomainOpsetPair > &opsets)
Model(OrtModel *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:3616
std::pair< std::string, int > DomainOpsetPair
Definition onnxruntime_cxx_api.h:3613
Model(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:3615
Wrapper around OrtModelMetadata.
Definition onnxruntime_cxx_api.h:1792
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:1796
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.
Wrapper around OrtNode.
Definition onnxruntime_cxx_api.h:3469
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:3471
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:3472
This struct provides life time management for custom op attribute.
Definition onnxruntime_cxx_api.h:2851
OpAttr(const char *name, const void *data, int len, OrtOpAttrType type)
OpAttr()=default
OpAttr(std::nullptr_t)
Definition onnxruntime_cxx_api.h:2856
ConstOpAttr GetConst() const
Definition onnxruntime_cxx_api.h:2859
Create and own custom defined operation.
Definition onnxruntime_cxx_api.h:3120
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:3124
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:3509
std::string domain
Definition onnxruntime_cxx_api.h:3510
int64_t version
Definition onnxruntime_cxx_api.h:3511
The PrepackedWeightsContainer.
Definition onnxruntime_cxx_api.h:898
PrepackedWeightsContainer()
Wraps OrtApi::CreatePrepackedWeightsContainer.
PrepackedWeightsContainer(OrtPrepackedWeightsContainer *p)
Definition onnxruntime_cxx_api.h:903
PrepackedWeightsContainer(std::nullptr_t)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:901
Owning wrapper around OrtProfilingEvent.
Definition onnxruntime_cxx_api.h:1305
ProfilingEvent(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:1306
ConstProfilingEvent GetConst() const
Definition onnxruntime_cxx_api.h:1330
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:1307
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:1499
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:1500
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:2130
SequenceTypeInfo(std::nullptr_t)
Create an empty SequenceTypeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:2134
ConstSequenceTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:2136
SequenceTypeInfo(OrtSequenceTypeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:2135
Wrapper around OrtSession.
Definition onnxruntime_cxx_api.h:2026
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:2028
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:2057
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:2029
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:2056
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:1732
SessionOptions(std::nullptr_t)
Create an empty SessionOptions object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1733
UnownedSessionOptions GetUnowned() const
Definition onnxruntime_cxx_api.h:1736
SessionOptions()
Wraps OrtApi::CreateSessionOptions.
ConstSessionOptions GetConst() const
Definition onnxruntime_cxx_api.h:1737
SessionOptions(OrtSessionOptions *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1735
Definition onnxruntime_cxx_api.h:3154
SymbolicInteger & operator=(const SymbolicInteger &)=default
SymbolicInteger(const SymbolicInteger &)=default
int64_t AsInt() const
Definition onnxruntime_cxx_api.h:3175
int64_t i_
Definition onnxruntime_cxx_api.h:3182
const char * s_
Definition onnxruntime_cxx_api.h:3183
bool operator==(const SymbolicInteger &dim) const
Definition onnxruntime_cxx_api.h:3163
SymbolicInteger & operator=(SymbolicInteger &&)=default
SymbolicInteger(SymbolicInteger &&)=default
const char * AsSym() const
Definition onnxruntime_cxx_api.h:3176
SymbolicInteger(int64_t i)
Definition onnxruntime_cxx_api.h:3155
SymbolicInteger(const char *s)
Definition onnxruntime_cxx_api.h:3156
bool IsInt() const
Definition onnxruntime_cxx_api.h:3174
Provide access to per-node attributes and input shapes, so one could compute and set output shapes.
Definition onnxruntime_cxx_api.h:3153
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:3188
std::vector< float > Floats
Definition onnxruntime_cxx_api.h:3205
std::string GetAttrString(const char *attr_name)
std::vector< int64_t > Ints
Definition onnxruntime_cxx_api.h:3200
ShapeInferContext(const OrtApi *ort_api, OrtShapeInferContext *ctx)
int64_t GetAttrInt(const char *attr_name)
size_t GetInputCount() const
Definition onnxruntime_cxx_api.h:3194
std::vector< std::string > Strings
Definition onnxruntime_cxx_api.h:3210
Floats GetAttrFloats(const char *attr_name)
const Shape & GetInputShape(size_t indice) const
Definition onnxruntime_cxx_api.h:3192
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:814
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:816
Definition onnxruntime_cxx_api.h:1107
SyncStream(OrtSyncStream *p)
Definition onnxruntime_cxx_api.h:1111
SyncStream(std::nullptr_t)
< Create an empty SyncStream object, must be assigned a valid one to be used
Definition onnxruntime_cxx_api.h:1109
The TensorRTOptions (V2)
Definition onnxruntime_cxx_api.h:860
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:861
TensorRTProviderOptions()
Wraps OrtApi::CreateTensorRTProviderOptionsV2.
Wrapper around OrtTensorTypeAndShapeInfo.
Definition onnxruntime_cxx_api.h:2096
TensorTypeAndShapeInfo(std::nullptr_t)
Create an empty TensorTypeAndShapeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:2101
ConstTensorTypeAndShapeInfo GetConst() const
Definition onnxruntime_cxx_api.h:2112
TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:2103
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:830
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:2202
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:2207
static TypeInfo CreateMapTypeInfo(ONNXTensorElementDataType key_type, ConstTypeInfo value_type)
ConstTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:2218
TypeInfo(OrtTypeInfo *p)
C API Interop.
Definition onnxruntime_cxx_api.h:2208
Wrapper around OrtValue.
Definition onnxruntime_cxx_api.h:2575
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:2581
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:2586
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:2585
Definition onnxruntime_cxx_api.h:3501
int64_t index
Definition onnxruntime_cxx_api.h:3505
ConstNode node
Definition onnxruntime_cxx_api.h:3502
Wrapper around OrtValueInfo.
Definition onnxruntime_cxx_api.h:3406
ConstValueInfo GetConst() const
Definition onnxruntime_cxx_api.h:3416
ValueInfo(std::nullptr_t)
Definition onnxruntime_cxx_api.h:3408
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:3410
ValueInfo()=default
Definition onnxruntime_cxx_api.h:776
AllocatedFree(OrtAllocator *allocator)
Definition onnxruntime_cxx_api.h:778
OrtAllocator * allocator_
Definition onnxruntime_cxx_api.h:777
void operator()(void *ptr) const
Definition onnxruntime_cxx_api.h:780
Base & operator=(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:762
constexpr contained_type & operator*() const noexcept
Definition onnxruntime_cxx_api.h:769
typename Unowned< T >::Type contained_type
Definition onnxruntime_cxx_api.h:751
Base(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:761
Base(const Base &)=default
constexpr Base(contained_type *p) noexcept
Definition onnxruntime_cxx_api.h:754
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:704
Base(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:716
constexpr Base()=default
constexpr contained_type & operator*() const noexcept
Definition onnxruntime_cxx_api.h:724
contained_type * release()
Relinquishes ownership of the contained C object pointer The underlying object is not destroyed.
Definition onnxruntime_cxx_api.h:728
Base(const Base &)=delete
constexpr Base(contained_type *p) noexcept
Definition onnxruntime_cxx_api.h:708
Base & operator=(const Base &)=delete
Base & operator=(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:717
contained_type * p_
Definition onnxruntime_cxx_api.h:735
~Base()
Definition onnxruntime_cxx_api.h:709
T contained_type
Definition onnxruntime_cxx_api.h:705
Definition onnxruntime_cxx_api.h:910
const std::basic_string< char > GetFilePath() const
Definition onnxruntime_cxx_api.h:3516
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:2754
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:3626
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:3428
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:2823
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:1266
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:1867
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:2247
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:3371
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:1137
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:1233
std::string GetDomain() const
std::string GetOperatorType() const
std::string GetName() const
Definition onnxruntime_cxx_api.h:1250
std::vector< ConstEpAssignedNode > GetNodes() const
Definition onnxruntime_cxx_api.h:1158
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:3545
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:1118
OrtHardwareDeviceType Type() const
const char * Vendor() const
ConstKeyValuePairs Metadata() const
Definition onnxruntime_cxx_api.h:2765
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:950
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:2154
ONNXTensorElementDataType GetMapKeyType() const
Wraps OrtApi::GetMapKeyType.
TypeInfo GetMapValueType() const
Wraps OrtApi::GetMapValueType.
Definition onnxruntime_cxx_api.h:989
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:3593
void AddGraph(Graph &graph)
Definition onnxruntime_cxx_api.h:3735
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:3710
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:2141
TypeInfo GetOptionalElementType() const
Wraps OrtApi::CastOptionalTypeToContainedTypeInfo.
Definition onnxruntime_cxx_api.h:2230
const char ** str
Definition onnxruntime_cxx_api.h:2235
const int64_t * values_shape
Definition onnxruntime_cxx_api.h:2231
size_t values_shape_len
Definition onnxruntime_cxx_api.h:2232
const void * p_data
Definition onnxruntime_cxx_api.h:2234
Definition onnxruntime_cxx_api.h:1335
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:2117
TypeInfo GetSequenceElementType() const
Wraps OrtApi::GetSequenceElementType.
Definition onnxruntime_cxx_api.h:1931
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:2241
const int64_t * shape
Definition onnxruntime_cxx_api.h:2242
size_t shape_len
Definition onnxruntime_cxx_api.h:2243
Definition onnxruntime_cxx_api.h:3785
Status StoreWeightData(void **buffer_data_ptrs, size_t *buffer_sizes, size_t num_buffers)
Definition onnxruntime_cxx_api.h:1099
void * GetHandle()
Wraps SyncStream_GetHandle.
Definition onnxruntime_cxx_api.h:2062
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:2179
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:680
T Type
Definition onnxruntime_cxx_api.h:681
Definition onnxruntime_cxx_api.h:2433
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:358
void(* Free)(struct OrtAllocator *this_, void *p)
Free a block of memory previously allocated with OrtAllocator::Alloc.
Definition onnxruntime_c_api.h:365
const OrtApi *(* GetApi)(uint32_t version)
Get a pointer to the requested version of the OrtApi.
Definition onnxruntime_c_api.h:939
The C API.
Definition onnxruntime_c_api.h:1294
const OrtEpApi *(* GetEpApi)(void)
Get the OrtEpApi instance for implementing an execution provider.
Definition onnxruntime_c_api.h:5766
const OrtInteropApi *(* GetInteropApi)(void)
Get the EP Interop API instance.
Definition onnxruntime_c_api.h:7014
const OrtCompileApi *(* GetCompileApi)(void)
Get the Compile API instance.
Definition onnxruntime_c_api.h:5498
void(* ReleaseTensorRTProviderOptions)(OrtTensorRTProviderOptionsV2 *input)
Release an OrtTensorRTProviderOptionsV2.
Definition onnxruntime_c_api.h:3551
const OrtModelEditorApi *(* GetModelEditorApi)(void)
Get the Model Editor API instance.
Definition onnxruntime_c_api.h:5440
void(* ReleaseCUDAProviderOptions)(OrtCUDAProviderOptionsV2 *input)
Release an OrtCUDAProviderOptionsV2.
Definition onnxruntime_c_api.h:4054
CUDA Provider Options.
Definition onnxruntime_c_api.h:639
The OrtCompileApi struct provides functions to compile ONNX models.
Definition onnxruntime_c_api.h:8105
Definition onnxruntime_c_api.h:7551
int(* GetVariadicInputHomogeneity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7600
OrtCustomOpInputOutputCharacteristic(* GetOutputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7584
size_t(* GetInputTypeCount)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7572
int(* GetVariadicOutputMinArity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7604
size_t(* GetAliasMap)(int **input_index, int **output_index)
Definition onnxruntime_c_api.h:7637
int(* GetStartVersion)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7622
void(* ReleaseMayInplace)(int *input_index, int *output_index)
Definition onnxruntime_c_api.h:7634
const char *(* GetName)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7565
size_t(* GetOutputTypeCount)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7574
void(* KernelDestroy)(void *op_kernel)
Definition onnxruntime_c_api.h:7580
int(* GetVariadicOutputHomogeneity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7609
OrtMemType(* GetInputMemoryType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7591
void *(* CreateKernel)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info)
Definition onnxruntime_c_api.h:7561
uint32_t version
Definition onnxruntime_c_api.h:7552
ONNXTensorElementDataType(* GetInputType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7571
void(* ReleaseAliasMap)(int *input_index, int *output_index)
Definition onnxruntime_c_api.h:7638
OrtCustomOpInputOutputCharacteristic(* GetInputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7583
const char *(* GetExecutionProviderType)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7568
ONNXTensorElementDataType(* GetOutputType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7573
int(* GetVariadicInputMinArity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7595
OrtStatusPtr(* InferOutputShapeFn)(const struct OrtCustomOp *op, OrtShapeInferContext *)
Definition onnxruntime_c_api.h:7619
int(* GetEndVersion)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7623
OrtStatusPtr(* CreateKernelV2)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info, void **kernel)
Definition onnxruntime_c_api.h:7612
size_t(* GetMayInplace)(int **input_index, int **output_index)
Definition onnxruntime_c_api.h:7630
OrtStatusPtr(* KernelComputeV2)(void *op_kernel, OrtKernelContext *context)
Definition onnxruntime_c_api.h:7617
void(* KernelCompute)(void *op_kernel, OrtKernelContext *context)
Definition onnxruntime_c_api.h:7579
Configuration options for creating an OrtEnv.
Definition onnxruntime_c_api.h:1206
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:2675
The OrtEp struct provides functions to implement for an execution provider.
Definition onnxruntime_ep_c_api.h:2118
The OrtInteropApi struct provides functions for external resource interop with execution providers.
Definition onnxruntime_c_api.h:8401
MIGraphX Provider Options.
Definition onnxruntime_c_api.h:843
The OrtModelEditorApi struct provides functions to create or edit an ONNX model.
Definition onnxruntime_c_api.h:7652
OpenVINO Provider Options.
Definition onnxruntime_c_api.h:882
ROCM Provider Options.
Definition onnxruntime_c_api.h:726
TensorRT Provider Options.
Definition onnxruntime_c_api.h:815
Configuration for thread pool work callbacks.
Definition onnxruntime_c_api.h:1032