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
243inline const OrtEpApi& GetEpApi() {
244 auto* api = GetApi().GetEpApi();
245 if (api == nullptr) {
246 // minimal build
247 ORT_CXX_API_THROW("EP API is not available in this build", ORT_FAIL);
248 }
249
250 return *api;
251}
252
271struct Float16_t : onnxruntime_float16::Float16Impl<Float16_t> {
272 private:
278 constexpr explicit Float16_t(uint16_t v) noexcept { val = v; }
279
280 public:
281 using Base = onnxruntime_float16::Float16Impl<Float16_t>;
282
286 Float16_t() = default;
287
293 constexpr static Float16_t FromBits(uint16_t v) noexcept { return Float16_t(v); }
294
299 explicit Float16_t(float v) noexcept { val = Base::ToUint16Impl(v); }
300
305 float ToFloat() const noexcept { return Base::ToFloatImpl(); }
306
311 using Base::IsNegative;
312
317 using Base::IsNaN;
318
323 using Base::IsFinite;
324
329 using Base::IsPositiveInfinity;
330
335 using Base::IsNegativeInfinity;
336
341 using Base::IsInfinity;
342
347 using Base::IsNaNOrZero;
348
353 using Base::IsNormal;
354
359 using Base::IsSubnormal;
360
365 using Base::Abs;
366
371 using Base::Negate;
372
381 using Base::AreZero;
382
386 explicit operator float() const noexcept { return ToFloat(); }
387
388 using Base::operator==;
389 using Base::operator!=;
390 using Base::operator<;
391};
392
393static_assert(sizeof(Float16_t) == sizeof(uint16_t), "Sizes must match");
394
413struct BFloat16_t : onnxruntime_float16::BFloat16Impl<BFloat16_t> {
414 private:
422 constexpr explicit BFloat16_t(uint16_t v) noexcept { val = v; }
423
424 public:
425 using Base = onnxruntime_float16::BFloat16Impl<BFloat16_t>;
426
427 BFloat16_t() = default;
428
434 static constexpr BFloat16_t FromBits(uint16_t v) noexcept { return BFloat16_t(v); }
435
440 explicit BFloat16_t(float v) noexcept { val = Base::ToUint16Impl(v); }
441
446 float ToFloat() const noexcept { return Base::ToFloatImpl(); }
447
452 using Base::IsNegative;
453
458 using Base::IsNaN;
459
464 using Base::IsFinite;
465
470 using Base::IsPositiveInfinity;
471
476 using Base::IsNegativeInfinity;
477
482 using Base::IsInfinity;
483
488 using Base::IsNaNOrZero;
489
494 using Base::IsNormal;
495
500 using Base::IsSubnormal;
501
506 using Base::Abs;
507
512 using Base::Negate;
513
522 using Base::AreZero;
523
527 explicit operator float() const noexcept { return ToFloat(); }
528
529 // We do not have an inherited impl for the below operators
530 // as the internal class implements them a little differently
531 bool operator==(const BFloat16_t& rhs) const noexcept;
532 bool operator!=(const BFloat16_t& rhs) const noexcept { return !(*this == rhs); }
533 bool operator<(const BFloat16_t& rhs) const noexcept;
534};
535
536static_assert(sizeof(BFloat16_t) == sizeof(uint16_t), "Sizes must match");
537
544 uint8_t value;
545 constexpr Float8E4M3FN_t() noexcept : value(0) {}
546 constexpr Float8E4M3FN_t(uint8_t v) noexcept : value(v) {}
547 constexpr operator uint8_t() const noexcept { return value; }
548 // nan values are treated like any other value for operator ==, !=
549 constexpr bool operator==(const Float8E4M3FN_t& rhs) const noexcept { return value == rhs.value; };
550 constexpr bool operator!=(const Float8E4M3FN_t& rhs) const noexcept { return value != rhs.value; };
551};
552
553static_assert(sizeof(Float8E4M3FN_t) == sizeof(uint8_t), "Sizes must match");
554
561 uint8_t value;
562 constexpr Float8E4M3FNUZ_t() noexcept : value(0) {}
563 constexpr Float8E4M3FNUZ_t(uint8_t v) noexcept : value(v) {}
564 constexpr operator uint8_t() const noexcept { return value; }
565 // nan values are treated like any other value for operator ==, !=
566 constexpr bool operator==(const Float8E4M3FNUZ_t& rhs) const noexcept { return value == rhs.value; };
567 constexpr bool operator!=(const Float8E4M3FNUZ_t& rhs) const noexcept { return value != rhs.value; };
568};
569
570static_assert(sizeof(Float8E4M3FNUZ_t) == sizeof(uint8_t), "Sizes must match");
571
578 uint8_t value;
579 constexpr Float8E5M2_t() noexcept : value(0) {}
580 constexpr Float8E5M2_t(uint8_t v) noexcept : value(v) {}
581 constexpr operator uint8_t() const noexcept { return value; }
582 // nan values are treated like any other value for operator ==, !=
583 constexpr bool operator==(const Float8E5M2_t& rhs) const noexcept { return value == rhs.value; };
584 constexpr bool operator!=(const Float8E5M2_t& rhs) const noexcept { return value != rhs.value; };
585};
586
587static_assert(sizeof(Float8E5M2_t) == sizeof(uint8_t), "Sizes must match");
588
595 uint8_t value;
596 constexpr Float8E5M2FNUZ_t() noexcept : value(0) {}
597 constexpr Float8E5M2FNUZ_t(uint8_t v) noexcept : value(v) {}
598 constexpr operator uint8_t() const noexcept { return value; }
599 // nan values are treated like any other value for operator ==, !=
600 constexpr bool operator==(const Float8E5M2FNUZ_t& rhs) const noexcept { return value == rhs.value; };
601 constexpr bool operator!=(const Float8E5M2FNUZ_t& rhs) const noexcept { return value != rhs.value; };
602};
603
604static_assert(sizeof(Float8E5M2FNUZ_t) == sizeof(uint8_t), "Sizes must match");
605
606namespace detail {
607// 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
608// This can't be done in the C API since C doesn't have function overloading.
609#define ORT_DEFINE_RELEASE(NAME) \
610 inline void OrtRelease(Ort##NAME* ptr) { GetApi().Release##NAME(ptr); }
611
612#define ORT_DEFINE_RELEASE_FROM_API_STRUCT(NAME, API_GETTER) \
613 inline void OrtRelease(Ort##NAME* ptr) { API_GETTER().Release##NAME(ptr); }
614
615ORT_DEFINE_RELEASE(Allocator);
616ORT_DEFINE_RELEASE(ArenaCfg);
617ORT_DEFINE_RELEASE(CustomOpDomain);
618ORT_DEFINE_RELEASE(Env);
619ORT_DEFINE_RELEASE(ExternalInitializerInfo);
620ORT_DEFINE_RELEASE(Graph);
621ORT_DEFINE_RELEASE(IoBinding);
622ORT_DEFINE_RELEASE(KernelInfo);
623ORT_DEFINE_RELEASE(KeyValuePairs);
624ORT_DEFINE_RELEASE(LoraAdapter);
625ORT_DEFINE_RELEASE(MemoryInfo);
626ORT_DEFINE_RELEASE(MapTypeInfo);
627ORT_DEFINE_RELEASE(Model);
628ORT_DEFINE_RELEASE(ModelMetadata);
629ORT_DEFINE_RELEASE(Node);
630ORT_DEFINE_RELEASE(Op);
631ORT_DEFINE_RELEASE(OpAttr);
632ORT_DEFINE_RELEASE(PrepackedWeightsContainer);
633ORT_DEFINE_RELEASE(RunOptions);
634ORT_DEFINE_RELEASE(Session);
635ORT_DEFINE_RELEASE(SessionOptions);
636ORT_DEFINE_RELEASE(SequenceTypeInfo);
637ORT_DEFINE_RELEASE(Status);
638ORT_DEFINE_RELEASE(SyncStream);
639ORT_DEFINE_RELEASE(TensorTypeAndShapeInfo);
640ORT_DEFINE_RELEASE(ThreadingOptions);
641ORT_DEFINE_RELEASE(TypeInfo);
642ORT_DEFINE_RELEASE(Value);
643ORT_DEFINE_RELEASE(ValueInfo);
644
645ORT_DEFINE_RELEASE_FROM_API_STRUCT(ModelCompilationOptions, GetCompileApi);
646ORT_DEFINE_RELEASE_FROM_API_STRUCT(EpDevice, GetEpApi);
647
648// This is defined explicitly since OrtTensorRTProviderOptionsV2 is not a C API type,
649// but the struct has V2 in its name to indicate that it is the second version of the options.
652
653#undef ORT_DEFINE_RELEASE
654#undef ORT_DEFINE_RELEASE_FROM_API_STRUCT
655
659template <typename T>
660struct Unowned {
661 using Type = T;
662};
663
683template <typename T>
684struct Base {
685 using contained_type = T;
686
687 constexpr Base() = default;
688 constexpr explicit Base(contained_type* p) noexcept : p_{p} {}
690 OrtRelease(p_);
691 }
692
693 Base(const Base&) = delete;
694 Base& operator=(const Base&) = delete;
695
696 Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }
697 Base& operator=(Base&& v) noexcept {
698 OrtRelease(p_);
699 p_ = v.release();
700 return *this;
701 }
702
703 constexpr operator contained_type*() const noexcept { return p_; }
704 constexpr contained_type& operator*() const noexcept { return *p_; }
705
709 T* p = p_;
710 p_ = nullptr;
711 return p;
712 }
713
714 protected:
716};
717
718// Undefined. For const types use Base<Unowned<const T>>
719template <typename T>
720struct Base<const T>;
721
729template <typename T>
730struct Base<Unowned<T>> {
732
733 constexpr Base() = default;
734 constexpr explicit Base(contained_type* p) noexcept : p_{p} {}
735
736 ~Base() = default;
737
738 Base(const Base&) = default;
739 Base& operator=(const Base&) = default;
740
741 Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }
742 Base& operator=(Base&& v) noexcept {
743 p_ = nullptr;
744 std::swap(p_, v.p_);
745 return *this;
746 }
747
748 constexpr operator contained_type*() const noexcept { return p_; }
749 constexpr contained_type& operator*() const noexcept { return *p_; }
750
751 protected:
753};
754
755// Light functor to release memory with OrtAllocator
758 explicit AllocatedFree(OrtAllocator* allocator)
759 : allocator_(allocator) {}
760 void operator()(void* ptr) const {
761 if (ptr) allocator_->Free(allocator_, ptr);
762 }
763};
764
765} // namespace detail
766
767struct AllocatorWithDefaultOptions;
768struct Env;
769struct EpDevice;
770struct ExternalInitializerInfo;
771struct Graph;
772struct Model;
773struct Node;
774struct ModelMetadata;
775struct TypeInfo;
776struct PrepackedWeightsContainer;
777struct Session;
778struct SessionOptions;
779struct SyncStream;
780struct TensorRTProviderOptions;
781struct Value;
782struct ValueInfo;
783
788using AllocatedStringPtr = std::unique_ptr<char, detail::AllocatedFree>;
789
794struct Status : detail::Base<OrtStatus> {
795 Status() = default; // Same as with std::nullptr_t. But can be used in re-sizable containers and represent success.
796 explicit Status(std::nullptr_t) noexcept {}
797 explicit Status(OrtStatus* status) noexcept;
798 explicit Status(const Exception&);
799 explicit Status(const std::exception&);
800 Status(const char* message, OrtErrorCode code);
801 std::string GetErrorMessage() const;
803 bool IsOK() const noexcept;
804};
805
835
840struct TensorRTProviderOptions : detail::Base<OrtTensorRTProviderOptionsV2> {
841 TensorRTProviderOptions(std::nullptr_t) {}
845 void Update(const std::unordered_map<std::string, std::string>& options);
847 void UpdateWithValue(const char* key, void* value);
848
850 void* GetOptionByName(const char* name) const;
853};
854
859struct CUDAProviderOptions : detail::Base<OrtCUDAProviderOptionsV2> {
860 CUDAProviderOptions(std::nullptr_t) {}
864 void Update(const std::unordered_map<std::string, std::string>& options);
868 void UpdateWithValue(const char* key, void* value);
870 void* GetOptionByName(const char* name) const;
871};
872
887
888namespace detail {
889template <typename T>
891 using B = Base<T>;
892 using B::B;
893
894 // Wraps OrtApi::ExternalInitializerInfo_GetFilePath
895 const std::basic_string<ORTCHAR_T> GetFilePath() const;
896 // Wraps OrtApi::ExternalInitializerInfo_GetFileOffset
897 int64_t GetFileOffset() const;
898 // Wraps OrtApi::ExternalInitializerInfo_GetByteSize
899 size_t GetByteSize() const;
900};
901} // namespace detail
902
903// Const object holder that does not own the underlying object
906
912 using Base::Base;
913
914 explicit ExternalInitializerInfo(std::nullptr_t) {}
916 : detail::ConstExternalInitializerInfoImpl<OrtExternalInitializerInfo>{p} {}
917
919
921 ExternalInitializerInfo(const ORTCHAR_T* filepath, int64_t file_offset, size_t byte_size);
922
924 static Status Create(const ORTCHAR_T* filepath, int64_t file_offset, size_t byte_size,
925 /*out*/ ExternalInitializerInfo& out);
926};
927
928namespace detail {
929template <typename T>
932 using B::B;
933
934 const char* GetValue(const char* key) const;
935
936 // get the pairs in unordered_map. needs to copy to std::string so the hash works as expected
937 std::unordered_map<std::string, std::string> GetKeyValuePairs() const;
938 // get the pairs in two vectors. entries will be 1:1 between keys and values. avoids copying to std::string
939 void GetKeyValuePairs(std::vector<const char*>& keys, std::vector<const char*>& values) const;
940};
941} // namespace detail
942
943// Const object holder that does not own the underlying object
945
947struct KeyValuePairs : detail::KeyValuePairsImpl<OrtKeyValuePairs> {
948 explicit KeyValuePairs(std::nullptr_t) {}
950 explicit KeyValuePairs(OrtKeyValuePairs* p) : KeyValuePairsImpl<OrtKeyValuePairs>{p} {}
951
953 explicit KeyValuePairs();
954
956 explicit KeyValuePairs(const std::unordered_map<std::string, std::string>& kv_pairs);
957
959 void Add(const char* key, const char* value);
960
962 void Remove(const char* key);
963
964 ConstKeyValuePairs GetConst() const { return ConstKeyValuePairs{this->p_}; }
965};
966
967namespace detail {
968template <typename T>
969struct MemoryInfoImpl : Base<T> {
970 using B = Base<T>;
971 using B::B;
972
973 std::string GetAllocatorName() const;
975 int GetDeviceId() const;
979 uint32_t GetVendorId() const;
980
981 template <typename U>
982 bool operator==(const MemoryInfoImpl<U>& o) const;
983};
984} // namespace detail
985
986// Const object holder that does not own the underlying object
988
992struct MemoryInfo : detail::MemoryInfoImpl<OrtMemoryInfo> {
994 explicit MemoryInfo(std::nullptr_t) {}
995 explicit MemoryInfo(OrtMemoryInfo* p) : MemoryInfoImpl<OrtMemoryInfo>{p} {}
996 MemoryInfo(const char* name, OrtAllocatorType type, int id, OrtMemType mem_type);
997 MemoryInfo(const char* name, OrtMemoryInfoDeviceType device_type, uint32_t vendor_id, uint32_t device_id,
998 OrtDeviceMemoryType mem_type, size_t alignment, OrtAllocatorType allocator_type);
999 ConstMemoryInfo GetConst() const { return ConstMemoryInfo{this->p_}; }
1000};
1001
1009 MemoryAllocation(OrtAllocator* allocator, void* p, size_t size);
1014 MemoryAllocation& operator=(MemoryAllocation&&) noexcept;
1015
1016 void* get() { return p_; }
1017 size_t size() const { return size_; }
1018
1019 private:
1020 OrtAllocator* allocator_;
1021 void* p_;
1022 size_t size_;
1023};
1024
1025namespace detail {
1026template <typename T>
1027struct AllocatorImpl : Base<T> {
1028 using B = Base<T>;
1029 using B::B;
1030
1031 void* Alloc(size_t size);
1032 MemoryAllocation GetAllocation(size_t size);
1033 void Free(void* p);
1034 ConstMemoryInfo GetInfo() const;
1035
1040 KeyValuePairs GetStats() const;
1041};
1042} // namespace detail
1043
1047struct AllocatorWithDefaultOptions : detail::AllocatorImpl<detail::Unowned<OrtAllocator>> {
1048 explicit AllocatorWithDefaultOptions(std::nullptr_t) {}
1050};
1051
1056struct Allocator : detail::AllocatorImpl<OrtAllocator> {
1057 explicit Allocator(std::nullptr_t) {}
1058 Allocator(const Session& session, const OrtMemoryInfo*);
1059};
1060
1061using UnownedAllocator = detail::AllocatorImpl<detail::Unowned<OrtAllocator>>;
1062
1067namespace detail {
1068template <typename T>
1070 using B = Base<T>;
1071 using B::B;
1072 // For some reason this is not a const method on the stream
1073 void* GetHandle();
1074};
1075} // namespace detail
1076
1077struct SyncStream : detail::SyncStreamImpl<OrtSyncStream> {
1079 explicit SyncStream(std::nullptr_t) {}
1081 explicit SyncStream(OrtSyncStream* p) : SyncStreamImpl<OrtSyncStream>{p} {}
1082};
1083
1085
1086namespace detail {
1087template <typename T>
1090 using B::B;
1091
1093 uint32_t VendorId() const;
1094 uint32_t DeviceId() const;
1095 const char* Vendor() const;
1097};
1098} // namespace detail
1099
1104
1105namespace detail {
1106template <typename T>
1109 using B::B;
1110
1111 const char* EpName() const;
1112 const char* EpVendor() const;
1118};
1119} // namespace detail
1120
1125
1128struct EpDevice : detail::EpDeviceImpl<OrtEpDevice> {
1129 explicit EpDevice(std::nullptr_t) {}
1130 explicit EpDevice(OrtEpDevice* p) : EpDeviceImpl<OrtEpDevice>{p} {}
1131
1133 EpDevice(OrtEpFactory& ep_factory, ConstHardwareDevice& hardware_device,
1134 ConstKeyValuePairs ep_metadata = {}, ConstKeyValuePairs ep_options = {});
1135};
1136
1144 const std::vector<ConstEpDevice>& ep_devices,
1145 const char* compatibility_info);
1146
1152struct Env : detail::Base<OrtEnv> {
1153 explicit Env(std::nullptr_t) {}
1154
1156 Env(OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
1157
1159 Env(OrtLoggingLevel logging_level, const char* logid, OrtLoggingFunction logging_function, void* logger_param);
1160
1162 Env(const OrtThreadingOptions* tp_options, OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
1163
1165 Env(const OrtThreadingOptions* tp_options, OrtLoggingFunction logging_function, void* logger_param,
1166 OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
1167
1169 explicit Env(OrtEnv* p) : Base<OrtEnv>{p} {}
1170
1173
1175
1176 Env& CreateAndRegisterAllocator(const OrtMemoryInfo* mem_info, const OrtArenaCfg* arena_cfg);
1177
1178 Env& CreateAndRegisterAllocatorV2(const std::string& provider_type, const OrtMemoryInfo* mem_info,
1179 const std::unordered_map<std::string, std::string>& options,
1180 const OrtArenaCfg* arena_cfg);
1181
1183
1185
1187 OrtAllocatorType allocator_type,
1188 const OrtKeyValuePairs* allocator_options);
1189
1190 // Result may be nullptr
1192
1194 OrtDeviceMemoryType mem_type);
1195
1196 Env& RegisterExecutionProviderLibrary(const char* registration_name, const std::basic_string<ORTCHAR_T>& path);
1197 Env& UnregisterExecutionProviderLibrary(const char* registration_name);
1198
1199 std::vector<ConstEpDevice> GetEpDevices() const;
1200
1201 Status CopyTensors(const std::vector<Value>& src_tensors,
1202 const std::vector<Value>& dst_tensors,
1203 OrtSyncStream* stream) const;
1204};
1205
1209struct CustomOpDomain : detail::Base<OrtCustomOpDomain> {
1211 using Base::Base;
1212
1213 explicit CustomOpDomain(std::nullptr_t) {}
1214
1216 explicit CustomOpDomain(const char* domain);
1217
1218 // This does not take ownership of the op, simply registers it.
1219 void Add(const OrtCustomOp* op);
1220};
1221
1223struct LoraAdapter : detail::Base<OrtLoraAdapter> {
1225 using Base::Base;
1226
1227 explicit LoraAdapter(std::nullptr_t) {}
1234 static LoraAdapter CreateLoraAdapter(const std::basic_string<ORTCHAR_T>& adapter_path,
1235 OrtAllocator* allocator);
1236
1244 static LoraAdapter CreateLoraAdapterFromArray(const void* bytes, size_t num_bytes,
1245 OrtAllocator* allocator);
1246};
1247
1251struct RunOptions : detail::Base<OrtRunOptions> {
1252 explicit RunOptions(std::nullptr_t) {}
1254
1257
1260
1261 RunOptions& SetRunTag(const char* run_tag);
1262 const char* GetRunTag() const;
1263
1264 RunOptions& AddConfigEntry(const char* config_key, const char* config_value);
1265 const char* GetConfigEntry(const char* config_key);
1266
1273
1279
1287};
1288
1289namespace detail {
1290// Utility function that returns a SessionOption config entry key for a specific custom operator.
1291// Ex: custom_op.[custom_op_name].[config]
1292std::string MakeCustomOpConfigEntryKey(const char* custom_op_name, const char* config);
1293} // namespace detail
1294
1305 CustomOpConfigs() = default;
1306 ~CustomOpConfigs() = default;
1311
1320 CustomOpConfigs& AddConfig(const char* custom_op_name, const char* config_key, const char* config_value);
1321
1330 const std::unordered_map<std::string, std::string>& GetFlattenedConfigs() const;
1331
1332 private:
1333 std::unordered_map<std::string, std::string> flat_configs_;
1334};
1335
1341namespace detail {
1342// we separate const-only methods because passing const ptr to non-const methods
1343// is only discovered when inline methods are compiled which is counter-intuitive
1344template <typename T>
1345struct ConstSessionOptionsImpl : Base<T> {
1346 using B = Base<T>;
1347 using B::B;
1348
1349 SessionOptions Clone() const;
1350
1351 std::string GetConfigEntry(const char* config_key) const;
1352 bool HasConfigEntry(const char* config_key) const;
1353 std::string GetConfigEntryOrDefault(const char* config_key, const std::string& def) const;
1354};
1355
1356template <typename T>
1357struct SessionOptionsImpl : ConstSessionOptionsImpl<T> {
1358 using B = ConstSessionOptionsImpl<T>;
1359 using B::B;
1360
1361 SessionOptionsImpl& SetIntraOpNumThreads(int intra_op_num_threads);
1362 SessionOptionsImpl& SetInterOpNumThreads(int inter_op_num_threads);
1363 SessionOptionsImpl& SetGraphOptimizationLevel(GraphOptimizationLevel graph_optimization_level);
1364 SessionOptionsImpl& SetDeterministicCompute(bool value);
1365
1366 SessionOptionsImpl& EnableCpuMemArena();
1367 SessionOptionsImpl& DisableCpuMemArena();
1368
1369 SessionOptionsImpl& SetOptimizedModelFilePath(const ORTCHAR_T* optimized_model_file);
1370
1371 SessionOptionsImpl& EnableProfiling(const ORTCHAR_T* profile_file_prefix);
1372 SessionOptionsImpl& DisableProfiling();
1373
1374 SessionOptionsImpl& EnableOrtCustomOps();
1375
1376 SessionOptionsImpl& EnableMemPattern();
1377 SessionOptionsImpl& DisableMemPattern();
1378
1379 SessionOptionsImpl& SetExecutionMode(ExecutionMode execution_mode);
1380
1381 SessionOptionsImpl& SetLoadCancellationFlag(bool value);
1382
1383 SessionOptionsImpl& SetLogId(const char* logid);
1384 SessionOptionsImpl& SetLogSeverityLevel(int level);
1385
1386 SessionOptionsImpl& Add(OrtCustomOpDomain* custom_op_domain);
1387
1388 SessionOptionsImpl& DisablePerSessionThreads();
1389
1390 SessionOptionsImpl& AddConfigEntry(const char* config_key, const char* config_value);
1391
1392 SessionOptionsImpl& AddInitializer(const char* name, const OrtValue* ort_val);
1393 SessionOptionsImpl& AddExternalInitializers(const std::vector<std::string>& names, const std::vector<Value>& ort_values);
1394 SessionOptionsImpl& AddExternalInitializersFromFilesInMemory(const std::vector<std::basic_string<ORTCHAR_T>>& external_initializer_file_names,
1395 const std::vector<char*>& external_initializer_file_buffer_array,
1396 const std::vector<size_t>& external_initializer_file_lengths);
1397
1398 SessionOptionsImpl& AppendExecutionProvider_CPU(int use_arena);
1399 SessionOptionsImpl& AppendExecutionProvider_CUDA(const OrtCUDAProviderOptions& provider_options);
1400 SessionOptionsImpl& AppendExecutionProvider_CUDA_V2(const OrtCUDAProviderOptionsV2& provider_options);
1401 SessionOptionsImpl& AppendExecutionProvider_ROCM(const OrtROCMProviderOptions& provider_options);
1402 SessionOptionsImpl& AppendExecutionProvider_OpenVINO(const OrtOpenVINOProviderOptions& provider_options);
1404 SessionOptionsImpl& AppendExecutionProvider_OpenVINO_V2(const std::unordered_map<std::string, std::string>& provider_options = {});
1405 SessionOptionsImpl& AppendExecutionProvider_TensorRT(const OrtTensorRTProviderOptions& provider_options);
1406 SessionOptionsImpl& AppendExecutionProvider_TensorRT_V2(const OrtTensorRTProviderOptionsV2& provider_options);
1407 SessionOptionsImpl& AppendExecutionProvider_MIGraphX(const OrtMIGraphXProviderOptions& provider_options);
1409 SessionOptionsImpl& AppendExecutionProvider_CANN(const OrtCANNProviderOptions& provider_options);
1411 SessionOptionsImpl& AppendExecutionProvider_Dnnl(const OrtDnnlProviderOptions& provider_options);
1413 SessionOptionsImpl& AppendExecutionProvider(const std::string& provider_name,
1414 const std::unordered_map<std::string, std::string>& provider_options = {});
1415
1418 SessionOptionsImpl& AppendExecutionProvider_V2(Env& env, const std::vector<ConstEpDevice>& ep_devices,
1419 const KeyValuePairs& ep_options);
1422 SessionOptionsImpl& AppendExecutionProvider_V2(Env& env, const std::vector<ConstEpDevice>& ep_devices,
1423 const std::unordered_map<std::string, std::string>& ep_options);
1424
1426 SessionOptionsImpl& SetEpSelectionPolicy(OrtExecutionProviderDevicePolicy policy);
1427
1429 SessionOptionsImpl& SetEpSelectionPolicy(EpSelectionDelegate delegate, void* state = nullptr);
1430
1431 SessionOptionsImpl& SetCustomCreateThreadFn(OrtCustomCreateThreadFn ort_custom_create_thread_fn);
1432 SessionOptionsImpl& SetCustomThreadCreationOptions(void* ort_custom_thread_creation_options);
1433 SessionOptionsImpl& SetCustomJoinThreadFn(OrtCustomJoinThreadFn ort_custom_join_thread_fn);
1434
1438 SessionOptionsImpl& RegisterCustomOpsLibrary(const ORTCHAR_T* library_name, const CustomOpConfigs& custom_op_configs = {});
1439
1440 SessionOptionsImpl& RegisterCustomOpsUsingFunction(const char* function_name);
1441
1443 SessionOptionsImpl& AppendExecutionProvider_VitisAI(const std::unordered_map<std::string, std::string>& provider_options = {});
1444
1446 SessionOptionsImpl& AddFreeDimensionOverride(const char* dim_denotation, int64_t dim_value);
1447
1449 SessionOptionsImpl& AddFreeDimensionOverrideByName(const char* dim_name, int64_t dim_value);
1450};
1451} // namespace detail
1452
1453using UnownedSessionOptions = detail::SessionOptionsImpl<detail::Unowned<OrtSessionOptions>>;
1454using ConstSessionOptions = detail::ConstSessionOptionsImpl<detail::Unowned<const OrtSessionOptions>>;
1455
1459struct SessionOptions : detail::SessionOptionsImpl<OrtSessionOptions> {
1460 explicit SessionOptions(std::nullptr_t) {}
1462 explicit SessionOptions(OrtSessionOptions* p) : SessionOptionsImpl<OrtSessionOptions>{p} {}
1465};
1466
1471struct ModelCompilationOptions : detail::Base<OrtModelCompilationOptions> {
1473 using Base::Base;
1474
1475 explicit ModelCompilationOptions(std::nullptr_t) {}
1476
1477 ModelCompilationOptions(const Env& env, const SessionOptions& session_options);
1478 ModelCompilationOptions(const Env& env, ConstSessionOptions session_options);
1479
1480 ModelCompilationOptions& SetInputModelPath(const ORTCHAR_T* input_model_path);
1482 size_t input_model_data_size);
1483 ModelCompilationOptions& SetEpContextEmbedMode(bool embed_ep_context_in_model);
1484 ModelCompilationOptions& SetOutputModelPath(const ORTCHAR_T* output_model_path);
1486 size_t initializer_size_threshold);
1487
1490 OrtGetInitializerLocationFunc get_initializer_location_func,
1491 void* state);
1492
1493 ModelCompilationOptions& SetOutputModelBuffer(OrtAllocator* allocator, void** output_model_buffer_ptr,
1494 size_t* output_model_buffer_size_ptr);
1495
1498
1499 ModelCompilationOptions& SetEpContextBinaryInformation(const ORTCHAR_T* output_directory,
1500 const ORTCHAR_T* model_name);
1502
1504};
1505
1512Status CompileModel(const Env& env, const ModelCompilationOptions& model_compilation_options);
1513
1517struct ModelMetadata : detail::Base<OrtModelMetadata> {
1519 using Base::Base;
1520
1521 explicit ModelMetadata(std::nullptr_t) {}
1522
1530
1538
1546
1554
1562
1569 std::vector<AllocatedStringPtr> GetCustomMetadataMapKeysAllocated(OrtAllocator* allocator) const;
1570
1581
1582 int64_t GetVersion() const;
1583};
1584
1585struct IoBinding;
1586
1587namespace detail {
1588
1589// we separate const-only methods because passing const ptr to non-const methods
1590// is only discovered when inline methods are compiled which is counter-intuitive
1591template <typename T>
1593 using B = Base<T>;
1594 using B::B;
1595
1596 size_t GetInputCount() const;
1597 size_t GetOutputCount() const;
1599
1600 std::vector<std::string> GetInputNames() const;
1601 std::vector<std::string> GetOutputNames() const;
1602 std::vector<std::string> GetOverridableInitializerNames() const;
1603
1604 std::vector<ConstMemoryInfo> GetMemoryInfoForInputs() const;
1605 std::vector<ConstMemoryInfo> GetMemoryInfoForOutputs() const;
1606 std::vector<ConstEpDevice> GetEpDeviceForInputs() const;
1607
1616
1625
1634
1635 uint64_t GetProfilingStartTimeNs() const;
1637
1638 TypeInfo GetInputTypeInfo(size_t index) const;
1639 TypeInfo GetOutputTypeInfo(size_t index) const;
1641
1642 int GetOpset(const std::string& domain) const;
1643
1644 // Will move before checkin if that's the case.
1645 std::vector<ValueInfo> GetInputs() const;
1646 std::vector<ValueInfo> GetOutputs() const;
1647};
1648
1649template <typename T>
1652 using B::B;
1653
1671 std::vector<Value> Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
1672 const char* const* output_names, size_t output_count);
1673
1677 void Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
1678 const char* const* output_names, Value* output_values, size_t output_count);
1679
1680 void Run(const RunOptions& run_options, const IoBinding&);
1681
1701 void RunAsync(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
1702 const char* const* output_names, Value* output_values, size_t output_count, RunAsyncCallbackFn callback, void* user_data);
1703
1711
1723 void SetEpDynamicOptions(const char* const* keys, const char* const* values, size_t kv_len);
1724
1725 void FinalizeModelEditorSession(const Model& model, const SessionOptions& options,
1726 OrtPrepackedWeightsContainer* prepacked_weights_container = nullptr);
1727};
1728
1729} // namespace detail
1730
1733
1737struct Session : detail::SessionImpl<OrtSession> {
1739 explicit Session(std::nullptr_t) {}
1740 explicit Session(OrtSession* p) : SessionImpl{p} {}
1741
1742 Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
1743
1745 Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options,
1746 OrtPrepackedWeightsContainer* prepacked_weights_container);
1747
1749 Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options);
1750
1752 Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options,
1753 OrtPrepackedWeightsContainer* prepacked_weights_container);
1754
1755#if !defined(ORT_MINIMAL_BUILD)
1757 Session(const Env& env, const Model& model, const SessionOptions& options);
1758
1760 static Session CreateModelEditorSession(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
1761
1763 static Session CreateModelEditorSession(const Env& env, const void* model_data, size_t model_data_length,
1764 const SessionOptions& options);
1765#endif // !defined(ORT_MINIMAL_BUILD)
1766
1767 ConstSession GetConst() const { return ConstSession{this->p_}; }
1768 UnownedSession GetUnowned() const { return UnownedSession{this->p_}; }
1769};
1770
1771namespace detail {
1772template <typename T>
1774 using B = Base<T>;
1775 using B::B;
1776
1778 size_t GetElementCount() const;
1779
1780 size_t GetDimensionsCount() const;
1781
1786 [[deprecated("use GetShape()")]] void GetDimensions(int64_t* values, size_t values_count) const;
1787
1788 void GetSymbolicDimensions(const char** values, size_t values_count) const;
1789 std::vector<const char*> GetSymbolicDimensions() const;
1790
1791 bool HasShape() const;
1792 std::vector<int64_t> GetShape() const;
1793};
1794
1795} // namespace detail
1796
1798
1804 using Base::Base;
1805
1807 explicit TensorTypeAndShapeInfo(std::nullptr_t) {}
1809 explicit TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* p) : TensorTypeAndShapeInfoImpl{p} {}
1810
1811 // Create a TensorTypeAndShapeInfo object with the specified element type and dimensions
1812 // symbolic_dims are optional, but should be 1:1 with dims.
1813 // The value in symbolic_dims will be used for all entries in dims that are -1.
1815 const std::vector<int64_t>& dims,
1816 const std::vector<std::string>* symbolic_dims = nullptr);
1817
1819};
1820
1821namespace detail {
1822template <typename T>
1824 using B = Base<T>;
1825 using B::B;
1827};
1828
1829} // namespace detail
1830
1832
1836struct SequenceTypeInfo : detail::SequenceTypeInfoImpl<OrtSequenceTypeInfo> {
1838 using Base::Base;
1839
1840 explicit SequenceTypeInfo(std::nullptr_t) {}
1841 explicit SequenceTypeInfo(OrtSequenceTypeInfo* p) : SequenceTypeInfoImpl<OrtSequenceTypeInfo>{p} {}
1843};
1844
1845namespace detail {
1846template <typename T>
1848 using B = Base<T>;
1849 using B::B;
1851};
1852
1853} // namespace detail
1854
1855// This is always owned by the TypeInfo and can only be obtained from it.
1857
1858namespace detail {
1859template <typename T>
1866
1867} // namespace detail
1868
1870
1874struct MapTypeInfo : detail::MapTypeInfoImpl<OrtMapTypeInfo> {
1876 using Base::Base;
1877
1878 explicit MapTypeInfo(std::nullptr_t) {}
1879 explicit MapTypeInfo(OrtMapTypeInfo* p) : MapTypeInfoImpl<OrtMapTypeInfo>{p} {}
1880 ConstMapTypeInfo GetConst() const { return ConstMapTypeInfo{this->p_}; }
1881};
1882
1883namespace detail {
1884template <typename T>
1896} // namespace detail
1897
1903
1908struct TypeInfo : detail::TypeInfoImpl<OrtTypeInfo> {
1910 using Base::Base;
1911
1913 explicit TypeInfo(std::nullptr_t) {}
1914 explicit TypeInfo(OrtTypeInfo* p) : TypeInfoImpl<OrtTypeInfo>{p} {}
1915
1916#if !defined(ORT_MINIMAL_BUILD)
1922#endif // !defined(ORT_MINIMAL_BUILD)
1923
1924 ConstTypeInfo GetConst() const { return ConstTypeInfo{this->p_}; }
1925};
1926
1927namespace detail {
1928// This structure is used to feed sparse tensor values
1929// information for use with FillSparseTensor<Format>() API
1930// if the data type for the sparse tensor values is numeric
1931// use data.p_data, otherwise, use data.str pointer to feed
1932// values. data.str is an array of const char* that are zero terminated.
1933// number of strings in the array must match shape size.
1934// For fully sparse tensors use shape {0} and set p_data/str
1935// to nullptr.
1937 const int64_t* values_shape;
1939 union {
1940 const void* p_data;
1941 const char** str;
1942 } data;
1943};
1944
1945// Provides a way to pass shape in a single
1946// argument
1947struct Shape {
1948 const int64_t* shape;
1950};
1951
1952template <typename T>
1954 using B = Base<T>;
1955 using B::B;
1956
1960 template <typename R>
1961 void GetOpaqueData(const char* domain, const char* type_name, R&) const;
1962
1963 bool IsTensor() const;
1964 bool HasValue() const;
1965
1966 size_t GetCount() const; // If a non tensor, returns 2 for map and N for sequence, where N is the number of elements
1967 Value GetValue(int index, OrtAllocator* allocator) const;
1968
1976
1991 void GetStringTensorContent(void* buffer, size_t buffer_length, size_t* offsets, size_t offsets_count) const;
1992
1999 template <typename R>
2000 const R* GetTensorData() const;
2001
2006 const void* GetTensorRawData() const;
2007
2015
2023
2029
2038 void GetStringTensorElement(size_t buffer_length, size_t element_index, void* buffer) const;
2039
2046 std::string GetStringTensorElement(size_t element_index) const;
2047
2054 size_t GetStringTensorElementLength(size_t element_index) const;
2055
2062 size_t GetTensorSizeInBytes() const;
2063
2064#if !defined(DISABLE_SPARSE_TENSORS)
2072
2079
2088
2098 template <typename R>
2099 const R* GetSparseTensorIndicesData(OrtSparseIndicesFormat indices_format, size_t& num_indices) const;
2100
2105 bool IsSparseTensor() const;
2106
2115 template <typename R>
2116 const R* GetSparseTensorValues() const;
2117
2118#endif
2119};
2120
2121template <typename T>
2124 using B::B;
2125
2131 template <typename R>
2133
2139
2141 // Obtain a reference to an element of data at the location specified
2147 template <typename R>
2148 R& At(const std::vector<int64_t>& location);
2149
2155 void FillStringTensor(const char* const* s, size_t s_len);
2156
2162 void FillStringTensorElement(const char* s, size_t index);
2163
2176 char* GetResizedStringTensorElementBuffer(size_t index, size_t buffer_length);
2177
2178#if !defined(DISABLE_SPARSE_TENSORS)
2187 void UseCooIndices(int64_t* indices_data, size_t indices_num);
2188
2199 void UseCsrIndices(int64_t* inner_data, size_t inner_num, int64_t* outer_data, size_t outer_num);
2200
2209 void UseBlockSparseIndices(const Shape& indices_shape, int32_t* indices_data);
2210
2220 void FillSparseTensorCoo(const OrtMemoryInfo* data_mem_info, const OrtSparseValuesParam& values_param,
2221 const int64_t* indices_data, size_t indices_num);
2222
2234 void FillSparseTensorCsr(const OrtMemoryInfo* data_mem_info,
2235 const OrtSparseValuesParam& values,
2236 const int64_t* inner_indices_data, size_t inner_indices_num,
2237 const int64_t* outer_indices_data, size_t outer_indices_num);
2238
2249 const OrtSparseValuesParam& values,
2250 const Shape& indices_shape,
2251 const int32_t* indices_data);
2252
2253#endif
2254};
2255
2256} // namespace detail
2257
2260
2264struct Value : detail::ValueImpl<OrtValue> {
2266 using Base::Base;
2269
2270 Value(std::nullptr_t) {}
2271 Value(Value&&) = default;
2272 Value& operator=(Value&&) = default;
2273
2274 ConstValue GetConst() const { return ConstValue{this->p_}; }
2275 UnownedValue GetUnowned() const { return UnownedValue{this->p_}; }
2276
2285 template <typename T>
2286 static Value CreateTensor(const OrtMemoryInfo* info, T* p_data, size_t p_data_element_count,
2287 const int64_t* shape, size_t shape_len);
2288
2298 static Value CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count,
2299 const int64_t* shape, size_t shape_len,
2301
2311 static Value CreateTensor(OrtAllocator* deleter, void* p_data, size_t p_data_byte_count,
2312 const int64_t* shape, size_t shape_len,
2314
2326 template <typename T>
2327 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len);
2328
2340 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len,
2342
2351 static Value CreateMap(const Value& keys, const Value& values);
2352
2360 static Value CreateSequence(const std::vector<Value>& values);
2361
2370 template <typename T>
2371 static Value CreateOpaque(const char* domain, const char* type_name, const T& value);
2372
2373#if !defined(DISABLE_SPARSE_TENSORS)
2384 template <typename T>
2385 static Value CreateSparseTensor(const OrtMemoryInfo* info, T* p_data, const Shape& dense_shape,
2386 const Shape& values_shape);
2387
2404 static Value CreateSparseTensor(const OrtMemoryInfo* info, void* p_data, const Shape& dense_shape,
2405 const Shape& values_shape, ONNXTensorElementDataType type);
2406
2416 template <typename T>
2417 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape);
2418
2430 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape, ONNXTensorElementDataType type);
2431
2432#endif // !defined(DISABLE_SPARSE_TENSORS)
2433};
2434
2435namespace detail {
2436namespace binding_utils {
2437// Bring these out of template
2438std::vector<std::string> GetOutputNamesHelper(const OrtIoBinding* binding, OrtAllocator*);
2439std::vector<Value> GetOutputValuesHelper(const OrtIoBinding* binding, OrtAllocator*);
2440} // namespace binding_utils
2441
2442template <typename T>
2444 using B = Base<T>;
2445 using B::B;
2446
2447 std::vector<std::string> GetOutputNames() const;
2448 std::vector<std::string> GetOutputNames(OrtAllocator*) const;
2449 std::vector<Value> GetOutputValues() const;
2450 std::vector<Value> GetOutputValues(OrtAllocator*) const;
2451};
2452
2453template <typename T>
2456 using B::B;
2457
2458 void BindInput(const char* name, const Value&);
2459 void BindOutput(const char* name, const Value&);
2460 void BindOutput(const char* name, const OrtMemoryInfo*);
2465};
2466
2467} // namespace detail
2468
2471
2475struct IoBinding : detail::IoBindingImpl<OrtIoBinding> {
2476 explicit IoBinding(std::nullptr_t) {}
2477 explicit IoBinding(Session& session);
2478 ConstIoBinding GetConst() const { return ConstIoBinding{this->p_}; }
2479 UnownedIoBinding GetUnowned() const { return UnownedIoBinding{this->p_}; }
2480};
2481
2486struct ArenaCfg : detail::Base<OrtArenaCfg> {
2487 explicit ArenaCfg(std::nullptr_t) {}
2496 ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk);
2497
2502 explicit ArenaCfg(const std::unordered_map<std::string, size_t>& arena_config);
2503};
2504
2505//
2506// Custom OPs (only needed to implement custom OPs)
2507//
2508
2509namespace detail {
2510// Need to define a templated ConstOpAttr with const members
2511template <typename T>
2514 using B::B;
2515
2516 // Wraps OrtApi::OpAttr_GetName
2517 std::string GetName() const;
2518 // Wraps OrtApi::OpAttr_GetType
2520
2521 // Wraps OrtApi::ReadAttr for a single value
2522 // This does not support Tensor Attribute
2523 // Call GetTensorAttributeAsOrtValue() instead.
2524 template <typename R>
2525 Status GetValue(R& out) const;
2526
2527 // Wraps OrtApi::ReadAttr for an array of values
2528 template <typename R>
2529 Status GetValueArray(std::vector<R>& out) const;
2530 // Wraps OrtApi::OpAttr_GetTensorAttributeAsOrtValue
2532};
2533} // namespace detail
2534
2536
2540struct OpAttr : detail::ConstOpAttrImpl<OrtOpAttr> {
2542 using Base::Base;
2543
2544 OpAttr() = default; // Enable storing it in the container for resize()
2545 explicit OpAttr(std::nullptr_t) {}
2546 OpAttr(const char* name, const void* data, int len, OrtOpAttrType type);
2547
2548 ConstOpAttr GetConst() const { return ConstOpAttr{this->p_}; }
2549};
2550
2559#define ORT_CXX_LOG(logger, message_severity, message) \
2560 do { \
2561 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2562 Ort::ThrowOnError(logger.LogMessage(message_severity, ORT_FILE, __LINE__, \
2563 static_cast<const char*>(__FUNCTION__), message)); \
2564 } \
2565 } while (false)
2566
2575#define ORT_CXX_LOG_NOEXCEPT(logger, message_severity, message) \
2576 do { \
2577 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2578 static_cast<void>(logger.LogMessage(message_severity, ORT_FILE, __LINE__, \
2579 static_cast<const char*>(__FUNCTION__), message)); \
2580 } \
2581 } while (false)
2582
2594#define ORT_CXX_LOGF(logger, message_severity, /*format,*/...) \
2595 do { \
2596 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2597 Ort::ThrowOnError(logger.LogFormattedMessage(message_severity, ORT_FILE, __LINE__, \
2598 static_cast<const char*>(__FUNCTION__), __VA_ARGS__)); \
2599 } \
2600 } while (false)
2601
2613#define ORT_CXX_LOGF_NOEXCEPT(logger, message_severity, /*format,*/...) \
2614 do { \
2615 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2616 static_cast<void>(logger.LogFormattedMessage(message_severity, ORT_FILE, __LINE__, \
2617 static_cast<const char*>(__FUNCTION__), __VA_ARGS__)); \
2618 } \
2619 } while (false)
2620
2631struct Logger {
2635 Logger() = default;
2636
2640 explicit Logger(std::nullptr_t) {}
2641
2648 explicit Logger(const OrtLogger* logger);
2649
2650 ~Logger() = default;
2651
2652 Logger(const Logger&) = default;
2653 Logger& operator=(const Logger&) = default;
2654
2655 Logger(Logger&& v) noexcept = default;
2656 Logger& operator=(Logger&& v) noexcept = default;
2657
2664
2677 Status LogMessage(OrtLoggingLevel log_severity_level, const ORTCHAR_T* file_path, int line_number,
2678 const char* func_name, const char* message) const noexcept;
2679
2694 template <typename... Args>
2695 Status LogFormattedMessage(OrtLoggingLevel log_severity_level, const ORTCHAR_T* file_path, int line_number,
2696 const char* func_name, const char* format, Args&&... args) const noexcept;
2697
2698 private:
2699 const OrtLogger* logger_{};
2700 OrtLoggingLevel cached_severity_level_{};
2701};
2702
2711 size_t GetInputCount() const;
2712 size_t GetOutputCount() const;
2713 // If input is optional and is not present, the method returns an empty ConstValue
2714 // which can be compared to nullptr.
2715 ConstValue GetInput(size_t index) const;
2716 // If output is optional and is not present, the method returns an empty UnownedValue
2717 // which can be compared to nullptr.
2718 UnownedValue GetOutput(size_t index, const int64_t* dim_values, size_t dim_count) const;
2719 UnownedValue GetOutput(size_t index, const std::vector<int64_t>& dims) const;
2720 void* GetGPUComputeStream() const;
2722 OrtAllocator* GetAllocator(const OrtMemoryInfo& memory_info) const;
2723 OrtKernelContext* GetOrtKernelContext() const { return ctx_; }
2724 void ParallelFor(void (*fn)(void*, size_t), size_t total, size_t num_batch, void* usr_data) const;
2725
2726 private:
2727 OrtKernelContext* ctx_;
2728};
2729
2730struct KernelInfo;
2731
2732namespace detail {
2733namespace attr_utils {
2734void GetAttr(const OrtKernelInfo* p, const char* name, float&);
2735void GetAttr(const OrtKernelInfo* p, const char* name, int64_t&);
2736void GetAttr(const OrtKernelInfo* p, const char* name, std::string&);
2737void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<float>&);
2738void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<int64_t>&);
2739} // namespace attr_utils
2740
2741template <typename T>
2742struct KernelInfoImpl : Base<T> {
2743 using B = Base<T>;
2744 using B::B;
2745
2746 KernelInfo Copy() const;
2747
2748 template <typename R> // R is only implemented for float, int64_t, and string
2749 R GetAttribute(const char* name) const {
2750 R val;
2751 attr_utils::GetAttr(this->p_, name, val);
2752 return val;
2753 }
2754
2755 template <typename R> // R is only implemented for std::vector<float>, std::vector<int64_t>
2756 std::vector<R> GetAttributes(const char* name) const {
2757 std::vector<R> result;
2758 attr_utils::GetAttrs(this->p_, name, result);
2759 return result;
2760 }
2761
2762 Value GetTensorAttribute(const char* name, OrtAllocator* allocator) const;
2763
2764 size_t GetInputCount() const;
2765 size_t GetOutputCount() const;
2766
2767 std::string GetInputName(size_t index) const;
2768 std::string GetOutputName(size_t index) const;
2769
2770 TypeInfo GetInputTypeInfo(size_t index) const;
2771 TypeInfo GetOutputTypeInfo(size_t index) const;
2772
2773 ConstValue GetTensorConstantInput(size_t index, int* is_constant) const;
2774
2775 std::string GetNodeName() const;
2776 Logger GetLogger() const;
2777
2778 KeyValuePairs GetConfigEntries() const;
2779};
2780
2781} // namespace detail
2782
2783using ConstKernelInfo = detail::KernelInfoImpl<detail::Unowned<const OrtKernelInfo>>;
2784
2791struct KernelInfo : detail::KernelInfoImpl<OrtKernelInfo> {
2792 using Base = detail::KernelInfoImpl<OrtKernelInfo>;
2793 using Base::Base;
2794 explicit KernelInfo(std::nullptr_t) {}
2795 explicit KernelInfo(OrtKernelInfo* info);
2796 ConstKernelInfo GetConst() const { return ConstKernelInfo{this->p_}; }
2797};
2798
2802struct Op : detail::Base<OrtOp> {
2804 using Base::Base;
2805
2806 explicit Op(std::nullptr_t) {}
2807
2808 explicit Op(OrtOp*);
2809
2810 static Op Create(const OrtKernelInfo* info, const char* op_name, const char* domain,
2811 int version, const char** type_constraint_names,
2812 const ONNXTensorElementDataType* type_constraint_values,
2813 size_t type_constraint_count,
2814 const OpAttr* attr_values,
2815 size_t attr_count,
2816 size_t input_count, size_t output_count);
2817
2818 void Invoke(const OrtKernelContext* context,
2819 const Value* input_values,
2820 size_t input_count,
2821 Value* output_values,
2822 size_t output_count);
2823
2824 // For easier refactoring
2825 void Invoke(const OrtKernelContext* context,
2826 const OrtValue* const* input_values,
2827 size_t input_count,
2828 OrtValue* const* output_values,
2829 size_t output_count);
2830};
2831
2837 SymbolicInteger(int64_t i) : i_(i), is_int_(true) {};
2838 SymbolicInteger(const char* s) : s_(s), is_int_(false) {};
2841
2844
2845 bool operator==(const SymbolicInteger& dim) const {
2846 if (is_int_ == dim.is_int_) {
2847 if (is_int_) {
2848 return i_ == dim.i_;
2849 } else {
2850 return std::string{s_} == std::string{dim.s_};
2851 }
2852 }
2853 return false;
2854 }
2855
2856 bool IsInt() const { return is_int_; }
2857 int64_t AsInt() const { return i_; }
2858 const char* AsSym() const { return s_; }
2859
2860 static constexpr int INVALID_INT_DIM = -2;
2861
2862 private:
2863 union {
2864 int64_t i_;
2865 const char* s_;
2866 };
2867 bool is_int_;
2868 };
2869
2870 using Shape = std::vector<SymbolicInteger>;
2871
2873
2874 const Shape& GetInputShape(size_t indice) const { return input_shapes_.at(indice); }
2875
2876 size_t GetInputCount() const { return input_shapes_.size(); }
2877
2879
2880 int64_t GetAttrInt(const char* attr_name);
2881
2882 using Ints = std::vector<int64_t>;
2883 Ints GetAttrInts(const char* attr_name);
2884
2885 float GetAttrFloat(const char* attr_name);
2886
2887 using Floats = std::vector<float>;
2888 Floats GetAttrFloats(const char* attr_name);
2889
2890 std::string GetAttrString(const char* attr_name);
2891
2892 using Strings = std::vector<std::string>;
2893 Strings GetAttrStrings(const char* attr_name);
2894
2895 private:
2896 ConstOpAttr GetAttrHdl(const char* attr_name) const;
2897 const OrtApi* ort_api_;
2899 std::vector<Shape> input_shapes_;
2900};
2901
2903
2904#define MAX_CUSTOM_OP_END_VER (1UL << 31) - 1
2905
2906template <typename TOp, typename TKernel, bool WithStatus = false>
2910 OrtCustomOp::GetName = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetName(); };
2911
2912 OrtCustomOp::GetExecutionProviderType = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetExecutionProviderType(); };
2913
2914 OrtCustomOp::GetInputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetInputTypeCount(); };
2915 OrtCustomOp::GetInputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputType(index); };
2916 OrtCustomOp::GetInputMemoryType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputMemoryType(index); };
2917
2918 OrtCustomOp::GetOutputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetOutputTypeCount(); };
2919 OrtCustomOp::GetOutputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputType(index); };
2920
2921#if defined(_MSC_VER) && !defined(__clang__)
2922#pragma warning(push)
2923#pragma warning(disable : 26409)
2924#endif
2925 OrtCustomOp::KernelDestroy = [](void* op_kernel) { delete static_cast<TKernel*>(op_kernel); };
2926#if defined(_MSC_VER) && !defined(__clang__)
2927#pragma warning(pop)
2928#endif
2929 OrtCustomOp::GetInputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputCharacteristic(index); };
2930 OrtCustomOp::GetOutputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputCharacteristic(index); };
2931
2932 OrtCustomOp::GetVariadicInputMinArity = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetVariadicInputMinArity(); };
2933 OrtCustomOp::GetVariadicInputHomogeneity = [](const OrtCustomOp* this_) { return static_cast<int>(static_cast<const TOp*>(this_)->GetVariadicInputHomogeneity()); };
2934 OrtCustomOp::GetVariadicOutputMinArity = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetVariadicOutputMinArity(); };
2935 OrtCustomOp::GetVariadicOutputHomogeneity = [](const OrtCustomOp* this_) { return static_cast<int>(static_cast<const TOp*>(this_)->GetVariadicOutputHomogeneity()); };
2936#ifdef __cpp_if_constexpr
2937 if constexpr (WithStatus) {
2938#else
2939 if (WithStatus) {
2940#endif
2941 OrtCustomOp::CreateKernelV2 = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info, void** op_kernel) -> OrtStatusPtr {
2942 return static_cast<const TOp*>(this_)->CreateKernelV2(*api, info, op_kernel);
2943 };
2944 OrtCustomOp::KernelComputeV2 = [](void* op_kernel, OrtKernelContext* context) -> OrtStatusPtr {
2945 return static_cast<TKernel*>(op_kernel)->ComputeV2(context);
2946 };
2947 } else {
2950
2951 OrtCustomOp::CreateKernel = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info) { return static_cast<const TOp*>(this_)->CreateKernel(*api, info); };
2952 OrtCustomOp::KernelCompute = [](void* op_kernel, OrtKernelContext* context) {
2953 static_cast<TKernel*>(op_kernel)->Compute(context);
2954 };
2955 }
2956
2957 SetShapeInferFn<TOp>(0);
2958
2959 OrtCustomOp::GetStartVersion = [](const OrtCustomOp* this_) {
2960 return static_cast<const TOp*>(this_)->start_ver_;
2961 };
2962
2963 OrtCustomOp::GetEndVersion = [](const OrtCustomOp* this_) {
2964 return static_cast<const TOp*>(this_)->end_ver_;
2965 };
2966
2969 OrtCustomOp::GetAliasMap = nullptr;
2971 }
2972
2973 // Default implementation of GetExecutionProviderType that returns nullptr to default to the CPU provider
2974 const char* GetExecutionProviderType() const { return nullptr; }
2975
2976 // Default implementations of GetInputCharacteristic() and GetOutputCharacteristic() below
2977 // (inputs and outputs are required by default)
2979 return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED;
2980 }
2981
2983 return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED;
2984 }
2985
2986 // Default implementation of GetInputMemoryType() that returns OrtMemTypeDefault
2987 OrtMemType GetInputMemoryType(size_t /*index*/) const {
2988 return OrtMemTypeDefault;
2989 }
2990
2991 // Default implementation of GetVariadicInputMinArity() returns 1 to specify that a variadic input
2992 // should expect at least 1 argument.
2994 return 1;
2995 }
2996
2997 // Default implementation of GetVariadicInputHomegeneity() returns true to specify that all arguments
2998 // to a variadic input should be of the same type.
3000 return true;
3001 }
3002
3003 // Default implementation of GetVariadicOutputMinArity() returns 1 to specify that a variadic output
3004 // should produce at least 1 output value.
3006 return 1;
3007 }
3008
3009 // Default implementation of GetVariadicOutputHomegeneity() returns true to specify that all output values
3010 // produced by a variadic output should be of the same type.
3012 return true;
3013 }
3014
3015 // Declare list of session config entries used by this Custom Op.
3016 // Implement this function in order to get configs from CustomOpBase::GetSessionConfigs().
3017 // This default implementation returns an empty vector of config entries.
3018 std::vector<std::string> GetSessionConfigKeys() const {
3019 return std::vector<std::string>{};
3020 }
3021
3022 // Ort::CustomOpBase derived class should provide the following static method with the type/shape inferencing
3023 // implementation if needed:
3024 // static OrtStatusPtr InferOutputShape(Ort::ShapeInferContext& context)
3025 template <typename C>
3026 decltype(&C::InferOutputShape) SetShapeInferFn(decltype(&C::InferOutputShape)) {
3028 ShapeInferContext ctx(&GetApi(), ort_ctx);
3029 return C::InferOutputShape(ctx);
3030 };
3031 return {};
3032 }
3033
3034 template <typename C>
3038
3039 protected:
3040 // Helper function that returns a map of session config entries specified by CustomOpBase::GetSessionConfigKeys.
3041 void GetSessionConfigs(std::unordered_map<std::string, std::string>& out, ConstSessionOptions options) const;
3042
3043 int start_ver_ = 1;
3044 int end_ver_ = MAX_CUSTOM_OP_END_VER;
3045};
3046
3047// Forward declaration to resolve circular dependency
3048// on ConstNode
3050
3051namespace detail {
3052template <typename T>
3054 using B = Base<T>;
3055 using B::B;
3056
3058 std::string GetName() const;
3064 std::vector<ValueInfoConsumerProducerInfo> GetConsumers() const;
3074 bool IsGraphOutput() const;
3078 bool IsFromOuterScope() const;
3079};
3080} // namespace detail
3081
3082// Const object holder that does not own the underlying object
3084
3089 ValueInfo() = default; // Same thing as with nullptr
3090 explicit ValueInfo(std::nullptr_t) {}
3092 explicit ValueInfo(OrtValueInfo* p) : ConstValueInfoImpl<OrtValueInfo>{p} {}
3093
3094#if !defined(ORT_MINIMAL_BUILD)
3095 // Create ValueInfo for a tensor
3096 explicit ValueInfo(const std::string& name, const ConstTypeInfo& type_info);
3097#endif
3098 ConstValueInfo GetConst() const { return ConstValueInfo{this->p_}; }
3099};
3100
3101// Forward declaration
3102struct AttrNameSubgraph;
3103
3104namespace detail {
3105// Forward decl
3106template <typename T>
3107struct ConstGraphImpl;
3108
3109template <typename T>
3110struct ConstNodeImpl : Base<T> {
3111 using B = Base<T>;
3112 using B::B;
3113
3114 // <Wraps OrtApi::Node_GetId
3115 size_t GetId() const;
3116 // <Wraps OrtApi::Node_GetName
3117 std::string GetName() const;
3118 // <Wraps OrtApi::Node_GetOperatorType
3119 std::string GetOperatorType() const;
3120 // <Wraps OrtApi::Node_GetDomain
3121 std::string GetDomain() const;
3122 // <Wraps OrtApi::Node_GetSinceVersion
3123 int GetSinceVersion() const;
3124
3125 // <Wraps OrtApi::Node_Inputs
3126 std::vector<ConstValueInfo> GetInputs() const;
3127 // <Wraps OrtApi::Node_Outputs
3128 std::vector<ConstValueInfo> GetOutputs() const;
3129 // <Wraps OrtApi::Node_ImplicitInputs
3130 std::vector<ConstValueInfo> GetImplicitInputs() const;
3131 // <Wraps OrtApi::Node_GetAttributes
3132 std::vector<ConstOpAttr> GetAttributes() const;
3133 // <Wraps OrtApi::Node_GetAttributeByName
3134 // Please, read C API doc for details
3135 Status GetAttributeByName(const std::string& name, ConstOpAttr& attr) const;
3136 // <Wraps OrtApi::Node_GetSubgraphs
3137 std::vector<AttrNameSubgraph> GetSubgraphs() const;
3138 // <Wraps OrtApi::Node_GetGraph
3139 // ConstGraph is not available yet
3141 // <Wraps OrtApi::Node_GetEpName
3142 std::string GetEpName() const;
3143};
3144} // namespace detail
3145
3147
3151struct Node : detail::ConstNodeImpl<OrtNode> {
3152 Node() = default; // Same thing as with nullptr
3153 explicit Node(std::nullptr_t) {}
3154 explicit Node(OrtNode* p) : ConstNodeImpl<OrtNode>{p} {}
3155
3156#if !defined(ORT_MINIMAL_BUILD)
3157 Node(const std::string& operator_name, const std::string& operator_domain,
3158 const std::string& node_name,
3159 const std::vector<std::string>& input_names,
3160 const std::vector<std::string>& output_names);
3161
3165 Node(const std::string& operator_name, const std::string& operator_domain,
3166 const std::string& node_name,
3167 const std::vector<std::string>& input_names,
3168 const std::vector<std::string>& output_names,
3169 std::vector<OpAttr>& attributes);
3170
3171 private:
3172 static void Init(const std::string& operator_name, const std::string& operator_domain,
3173 const std::string& node_name,
3174 const std::vector<std::string>& input_names,
3175 const std::vector<std::string>& output_names,
3176 std::vector<OpAttr>& attributes,
3177 OrtNode*& node);
3178#endif // !defined(ORT_MINIMAL_BUILD)
3179};
3180
3181// Return struct for some of ValueInfo APIs.
3182// Must be declared after ConstNode is available.
3185 // either producer output or consumer output index
3186 // producer is unsigned only, output can be -1
3187 int64_t index;
3188};
3189
3190// Represents a return value for Graph::GetOperatorSets()
3192 std::string domain;
3193 int64_t version;
3194};
3195
3196namespace detail {
3197template <typename T>
3199 using B = Base<T>;
3200 using B::B;
3201
3202 // <Wraps OrtApi::Graph_GetName
3203 std::string GetName() const;
3204 // <Wraps OrtApi::Graph_GetModelPath
3205 std::basic_string<ORTCHAR_T> GetModelPath() const;
3206 // <Wraps OrtApi::Graph_GetOnnxIRVersion
3207 int64_t GetOnnxIRVersion() const;
3208 // <Wraps OrtApi::Graph_GetOperatorSets
3209 std::vector<OperatorSet> GetOperatorSets() const;
3210 // <Wraps OrtApi::Graph_Inputs
3211 std::vector<ConstValueInfo> GetInputs() const;
3212 // <Wraps OrtApi::Graph_Outputs
3213 std::vector<ConstValueInfo> GetOutputs() const;
3214 // <Wraps OrtApi::Graph_Initializers
3215 std::vector<ConstValueInfo> GetInitializers() const;
3216 // <Wraps OrtApi::Graph_GetNodes
3217 std::vector<ConstNode> GetNodes() const;
3218 // <Wraps OrtApi::Graph_GetParentGraph
3220 // <Wraps OrtApi::Graph_GetGraphView
3221 Graph GetGraphView(const std::vector<ConstNode>& nodes) const;
3222 // <Wraps OrtApi::Graph_GetModelMetadata
3224};
3225
3226template <typename T>
3229 using B::B;
3230
3231#if !defined(ORT_MINIMAL_BUILD)
3232 // <Wraps GetModelEditorApi().SetGraphInputs()
3233 void SetInputs(std::vector<ValueInfo>& inputs);
3234 // <Wraps GetModelEditorApi().SetGraphOutputs()
3235 void SetOutputs(std::vector<ValueInfo>& outputs);
3236 // <Wraps GetModelEditorApi().AddInitializerToGraph()
3237 void AddInitializer(const std::string& name, Value& initializer, bool data_is_external); // Graph takes ownership of Value
3238 // <Wraps GetModelEditorApi().AddNodeToGraph()
3239 void AddNode(Node& node); // Graph takes ownership of Node
3240#endif // !defined(ORT_MINIMAL_BUILD)
3241};
3242} // namespace detail
3243
3245
3246// Return value for Node API
3247// Must be declared after ConstGraph
3252
3256struct Graph : detail::GraphImpl<OrtGraph> {
3257 explicit Graph(std::nullptr_t) {}
3258 explicit Graph(OrtGraph* p) : GraphImpl<OrtGraph>{p} {}
3259#if !defined(ORT_MINIMAL_BUILD)
3260 // <Wraps GetModelEditorApi().CreateGraph()
3262#endif
3263};
3264
3265namespace detail {
3266template <typename T>
3269 using B::B;
3270
3271#if !defined(ORT_MINIMAL_BUILD)
3272 // <Wraps GetModelEditorApi().AddGraphToModel()
3273 void AddGraph(Graph& graph);
3274#endif
3275};
3276} // namespace detail
3277
3278// Const object holder that does not own the underlying object
3280
3284struct Model : detail::ModelImpl<OrtModel> {
3285 using DomainOpsetPair = std::pair<std::string, int>;
3286
3287 explicit Model(std::nullptr_t) {}
3288 explicit Model(OrtModel* p) : ModelImpl<OrtModel>{p} {}
3289
3290#if !defined(ORT_MINIMAL_BUILD)
3291 //< Wraps GetModelEditorApi().CreateModel()
3292 explicit Model(const std::vector<DomainOpsetPair>& opsets);
3293#endif
3294};
3295} // namespace Ort
3296#include "onnxruntime_cxx_inline.h"
struct OrtMemoryInfo OrtMemoryInfo
Definition onnxruntime_c_api.h:296
struct OrtKernelInfo OrtKernelInfo
Definition onnxruntime_c_api.h:450
struct OrtNode OrtNode
Definition onnxruntime_c_api.h:324
OrtLoggingLevel
Logging severity levels.
Definition onnxruntime_c_api.h:246
OrtMemoryInfoDeviceType
This mimics OrtDevice type constants so they can be returned in the API.
Definition onnxruntime_c_api.h:485
struct OrtShapeInferContext OrtShapeInferContext
Definition onnxruntime_c_api.h:321
void(* OrtLoggingFunction)(void *param, OrtLoggingLevel severity, const char *category, const char *logid, const char *code_location, const char *message)
Definition onnxruntime_c_api.h:414
void(* OrtCustomJoinThreadFn)(OrtCustomThreadHandle ort_custom_thread_handle)
Custom thread join function.
Definition onnxruntime_c_api.h:938
OrtCustomOpInputOutputCharacteristic
Definition onnxruntime_c_api.h:6628
struct OrtTensorRTProviderOptionsV2 OrtTensorRTProviderOptionsV2
Definition onnxruntime_c_api.h:313
struct OrtThreadingOptions OrtThreadingOptions
Definition onnxruntime_c_api.h:310
struct OrtSequenceTypeInfo OrtSequenceTypeInfo
Definition onnxruntime_c_api.h:304
struct OrtValueInfo OrtValueInfo
Definition onnxruntime_c_api.h:323
struct OrtDnnlProviderOptions OrtDnnlProviderOptions
Definition onnxruntime_c_api.h:317
OrtSparseIndicesFormat
Definition onnxruntime_c_api.h:235
struct OrtPrepackedWeightsContainer OrtPrepackedWeightsContainer
Definition onnxruntime_c_api.h:312
struct OrtSession OrtSession
Definition onnxruntime_c_api.h:298
OrtCompiledModelCompatibility
The C API.
Definition onnxruntime_c_api.h:961
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:529
struct OrtCustomOpDomain OrtCustomOpDomain
Definition onnxruntime_c_api.h:307
struct OrtIoBinding OrtIoBinding
Definition onnxruntime_c_api.h:297
struct OrtExternalInitializerInfo OrtExternalInitializerInfo
Definition onnxruntime_c_api.h:332
OrtAllocatorType
Definition onnxruntime_c_api.h:456
struct OrtOp OrtOp
Definition onnxruntime_c_api.h:318
struct OrtTypeInfo OrtTypeInfo
Definition onnxruntime_c_api.h:301
struct OrtTensorTypeAndShapeInfo OrtTensorTypeAndShapeInfo
Definition onnxruntime_c_api.h:302
struct OrtCUDAProviderOptionsV2 OrtCUDAProviderOptionsV2
Definition onnxruntime_c_api.h:315
struct OrtKernelContext OrtKernelContext
Definition onnxruntime_c_api.h:452
struct OrtCANNProviderOptions OrtCANNProviderOptions
Definition onnxruntime_c_api.h:316
struct OrtEpDevice OrtEpDevice
Definition onnxruntime_c_api.h:329
void(* RunAsyncCallbackFn)(void *user_data, OrtValue **outputs, size_t num_outputs, OrtStatusPtr status)
Callback function for RunAsync.
Definition onnxruntime_c_api.h:949
OrtHardwareDeviceType
Definition onnxruntime_c_api.h:492
struct OrtModel OrtModel
Definition onnxruntime_c_api.h:326
struct OrtGraph OrtGraph
Definition onnxruntime_c_api.h:325
struct OrtSyncStream OrtSyncStream
Definition onnxruntime_c_api.h:331
struct OrtSessionOptions OrtSessionOptions
Definition onnxruntime_c_api.h:306
OrtDeviceMemoryType
This matches OrtDevice::MemoryType values.
Definition onnxruntime_c_api.h:478
struct OrtValue OrtValue
Definition onnxruntime_c_api.h:299
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:548
GraphOptimizationLevel
Graph optimization level.
Definition onnxruntime_c_api.h:423
struct OrtKeyValuePairs OrtKeyValuePairs
Definition onnxruntime_c_api.h:330
OrtStatus * OrtStatusPtr
Definition onnxruntime_c_api.h:337
OrtMemType
Memory types for allocated memory, execution provider specific types should be extended in each provi...
Definition onnxruntime_c_api.h:466
OrtSparseFormat
Definition onnxruntime_c_api.h:227
ONNXType
Definition onnxruntime_c_api.h:215
struct OrtEnv OrtEnv
Definition onnxruntime_c_api.h:294
OrtErrorCode
Definition onnxruntime_c_api.h:254
struct OrtStatus OrtStatus
Definition onnxruntime_c_api.h:295
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:582
#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:320
struct OrtMapTypeInfo OrtMapTypeInfo
Definition onnxruntime_c_api.h:303
struct OrtArenaCfg OrtArenaCfg
Definition onnxruntime_c_api.h:311
ExecutionMode
Definition onnxruntime_c_api.h:431
OrtOpAttrType
Definition onnxruntime_c_api.h:272
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:931
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:500
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:249
@ OrtMemTypeDefault
The default allocator for execution provider.
Definition onnxruntime_c_api.h:474
@ ORT_FAIL
Definition onnxruntime_c_api.h:256
@ 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:615
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
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:788
detail::ConstSessionOptionsImpl< detail::Unowned< const OrtSessionOptions > > ConstSessionOptions
Definition onnxruntime_cxx_api.h:1454
detail::KernelInfoImpl< detail::Unowned< const OrtKernelInfo > > ConstKernelInfo
Definition onnxruntime_cxx_api.h:2783
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
detail::AllocatorImpl< detail::Unowned< OrtAllocator > > UnownedAllocator
Definition onnxruntime_cxx_api.h:1061
OrtCompiledModelCompatibility GetModelCompatibilityForEpDevices(const std::vector< ConstEpDevice > &ep_devices, const char *compatibility_info)
Validate a compiled model's compatibility for one or more EP devices.
detail::SessionOptionsImpl< detail::Unowned< OrtSessionOptions > > UnownedSessionOptions
Definition onnxruntime_cxx_api.h:1453
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:243
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:2902
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:1056
Allocator(const Session &session, const OrtMemoryInfo *)
Allocator(std::nullptr_t)
Convenience to create a class member and then replace with an instance.
Definition onnxruntime_cxx_api.h:1057
Wrapper around OrtAllocator default instance that is owned by Onnxruntime.
Definition onnxruntime_cxx_api.h:1047
AllocatorWithDefaultOptions(std::nullptr_t)
Convenience to create a class member and then replace with an instance.
Definition onnxruntime_cxx_api.h:1048
it is a structure that represents the configuration of an arena based allocator
Definition onnxruntime_cxx_api.h:2486
ArenaCfg(std::nullptr_t)
Create an empty ArenaCfg object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:2487
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:3248
ConstGraph sub_graph
Definition onnxruntime_cxx_api.h:3250
std::string attr_name
Definition onnxruntime_cxx_api.h:3249
bfloat16 (Brain Floating Point) data type
Definition onnxruntime_cxx_api.h:413
bool operator==(const BFloat16_t &rhs) const noexcept
onnxruntime_float16::BFloat16Impl< BFloat16_t > Base
Definition onnxruntime_cxx_api.h:425
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:434
bool operator!=(const BFloat16_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:532
BFloat16_t(float v) noexcept
__ctor from float. Float is converted into bfloat16 16-bit representation.
Definition onnxruntime_cxx_api.h:440
float ToFloat() const noexcept
Converts bfloat16 to float.
Definition onnxruntime_cxx_api.h:446
bool operator<(const BFloat16_t &rhs) const noexcept
The CUDAProviderOptions (V2)
Definition onnxruntime_cxx_api.h:859
CUDAProviderOptions()
Wraps OrtApi::CreateCUDAProviderOptions.
CUDAProviderOptions(std::nullptr_t)
Definition onnxruntime_cxx_api.h:860
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:2907
OrtCustomOpInputOutputCharacteristic GetOutputCharacteristic(size_t) const
Definition onnxruntime_cxx_api.h:2982
OrtCustomOpInputOutputCharacteristic GetInputCharacteristic(size_t) const
Definition onnxruntime_cxx_api.h:2978
OrtMemType GetInputMemoryType(size_t) const
Definition onnxruntime_cxx_api.h:2987
std::vector< std::string > GetSessionConfigKeys() const
Definition onnxruntime_cxx_api.h:3018
bool GetVariadicInputHomogeneity() const
Definition onnxruntime_cxx_api.h:2999
int GetVariadicInputMinArity() const
Definition onnxruntime_cxx_api.h:2993
void SetShapeInferFn(...)
Definition onnxruntime_cxx_api.h:3035
CustomOpBase()
Definition onnxruntime_cxx_api.h:2908
bool GetVariadicOutputHomogeneity() const
Definition onnxruntime_cxx_api.h:3011
int GetVariadicOutputMinArity() const
Definition onnxruntime_cxx_api.h:3005
decltype(&C::InferOutputShape) SetShapeInferFn(decltype(&C::InferOutputShape))
Definition onnxruntime_cxx_api.h:3026
const char * GetExecutionProviderType() const
Definition onnxruntime_cxx_api.h:2974
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:1304
~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:1209
CustomOpDomain(std::nullptr_t)
Create an empty CustomOpDomain object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1213
CustomOpDomain(const char *domain)
Wraps OrtApi::CreateCustomOpDomain.
void Add(const OrtCustomOp *op)
Wraps CustomOpDomain_Add.
The Env (Environment)
Definition onnxruntime_cxx_api.h:1152
Env & EnableTelemetryEvents()
Wraps OrtApi::EnableTelemetryEvents.
Env(OrtEnv *p)
C Interop Helper.
Definition onnxruntime_cxx_api.h:1169
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:1153
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 & 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:1128
EpDevice(OrtEpDevice *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:1130
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:1129
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:910
ConstExternalInitializerInfo GetConst() const
Wraps OrtApi::CreateExternalInitializerInfo.
Definition onnxruntime_cxx_api.h:918
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:914
ExternalInitializerInfo(OrtExternalInitializerInfo *p)
Definition onnxruntime_cxx_api.h:915
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:271
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:299
onnxruntime_float16::Float16Impl< Float16_t > Base
Definition onnxruntime_cxx_api.h:281
float ToFloat() const noexcept
Converts float16 to float.
Definition onnxruntime_cxx_api.h:305
static constexpr Float16_t FromBits(uint16_t v) noexcept
Explicit conversion to uint16_t representation of float16.
Definition onnxruntime_cxx_api.h:293
float8e4m3fn (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:543
uint8_t value
Definition onnxruntime_cxx_api.h:544
constexpr Float8E4M3FN_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:546
constexpr bool operator==(const Float8E4M3FN_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:549
constexpr Float8E4M3FN_t() noexcept
Definition onnxruntime_cxx_api.h:545
constexpr bool operator!=(const Float8E4M3FN_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:550
float8e4m3fnuz (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:560
constexpr bool operator==(const Float8E4M3FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:566
uint8_t value
Definition onnxruntime_cxx_api.h:561
constexpr Float8E4M3FNUZ_t() noexcept
Definition onnxruntime_cxx_api.h:562
constexpr bool operator!=(const Float8E4M3FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:567
constexpr Float8E4M3FNUZ_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:563
float8e5m2 (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:577
constexpr Float8E5M2_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:580
uint8_t value
Definition onnxruntime_cxx_api.h:578
constexpr bool operator!=(const Float8E5M2_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:584
constexpr Float8E5M2_t() noexcept
Definition onnxruntime_cxx_api.h:579
constexpr bool operator==(const Float8E5M2_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:583
float8e5m2fnuz (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:594
constexpr Float8E5M2FNUZ_t() noexcept
Definition onnxruntime_cxx_api.h:596
constexpr Float8E5M2FNUZ_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:597
constexpr bool operator!=(const Float8E5M2FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:601
constexpr bool operator==(const Float8E5M2FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:600
uint8_t value
Definition onnxruntime_cxx_api.h:595
Wrapper around OrtGraph.
Definition onnxruntime_cxx_api.h:3256
Graph(OrtGraph *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:3258
Graph(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:3257
Wrapper around OrtIoBinding.
Definition onnxruntime_cxx_api.h:2475
UnownedIoBinding GetUnowned() const
Definition onnxruntime_cxx_api.h:2479
ConstIoBinding GetConst() const
Definition onnxruntime_cxx_api.h:2478
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:2476
This class wraps a raw pointer OrtKernelContext* that is being passed to the custom kernel Compute() ...
Definition onnxruntime_cxx_api.h:2709
KernelContext(OrtKernelContext *context)
Logger GetLogger() const
ConstValue GetInput(size_t index) const
OrtKernelContext * GetOrtKernelContext() const
Definition onnxruntime_cxx_api.h:2723
void ParallelFor(void(*fn)(void *, size_t), size_t total, size_t num_batch, void *usr_data) const
OrtAllocator * GetAllocator(const OrtMemoryInfo &memory_info) const
void * GetGPUComputeStream() const
size_t GetInputCount() 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
This struct owns the OrtKernInfo* pointer when a copy is made. For convenient wrapping of OrtKernelIn...
Definition onnxruntime_cxx_api.h:2791
KernelInfo(OrtKernelInfo *info)
Take ownership of the instance.
ConstKernelInfo GetConst() const
Definition onnxruntime_cxx_api.h:2796
detail::KernelInfoImpl< OrtKernelInfo > Base
Definition onnxruntime_cxx_api.h:2792
KernelInfo(std::nullptr_t)
Create an empty instance to initialize later.
Definition onnxruntime_cxx_api.h:2794
Wrapper around OrtKeyValuePairs.
Definition onnxruntime_cxx_api.h:947
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:948
ConstKeyValuePairs GetConst() const
Definition onnxruntime_cxx_api.h:964
KeyValuePairs(OrtKeyValuePairs *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:950
This class represents an ONNX Runtime logger that can be used to log information with an associated s...
Definition onnxruntime_cxx_api.h:2631
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:2640
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:1223
static LoraAdapter CreateLoraAdapter(const std::basic_string< char > &adapter_path, OrtAllocator *allocator)
Wraps OrtApi::CreateLoraAdapter.
LoraAdapter(std::nullptr_t)
Definition onnxruntime_cxx_api.h:1227
static LoraAdapter CreateLoraAdapterFromArray(const void *bytes, size_t num_bytes, OrtAllocator *allocator)
Wraps OrtApi::CreateLoraAdapterFromArray.
Wrapper around OrtMapTypeInfo.
Definition onnxruntime_cxx_api.h:1874
ConstMapTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:1880
MapTypeInfo(OrtMapTypeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1879
MapTypeInfo(std::nullptr_t)
Create an empty MapTypeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1878
Represents native memory allocation coming from one of the OrtAllocators registered with OnnxRuntime....
Definition onnxruntime_cxx_api.h:1008
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:1017
Wrapper around OrtMemoryInfo.
Definition onnxruntime_cxx_api.h:992
MemoryInfo(const char *name, OrtAllocatorType type, int id, OrtMemType mem_type)
MemoryInfo(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:994
MemoryInfo(OrtMemoryInfo *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:995
static MemoryInfo CreateCpu(OrtAllocatorType type, OrtMemType mem_type1)
ConstMemoryInfo GetConst() const
Definition onnxruntime_cxx_api.h:999
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:1471
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:1475
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:3284
Model(const std::vector< DomainOpsetPair > &opsets)
Model(OrtModel *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:3288
std::pair< std::string, int > DomainOpsetPair
Definition onnxruntime_cxx_api.h:3285
Model(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:3287
Wrapper around OrtModelMetadata.
Definition onnxruntime_cxx_api.h:1517
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:1521
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:3151
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:3153
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:3154
This struct provides life time management for custom op attribute.
Definition onnxruntime_cxx_api.h:2540
OpAttr(const char *name, const void *data, int len, OrtOpAttrType type)
OpAttr()=default
OpAttr(std::nullptr_t)
Definition onnxruntime_cxx_api.h:2545
ConstOpAttr GetConst() const
Definition onnxruntime_cxx_api.h:2548
Create and own custom defined operation.
Definition onnxruntime_cxx_api.h:2802
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:2806
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:3191
std::string domain
Definition onnxruntime_cxx_api.h:3192
int64_t version
Definition onnxruntime_cxx_api.h:3193
The PrepackedWeightsContainer.
Definition onnxruntime_cxx_api.h:878
PrepackedWeightsContainer()
Wraps OrtApi::CreatePrepackedWeightsContainer.
PrepackedWeightsContainer(OrtPrepackedWeightsContainer *p)
Definition onnxruntime_cxx_api.h:883
PrepackedWeightsContainer(std::nullptr_t)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:881
RunOptions.
Definition onnxruntime_cxx_api.h:1251
int GetRunLogSeverityLevel() const
Wraps OrtApi::RunOptionsGetRunLogSeverityLevel.
RunOptions & SetTerminate()
Terminates all currently executing Session::Run calls that were made using this RunOptions instance.
RunOptions & SetRunTag(const char *run_tag)
wraps OrtApi::RunOptionsSetRunTag
RunOptions & 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:1252
RunOptions & SetRunLogVerbosityLevel(int)
Wraps OrtApi::RunOptionsSetRunLogVerbosityLevel.
RunOptions & SetRunLogSeverityLevel(int)
Wraps OrtApi::RunOptionsSetRunLogSeverityLevel.
RunOptions & AddConfigEntry(const char *config_key, const char *config_value)
Wraps OrtApi::AddRunConfigEntry.
const char * GetRunTag() const
Wraps OrtApi::RunOptionsGetRunTag.
RunOptions()
Wraps OrtApi::CreateRunOptions.
const char * GetConfigEntry(const char *config_key)
Wraps OrtApi::GetRunConfigEntry.
Wrapper around OrtSequenceTypeInfo.
Definition onnxruntime_cxx_api.h:1836
SequenceTypeInfo(std::nullptr_t)
Create an empty SequenceTypeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1840
ConstSequenceTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:1842
SequenceTypeInfo(OrtSequenceTypeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1841
Wrapper around OrtSession.
Definition onnxruntime_cxx_api.h:1737
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:1739
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:1768
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:1740
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:1767
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:1459
SessionOptions(std::nullptr_t)
Create an empty SessionOptions object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1460
UnownedSessionOptions GetUnowned() const
Definition onnxruntime_cxx_api.h:1463
SessionOptions()
Wraps OrtApi::CreateSessionOptions.
ConstSessionOptions GetConst() const
Definition onnxruntime_cxx_api.h:1464
SessionOptions(OrtSessionOptions *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1462
Definition onnxruntime_cxx_api.h:2836
SymbolicInteger & operator=(const SymbolicInteger &)=default
SymbolicInteger(const SymbolicInteger &)=default
int64_t AsInt() const
Definition onnxruntime_cxx_api.h:2857
int64_t i_
Definition onnxruntime_cxx_api.h:2864
const char * s_
Definition onnxruntime_cxx_api.h:2865
bool operator==(const SymbolicInteger &dim) const
Definition onnxruntime_cxx_api.h:2845
SymbolicInteger & operator=(SymbolicInteger &&)=default
SymbolicInteger(SymbolicInteger &&)=default
const char * AsSym() const
Definition onnxruntime_cxx_api.h:2858
SymbolicInteger(int64_t i)
Definition onnxruntime_cxx_api.h:2837
SymbolicInteger(const char *s)
Definition onnxruntime_cxx_api.h:2838
bool IsInt() const
Definition onnxruntime_cxx_api.h:2856
Provide access to per-node attributes and input shapes, so one could compute and set output shapes.
Definition onnxruntime_cxx_api.h:2835
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:2870
std::vector< float > Floats
Definition onnxruntime_cxx_api.h:2887
std::string GetAttrString(const char *attr_name)
std::vector< int64_t > Ints
Definition onnxruntime_cxx_api.h:2882
ShapeInferContext(const OrtApi *ort_api, OrtShapeInferContext *ctx)
int64_t GetAttrInt(const char *attr_name)
size_t GetInputCount() const
Definition onnxruntime_cxx_api.h:2876
std::vector< std::string > Strings
Definition onnxruntime_cxx_api.h:2892
Floats GetAttrFloats(const char *attr_name)
const Shape & GetInputShape(size_t indice) const
Definition onnxruntime_cxx_api.h:2874
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:794
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:796
Definition onnxruntime_cxx_api.h:1077
SyncStream(OrtSyncStream *p)
Definition onnxruntime_cxx_api.h:1081
SyncStream(std::nullptr_t)
< Create an empty SyncStream object, must be assigned a valid one to be used
Definition onnxruntime_cxx_api.h:1079
The TensorRTOptions (V2)
Definition onnxruntime_cxx_api.h:840
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:841
TensorRTProviderOptions()
Wraps OrtApi::CreateTensorRTProviderOptionsV2.
Wrapper around OrtTensorTypeAndShapeInfo.
Definition onnxruntime_cxx_api.h:1802
TensorTypeAndShapeInfo(std::nullptr_t)
Create an empty TensorTypeAndShapeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1807
ConstTensorTypeAndShapeInfo GetConst() const
Definition onnxruntime_cxx_api.h:1818
TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1809
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:810
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:1908
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:1913
static TypeInfo CreateMapTypeInfo(ONNXTensorElementDataType key_type, ConstTypeInfo value_type)
ConstTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:1924
TypeInfo(OrtTypeInfo *p)
C API Interop.
Definition onnxruntime_cxx_api.h:1914
Wrapper around OrtValue.
Definition onnxruntime_cxx_api.h:2264
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:2270
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:2275
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:2274
Definition onnxruntime_cxx_api.h:3183
int64_t index
Definition onnxruntime_cxx_api.h:3187
ConstNode node
Definition onnxruntime_cxx_api.h:3184
Wrapper around OrtValueInfo.
Definition onnxruntime_cxx_api.h:3088
ConstValueInfo GetConst() const
Definition onnxruntime_cxx_api.h:3098
ValueInfo(std::nullptr_t)
Definition onnxruntime_cxx_api.h:3090
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:3092
ValueInfo()=default
Definition onnxruntime_cxx_api.h:756
AllocatedFree(OrtAllocator *allocator)
Definition onnxruntime_cxx_api.h:758
OrtAllocator * allocator_
Definition onnxruntime_cxx_api.h:757
void operator()(void *ptr) const
Definition onnxruntime_cxx_api.h:760
Base & operator=(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:742
constexpr contained_type & operator*() const noexcept
Definition onnxruntime_cxx_api.h:749
typename Unowned< T >::Type contained_type
Definition onnxruntime_cxx_api.h:731
Base(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:741
Base(const Base &)=default
constexpr Base(contained_type *p) noexcept
Definition onnxruntime_cxx_api.h:734
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:684
Base(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:696
constexpr Base()=default
constexpr contained_type & operator*() const noexcept
Definition onnxruntime_cxx_api.h:704
contained_type * release()
Relinquishes ownership of the contained C object pointer The underlying object is not destroyed.
Definition onnxruntime_cxx_api.h:708
Base(const Base &)=delete
constexpr Base(contained_type *p) noexcept
Definition onnxruntime_cxx_api.h:688
Base & operator=(const Base &)=delete
Base & operator=(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:697
contained_type * p_
Definition onnxruntime_cxx_api.h:715
~Base()
Definition onnxruntime_cxx_api.h:689
T contained_type
Definition onnxruntime_cxx_api.h:685
Definition onnxruntime_cxx_api.h:890
const std::basic_string< char > GetFilePath() const
Definition onnxruntime_cxx_api.h:3198
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:2443
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:3110
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:2512
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:1592
std::vector< std::string > GetOutputNames() const
TypeInfo GetInputTypeInfo(size_t index) const
Wraps OrtApi::SessionGetInputTypeInfo.
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< 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:1953
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....
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:3053
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:1107
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:3227
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:1088
OrtHardwareDeviceType Type() const
const char * Vendor() const
ConstKeyValuePairs Metadata() const
Definition onnxruntime_cxx_api.h:2454
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:930
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:1860
ONNXTensorElementDataType GetMapKeyType() const
Wraps OrtApi::GetMapKeyType.
TypeInfo GetMapValueType() const
Wraps OrtApi::GetMapValueType.
Definition onnxruntime_cxx_api.h:969
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:3267
void AddGraph(Graph &graph)
Definition onnxruntime_cxx_api.h:1847
TypeInfo GetOptionalElementType() const
Wraps OrtApi::CastOptionalTypeToContainedTypeInfo.
Definition onnxruntime_cxx_api.h:1936
const char ** str
Definition onnxruntime_cxx_api.h:1941
const int64_t * values_shape
Definition onnxruntime_cxx_api.h:1937
size_t values_shape_len
Definition onnxruntime_cxx_api.h:1938
const void * p_data
Definition onnxruntime_cxx_api.h:1940
Definition onnxruntime_cxx_api.h:1823
TypeInfo GetSequenceElementType() const
Wraps OrtApi::GetSequenceElementType.
Definition onnxruntime_cxx_api.h:1650
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:1947
const int64_t * shape
Definition onnxruntime_cxx_api.h:1948
size_t shape_len
Definition onnxruntime_cxx_api.h:1949
Definition onnxruntime_cxx_api.h:1069
void * GetHandle()
Wraps SyncStream_GetHandle.
Definition onnxruntime_cxx_api.h:1773
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:1885
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:660
T Type
Definition onnxruntime_cxx_api.h:661
Definition onnxruntime_cxx_api.h:2122
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:346
void(* Free)(struct OrtAllocator *this_, void *p)
Free a block of memory previously allocated with OrtAllocator::Alloc.
Definition onnxruntime_c_api.h:353
const OrtApi *(* GetApi)(uint32_t version)
Get a pointer to the requested version of the OrtApi.
Definition onnxruntime_c_api.h:898
Definition onnxruntime_c_api.h:968
const OrtEpApi *(* GetEpApi)(void)
Get the OrtEpApi instance for implementing an execution provider.
Definition onnxruntime_c_api.h:5441
const OrtCompileApi *(* GetCompileApi)(void)
Get the Compile API instance.
Definition onnxruntime_c_api.h:5173
void(* ReleaseTensorRTProviderOptions)(OrtTensorRTProviderOptionsV2 *input)
Release an OrtTensorRTProviderOptionsV2.
Definition onnxruntime_c_api.h:3224
const OrtModelEditorApi *(* GetModelEditorApi)(void)
Get the Model Editor API instance.
Definition onnxruntime_c_api.h:5115
void(* ReleaseCUDAProviderOptions)(OrtCUDAProviderOptionsV2 *input)
Release an OrtCUDAProviderOptionsV2.
Definition onnxruntime_c_api.h:3727
CUDA Provider Options.
Definition onnxruntime_c_api.h:601
The OrtCompileApi struct provides functions to compile ONNX models.
Definition onnxruntime_c_api.h:7165
Definition onnxruntime_c_api.h:6638
int(* GetVariadicInputHomogeneity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:6684
OrtCustomOpInputOutputCharacteristic(* GetOutputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:6668
size_t(* GetInputTypeCount)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:6656
int(* GetVariadicOutputMinArity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:6688
size_t(* GetAliasMap)(int **input_index, int **output_index)
Definition onnxruntime_c_api.h:6721
int(* GetStartVersion)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:6706
void(* ReleaseMayInplace)(int *input_index, int *output_index)
Definition onnxruntime_c_api.h:6718
const char *(* GetName)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:6649
size_t(* GetOutputTypeCount)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:6658
void(* KernelDestroy)(void *op_kernel)
Definition onnxruntime_c_api.h:6664
int(* GetVariadicOutputHomogeneity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:6693
OrtMemType(* GetInputMemoryType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:6675
void *(* CreateKernel)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info)
Definition onnxruntime_c_api.h:6645
uint32_t version
Definition onnxruntime_c_api.h:6639
ONNXTensorElementDataType(* GetInputType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:6655
void(* ReleaseAliasMap)(int *input_index, int *output_index)
Definition onnxruntime_c_api.h:6722
OrtCustomOpInputOutputCharacteristic(* GetInputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:6667
const char *(* GetExecutionProviderType)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:6652
ONNXTensorElementDataType(* GetOutputType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:6657
int(* GetVariadicInputMinArity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:6679
OrtStatusPtr(* InferOutputShapeFn)(const struct OrtCustomOp *op, OrtShapeInferContext *)
Definition onnxruntime_c_api.h:6703
int(* GetEndVersion)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:6707
OrtStatusPtr(* CreateKernelV2)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info, void **kernel)
Definition onnxruntime_c_api.h:6696
size_t(* GetMayInplace)(int **input_index, int **output_index)
Definition onnxruntime_c_api.h:6714
OrtStatusPtr(* KernelComputeV2)(void *op_kernel, OrtKernelContext *context)
Definition onnxruntime_c_api.h:6701
void(* KernelCompute)(void *op_kernel, OrtKernelContext *context)
Definition onnxruntime_c_api.h:6663
The OrtEpApi struct provides functions that are relevant to the implementation of an execution provid...
Definition onnxruntime_ep_c_api.h:282
The OrtEpFactory provides functions to create and manage execution providers.
Definition onnxruntime_ep_c_api.h:813
MIGraphX Provider Options.
Definition onnxruntime_c_api.h:805
The OrtModelEditorApi struct provides functions to create or edit an ONNX model.
Definition onnxruntime_c_api.h:6736
OpenVINO Provider Options.
Definition onnxruntime_c_api.h:844
ROCM Provider Options.
Definition onnxruntime_c_api.h:688
TensorRT Provider Options.
Definition onnxruntime_c_api.h:777