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);
632ORT_DEFINE_RELEASE(Env);
633ORT_DEFINE_RELEASE(ExternalInitializerInfo);
634ORT_DEFINE_RELEASE(Graph);
635ORT_DEFINE_RELEASE(IoBinding);
636ORT_DEFINE_RELEASE(KernelInfo);
637ORT_DEFINE_RELEASE(KeyValuePairs);
638ORT_DEFINE_RELEASE(LoraAdapter);
639ORT_DEFINE_RELEASE(MemoryInfo);
640ORT_DEFINE_RELEASE(MapTypeInfo);
641ORT_DEFINE_RELEASE(Model);
642ORT_DEFINE_RELEASE(ModelMetadata);
643ORT_DEFINE_RELEASE(Node);
644ORT_DEFINE_RELEASE(Op);
645ORT_DEFINE_RELEASE(OpAttr);
646ORT_DEFINE_RELEASE(PrepackedWeightsContainer);
647ORT_DEFINE_RELEASE(RunOptions);
648ORT_DEFINE_RELEASE(Session);
649ORT_DEFINE_RELEASE(SessionOptions);
650ORT_DEFINE_RELEASE(SequenceTypeInfo);
651ORT_DEFINE_RELEASE(Status);
652ORT_DEFINE_RELEASE(SyncStream);
653ORT_DEFINE_RELEASE(TensorTypeAndShapeInfo);
654ORT_DEFINE_RELEASE(ThreadingOptions);
655ORT_DEFINE_RELEASE(TypeInfo);
656ORT_DEFINE_RELEASE(Value);
657ORT_DEFINE_RELEASE(ValueInfo);
658
659ORT_DEFINE_RELEASE_FROM_API_STRUCT(ModelCompilationOptions, GetCompileApi);
660ORT_DEFINE_RELEASE_FROM_API_STRUCT(EpDevice, GetEpApi);
661ORT_DEFINE_RELEASE_FROM_API_STRUCT(KernelDef, GetEpApi);
662ORT_DEFINE_RELEASE_FROM_API_STRUCT(KernelDefBuilder, GetEpApi);
663ORT_DEFINE_RELEASE_FROM_API_STRUCT(KernelRegistry, GetEpApi);
664
665// This is defined explicitly since OrtTensorRTProviderOptionsV2 is not a C API type,
666// but the struct has V2 in its name to indicate that it is the second version of the options.
669
670#undef ORT_DEFINE_RELEASE
671#undef ORT_DEFINE_RELEASE_FROM_API_STRUCT
672
676template <typename T>
677struct Unowned {
678 using Type = T;
679};
680
700template <typename T>
701struct Base {
702 using contained_type = T;
703
704 constexpr Base() = default;
705 constexpr explicit Base(contained_type* p) noexcept : p_{p} {}
707 OrtRelease(p_);
708 }
709
710 Base(const Base&) = delete;
711 Base& operator=(const Base&) = delete;
712
713 Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }
714 Base& operator=(Base&& v) noexcept {
715 OrtRelease(p_);
716 p_ = v.release();
717 return *this;
718 }
719
720 constexpr operator contained_type*() const noexcept { return p_; }
721 constexpr contained_type& operator*() const noexcept { return *p_; }
722
726 T* p = p_;
727 p_ = nullptr;
728 return p;
729 }
730
731 protected:
733};
734
735// Undefined. For const types use Base<Unowned<const T>>
736template <typename T>
737struct Base<const T>;
738
746template <typename T>
747struct Base<Unowned<T>> {
749
750 constexpr Base() = default;
751 constexpr explicit Base(contained_type* p) noexcept : p_{p} {}
752
753 ~Base() = default;
754
755 Base(const Base&) = default;
756 Base& operator=(const Base&) = default;
757
758 Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }
759 Base& operator=(Base&& v) noexcept {
760 p_ = nullptr;
761 std::swap(p_, v.p_);
762 return *this;
763 }
764
765 constexpr operator contained_type*() const noexcept { return p_; }
766 constexpr contained_type& operator*() const noexcept { return *p_; }
767
768 protected:
770};
771
772// Light functor to release memory with OrtAllocator
775 explicit AllocatedFree(OrtAllocator* allocator)
776 : allocator_(allocator) {}
777 void operator()(void* ptr) const {
778 if (ptr) allocator_->Free(allocator_, ptr);
779 }
780};
781
782} // namespace detail
783
784struct AllocatorWithDefaultOptions;
785struct Env;
786struct EpDevice;
787struct ExternalInitializerInfo;
788struct Graph;
789struct Model;
790struct Node;
791struct ModelMetadata;
792struct TypeInfo;
793struct PrepackedWeightsContainer;
794struct Session;
795struct SessionOptions;
796struct SyncStream;
797struct TensorRTProviderOptions;
798struct Value;
799struct ValueInfo;
800
805using AllocatedStringPtr = std::unique_ptr<char, detail::AllocatedFree>;
806
811struct Status : detail::Base<OrtStatus> {
812 Status() = default; // Same as with std::nullptr_t. But can be used in re-sizable containers and represent success.
813 explicit Status(std::nullptr_t) noexcept {}
814 explicit Status(OrtStatus* status) noexcept;
815 explicit Status(const Exception&);
816 explicit Status(const std::exception&);
817 Status(const char* message, OrtErrorCode code);
818 std::string GetErrorMessage() const;
820 bool IsOK() const noexcept;
821};
822
852
857struct TensorRTProviderOptions : detail::Base<OrtTensorRTProviderOptionsV2> {
858 TensorRTProviderOptions(std::nullptr_t) {}
862 void Update(const std::unordered_map<std::string, std::string>& options);
864 void UpdateWithValue(const char* key, void* value);
865
867 void* GetOptionByName(const char* name) const;
870};
871
876struct CUDAProviderOptions : detail::Base<OrtCUDAProviderOptionsV2> {
877 CUDAProviderOptions(std::nullptr_t) {}
881 void Update(const std::unordered_map<std::string, std::string>& options);
885 void UpdateWithValue(const char* key, void* value);
887 void* GetOptionByName(const char* name) const;
888};
889
904
905namespace detail {
906template <typename T>
908 using B = Base<T>;
909 using B::B;
910
911 // Wraps OrtApi::ExternalInitializerInfo_GetFilePath
912 const std::basic_string<ORTCHAR_T> GetFilePath() const;
913 // Wraps OrtApi::ExternalInitializerInfo_GetFileOffset
914 int64_t GetFileOffset() const;
915 // Wraps OrtApi::ExternalInitializerInfo_GetByteSize
916 size_t GetByteSize() const;
917};
918} // namespace detail
919
920// Const object holder that does not own the underlying object
923
929 using Base::Base;
930
931 explicit ExternalInitializerInfo(std::nullptr_t) {}
933 : detail::ConstExternalInitializerInfoImpl<OrtExternalInitializerInfo>{p} {}
934
936
938 ExternalInitializerInfo(const ORTCHAR_T* filepath, int64_t file_offset, size_t byte_size);
939
941 static Status Create(const ORTCHAR_T* filepath, int64_t file_offset, size_t byte_size,
942 /*out*/ ExternalInitializerInfo& out);
943};
944
945namespace detail {
946template <typename T>
949 using B::B;
950
951 const char* GetValue(const char* key) const;
952
953 // get the pairs in unordered_map. needs to copy to std::string so the hash works as expected
954 std::unordered_map<std::string, std::string> GetKeyValuePairs() const;
955 // get the pairs in two vectors. entries will be 1:1 between keys and values. avoids copying to std::string
956 void GetKeyValuePairs(std::vector<const char*>& keys, std::vector<const char*>& values) const;
957};
958} // namespace detail
959
960// Const object holder that does not own the underlying object
962
964struct KeyValuePairs : detail::KeyValuePairsImpl<OrtKeyValuePairs> {
965 explicit KeyValuePairs(std::nullptr_t) {}
967 explicit KeyValuePairs(OrtKeyValuePairs* p) : KeyValuePairsImpl<OrtKeyValuePairs>{p} {}
968
970 explicit KeyValuePairs();
971
973 explicit KeyValuePairs(const std::unordered_map<std::string, std::string>& kv_pairs);
974
976 void Add(const char* key, const char* value);
977
979 void Remove(const char* key);
980
981 ConstKeyValuePairs GetConst() const { return ConstKeyValuePairs{this->p_}; }
982};
983
984namespace detail {
985template <typename T>
986struct MemoryInfoImpl : Base<T> {
987 using B = Base<T>;
988 using B::B;
989
990 std::string GetAllocatorName() const;
992 int GetDeviceId() const;
996 uint32_t GetVendorId() const;
997
998 template <typename U>
999 bool operator==(const MemoryInfoImpl<U>& o) const;
1000};
1001} // namespace detail
1002
1003// Const object holder that does not own the underlying object
1005
1009struct MemoryInfo : detail::MemoryInfoImpl<OrtMemoryInfo> {
1011 explicit MemoryInfo(std::nullptr_t) {}
1012 explicit MemoryInfo(OrtMemoryInfo* p) : MemoryInfoImpl<OrtMemoryInfo>{p} {}
1013 MemoryInfo(const char* name, OrtAllocatorType type, int id, OrtMemType mem_type);
1014 MemoryInfo(const char* name, OrtMemoryInfoDeviceType device_type, uint32_t vendor_id, uint32_t device_id,
1015 OrtDeviceMemoryType mem_type, size_t alignment, OrtAllocatorType allocator_type);
1016 ConstMemoryInfo GetConst() const { return ConstMemoryInfo{this->p_}; }
1017};
1018
1026 MemoryAllocation(OrtAllocator* allocator, void* p, size_t size);
1031 MemoryAllocation& operator=(MemoryAllocation&&) noexcept;
1032
1033 void* get() { return p_; }
1034 size_t size() const { return size_; }
1035
1036 private:
1037 OrtAllocator* allocator_;
1038 void* p_;
1039 size_t size_;
1040};
1041
1042namespace detail {
1043template <typename T>
1044struct AllocatorImpl : Base<T> {
1045 using B = Base<T>;
1046 using B::B;
1047
1048 void* Alloc(size_t size);
1049 MemoryAllocation GetAllocation(size_t size);
1050 void Free(void* p);
1051 ConstMemoryInfo GetInfo() const;
1052
1057 KeyValuePairs GetStats() const;
1058};
1059} // namespace detail
1060
1064struct AllocatorWithDefaultOptions : detail::AllocatorImpl<detail::Unowned<OrtAllocator>> {
1065 explicit AllocatorWithDefaultOptions(std::nullptr_t) {}
1067};
1068
1073struct Allocator : detail::AllocatorImpl<OrtAllocator> {
1074 explicit Allocator(std::nullptr_t) {}
1075 Allocator(const Session& session, const OrtMemoryInfo*);
1076
1078 explicit Allocator(OrtAllocator* p) : AllocatorImpl<OrtAllocator>{p} {}
1079};
1080
1081using UnownedAllocator = detail::AllocatorImpl<detail::Unowned<OrtAllocator>>;
1082
1087namespace detail {
1088template <typename T>
1090 using B = Base<T>;
1091 using B::B;
1092 // For some reason this is not a const method on the stream
1093 void* GetHandle();
1094};
1095} // namespace detail
1096
1097struct SyncStream : detail::SyncStreamImpl<OrtSyncStream> {
1099 explicit SyncStream(std::nullptr_t) {}
1101 explicit SyncStream(OrtSyncStream* p) : SyncStreamImpl<OrtSyncStream>{p} {}
1102};
1103
1105
1106namespace detail {
1107template <typename T>
1110 using B::B;
1111
1113 uint32_t VendorId() const;
1114 uint32_t DeviceId() const;
1115 const char* Vendor() const;
1117};
1118} // namespace detail
1119
1124
1125namespace detail {
1126template <typename T>
1129 using B::B;
1130
1131 const char* EpName() const;
1132 const char* EpVendor() const;
1138};
1139} // namespace detail
1140
1145
1148struct EpDevice : detail::EpDeviceImpl<OrtEpDevice> {
1149 explicit EpDevice(std::nullptr_t) {}
1150 explicit EpDevice(OrtEpDevice* p) : EpDeviceImpl<OrtEpDevice>{p} {}
1151
1153 EpDevice(OrtEpFactory& ep_factory, ConstHardwareDevice& hardware_device,
1154 ConstKeyValuePairs ep_metadata = {}, ConstKeyValuePairs ep_options = {});
1155};
1156
1164 const std::vector<ConstEpDevice>& ep_devices,
1165 const char* compatibility_info);
1166
1182AllocatedStringPtr GetCompatibilityInfoFromModelAllocated(const ORTCHAR_T* model_path, const char* ep_type,
1183 OrtAllocator* allocator);
1184
1197AllocatedStringPtr GetCompatibilityInfoFromModelBytesAllocated(const void* model_data, size_t model_data_length,
1198 const char* ep_type, OrtAllocator* allocator);
1199
1200namespace detail {
1201template <typename T>
1204 using B::B;
1205
1206 std::string GetName() const;
1207 std::string GetDomain() const;
1208 std::string GetOperatorType() const;
1209};
1210} // namespace detail
1211
1216
1217namespace detail {
1218template <typename T>
1221 using B::B;
1222
1223 std::string GetEpName() const;
1224 std::vector<ConstEpAssignedNode> GetNodes() const;
1225};
1226} // namespace detail
1227
1232
1238struct Env : detail::Base<OrtEnv> {
1239 explicit Env(std::nullptr_t) {}
1240
1242 Env(OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
1243
1245 Env(OrtLoggingLevel logging_level, const char* logid, OrtLoggingFunction logging_function, void* logger_param);
1246
1248 Env(const OrtThreadingOptions* tp_options, OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
1249
1251 Env(const OrtThreadingOptions* tp_options, OrtLoggingFunction logging_function, void* logger_param,
1252 OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
1253
1255 explicit Env(const OrtEnvCreationOptions* options);
1256
1258 explicit Env(OrtEnv* p) : Base<OrtEnv>{p} {}
1259
1262
1264
1265 Env& CreateAndRegisterAllocator(const OrtMemoryInfo* mem_info, const OrtArenaCfg* arena_cfg);
1266
1267 Env& CreateAndRegisterAllocatorV2(const std::string& provider_type, const OrtMemoryInfo* mem_info,
1268 const std::unordered_map<std::string, std::string>& options,
1269 const OrtArenaCfg* arena_cfg);
1270
1272
1274
1276 OrtAllocatorType allocator_type,
1277 const OrtKeyValuePairs* allocator_options);
1278
1279 // Result may be nullptr
1281
1283 OrtDeviceMemoryType mem_type);
1284
1285 Env& RegisterExecutionProviderLibrary(const char* registration_name, const std::basic_string<ORTCHAR_T>& path);
1286 Env& UnregisterExecutionProviderLibrary(const char* registration_name);
1287
1288 std::vector<ConstEpDevice> GetEpDevices() const;
1289
1290 Status CopyTensors(const std::vector<Value>& src_tensors,
1291 const std::vector<Value>& dst_tensors,
1292 OrtSyncStream* stream) const;
1293};
1294
1298struct CustomOpDomain : detail::Base<OrtCustomOpDomain> {
1300 using Base::Base;
1301
1302 explicit CustomOpDomain(std::nullptr_t) {}
1303
1305 explicit CustomOpDomain(const char* domain);
1306
1307 // This does not take ownership of the op, simply registers it.
1308 void Add(const OrtCustomOp* op);
1309};
1310
1312struct LoraAdapter : detail::Base<OrtLoraAdapter> {
1314 using Base::Base;
1315
1316 explicit LoraAdapter(std::nullptr_t) {}
1323 static LoraAdapter CreateLoraAdapter(const std::basic_string<ORTCHAR_T>& adapter_path,
1324 OrtAllocator* allocator);
1325
1333 static LoraAdapter CreateLoraAdapterFromArray(const void* bytes, size_t num_bytes,
1334 OrtAllocator* allocator);
1335};
1336
1340struct RunOptions : detail::Base<OrtRunOptions> {
1341 explicit RunOptions(std::nullptr_t) {}
1343
1346
1349
1350 RunOptions& SetRunTag(const char* run_tag);
1351 const char* GetRunTag() const;
1352
1353 RunOptions& AddConfigEntry(const char* config_key, const char* config_value);
1354 const char* GetConfigEntry(const char* config_key);
1355
1362
1368
1376
1385
1391 RunOptions& EnableProfiling(const ORTCHAR_T* profile_file_prefix);
1392
1398};
1399
1400namespace detail {
1401// Utility function that returns a SessionOption config entry key for a specific custom operator.
1402// Ex: custom_op.[custom_op_name].[config]
1403std::string MakeCustomOpConfigEntryKey(const char* custom_op_name, const char* config);
1404} // namespace detail
1405
1416 CustomOpConfigs() = default;
1417 ~CustomOpConfigs() = default;
1422
1431 CustomOpConfigs& AddConfig(const char* custom_op_name, const char* config_key, const char* config_value);
1432
1441 const std::unordered_map<std::string, std::string>& GetFlattenedConfigs() const;
1442
1443 private:
1444 std::unordered_map<std::string, std::string> flat_configs_;
1445};
1446
1452namespace detail {
1453// we separate const-only methods because passing const ptr to non-const methods
1454// is only discovered when inline methods are compiled which is counter-intuitive
1455template <typename T>
1456struct ConstSessionOptionsImpl : Base<T> {
1457 using B = Base<T>;
1458 using B::B;
1459
1460 SessionOptions Clone() const;
1461
1462 std::string GetConfigEntry(const char* config_key) const;
1463 bool HasConfigEntry(const char* config_key) const;
1464 std::string GetConfigEntryOrDefault(const char* config_key, const std::string& def) const;
1465};
1466
1467template <typename T>
1468struct SessionOptionsImpl : ConstSessionOptionsImpl<T> {
1469 using B = ConstSessionOptionsImpl<T>;
1470 using B::B;
1471
1472 SessionOptionsImpl& SetIntraOpNumThreads(int intra_op_num_threads);
1473 SessionOptionsImpl& SetInterOpNumThreads(int inter_op_num_threads);
1474 SessionOptionsImpl& SetGraphOptimizationLevel(GraphOptimizationLevel graph_optimization_level);
1475 SessionOptionsImpl& SetDeterministicCompute(bool value);
1476
1477 SessionOptionsImpl& EnableCpuMemArena();
1478 SessionOptionsImpl& DisableCpuMemArena();
1479
1480 SessionOptionsImpl& SetOptimizedModelFilePath(const ORTCHAR_T* optimized_model_file);
1481
1482 SessionOptionsImpl& EnableProfiling(const ORTCHAR_T* profile_file_prefix);
1483 SessionOptionsImpl& DisableProfiling();
1484
1485 SessionOptionsImpl& EnableOrtCustomOps();
1486
1487 SessionOptionsImpl& EnableMemPattern();
1488 SessionOptionsImpl& DisableMemPattern();
1489
1490 SessionOptionsImpl& SetExecutionMode(ExecutionMode execution_mode);
1491
1492 SessionOptionsImpl& SetLoadCancellationFlag(bool value);
1493
1494 SessionOptionsImpl& SetLogId(const char* logid);
1495 SessionOptionsImpl& SetLogSeverityLevel(int level);
1496
1497 SessionOptionsImpl& Add(OrtCustomOpDomain* custom_op_domain);
1498
1499 SessionOptionsImpl& DisablePerSessionThreads();
1500
1501 SessionOptionsImpl& AddConfigEntry(const char* config_key, const char* config_value);
1502
1503 SessionOptionsImpl& AddInitializer(const char* name, const OrtValue* ort_val);
1504 SessionOptionsImpl& AddExternalInitializers(const std::vector<std::string>& names, const std::vector<Value>& ort_values);
1505 SessionOptionsImpl& AddExternalInitializersFromFilesInMemory(const std::vector<std::basic_string<ORTCHAR_T>>& external_initializer_file_names,
1506 const std::vector<char*>& external_initializer_file_buffer_array,
1507 const std::vector<size_t>& external_initializer_file_lengths);
1508
1509 SessionOptionsImpl& AppendExecutionProvider_CPU(int use_arena);
1510 SessionOptionsImpl& AppendExecutionProvider_CUDA(const OrtCUDAProviderOptions& provider_options);
1511 SessionOptionsImpl& AppendExecutionProvider_CUDA_V2(const OrtCUDAProviderOptionsV2& provider_options);
1512 SessionOptionsImpl& AppendExecutionProvider_ROCM(const OrtROCMProviderOptions& provider_options);
1513 SessionOptionsImpl& AppendExecutionProvider_OpenVINO(const OrtOpenVINOProviderOptions& provider_options);
1515 SessionOptionsImpl& AppendExecutionProvider_OpenVINO_V2(const std::unordered_map<std::string, std::string>& provider_options = {});
1516 SessionOptionsImpl& AppendExecutionProvider_TensorRT(const OrtTensorRTProviderOptions& provider_options);
1517 SessionOptionsImpl& AppendExecutionProvider_TensorRT_V2(const OrtTensorRTProviderOptionsV2& provider_options);
1518 SessionOptionsImpl& AppendExecutionProvider_MIGraphX(const OrtMIGraphXProviderOptions& provider_options);
1520 SessionOptionsImpl& AppendExecutionProvider_CANN(const OrtCANNProviderOptions& provider_options);
1522 SessionOptionsImpl& AppendExecutionProvider_Dnnl(const OrtDnnlProviderOptions& provider_options);
1524 SessionOptionsImpl& AppendExecutionProvider(const std::string& provider_name,
1525 const std::unordered_map<std::string, std::string>& provider_options = {});
1526
1529 SessionOptionsImpl& AppendExecutionProvider_V2(Env& env, const std::vector<ConstEpDevice>& ep_devices,
1530 const KeyValuePairs& ep_options);
1533 SessionOptionsImpl& AppendExecutionProvider_V2(Env& env, const std::vector<ConstEpDevice>& ep_devices,
1534 const std::unordered_map<std::string, std::string>& ep_options);
1535
1537 SessionOptionsImpl& SetEpSelectionPolicy(OrtExecutionProviderDevicePolicy policy);
1538
1540 SessionOptionsImpl& SetEpSelectionPolicy(EpSelectionDelegate delegate, void* state = nullptr);
1541
1542 SessionOptionsImpl& SetCustomCreateThreadFn(OrtCustomCreateThreadFn ort_custom_create_thread_fn);
1543 SessionOptionsImpl& SetCustomThreadCreationOptions(void* ort_custom_thread_creation_options);
1544 SessionOptionsImpl& SetCustomJoinThreadFn(OrtCustomJoinThreadFn ort_custom_join_thread_fn);
1545
1549 SessionOptionsImpl& RegisterCustomOpsLibrary(const ORTCHAR_T* library_name, const CustomOpConfigs& custom_op_configs = {});
1550
1551 SessionOptionsImpl& RegisterCustomOpsUsingFunction(const char* function_name);
1552
1554 SessionOptionsImpl& AppendExecutionProvider_VitisAI(const std::unordered_map<std::string, std::string>& provider_options = {});
1555
1557 SessionOptionsImpl& AddFreeDimensionOverride(const char* dim_denotation, int64_t dim_value);
1558
1560 SessionOptionsImpl& AddFreeDimensionOverrideByName(const char* dim_name, int64_t dim_value);
1561};
1562} // namespace detail
1563
1564using UnownedSessionOptions = detail::SessionOptionsImpl<detail::Unowned<OrtSessionOptions>>;
1565using ConstSessionOptions = detail::ConstSessionOptionsImpl<detail::Unowned<const OrtSessionOptions>>;
1566
1570struct SessionOptions : detail::SessionOptionsImpl<OrtSessionOptions> {
1571 explicit SessionOptions(std::nullptr_t) {}
1573 explicit SessionOptions(OrtSessionOptions* p) : SessionOptionsImpl<OrtSessionOptions>{p} {}
1576};
1577
1582struct ModelCompilationOptions : detail::Base<OrtModelCompilationOptions> {
1584 using Base::Base;
1585
1586 explicit ModelCompilationOptions(std::nullptr_t) {}
1587
1588 ModelCompilationOptions(const Env& env, const SessionOptions& session_options);
1589 ModelCompilationOptions(const Env& env, ConstSessionOptions session_options);
1590
1591 ModelCompilationOptions& SetInputModelPath(const ORTCHAR_T* input_model_path);
1593 size_t input_model_data_size);
1594 ModelCompilationOptions& SetEpContextEmbedMode(bool embed_ep_context_in_model);
1595 ModelCompilationOptions& SetOutputModelPath(const ORTCHAR_T* output_model_path);
1597 size_t initializer_size_threshold);
1598
1601 OrtGetInitializerLocationFunc get_initializer_location_func,
1602 void* state);
1603
1604 ModelCompilationOptions& SetOutputModelBuffer(OrtAllocator* allocator, void** output_model_buffer_ptr,
1605 size_t* output_model_buffer_size_ptr);
1606
1609
1610 ModelCompilationOptions& SetEpContextBinaryInformation(const ORTCHAR_T* output_directory,
1611 const ORTCHAR_T* model_name);
1613
1615};
1616
1623Status CompileModel(const Env& env, const ModelCompilationOptions& model_compilation_options);
1624
1628struct ModelMetadata : detail::Base<OrtModelMetadata> {
1630 using Base::Base;
1631
1632 explicit ModelMetadata(std::nullptr_t) {}
1633
1641
1649
1657
1665
1673
1680 std::vector<AllocatedStringPtr> GetCustomMetadataMapKeysAllocated(OrtAllocator* allocator) const;
1681
1692
1693 int64_t GetVersion() const;
1694};
1695
1696struct IoBinding;
1697
1698namespace detail {
1699
1700// we separate const-only methods because passing const ptr to non-const methods
1701// is only discovered when inline methods are compiled which is counter-intuitive
1702template <typename T>
1704 using B = Base<T>;
1705 using B::B;
1706
1707 size_t GetInputCount() const;
1708 size_t GetOutputCount() const;
1710
1711 std::vector<std::string> GetInputNames() const;
1712 std::vector<std::string> GetOutputNames() const;
1713 std::vector<std::string> GetOverridableInitializerNames() const;
1714
1715 std::vector<ConstMemoryInfo> GetMemoryInfoForInputs() const;
1716 std::vector<ConstMemoryInfo> GetMemoryInfoForOutputs() const;
1717 std::vector<ConstEpDevice> GetEpDeviceForInputs() const;
1718 std::vector<ConstEpDevice> GetEpDeviceForOutputs() const;
1719
1728
1737
1746
1747 uint64_t GetProfilingStartTimeNs() const;
1749
1750 TypeInfo GetInputTypeInfo(size_t index) const;
1751 TypeInfo GetOutputTypeInfo(size_t index) const;
1753
1754 int GetOpset(const std::string& domain) const;
1755
1756 std::vector<ValueInfo> GetInputs() const;
1757 std::vector<ValueInfo> GetOutputs() const;
1758
1763 std::vector<ConstEpAssignedSubgraph> GetEpGraphAssignmentInfo() const;
1764};
1765
1766template <typename T>
1769 using B::B;
1770
1788 std::vector<Value> Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
1789 const char* const* output_names, size_t output_count);
1790
1794 void Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
1795 const char* const* output_names, Value* output_values, size_t output_count);
1796
1797 void Run(const RunOptions& run_options, const IoBinding&);
1798
1818 void RunAsync(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
1819 const char* const* output_names, Value* output_values, size_t output_count, RunAsyncCallbackFn callback, void* user_data);
1820
1828
1840 void SetEpDynamicOptions(const char* const* keys, const char* const* values, size_t kv_len);
1841
1842 void FinalizeModelEditorSession(const Model& model, const SessionOptions& options,
1843 OrtPrepackedWeightsContainer* prepacked_weights_container = nullptr);
1844};
1845
1846} // namespace detail
1847
1850
1854struct Session : detail::SessionImpl<OrtSession> {
1856 explicit Session(std::nullptr_t) {}
1857 explicit Session(OrtSession* p) : SessionImpl{p} {}
1858
1859 Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
1860
1862 Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options,
1863 OrtPrepackedWeightsContainer* prepacked_weights_container);
1864
1866 Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options);
1867
1869 Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options,
1870 OrtPrepackedWeightsContainer* prepacked_weights_container);
1871
1872#if !defined(ORT_MINIMAL_BUILD)
1874 Session(const Env& env, const Model& model, const SessionOptions& options);
1875
1877 static Session CreateModelEditorSession(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
1878
1880 static Session CreateModelEditorSession(const Env& env, const void* model_data, size_t model_data_length,
1881 const SessionOptions& options);
1882#endif // !defined(ORT_MINIMAL_BUILD)
1883
1884 ConstSession GetConst() const { return ConstSession{this->p_}; }
1885 UnownedSession GetUnowned() const { return UnownedSession{this->p_}; }
1886};
1887
1888namespace detail {
1889template <typename T>
1891 using B = Base<T>;
1892 using B::B;
1893
1895 size_t GetElementCount() const;
1896
1897 size_t GetDimensionsCount() const;
1898
1903 [[deprecated("use GetShape()")]] void GetDimensions(int64_t* values, size_t values_count) const;
1904
1905 void GetSymbolicDimensions(const char** values, size_t values_count) const;
1906 std::vector<const char*> GetSymbolicDimensions() const;
1907
1908 bool HasShape() const;
1909 std::vector<int64_t> GetShape() const;
1910};
1911
1912} // namespace detail
1913
1915
1921 using Base::Base;
1922
1924 explicit TensorTypeAndShapeInfo(std::nullptr_t) {}
1926 explicit TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* p) : TensorTypeAndShapeInfoImpl{p} {}
1927
1928 // Create a TensorTypeAndShapeInfo object with the specified element type and dimensions
1929 // symbolic_dims are optional, but should be 1:1 with dims.
1930 // The value in symbolic_dims will be used for all entries in dims that are -1.
1932 const std::vector<int64_t>& dims,
1933 const std::vector<std::string>* symbolic_dims = nullptr);
1934
1936};
1937
1938namespace detail {
1939template <typename T>
1941 using B = Base<T>;
1942 using B::B;
1944};
1945
1946} // namespace detail
1947
1949
1953struct SequenceTypeInfo : detail::SequenceTypeInfoImpl<OrtSequenceTypeInfo> {
1955 using Base::Base;
1956
1957 explicit SequenceTypeInfo(std::nullptr_t) {}
1958 explicit SequenceTypeInfo(OrtSequenceTypeInfo* p) : SequenceTypeInfoImpl<OrtSequenceTypeInfo>{p} {}
1960};
1961
1962namespace detail {
1963template <typename T>
1965 using B = Base<T>;
1966 using B::B;
1968};
1969
1970} // namespace detail
1971
1972// This is always owned by the TypeInfo and can only be obtained from it.
1974
1975namespace detail {
1976template <typename T>
1983
1984} // namespace detail
1985
1987
1991struct MapTypeInfo : detail::MapTypeInfoImpl<OrtMapTypeInfo> {
1993 using Base::Base;
1994
1995 explicit MapTypeInfo(std::nullptr_t) {}
1996 explicit MapTypeInfo(OrtMapTypeInfo* p) : MapTypeInfoImpl<OrtMapTypeInfo>{p} {}
1997 ConstMapTypeInfo GetConst() const { return ConstMapTypeInfo{this->p_}; }
1998};
1999
2000namespace detail {
2001template <typename T>
2013} // namespace detail
2014
2020
2025struct TypeInfo : detail::TypeInfoImpl<OrtTypeInfo> {
2027 using Base::Base;
2028
2030 explicit TypeInfo(std::nullptr_t) {}
2031 explicit TypeInfo(OrtTypeInfo* p) : TypeInfoImpl<OrtTypeInfo>{p} {}
2032
2033#if !defined(ORT_MINIMAL_BUILD)
2039#endif // !defined(ORT_MINIMAL_BUILD)
2040
2041 ConstTypeInfo GetConst() const { return ConstTypeInfo{this->p_}; }
2042};
2043
2044namespace detail {
2045// This structure is used to feed sparse tensor values
2046// information for use with FillSparseTensor<Format>() API
2047// if the data type for the sparse tensor values is numeric
2048// use data.p_data, otherwise, use data.str pointer to feed
2049// values. data.str is an array of const char* that are zero terminated.
2050// number of strings in the array must match shape size.
2051// For fully sparse tensors use shape {0} and set p_data/str
2052// to nullptr.
2054 const int64_t* values_shape;
2056 union {
2057 const void* p_data;
2058 const char** str;
2059 } data;
2060};
2061
2062// Provides a way to pass shape in a single
2063// argument
2064struct Shape {
2065 const int64_t* shape;
2067};
2068
2069template <typename T>
2071 using B = Base<T>;
2072 using B::B;
2073
2077 template <typename R>
2078 void GetOpaqueData(const char* domain, const char* type_name, R&) const;
2079
2080 bool IsTensor() const;
2081 bool HasValue() const;
2082
2083 size_t GetCount() const; // If a non tensor, returns 2 for map and N for sequence, where N is the number of elements
2084 Value GetValue(int index, OrtAllocator* allocator) const;
2085
2093
2108 void GetStringTensorContent(void* buffer, size_t buffer_length, size_t* offsets, size_t offsets_count) const;
2109
2116 template <typename R>
2117 const R* GetTensorData() const;
2118
2123 const void* GetTensorRawData() const;
2124
2132
2140
2146
2155 void GetStringTensorElement(size_t buffer_length, size_t element_index, void* buffer) const;
2156
2163 std::string GetStringTensorElement(size_t element_index) const;
2164
2171 size_t GetStringTensorElementLength(size_t element_index) const;
2172
2179 size_t GetTensorSizeInBytes() const;
2180
2181#if !defined(DISABLE_SPARSE_TENSORS)
2189
2196
2205
2215 template <typename R>
2216 const R* GetSparseTensorIndicesData(OrtSparseIndicesFormat indices_format, size_t& num_indices) const;
2217
2222 bool IsSparseTensor() const;
2223
2232 template <typename R>
2233 const R* GetSparseTensorValues() const;
2234
2235#endif
2236
2249};
2250
2251template <typename T>
2254 using B::B;
2255
2261 template <typename R>
2263
2269
2271 // Obtain a reference to an element of data at the location specified
2277 template <typename R>
2278 R& At(const std::vector<int64_t>& location);
2279
2285 void FillStringTensor(const char* const* s, size_t s_len);
2286
2292 void FillStringTensorElement(const char* s, size_t index);
2293
2306 char* GetResizedStringTensorElementBuffer(size_t index, size_t buffer_length);
2307
2308#if !defined(DISABLE_SPARSE_TENSORS)
2317 void UseCooIndices(int64_t* indices_data, size_t indices_num);
2318
2329 void UseCsrIndices(int64_t* inner_data, size_t inner_num, int64_t* outer_data, size_t outer_num);
2330
2339 void UseBlockSparseIndices(const Shape& indices_shape, int32_t* indices_data);
2340
2350 void FillSparseTensorCoo(const OrtMemoryInfo* data_mem_info, const OrtSparseValuesParam& values_param,
2351 const int64_t* indices_data, size_t indices_num);
2352
2364 void FillSparseTensorCsr(const OrtMemoryInfo* data_mem_info,
2365 const OrtSparseValuesParam& values,
2366 const int64_t* inner_indices_data, size_t inner_indices_num,
2367 const int64_t* outer_indices_data, size_t outer_indices_num);
2368
2379 const OrtSparseValuesParam& values,
2380 const Shape& indices_shape,
2381 const int32_t* indices_data);
2382
2383#endif
2384};
2385
2386} // namespace detail
2387
2390
2394struct Value : detail::ValueImpl<OrtValue> {
2396 using Base::Base;
2399
2400 Value(std::nullptr_t) {}
2401 Value(Value&&) = default;
2402 Value& operator=(Value&&) = default;
2403
2404 ConstValue GetConst() const { return ConstValue{this->p_}; }
2405 UnownedValue GetUnowned() const { return UnownedValue{this->p_}; }
2406
2415 template <typename T>
2416 static Value CreateTensor(const OrtMemoryInfo* info, T* p_data, size_t p_data_element_count,
2417 const int64_t* shape, size_t shape_len);
2418
2428 static Value CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count,
2429 const int64_t* shape, size_t shape_len,
2431
2441 static Value CreateTensor(OrtAllocator* deleter, void* p_data, size_t p_data_byte_count,
2442 const int64_t* shape, size_t shape_len,
2444
2456 template <typename T>
2457 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len);
2458
2470 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len,
2472
2481 static Value CreateMap(const Value& keys, const Value& values);
2482
2490 static Value CreateSequence(const std::vector<Value>& values);
2491
2500 template <typename T>
2501 static Value CreateOpaque(const char* domain, const char* type_name, const T& value);
2502
2503#if !defined(DISABLE_SPARSE_TENSORS)
2514 template <typename T>
2515 static Value CreateSparseTensor(const OrtMemoryInfo* info, T* p_data, const Shape& dense_shape,
2516 const Shape& values_shape);
2517
2534 static Value CreateSparseTensor(const OrtMemoryInfo* info, void* p_data, const Shape& dense_shape,
2535 const Shape& values_shape, ONNXTensorElementDataType type);
2536
2546 template <typename T>
2547 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape);
2548
2560 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape, ONNXTensorElementDataType type);
2561
2562#endif // !defined(DISABLE_SPARSE_TENSORS)
2563};
2564
2565namespace detail {
2566namespace binding_utils {
2567// Bring these out of template
2568std::vector<std::string> GetOutputNamesHelper(const OrtIoBinding* binding, OrtAllocator*);
2569std::vector<Value> GetOutputValuesHelper(const OrtIoBinding* binding, OrtAllocator*);
2570} // namespace binding_utils
2571
2572template <typename T>
2574 using B = Base<T>;
2575 using B::B;
2576
2577 std::vector<std::string> GetOutputNames() const;
2578 std::vector<std::string> GetOutputNames(OrtAllocator*) const;
2579 std::vector<Value> GetOutputValues() const;
2580 std::vector<Value> GetOutputValues(OrtAllocator*) const;
2581};
2582
2583template <typename T>
2586 using B::B;
2587
2588 void BindInput(const char* name, const Value&);
2589 void BindOutput(const char* name, const Value&);
2590 void BindOutput(const char* name, const OrtMemoryInfo*);
2595};
2596
2597} // namespace detail
2598
2601
2605struct IoBinding : detail::IoBindingImpl<OrtIoBinding> {
2606 explicit IoBinding(std::nullptr_t) {}
2607 explicit IoBinding(Session& session);
2608 ConstIoBinding GetConst() const { return ConstIoBinding{this->p_}; }
2609 UnownedIoBinding GetUnowned() const { return UnownedIoBinding{this->p_}; }
2610};
2611
2616struct ArenaCfg : detail::Base<OrtArenaCfg> {
2617 explicit ArenaCfg(std::nullptr_t) {}
2626 ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk);
2627
2632 explicit ArenaCfg(const std::unordered_map<std::string, size_t>& arena_config);
2633};
2634
2635//
2636// Custom OPs (only needed to implement custom OPs)
2637//
2638
2639namespace detail {
2640// Need to define a templated ConstOpAttr with const members
2641template <typename T>
2644 using B::B;
2645
2646 // Wraps OrtApi::OpAttr_GetName
2647 std::string GetName() const;
2648 // Wraps OrtApi::OpAttr_GetType
2650
2651 // Wraps OrtApi::ReadAttr for a single value
2652 // This does not support Tensor Attribute
2653 // Call GetTensorAttributeAsOrtValue() instead.
2654 template <typename R>
2655 Status GetValue(R& out) const;
2656
2657 // Wraps OrtApi::ReadAttr for an array of values
2658 template <typename R>
2659 Status GetValueArray(std::vector<R>& out) const;
2660 // Wraps OrtApi::OpAttr_GetTensorAttributeAsOrtValue
2662};
2663} // namespace detail
2664
2666
2670struct OpAttr : detail::ConstOpAttrImpl<OrtOpAttr> {
2672 using Base::Base;
2673
2674 OpAttr() = default; // Enable storing it in the container for resize()
2675 explicit OpAttr(std::nullptr_t) {}
2676 OpAttr(const char* name, const void* data, int len, OrtOpAttrType type);
2677
2678 ConstOpAttr GetConst() const { return ConstOpAttr{this->p_}; }
2679};
2680
2689#define ORT_CXX_LOG(logger, message_severity, message) \
2690 do { \
2691 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2692 Ort::ThrowOnError(logger.LogMessage(message_severity, ORT_FILE, __LINE__, \
2693 static_cast<const char*>(__FUNCTION__), message)); \
2694 } \
2695 } while (false)
2696
2705#define ORT_CXX_LOG_NOEXCEPT(logger, message_severity, message) \
2706 do { \
2707 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2708 static_cast<void>(logger.LogMessage(message_severity, ORT_FILE, __LINE__, \
2709 static_cast<const char*>(__FUNCTION__), message)); \
2710 } \
2711 } while (false)
2712
2724#define ORT_CXX_LOGF(logger, message_severity, /*format,*/...) \
2725 do { \
2726 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2727 Ort::ThrowOnError(logger.LogFormattedMessage(message_severity, ORT_FILE, __LINE__, \
2728 static_cast<const char*>(__FUNCTION__), __VA_ARGS__)); \
2729 } \
2730 } while (false)
2731
2743#define ORT_CXX_LOGF_NOEXCEPT(logger, message_severity, /*format,*/...) \
2744 do { \
2745 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2746 static_cast<void>(logger.LogFormattedMessage(message_severity, ORT_FILE, __LINE__, \
2747 static_cast<const char*>(__FUNCTION__), __VA_ARGS__)); \
2748 } \
2749 } while (false)
2750
2761struct Logger {
2765 Logger() = default;
2766
2770 explicit Logger(std::nullptr_t) {}
2771
2778 explicit Logger(const OrtLogger* logger);
2779
2780 ~Logger() = default;
2781
2782 Logger(const Logger&) = default;
2783 Logger& operator=(const Logger&) = default;
2784
2785 Logger(Logger&& v) noexcept = default;
2786 Logger& operator=(Logger&& v) noexcept = default;
2787
2794
2807 Status LogMessage(OrtLoggingLevel log_severity_level, const ORTCHAR_T* file_path, int line_number,
2808 const char* func_name, const char* message) const noexcept;
2809
2824 template <typename... Args>
2825 Status LogFormattedMessage(OrtLoggingLevel log_severity_level, const ORTCHAR_T* file_path, int line_number,
2826 const char* func_name, const char* format, Args&&... args) const noexcept;
2827
2828 private:
2829 const OrtLogger* logger_{};
2830 OrtLoggingLevel cached_severity_level_{};
2831};
2832
2841 size_t GetInputCount() const;
2842 size_t GetOutputCount() const;
2843 // If input is optional and is not present, the method returns an empty ConstValue
2844 // which can be compared to nullptr.
2845 ConstValue GetInput(size_t index) const;
2846 // If output is optional and is not present, the method returns an empty UnownedValue
2847 // which can be compared to nullptr.
2848 UnownedValue GetOutput(size_t index, const int64_t* dim_values, size_t dim_count) const;
2849 UnownedValue GetOutput(size_t index, const std::vector<int64_t>& dims) const;
2850 void* GetGPUComputeStream() const;
2852 Ort::Allocator GetAllocator(const OrtMemoryInfo& memory_info) const;
2853 OrtKernelContext* GetOrtKernelContext() const { return ctx_; }
2854 void ParallelFor(void (*fn)(void*, size_t), size_t total, size_t num_batch, void* usr_data) const;
2855
2856 private:
2857 OrtKernelContext* ctx_;
2858};
2859
2860struct KernelInfo;
2861
2862namespace detail {
2863namespace attr_utils {
2864void GetAttr(const OrtKernelInfo* p, const char* name, float&);
2865void GetAttr(const OrtKernelInfo* p, const char* name, int64_t&);
2866void GetAttr(const OrtKernelInfo* p, const char* name, std::string&);
2867void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<float>&);
2868void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<int64_t>&);
2869} // namespace attr_utils
2870
2871template <typename T>
2872struct KernelInfoImpl : Base<T> {
2873 using B = Base<T>;
2874 using B::B;
2875
2876 KernelInfo Copy() const;
2877
2878 template <typename R> // R is only implemented for float, int64_t, and string
2879 R GetAttribute(const char* name) const {
2880 R val;
2881 attr_utils::GetAttr(this->p_, name, val);
2882 return val;
2883 }
2884
2885 template <typename R> // R is only implemented for std::vector<float>, std::vector<int64_t>
2886 std::vector<R> GetAttributes(const char* name) const {
2887 std::vector<R> result;
2888 attr_utils::GetAttrs(this->p_, name, result);
2889 return result;
2890 }
2891
2892 Value GetTensorAttribute(const char* name, OrtAllocator* allocator) const;
2893
2894 size_t GetInputCount() const;
2895 size_t GetOutputCount() const;
2896
2897 std::string GetInputName(size_t index) const;
2898 std::string GetOutputName(size_t index) const;
2899
2900 TypeInfo GetInputTypeInfo(size_t index) const;
2901 TypeInfo GetOutputTypeInfo(size_t index) const;
2902
2903 ConstValue GetTensorConstantInput(size_t index, int* is_constant) const;
2904
2905 std::string GetNodeName() const;
2906 Logger GetLogger() const;
2907
2908 KeyValuePairs GetConfigEntries() const;
2909
2910 std::string GetOperatorDomain() const;
2911 std::string GetOperatorType() const;
2912 int GetOperatorSinceVersion() const;
2913 const OrtEp* GetEp() const;
2914};
2915
2916} // namespace detail
2917
2918using ConstKernelInfo = detail::KernelInfoImpl<detail::Unowned<const OrtKernelInfo>>;
2919
2926struct KernelInfo : detail::KernelInfoImpl<OrtKernelInfo> {
2927 using Base = detail::KernelInfoImpl<OrtKernelInfo>;
2928 using Base::Base;
2929 explicit KernelInfo(std::nullptr_t) {}
2930 explicit KernelInfo(OrtKernelInfo* info);
2931 ConstKernelInfo GetConst() const { return ConstKernelInfo{this->p_}; }
2932};
2933
2937struct Op : detail::Base<OrtOp> {
2939 using Base::Base;
2940
2941 explicit Op(std::nullptr_t) {}
2942
2943 explicit Op(OrtOp*);
2944
2945 static Op Create(const OrtKernelInfo* info, const char* op_name, const char* domain,
2946 int version, const char** type_constraint_names,
2947 const ONNXTensorElementDataType* type_constraint_values,
2948 size_t type_constraint_count,
2949 const OpAttr* attr_values,
2950 size_t attr_count,
2951 size_t input_count, size_t output_count);
2952
2953 void Invoke(const OrtKernelContext* context,
2954 const Value* input_values,
2955 size_t input_count,
2956 Value* output_values,
2957 size_t output_count);
2958
2959 // For easier refactoring
2960 void Invoke(const OrtKernelContext* context,
2961 const OrtValue* const* input_values,
2962 size_t input_count,
2963 OrtValue* const* output_values,
2964 size_t output_count);
2965};
2966
2972 SymbolicInteger(int64_t i) : i_(i), is_int_(true) {};
2973 SymbolicInteger(const char* s) : s_(s), is_int_(false) {};
2976
2979
2980 bool operator==(const SymbolicInteger& dim) const {
2981 if (is_int_ == dim.is_int_) {
2982 if (is_int_) {
2983 return i_ == dim.i_;
2984 } else {
2985 return std::string{s_} == std::string{dim.s_};
2986 }
2987 }
2988 return false;
2989 }
2990
2991 bool IsInt() const { return is_int_; }
2992 int64_t AsInt() const { return i_; }
2993 const char* AsSym() const { return s_; }
2994
2995 static constexpr int INVALID_INT_DIM = -2;
2996
2997 private:
2998 union {
2999 int64_t i_;
3000 const char* s_;
3001 };
3002 bool is_int_;
3003 };
3004
3005 using Shape = std::vector<SymbolicInteger>;
3006
3008
3009 const Shape& GetInputShape(size_t indice) const { return input_shapes_.at(indice); }
3010
3011 size_t GetInputCount() const { return input_shapes_.size(); }
3012
3014
3015 int64_t GetAttrInt(const char* attr_name);
3016
3017 using Ints = std::vector<int64_t>;
3018 Ints GetAttrInts(const char* attr_name);
3019
3020 float GetAttrFloat(const char* attr_name);
3021
3022 using Floats = std::vector<float>;
3023 Floats GetAttrFloats(const char* attr_name);
3024
3025 std::string GetAttrString(const char* attr_name);
3026
3027 using Strings = std::vector<std::string>;
3028 Strings GetAttrStrings(const char* attr_name);
3029
3030 private:
3031 ConstOpAttr GetAttrHdl(const char* attr_name) const;
3032 const OrtApi* ort_api_;
3034 std::vector<Shape> input_shapes_;
3035};
3036
3038
3039#define MAX_CUSTOM_OP_END_VER (1UL << 31) - 1
3040
3041template <typename TOp, typename TKernel, bool WithStatus = false>
3045 OrtCustomOp::GetName = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetName(); };
3046
3047 OrtCustomOp::GetExecutionProviderType = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetExecutionProviderType(); };
3048
3049 OrtCustomOp::GetInputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetInputTypeCount(); };
3050 OrtCustomOp::GetInputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputType(index); };
3051 OrtCustomOp::GetInputMemoryType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputMemoryType(index); };
3052
3053 OrtCustomOp::GetOutputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetOutputTypeCount(); };
3054 OrtCustomOp::GetOutputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputType(index); };
3055
3056#if defined(_MSC_VER) && !defined(__clang__)
3057#pragma warning(push)
3058#pragma warning(disable : 26409)
3059#endif
3060 OrtCustomOp::KernelDestroy = [](void* op_kernel) { delete static_cast<TKernel*>(op_kernel); };
3061#if defined(_MSC_VER) && !defined(__clang__)
3062#pragma warning(pop)
3063#endif
3064 OrtCustomOp::GetInputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputCharacteristic(index); };
3065 OrtCustomOp::GetOutputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputCharacteristic(index); };
3066
3067 OrtCustomOp::GetVariadicInputMinArity = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetVariadicInputMinArity(); };
3068 OrtCustomOp::GetVariadicInputHomogeneity = [](const OrtCustomOp* this_) { return static_cast<int>(static_cast<const TOp*>(this_)->GetVariadicInputHomogeneity()); };
3069 OrtCustomOp::GetVariadicOutputMinArity = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetVariadicOutputMinArity(); };
3070 OrtCustomOp::GetVariadicOutputHomogeneity = [](const OrtCustomOp* this_) { return static_cast<int>(static_cast<const TOp*>(this_)->GetVariadicOutputHomogeneity()); };
3071#ifdef __cpp_if_constexpr
3072 if constexpr (WithStatus) {
3073#else
3074 if (WithStatus) {
3075#endif
3076 OrtCustomOp::CreateKernelV2 = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info, void** op_kernel) -> OrtStatusPtr {
3077 return static_cast<const TOp*>(this_)->CreateKernelV2(*api, info, op_kernel);
3078 };
3079 OrtCustomOp::KernelComputeV2 = [](void* op_kernel, OrtKernelContext* context) -> OrtStatusPtr {
3080 return static_cast<TKernel*>(op_kernel)->ComputeV2(context);
3081 };
3082 } else {
3085
3086 OrtCustomOp::CreateKernel = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info) { return static_cast<const TOp*>(this_)->CreateKernel(*api, info); };
3087 OrtCustomOp::KernelCompute = [](void* op_kernel, OrtKernelContext* context) {
3088 static_cast<TKernel*>(op_kernel)->Compute(context);
3089 };
3090 }
3091
3092 SetShapeInferFn<TOp>(0);
3093
3094 OrtCustomOp::GetStartVersion = [](const OrtCustomOp* this_) {
3095 return static_cast<const TOp*>(this_)->start_ver_;
3096 };
3097
3098 OrtCustomOp::GetEndVersion = [](const OrtCustomOp* this_) {
3099 return static_cast<const TOp*>(this_)->end_ver_;
3100 };
3101
3104 OrtCustomOp::GetAliasMap = nullptr;
3106 }
3107
3108 // Default implementation of GetExecutionProviderType that returns nullptr to default to the CPU provider
3109 const char* GetExecutionProviderType() const { return nullptr; }
3110
3111 // Default implementations of GetInputCharacteristic() and GetOutputCharacteristic() below
3112 // (inputs and outputs are required by default)
3114 return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED;
3115 }
3116
3118 return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED;
3119 }
3120
3121 // Default implementation of GetInputMemoryType() that returns OrtMemTypeDefault
3122 OrtMemType GetInputMemoryType(size_t /*index*/) const {
3123 return OrtMemTypeDefault;
3124 }
3125
3126 // Default implementation of GetVariadicInputMinArity() returns 1 to specify that a variadic input
3127 // should expect at least 1 argument.
3129 return 1;
3130 }
3131
3132 // Default implementation of GetVariadicInputHomegeneity() returns true to specify that all arguments
3133 // to a variadic input should be of the same type.
3135 return true;
3136 }
3137
3138 // Default implementation of GetVariadicOutputMinArity() returns 1 to specify that a variadic output
3139 // should produce at least 1 output value.
3141 return 1;
3142 }
3143
3144 // Default implementation of GetVariadicOutputHomegeneity() returns true to specify that all output values
3145 // produced by a variadic output should be of the same type.
3147 return true;
3148 }
3149
3150 // Declare list of session config entries used by this Custom Op.
3151 // Implement this function in order to get configs from CustomOpBase::GetSessionConfigs().
3152 // This default implementation returns an empty vector of config entries.
3153 std::vector<std::string> GetSessionConfigKeys() const {
3154 return std::vector<std::string>{};
3155 }
3156
3157 // Ort::CustomOpBase derived class should provide the following static method with the type/shape inferencing
3158 // implementation if needed:
3159 // static OrtStatusPtr InferOutputShape(Ort::ShapeInferContext& context)
3160 template <typename C>
3161 decltype(&C::InferOutputShape) SetShapeInferFn(decltype(&C::InferOutputShape)) {
3163 ShapeInferContext ctx(&GetApi(), ort_ctx);
3164 return C::InferOutputShape(ctx);
3165 };
3166 return {};
3167 }
3168
3169 template <typename C>
3173
3174 protected:
3175 // Helper function that returns a map of session config entries specified by CustomOpBase::GetSessionConfigKeys.
3176 void GetSessionConfigs(std::unordered_map<std::string, std::string>& out, ConstSessionOptions options) const;
3177
3178 int start_ver_ = 1;
3179 int end_ver_ = MAX_CUSTOM_OP_END_VER;
3180};
3181
3182// Forward declaration to resolve circular dependency
3183// on ConstNode
3185
3186namespace detail {
3187template <typename T>
3189 using B = Base<T>;
3190 using B::B;
3191
3193 std::string GetName() const;
3199 std::vector<ValueInfoConsumerProducerInfo> GetConsumers() const;
3209 bool IsGraphOutput() const;
3213 bool IsFromOuterScope() const;
3214};
3215} // namespace detail
3216
3217// Const object holder that does not own the underlying object
3219
3224 ValueInfo() = default; // Same thing as with nullptr
3225 explicit ValueInfo(std::nullptr_t) {}
3227 explicit ValueInfo(OrtValueInfo* p) : ConstValueInfoImpl<OrtValueInfo>{p} {}
3228
3229#if !defined(ORT_MINIMAL_BUILD)
3230 // Create ValueInfo for a tensor
3231 explicit ValueInfo(const std::string& name, const ConstTypeInfo& type_info);
3232#endif
3233 ConstValueInfo GetConst() const { return ConstValueInfo{this->p_}; }
3234};
3235
3236// Forward declaration
3237struct AttrNameSubgraph;
3238
3239namespace detail {
3240// Forward decl
3241template <typename T>
3242struct ConstGraphImpl;
3243
3244template <typename T>
3245struct ConstNodeImpl : Base<T> {
3246 using B = Base<T>;
3247 using B::B;
3248
3249 // <Wraps OrtApi::Node_GetId
3250 size_t GetId() const;
3251 // <Wraps OrtApi::Node_GetName
3252 std::string GetName() const;
3253 // <Wraps OrtApi::Node_GetOperatorType
3254 std::string GetOperatorType() const;
3255 // <Wraps OrtApi::Node_GetDomain
3256 std::string GetDomain() const;
3257 // <Wraps OrtApi::Node_GetSinceVersion
3258 int GetSinceVersion() const;
3259
3260 // <Wraps OrtApi::Node_Inputs
3261 std::vector<ConstValueInfo> GetInputs() const;
3262 // <Wraps OrtApi::Node_Outputs
3263 std::vector<ConstValueInfo> GetOutputs() const;
3264 // <Wraps OrtApi::Node_ImplicitInputs
3265 std::vector<ConstValueInfo> GetImplicitInputs() const;
3266 // <Wraps OrtApi::Node_GetAttributes
3267 std::vector<ConstOpAttr> GetAttributes() const;
3268 // <Wraps OrtApi::Node_GetAttributeByName
3269 // Please, read C API doc for details
3270 Status GetAttributeByName(const std::string& name, ConstOpAttr& attr) const;
3271 // <Wraps OrtApi::Node_GetSubgraphs
3272 std::vector<AttrNameSubgraph> GetSubgraphs() const;
3273 // <Wraps OrtApi::Node_GetGraph
3274 // ConstGraph is not available yet
3276 // <Wraps OrtApi::Node_GetEpName
3277 std::string GetEpName() const;
3278};
3279} // namespace detail
3280
3282
3286struct Node : detail::ConstNodeImpl<OrtNode> {
3287 Node() = default; // Same thing as with nullptr
3288 explicit Node(std::nullptr_t) {}
3289 explicit Node(OrtNode* p) : ConstNodeImpl<OrtNode>{p} {}
3290
3291#if !defined(ORT_MINIMAL_BUILD)
3292 Node(const std::string& operator_name, const std::string& operator_domain,
3293 const std::string& node_name,
3294 const std::vector<std::string>& input_names,
3295 const std::vector<std::string>& output_names);
3296
3300 Node(const std::string& operator_name, const std::string& operator_domain,
3301 const std::string& node_name,
3302 const std::vector<std::string>& input_names,
3303 const std::vector<std::string>& output_names,
3304 std::vector<OpAttr>& attributes);
3305
3306 private:
3307 static void Init(const std::string& operator_name, const std::string& operator_domain,
3308 const std::string& node_name,
3309 const std::vector<std::string>& input_names,
3310 const std::vector<std::string>& output_names,
3311 std::vector<OpAttr>& attributes,
3312 OrtNode*& node);
3313#endif // !defined(ORT_MINIMAL_BUILD)
3314};
3315
3316// Return struct for some of ValueInfo APIs.
3317// Must be declared after ConstNode is available.
3320 // either producer output or consumer output index
3321 // producer is unsigned only, output can be -1
3322 int64_t index;
3323};
3324
3325// Represents a return value for Graph::GetOperatorSets()
3327 std::string domain;
3328 int64_t version;
3329};
3330
3331namespace detail {
3332template <typename T>
3334 using B = Base<T>;
3335 using B::B;
3336
3337 // <Wraps OrtApi::Graph_GetName
3338 std::string GetName() const;
3339 // <Wraps OrtApi::Graph_GetModelPath
3340 std::basic_string<ORTCHAR_T> GetModelPath() const;
3341 // <Wraps OrtApi::Graph_GetOnnxIRVersion
3342 int64_t GetOnnxIRVersion() const;
3343 // <Wraps OrtApi::Graph_GetOperatorSets
3344 std::vector<OperatorSet> GetOperatorSets() const;
3345 // <Wraps OrtApi::Graph_Inputs
3346 std::vector<ConstValueInfo> GetInputs() const;
3347 // <Wraps OrtApi::Graph_Outputs
3348 std::vector<ConstValueInfo> GetOutputs() const;
3349 // <Wraps OrtApi::Graph_Initializers
3350 std::vector<ConstValueInfo> GetInitializers() const;
3351 // <Wraps OrtApi::Graph_GetNodes
3352 std::vector<ConstNode> GetNodes() const;
3353 // <Wraps OrtApi::Graph_GetParentGraph
3355 // <Wraps OrtApi::Graph_GetGraphView
3356 Graph GetGraphView(const std::vector<ConstNode>& nodes) const;
3357 // <Wraps OrtApi::Graph_GetModelMetadata
3359};
3360
3361template <typename T>
3364 using B::B;
3365
3366#if !defined(ORT_MINIMAL_BUILD)
3367 // <Wraps GetModelEditorApi().SetGraphInputs()
3368 void SetInputs(std::vector<ValueInfo>& inputs);
3369 // <Wraps GetModelEditorApi().SetGraphOutputs()
3370 void SetOutputs(std::vector<ValueInfo>& outputs);
3371 // <Wraps GetModelEditorApi().AddInitializerToGraph()
3372 void AddInitializer(const std::string& name, Value& initializer, bool data_is_external); // Graph takes ownership of Value
3373 // <Wraps GetModelEditorApi().AddNodeToGraph()
3374 void AddNode(Node& node); // Graph takes ownership of Node
3375#endif // !defined(ORT_MINIMAL_BUILD)
3376};
3377} // namespace detail
3378
3380
3381// Return value for Node API
3382// Must be declared after ConstGraph
3387
3391struct Graph : detail::GraphImpl<OrtGraph> {
3392 explicit Graph(std::nullptr_t) {}
3393 explicit Graph(OrtGraph* p) : GraphImpl<OrtGraph>{p} {}
3394#if !defined(ORT_MINIMAL_BUILD)
3395 // <Wraps GetModelEditorApi().CreateGraph()
3397#endif
3398};
3399
3400namespace detail {
3401template <typename T>
3404 using B::B;
3405
3406#if !defined(ORT_MINIMAL_BUILD)
3407 // <Wraps GetModelEditorApi().AddGraphToModel()
3408 void AddGraph(Graph& graph);
3409#endif
3410};
3411} // namespace detail
3412
3413// Const object holder that does not own the underlying object
3415
3419struct Model : detail::ModelImpl<OrtModel> {
3420 using DomainOpsetPair = std::pair<std::string, int>;
3421
3422 explicit Model(std::nullptr_t) {}
3423 explicit Model(OrtModel* p) : ModelImpl<OrtModel>{p} {}
3424
3425#if !defined(ORT_MINIMAL_BUILD)
3426 //< Wraps GetModelEditorApi().CreateModel()
3427 explicit Model(const std::vector<DomainOpsetPair>& opsets);
3428#endif
3429};
3430
3431namespace detail {
3432template <typename T>
3434 using B = Base<T>;
3435 using B::B;
3436
3438 const char* GetOperatorType() const;
3439
3441 const char* GetDomain() const;
3442
3444 std::pair<int, int> GetSinceVersion() const;
3445
3447 const char* GetExecutionProvider() const;
3448
3450 OrtMemType GetInputMemType(size_t input_index) const;
3451
3453 OrtMemType GetOutputMemType(size_t output_index) const;
3454};
3455} // namespace detail
3456
3458
3461 using Base::Base;
3462
3463 explicit KernelDef(std::nullptr_t) {}
3464 explicit KernelDef(OrtKernelDef* p) : detail::ConstKernelDefImpl<OrtKernelDef>{p} {}
3465
3466 ConstKernelDef GetConst() const { return ConstKernelDef{this->p_}; }
3467};
3468
3473struct KernelDefBuilder : detail::Base<OrtKernelDefBuilder> {
3475 explicit KernelDefBuilder(std::nullptr_t) {}
3476 explicit KernelDefBuilder(OrtKernelDefBuilder* ort_kernel_def_builder);
3477
3478 KernelDefBuilder& SetOperatorType(const char* op_type);
3479 KernelDefBuilder& SetDomain(const char* domain);
3480 KernelDefBuilder& SetSinceVersion(int since_version_start, int since_version_end);
3482 KernelDefBuilder& SetInputMemType(size_t input_index, OrtMemType mem_type);
3483 KernelDefBuilder& SetOutputMemType(size_t output_index, OrtMemType mem_type);
3484 KernelDefBuilder& AddTypeConstraint(const char* arg_name, const OrtDataType* data_type);
3485 KernelDefBuilder& AddTypeConstraint(const char* arg_name, const std::vector<const OrtDataType*>& data_types);
3486 KernelDefBuilder& AddInputOutputAlias(int input_index, int output_index);
3487 KernelDefBuilder& AddInputOutputAliases(const std::vector<int>& input_indices,
3488 const std::vector<int>& output_indices);
3489 KernelDefBuilder& AddInputOutputMutableAlias(int input_index, int output_index);
3490 KernelDefBuilder& AddInputOutputMutableAliases(const std::vector<int>& input_indices,
3491 const std::vector<int>& output_indices);
3492
3494};
3495
3500struct KernelRegistry : detail::Base<OrtKernelRegistry> {
3503
3505 explicit KernelRegistry(std::nullptr_t) {}
3506
3508 explicit KernelRegistry(OrtKernelRegistry* ort_kernel_registry);
3509
3511 Status AddKernel(const OrtKernelDef* kernel_def, OrtKernelCreateFunc kernel_create_func,
3512 void* kernel_create_func_state);
3513};
3514
3515namespace detail {
3516template <typename T>
3519 using B::B;
3520
3521 //< Wraps SharedPrePackedWeightCache_StoreWeightData
3522 Status StoreWeightData(void** buffer_data_ptrs, size_t* buffer_sizes, size_t num_buffers);
3523};
3524} // namespace detail
3525
3543
3546} // namespace Ort
3547#include "onnxruntime_cxx_inline.h"
struct OrtMemoryInfo OrtMemoryInfo
Definition onnxruntime_c_api.h:299
struct OrtKernelInfo OrtKernelInfo
Definition onnxruntime_c_api.h:459
struct OrtNode OrtNode
Definition onnxruntime_c_api.h:327
OrtLoggingLevel
Logging severity levels.
Definition onnxruntime_c_api.h:249
OrtMemoryInfoDeviceType
This mimics OrtDevice type constants so they can be returned in the API.
Definition onnxruntime_c_api.h:494
struct OrtShapeInferContext OrtShapeInferContext
Definition onnxruntime_c_api.h:324
void(* OrtLoggingFunction)(void *param, OrtLoggingLevel severity, const char *category, const char *logid, const char *code_location, const char *message)
Definition onnxruntime_c_api.h:423
void(* OrtCustomJoinThreadFn)(OrtCustomThreadHandle ort_custom_thread_handle)
Custom thread join function.
Definition onnxruntime_c_api.h:960
OrtCustomOpInputOutputCharacteristic
Definition onnxruntime_c_api.h:7262
struct OrtTensorRTProviderOptionsV2 OrtTensorRTProviderOptionsV2
Definition onnxruntime_c_api.h:316
struct OrtThreadingOptions OrtThreadingOptions
Definition onnxruntime_c_api.h:313
struct OrtSequenceTypeInfo OrtSequenceTypeInfo
Definition onnxruntime_c_api.h:307
struct OrtValueInfo OrtValueInfo
Definition onnxruntime_c_api.h:326
struct OrtDnnlProviderOptions OrtDnnlProviderOptions
Definition onnxruntime_c_api.h:320
OrtSparseIndicesFormat
Definition onnxruntime_c_api.h:238
struct OrtPrepackedWeightsContainer OrtPrepackedWeightsContainer
Definition onnxruntime_c_api.h:315
struct OrtSession OrtSession
Definition onnxruntime_c_api.h:301
OrtCompiledModelCompatibility
Definition onnxruntime_c_api.h:1043
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:548
struct OrtCustomOpDomain OrtCustomOpDomain
Definition onnxruntime_c_api.h:310
struct OrtIoBinding OrtIoBinding
Definition onnxruntime_c_api.h:300
struct OrtExternalInitializerInfo OrtExternalInitializerInfo
Definition onnxruntime_c_api.h:335
OrtAllocatorType
Definition onnxruntime_c_api.h:465
struct OrtOp OrtOp
Definition onnxruntime_c_api.h:321
struct OrtTypeInfo OrtTypeInfo
Definition onnxruntime_c_api.h:304
struct OrtTensorTypeAndShapeInfo OrtTensorTypeAndShapeInfo
Definition onnxruntime_c_api.h:305
struct OrtCUDAProviderOptionsV2 OrtCUDAProviderOptionsV2
Definition onnxruntime_c_api.h:318
struct OrtKernelContext OrtKernelContext
Definition onnxruntime_c_api.h:461
struct OrtCANNProviderOptions OrtCANNProviderOptions
Definition onnxruntime_c_api.h:319
struct OrtEpDevice OrtEpDevice
Definition onnxruntime_c_api.h:332
void(* RunAsyncCallbackFn)(void *user_data, OrtValue **outputs, size_t num_outputs, OrtStatusPtr status)
Callback function for RunAsync.
Definition onnxruntime_c_api.h:971
OrtHardwareDeviceType
Definition onnxruntime_c_api.h:501
struct OrtModel OrtModel
Definition onnxruntime_c_api.h:329
struct OrtGraph OrtGraph
Definition onnxruntime_c_api.h:328
struct OrtSyncStream OrtSyncStream
Definition onnxruntime_c_api.h:334
struct OrtSessionOptions OrtSessionOptions
Definition onnxruntime_c_api.h:309
OrtDeviceMemoryType
This matches OrtDevice::MemoryType values.
Definition onnxruntime_c_api.h:487
struct OrtValue OrtValue
Definition onnxruntime_c_api.h:302
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:567
GraphOptimizationLevel
Graph optimization level.
Definition onnxruntime_c_api.h:432
struct OrtKeyValuePairs OrtKeyValuePairs
Definition onnxruntime_c_api.h:333
OrtStatus * OrtStatusPtr
Definition onnxruntime_c_api.h:346
OrtMemType
Memory types for allocated memory, execution provider specific types should be extended in each provi...
Definition onnxruntime_c_api.h:475
OrtSparseFormat
Definition onnxruntime_c_api.h:230
ONNXType
Definition onnxruntime_c_api.h:218
struct OrtEnv OrtEnv
Definition onnxruntime_c_api.h:297
OrtErrorCode
Definition onnxruntime_c_api.h:257
struct OrtStatus OrtStatus
Definition onnxruntime_c_api.h:298
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:601
#define ORT_API_VERSION
The API version defined in this header.
Definition onnxruntime_c_api.h:41
struct OrtLogger OrtLogger
Definition onnxruntime_c_api.h:323
struct OrtMapTypeInfo OrtMapTypeInfo
Definition onnxruntime_c_api.h:306
struct OrtArenaCfg OrtArenaCfg
Definition onnxruntime_c_api.h:314
ExecutionMode
Definition onnxruntime_c_api.h:440
OrtOpAttrType
Definition onnxruntime_c_api.h:275
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:953
ONNXTensorElementDataType
Definition onnxruntime_c_api.h:184
OrtExecutionProviderDevicePolicy
These are the default EP selection policies used by ORT when doing automatic EP selection.
Definition onnxruntime_c_api.h:509
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:252
@ OrtMemTypeDefault
The default allocator for execution provider.
Definition onnxruntime_c_api.h:483
@ ORT_FAIL
Definition onnxruntime_c_api.h:259
@ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT
Definition onnxruntime_c_api.h:186
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:805
detail::ConstSessionOptionsImpl< detail::Unowned< const OrtSessionOptions > > ConstSessionOptions
Definition onnxruntime_cxx_api.h:1565
detail::KernelInfoImpl< detail::Unowned< const OrtKernelInfo > > ConstKernelInfo
Definition onnxruntime_cxx_api.h:2918
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:1081
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
detail::SessionOptionsImpl< detail::Unowned< OrtSessionOptions > > UnownedSessionOptions
Definition onnxruntime_cxx_api.h:1564
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:3037
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:1073
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:1074
Allocator(OrtAllocator *p)
Definition onnxruntime_cxx_api.h:1078
Wrapper around OrtAllocator default instance that is owned by Onnxruntime.
Definition onnxruntime_cxx_api.h:1064
AllocatorWithDefaultOptions(std::nullptr_t)
Convenience to create a class member and then replace with an instance.
Definition onnxruntime_cxx_api.h:1065
it is a structure that represents the configuration of an arena based allocator
Definition onnxruntime_cxx_api.h:2616
ArenaCfg(std::nullptr_t)
Create an empty ArenaCfg object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:2617
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:3383
ConstGraph sub_graph
Definition onnxruntime_cxx_api.h:3385
std::string attr_name
Definition onnxruntime_cxx_api.h:3384
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:876
CUDAProviderOptions()
Wraps OrtApi::CreateCUDAProviderOptions.
CUDAProviderOptions(std::nullptr_t)
Definition onnxruntime_cxx_api.h:877
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:3042
OrtCustomOpInputOutputCharacteristic GetOutputCharacteristic(size_t) const
Definition onnxruntime_cxx_api.h:3117
OrtCustomOpInputOutputCharacteristic GetInputCharacteristic(size_t) const
Definition onnxruntime_cxx_api.h:3113
OrtMemType GetInputMemoryType(size_t) const
Definition onnxruntime_cxx_api.h:3122
std::vector< std::string > GetSessionConfigKeys() const
Definition onnxruntime_cxx_api.h:3153
bool GetVariadicInputHomogeneity() const
Definition onnxruntime_cxx_api.h:3134
int GetVariadicInputMinArity() const
Definition onnxruntime_cxx_api.h:3128
void SetShapeInferFn(...)
Definition onnxruntime_cxx_api.h:3170
CustomOpBase()
Definition onnxruntime_cxx_api.h:3043
bool GetVariadicOutputHomogeneity() const
Definition onnxruntime_cxx_api.h:3146
int GetVariadicOutputMinArity() const
Definition onnxruntime_cxx_api.h:3140
decltype(&C::InferOutputShape) SetShapeInferFn(decltype(&C::InferOutputShape))
Definition onnxruntime_cxx_api.h:3161
const char * GetExecutionProviderType() const
Definition onnxruntime_cxx_api.h:3109
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:1415
~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:1298
CustomOpDomain(std::nullptr_t)
Create an empty CustomOpDomain object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1302
CustomOpDomain(const char *domain)
Wraps OrtApi::CreateCustomOpDomain.
void Add(const OrtCustomOp *op)
Wraps CustomOpDomain_Add.
The Env (Environment)
Definition onnxruntime_cxx_api.h:1238
Env & EnableTelemetryEvents()
Wraps OrtApi::EnableTelemetryEvents.
Env(OrtEnv *p)
C Interop Helper.
Definition onnxruntime_cxx_api.h:1258
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.
std::vector< ConstEpDevice > GetEpDevices() const
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:1239
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.
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:1148
EpDevice(OrtEpDevice *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:1150
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:1149
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:927
ConstExternalInitializerInfo GetConst() const
Wraps OrtApi::CreateExternalInitializerInfo.
Definition onnxruntime_cxx_api.h:935
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:931
ExternalInitializerInfo(OrtExternalInitializerInfo *p)
Definition onnxruntime_cxx_api.h:932
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:3391
Graph(OrtGraph *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:3393
Graph(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:3392
Wrapper around OrtIoBinding.
Definition onnxruntime_cxx_api.h:2605
UnownedIoBinding GetUnowned() const
Definition onnxruntime_cxx_api.h:2609
ConstIoBinding GetConst() const
Definition onnxruntime_cxx_api.h:2608
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:2606
This class wraps a raw pointer OrtKernelContext* that is being passed to the custom kernel Compute() ...
Definition onnxruntime_cxx_api.h:2839
KernelContext(OrtKernelContext *context)
Logger GetLogger() const
ConstValue GetInput(size_t index) const
OrtKernelContext * GetOrtKernelContext() const
Definition onnxruntime_cxx_api.h:2853
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:3473
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:3475
KernelDefBuilder(OrtKernelDefBuilder *ort_kernel_def_builder)
KernelDefBuilder & SetSinceVersion(int since_version_start, int since_version_end)
Definition onnxruntime_cxx_api.h:3459
KernelDef(OrtKernelDef *p)
Definition onnxruntime_cxx_api.h:3464
KernelDef(std::nullptr_t)
Definition onnxruntime_cxx_api.h:3463
ConstKernelDef GetConst() const
Definition onnxruntime_cxx_api.h:3466
This struct owns the OrtKernInfo* pointer when a copy is made. For convenient wrapping of OrtKernelIn...
Definition onnxruntime_cxx_api.h:2926
KernelInfo(OrtKernelInfo *info)
Take ownership of the instance.
ConstKernelInfo GetConst() const
Definition onnxruntime_cxx_api.h:2931
detail::KernelInfoImpl< OrtKernelInfo > Base
Definition onnxruntime_cxx_api.h:2927
KernelInfo(std::nullptr_t)
Create an empty instance to initialize later.
Definition onnxruntime_cxx_api.h:2929
Registry for kernels supported by an EP.
Definition onnxruntime_cxx_api.h:3500
KernelRegistry()
< Wrapper around OrtEpApi::CreateKernelRegistry
KernelRegistry(std::nullptr_t)
Take ownership of a pointer created with the C API.
Definition onnxruntime_cxx_api.h:3505
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:964
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:965
ConstKeyValuePairs GetConst() const
Definition onnxruntime_cxx_api.h:981
KeyValuePairs(OrtKeyValuePairs *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:967
This class represents an ONNX Runtime logger that can be used to log information with an associated s...
Definition onnxruntime_cxx_api.h:2761
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:2770
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:1312
static LoraAdapter CreateLoraAdapter(const std::basic_string< char > &adapter_path, OrtAllocator *allocator)
Wraps OrtApi::CreateLoraAdapter.
LoraAdapter(std::nullptr_t)
Definition onnxruntime_cxx_api.h:1316
static LoraAdapter CreateLoraAdapterFromArray(const void *bytes, size_t num_bytes, OrtAllocator *allocator)
Wraps OrtApi::CreateLoraAdapterFromArray.
Wrapper around OrtMapTypeInfo.
Definition onnxruntime_cxx_api.h:1991
ConstMapTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:1997
MapTypeInfo(OrtMapTypeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1996
MapTypeInfo(std::nullptr_t)
Create an empty MapTypeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1995
Represents native memory allocation coming from one of the OrtAllocators registered with OnnxRuntime....
Definition onnxruntime_cxx_api.h:1025
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:1034
Wrapper around OrtMemoryInfo.
Definition onnxruntime_cxx_api.h:1009
MemoryInfo(const char *name, OrtAllocatorType type, int id, OrtMemType mem_type)
MemoryInfo(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:1011
MemoryInfo(OrtMemoryInfo *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:1012
static MemoryInfo CreateCpu(OrtAllocatorType type, OrtMemType mem_type1)
ConstMemoryInfo GetConst() const
Definition onnxruntime_cxx_api.h:1016
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:1582
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:1586
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.
Wrapper around OrtModel.
Definition onnxruntime_cxx_api.h:3419
Model(const std::vector< DomainOpsetPair > &opsets)
Model(OrtModel *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:3423
std::pair< std::string, int > DomainOpsetPair
Definition onnxruntime_cxx_api.h:3420
Model(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:3422
Wrapper around OrtModelMetadata.
Definition onnxruntime_cxx_api.h:1628
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:1632
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:3286
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:3288
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:3289
This struct provides life time management for custom op attribute.
Definition onnxruntime_cxx_api.h:2670
OpAttr(const char *name, const void *data, int len, OrtOpAttrType type)
OpAttr()=default
OpAttr(std::nullptr_t)
Definition onnxruntime_cxx_api.h:2675
ConstOpAttr GetConst() const
Definition onnxruntime_cxx_api.h:2678
Create and own custom defined operation.
Definition onnxruntime_cxx_api.h:2937
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:2941
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:3326
std::string domain
Definition onnxruntime_cxx_api.h:3327
int64_t version
Definition onnxruntime_cxx_api.h:3328
The PrepackedWeightsContainer.
Definition onnxruntime_cxx_api.h:895
PrepackedWeightsContainer()
Wraps OrtApi::CreatePrepackedWeightsContainer.
PrepackedWeightsContainer(OrtPrepackedWeightsContainer *p)
Definition onnxruntime_cxx_api.h:900
PrepackedWeightsContainer(std::nullptr_t)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:898
RunOptions.
Definition onnxruntime_cxx_api.h:1340
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:1341
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:1953
SequenceTypeInfo(std::nullptr_t)
Create an empty SequenceTypeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1957
ConstSequenceTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:1959
SequenceTypeInfo(OrtSequenceTypeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1958
Wrapper around OrtSession.
Definition onnxruntime_cxx_api.h:1854
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:1856
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:1885
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:1857
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:1884
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:1570
SessionOptions(std::nullptr_t)
Create an empty SessionOptions object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1571
UnownedSessionOptions GetUnowned() const
Definition onnxruntime_cxx_api.h:1574
SessionOptions()
Wraps OrtApi::CreateSessionOptions.
ConstSessionOptions GetConst() const
Definition onnxruntime_cxx_api.h:1575
SessionOptions(OrtSessionOptions *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1573
Definition onnxruntime_cxx_api.h:2971
SymbolicInteger & operator=(const SymbolicInteger &)=default
SymbolicInteger(const SymbolicInteger &)=default
int64_t AsInt() const
Definition onnxruntime_cxx_api.h:2992
int64_t i_
Definition onnxruntime_cxx_api.h:2999
const char * s_
Definition onnxruntime_cxx_api.h:3000
bool operator==(const SymbolicInteger &dim) const
Definition onnxruntime_cxx_api.h:2980
SymbolicInteger & operator=(SymbolicInteger &&)=default
SymbolicInteger(SymbolicInteger &&)=default
const char * AsSym() const
Definition onnxruntime_cxx_api.h:2993
SymbolicInteger(int64_t i)
Definition onnxruntime_cxx_api.h:2972
SymbolicInteger(const char *s)
Definition onnxruntime_cxx_api.h:2973
bool IsInt() const
Definition onnxruntime_cxx_api.h:2991
Provide access to per-node attributes and input shapes, so one could compute and set output shapes.
Definition onnxruntime_cxx_api.h:2970
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:3005
std::vector< float > Floats
Definition onnxruntime_cxx_api.h:3022
std::string GetAttrString(const char *attr_name)
std::vector< int64_t > Ints
Definition onnxruntime_cxx_api.h:3017
ShapeInferContext(const OrtApi *ort_api, OrtShapeInferContext *ctx)
int64_t GetAttrInt(const char *attr_name)
size_t GetInputCount() const
Definition onnxruntime_cxx_api.h:3011
std::vector< std::string > Strings
Definition onnxruntime_cxx_api.h:3027
Floats GetAttrFloats(const char *attr_name)
const Shape & GetInputShape(size_t indice) const
Definition onnxruntime_cxx_api.h:3009
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:811
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:813
Definition onnxruntime_cxx_api.h:1097
SyncStream(OrtSyncStream *p)
Definition onnxruntime_cxx_api.h:1101
SyncStream(std::nullptr_t)
< Create an empty SyncStream object, must be assigned a valid one to be used
Definition onnxruntime_cxx_api.h:1099
The TensorRTOptions (V2)
Definition onnxruntime_cxx_api.h:857
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:858
TensorRTProviderOptions()
Wraps OrtApi::CreateTensorRTProviderOptionsV2.
Wrapper around OrtTensorTypeAndShapeInfo.
Definition onnxruntime_cxx_api.h:1919
TensorTypeAndShapeInfo(std::nullptr_t)
Create an empty TensorTypeAndShapeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1924
ConstTensorTypeAndShapeInfo GetConst() const
Definition onnxruntime_cxx_api.h:1935
TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1926
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:827
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:2025
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:2030
static TypeInfo CreateMapTypeInfo(ONNXTensorElementDataType key_type, ConstTypeInfo value_type)
ConstTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:2041
TypeInfo(OrtTypeInfo *p)
C API Interop.
Definition onnxruntime_cxx_api.h:2031
Wrapper around OrtValue.
Definition onnxruntime_cxx_api.h:2394
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:2400
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:2405
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:2404
Definition onnxruntime_cxx_api.h:3318
int64_t index
Definition onnxruntime_cxx_api.h:3322
ConstNode node
Definition onnxruntime_cxx_api.h:3319
Wrapper around OrtValueInfo.
Definition onnxruntime_cxx_api.h:3223
ConstValueInfo GetConst() const
Definition onnxruntime_cxx_api.h:3233
ValueInfo(std::nullptr_t)
Definition onnxruntime_cxx_api.h:3225
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:3227
ValueInfo()=default
Definition onnxruntime_cxx_api.h:773
AllocatedFree(OrtAllocator *allocator)
Definition onnxruntime_cxx_api.h:775
OrtAllocator * allocator_
Definition onnxruntime_cxx_api.h:774
void operator()(void *ptr) const
Definition onnxruntime_cxx_api.h:777
Base & operator=(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:759
constexpr contained_type & operator*() const noexcept
Definition onnxruntime_cxx_api.h:766
typename Unowned< T >::Type contained_type
Definition onnxruntime_cxx_api.h:748
Base(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:758
Base(const Base &)=default
constexpr Base(contained_type *p) noexcept
Definition onnxruntime_cxx_api.h:751
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:701
Base(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:713
constexpr Base()=default
constexpr contained_type & operator*() const noexcept
Definition onnxruntime_cxx_api.h:721
contained_type * release()
Relinquishes ownership of the contained C object pointer The underlying object is not destroyed.
Definition onnxruntime_cxx_api.h:725
Base(const Base &)=delete
constexpr Base(contained_type *p) noexcept
Definition onnxruntime_cxx_api.h:705
Base & operator=(const Base &)=delete
Base & operator=(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:714
contained_type * p_
Definition onnxruntime_cxx_api.h:732
~Base()
Definition onnxruntime_cxx_api.h:706
T contained_type
Definition onnxruntime_cxx_api.h:702
Definition onnxruntime_cxx_api.h:907
const std::basic_string< char > GetFilePath() const
Definition onnxruntime_cxx_api.h:3333
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:2573
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:3433
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:3245
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:2642
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:1703
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:2070
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:3188
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:1202
std::string GetDomain() const
std::string GetOperatorType() const
std::string GetName() const
Definition onnxruntime_cxx_api.h:1219
std::vector< ConstEpAssignedNode > GetNodes() const
Definition onnxruntime_cxx_api.h:1127
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:3362
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:1108
OrtHardwareDeviceType Type() const
const char * Vendor() const
ConstKeyValuePairs Metadata() const
Definition onnxruntime_cxx_api.h:2584
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:947
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:1977
ONNXTensorElementDataType GetMapKeyType() const
Wraps OrtApi::GetMapKeyType.
TypeInfo GetMapValueType() const
Wraps OrtApi::GetMapValueType.
Definition onnxruntime_cxx_api.h:986
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:3402
void AddGraph(Graph &graph)
Definition onnxruntime_cxx_api.h:1964
TypeInfo GetOptionalElementType() const
Wraps OrtApi::CastOptionalTypeToContainedTypeInfo.
Definition onnxruntime_cxx_api.h:2053
const char ** str
Definition onnxruntime_cxx_api.h:2058
const int64_t * values_shape
Definition onnxruntime_cxx_api.h:2054
size_t values_shape_len
Definition onnxruntime_cxx_api.h:2055
const void * p_data
Definition onnxruntime_cxx_api.h:2057
Definition onnxruntime_cxx_api.h:1940
TypeInfo GetSequenceElementType() const
Wraps OrtApi::GetSequenceElementType.
Definition onnxruntime_cxx_api.h:1767
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 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:2064
const int64_t * shape
Definition onnxruntime_cxx_api.h:2065
size_t shape_len
Definition onnxruntime_cxx_api.h:2066
Definition onnxruntime_cxx_api.h:3517
Status StoreWeightData(void **buffer_data_ptrs, size_t *buffer_sizes, size_t num_buffers)
Definition onnxruntime_cxx_api.h:1089
void * GetHandle()
Wraps SyncStream_GetHandle.
Definition onnxruntime_cxx_api.h:1890
size_t GetElementCount() const
Wraps OrtApi::GetTensorShapeElementCount.
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:2002
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:677
T Type
Definition onnxruntime_cxx_api.h:678
Definition onnxruntime_cxx_api.h:2252
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:355
void(* Free)(struct OrtAllocator *this_, void *p)
Free a block of memory previously allocated with OrtAllocator::Alloc.
Definition onnxruntime_c_api.h:362
const OrtApi *(* GetApi)(uint32_t version)
Get a pointer to the requested version of the OrtApi.
Definition onnxruntime_c_api.h:920
The C API.
Definition onnxruntime_c_api.h:1145
const OrtEpApi *(* GetEpApi)(void)
Get the OrtEpApi instance for implementing an execution provider.
Definition onnxruntime_c_api.h:5618
const OrtInteropApi *(* GetInteropApi)(void)
Get the EP Interop API instance.
Definition onnxruntime_c_api.h:6862
const OrtCompileApi *(* GetCompileApi)(void)
Get the Compile API instance.
Definition onnxruntime_c_api.h:5350
void(* ReleaseTensorRTProviderOptions)(OrtTensorRTProviderOptionsV2 *input)
Release an OrtTensorRTProviderOptionsV2.
Definition onnxruntime_c_api.h:3401
const OrtModelEditorApi *(* GetModelEditorApi)(void)
Get the Model Editor API instance.
Definition onnxruntime_c_api.h:5292
void(* ReleaseCUDAProviderOptions)(OrtCUDAProviderOptionsV2 *input)
Release an OrtCUDAProviderOptionsV2.
Definition onnxruntime_c_api.h:3904
CUDA Provider Options.
Definition onnxruntime_c_api.h:620
The OrtCompileApi struct provides functions to compile ONNX models.
Definition onnxruntime_c_api.h:7799
Definition onnxruntime_c_api.h:7272
int(* GetVariadicInputHomogeneity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7318
OrtCustomOpInputOutputCharacteristic(* GetOutputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7302
size_t(* GetInputTypeCount)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7290
int(* GetVariadicOutputMinArity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7322
size_t(* GetAliasMap)(int **input_index, int **output_index)
Definition onnxruntime_c_api.h:7355
int(* GetStartVersion)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7340
void(* ReleaseMayInplace)(int *input_index, int *output_index)
Definition onnxruntime_c_api.h:7352
const char *(* GetName)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7283
size_t(* GetOutputTypeCount)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7292
void(* KernelDestroy)(void *op_kernel)
Definition onnxruntime_c_api.h:7298
int(* GetVariadicOutputHomogeneity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7327
OrtMemType(* GetInputMemoryType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7309
void *(* CreateKernel)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info)
Definition onnxruntime_c_api.h:7279
uint32_t version
Definition onnxruntime_c_api.h:7273
ONNXTensorElementDataType(* GetInputType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7289
void(* ReleaseAliasMap)(int *input_index, int *output_index)
Definition onnxruntime_c_api.h:7356
OrtCustomOpInputOutputCharacteristic(* GetInputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7301
const char *(* GetExecutionProviderType)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7286
ONNXTensorElementDataType(* GetOutputType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:7291
int(* GetVariadicInputMinArity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7313
OrtStatusPtr(* InferOutputShapeFn)(const struct OrtCustomOp *op, OrtShapeInferContext *)
Definition onnxruntime_c_api.h:7337
int(* GetEndVersion)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:7341
OrtStatusPtr(* CreateKernelV2)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info, void **kernel)
Definition onnxruntime_c_api.h:7330
size_t(* GetMayInplace)(int **input_index, int **output_index)
Definition onnxruntime_c_api.h:7348
OrtStatusPtr(* KernelComputeV2)(void *op_kernel, OrtKernelContext *context)
Definition onnxruntime_c_api.h:7335
void(* KernelCompute)(void *op_kernel, OrtKernelContext *context)
Definition onnxruntime_c_api.h:7297
Configuration options for creating an OrtEnv.
Definition onnxruntime_c_api.h:1057
The OrtEpApi struct provides functions that are relevant to the implementation of an execution provid...
Definition onnxruntime_ep_c_api.h:751
The OrtEpFactory provides functions to create and manage execution providers.
Definition onnxruntime_ep_c_api.h:1786
The OrtEp struct provides functions to implement for an execution provider.
Definition onnxruntime_ep_c_api.h:1468
The OrtInteropApi struct provides functions for external resource interop with execution providers.
Definition onnxruntime_c_api.h:8072
MIGraphX Provider Options.
Definition onnxruntime_c_api.h:824
The OrtModelEditorApi struct provides functions to create or edit an ONNX model.
Definition onnxruntime_c_api.h:7370
OpenVINO Provider Options.
Definition onnxruntime_c_api.h:863
ROCM Provider Options.
Definition onnxruntime_c_api.h:707
TensorRT Provider Options.
Definition onnxruntime_c_api.h:796