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(std::string&& string, OrtErrorCode code) : message_{std::move(string)}, code_{code} {}
56
57 OrtErrorCode GetOrtErrorCode() const { return code_; }
58 const char* what() const noexcept override { return message_.c_str(); }
59
60 private:
61 std::string message_;
62 OrtErrorCode code_;
63};
64
65#ifdef ORT_NO_EXCEPTIONS
66// The #ifndef is for the very special case where the user of this library wants to define their own way of handling errors.
67// NOTE: This header expects control flow to not continue after calling ORT_CXX_API_THROW
68#ifndef ORT_CXX_API_THROW
69#define ORT_CXX_API_THROW(string, code) \
70 do { \
71 std::cerr << Ort::Exception(string, code) \
72 .what() \
73 << std::endl; \
74 abort(); \
75 } while (false)
76#endif
77#else
78#define ORT_CXX_API_THROW(string, code) \
79 throw Ort::Exception(string, code)
80#endif
81
82// This is used internally by the C++ API. This class holds the global variable that points to the OrtApi,
83// it's in a template so that we can define a global variable in a header and make
84// it transparent to the users of the API.
85template <typename T>
86struct Global {
87 static const OrtApi* api_;
88};
89
90// If macro ORT_API_MANUAL_INIT is defined, no static initialization will be performed. Instead, user must call InitApi() before using it.
91template <typename T>
92#ifdef ORT_API_MANUAL_INIT
93const OrtApi* Global<T>::api_{};
94inline void InitApi() noexcept { Global<void>::api_ = OrtGetApiBase()->GetApi(ORT_API_VERSION); }
95
96// Used by custom operator libraries that are not linked to onnxruntime. Sets the global API object, which is
97// required by C++ APIs.
98//
99// Example mycustomop.cc:
100//
101// #define ORT_API_MANUAL_INIT
102// #include <onnxruntime_cxx_api.h>
103// #undef ORT_API_MANUAL_INIT
104//
105// OrtStatus* ORT_API_CALL RegisterCustomOps(OrtSessionOptions* options, const OrtApiBase* api_base) {
106// Ort::InitApi(api_base->GetApi(ORT_API_VERSION));
107// // ...
108// }
109//
110inline void InitApi(const OrtApi* api) noexcept { Global<void>::api_ = api; }
111#else
112#if defined(_MSC_VER) && !defined(__clang__)
113#pragma warning(push)
114// "Global initializer calls a non-constexpr function." Therefore you can't use ORT APIs in the other global initializers.
115// Please define ORT_API_MANUAL_INIT if it conerns you.
116#pragma warning(disable : 26426)
117#endif
119#if defined(_MSC_VER) && !defined(__clang__)
120#pragma warning(pop)
121#endif
122#endif
123
125inline const OrtApi& GetApi() noexcept { return *Global<void>::api_; }
126
131std::string GetVersionString();
132
138std::string GetBuildInfoString();
139
145std::vector<std::string> GetAvailableProviders();
146
152 auto* api = GetApi().GetModelEditorApi();
153 if (api == nullptr) {
154 // minimal build
155 ORT_CXX_API_THROW("Model Editor API is not available in this build", ORT_FAIL);
156 }
157
158 return *api;
159}
160
166 auto* api = GetApi().GetCompileApi();
167 if (api == nullptr) {
168 // minimal build
169 ORT_CXX_API_THROW("Compile API is not available in this build", ORT_FAIL);
170 }
171
172 return *api;
173}
174
179inline const OrtEpApi& GetEpApi() {
180 auto* api = GetApi().GetEpApi();
181 if (api == nullptr) {
182 // minimal build
183 ORT_CXX_API_THROW("EP API is not available in this build", ORT_FAIL);
184 }
185
186 return *api;
187}
188
207struct Float16_t : onnxruntime_float16::Float16Impl<Float16_t> {
208 private:
214 constexpr explicit Float16_t(uint16_t v) noexcept { val = v; }
215
216 public:
217 using Base = onnxruntime_float16::Float16Impl<Float16_t>;
218
222 Float16_t() = default;
223
229 constexpr static Float16_t FromBits(uint16_t v) noexcept { return Float16_t(v); }
230
235 explicit Float16_t(float v) noexcept { val = Base::ToUint16Impl(v); }
236
241 float ToFloat() const noexcept { return Base::ToFloatImpl(); }
242
247 using Base::IsNegative;
248
253 using Base::IsNaN;
254
259 using Base::IsFinite;
260
265 using Base::IsPositiveInfinity;
266
271 using Base::IsNegativeInfinity;
272
277 using Base::IsInfinity;
278
283 using Base::IsNaNOrZero;
284
289 using Base::IsNormal;
290
295 using Base::IsSubnormal;
296
301 using Base::Abs;
302
307 using Base::Negate;
308
317 using Base::AreZero;
318
322 explicit operator float() const noexcept { return ToFloat(); }
323
324 using Base::operator==;
325 using Base::operator!=;
326 using Base::operator<;
327};
328
329static_assert(sizeof(Float16_t) == sizeof(uint16_t), "Sizes must match");
330
349struct BFloat16_t : onnxruntime_float16::BFloat16Impl<BFloat16_t> {
350 private:
358 constexpr explicit BFloat16_t(uint16_t v) noexcept { val = v; }
359
360 public:
361 using Base = onnxruntime_float16::BFloat16Impl<BFloat16_t>;
362
363 BFloat16_t() = default;
364
370 static constexpr BFloat16_t FromBits(uint16_t v) noexcept { return BFloat16_t(v); }
371
376 explicit BFloat16_t(float v) noexcept { val = Base::ToUint16Impl(v); }
377
382 float ToFloat() const noexcept { return Base::ToFloatImpl(); }
383
388 using Base::IsNegative;
389
394 using Base::IsNaN;
395
400 using Base::IsFinite;
401
406 using Base::IsPositiveInfinity;
407
412 using Base::IsNegativeInfinity;
413
418 using Base::IsInfinity;
419
424 using Base::IsNaNOrZero;
425
430 using Base::IsNormal;
431
436 using Base::IsSubnormal;
437
442 using Base::Abs;
443
448 using Base::Negate;
449
458 using Base::AreZero;
459
463 explicit operator float() const noexcept { return ToFloat(); }
464
465 // We do not have an inherited impl for the below operators
466 // as the internal class implements them a little differently
467 bool operator==(const BFloat16_t& rhs) const noexcept;
468 bool operator!=(const BFloat16_t& rhs) const noexcept { return !(*this == rhs); }
469 bool operator<(const BFloat16_t& rhs) const noexcept;
470};
471
472static_assert(sizeof(BFloat16_t) == sizeof(uint16_t), "Sizes must match");
473
480 uint8_t value;
481 constexpr Float8E4M3FN_t() noexcept : value(0) {}
482 constexpr Float8E4M3FN_t(uint8_t v) noexcept : value(v) {}
483 constexpr operator uint8_t() const noexcept { return value; }
484 // nan values are treated like any other value for operator ==, !=
485 constexpr bool operator==(const Float8E4M3FN_t& rhs) const noexcept { return value == rhs.value; };
486 constexpr bool operator!=(const Float8E4M3FN_t& rhs) const noexcept { return value != rhs.value; };
487};
488
489static_assert(sizeof(Float8E4M3FN_t) == sizeof(uint8_t), "Sizes must match");
490
497 uint8_t value;
498 constexpr Float8E4M3FNUZ_t() noexcept : value(0) {}
499 constexpr Float8E4M3FNUZ_t(uint8_t v) noexcept : value(v) {}
500 constexpr operator uint8_t() const noexcept { return value; }
501 // nan values are treated like any other value for operator ==, !=
502 constexpr bool operator==(const Float8E4M3FNUZ_t& rhs) const noexcept { return value == rhs.value; };
503 constexpr bool operator!=(const Float8E4M3FNUZ_t& rhs) const noexcept { return value != rhs.value; };
504};
505
506static_assert(sizeof(Float8E4M3FNUZ_t) == sizeof(uint8_t), "Sizes must match");
507
514 uint8_t value;
515 constexpr Float8E5M2_t() noexcept : value(0) {}
516 constexpr Float8E5M2_t(uint8_t v) noexcept : value(v) {}
517 constexpr operator uint8_t() const noexcept { return value; }
518 // nan values are treated like any other value for operator ==, !=
519 constexpr bool operator==(const Float8E5M2_t& rhs) const noexcept { return value == rhs.value; };
520 constexpr bool operator!=(const Float8E5M2_t& rhs) const noexcept { return value != rhs.value; };
521};
522
523static_assert(sizeof(Float8E5M2_t) == sizeof(uint8_t), "Sizes must match");
524
531 uint8_t value;
532 constexpr Float8E5M2FNUZ_t() noexcept : value(0) {}
533 constexpr Float8E5M2FNUZ_t(uint8_t v) noexcept : value(v) {}
534 constexpr operator uint8_t() const noexcept { return value; }
535 // nan values are treated like any other value for operator ==, !=
536 constexpr bool operator==(const Float8E5M2FNUZ_t& rhs) const noexcept { return value == rhs.value; };
537 constexpr bool operator!=(const Float8E5M2FNUZ_t& rhs) const noexcept { return value != rhs.value; };
538};
539
540static_assert(sizeof(Float8E5M2FNUZ_t) == sizeof(uint8_t), "Sizes must match");
541
542namespace detail {
543// 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
544// This can't be done in the C API since C doesn't have function overloading.
545#define ORT_DEFINE_RELEASE(NAME) \
546 inline void OrtRelease(Ort##NAME* ptr) { GetApi().Release##NAME(ptr); }
547
548#define ORT_DEFINE_RELEASE_FROM_API_STRUCT(NAME, API_GETTER) \
549 inline void OrtRelease(Ort##NAME* ptr) { API_GETTER().Release##NAME(ptr); }
550
551ORT_DEFINE_RELEASE(Allocator);
552ORT_DEFINE_RELEASE(MemoryInfo);
553ORT_DEFINE_RELEASE(CustomOpDomain);
554ORT_DEFINE_RELEASE(ThreadingOptions);
555ORT_DEFINE_RELEASE(Env);
556ORT_DEFINE_RELEASE(RunOptions);
557ORT_DEFINE_RELEASE(LoraAdapter);
558ORT_DEFINE_RELEASE(Session);
559ORT_DEFINE_RELEASE(SessionOptions);
560ORT_DEFINE_RELEASE(TensorTypeAndShapeInfo);
561ORT_DEFINE_RELEASE(SequenceTypeInfo);
562ORT_DEFINE_RELEASE(MapTypeInfo);
563ORT_DEFINE_RELEASE(TypeInfo);
564ORT_DEFINE_RELEASE(Value);
565ORT_DEFINE_RELEASE(ModelMetadata);
566ORT_DEFINE_RELEASE(IoBinding);
567ORT_DEFINE_RELEASE(ArenaCfg);
568ORT_DEFINE_RELEASE(Status);
569ORT_DEFINE_RELEASE(OpAttr);
570ORT_DEFINE_RELEASE(Op);
571ORT_DEFINE_RELEASE(KernelInfo);
572ORT_DEFINE_RELEASE(ValueInfo);
573ORT_DEFINE_RELEASE(Node);
574ORT_DEFINE_RELEASE(Graph);
575ORT_DEFINE_RELEASE(Model);
576ORT_DEFINE_RELEASE(KeyValuePairs)
577ORT_DEFINE_RELEASE_FROM_API_STRUCT(ModelCompilationOptions, GetCompileApi);
578ORT_DEFINE_RELEASE_FROM_API_STRUCT(EpDevice, GetEpApi);
579
580#undef ORT_DEFINE_RELEASE
581#undef ORT_DEFINE_RELEASE_FROM_API_STRUCT
582
586template <typename T>
587struct Unowned {
588 using Type = T;
589};
590
610template <typename T>
611struct Base {
612 using contained_type = T;
613
614 constexpr Base() = default;
615 constexpr explicit Base(contained_type* p) noexcept : p_{p} {}
617 OrtRelease(p_);
618 }
619
620 Base(const Base&) = delete;
621 Base& operator=(const Base&) = delete;
622
623 Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }
624 Base& operator=(Base&& v) noexcept {
625 OrtRelease(p_);
626 p_ = v.release();
627 return *this;
628 }
629
630 constexpr operator contained_type*() const noexcept { return p_; }
631
635 T* p = p_;
636 p_ = nullptr;
637 return p;
638 }
639
640 protected:
642};
643
644// Undefined. For const types use Base<Unowned<const T>>
645template <typename T>
646struct Base<const T>;
647
655template <typename T>
656struct Base<Unowned<T>> {
658
659 constexpr Base() = default;
660 constexpr explicit Base(contained_type* p) noexcept : p_{p} {}
661
662 ~Base() = default;
663
664 Base(const Base&) = default;
665 Base& operator=(const Base&) = default;
666
667 Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }
668 Base& operator=(Base&& v) noexcept {
669 p_ = nullptr;
670 std::swap(p_, v.p_);
671 return *this;
672 }
673
674 constexpr operator contained_type*() const noexcept { return p_; }
675
676 protected:
678};
679
680// Light functor to release memory with OrtAllocator
683 explicit AllocatedFree(OrtAllocator* allocator)
684 : allocator_(allocator) {}
685 void operator()(void* ptr) const {
686 if (ptr) allocator_->Free(allocator_, ptr);
687 }
688};
689
690} // namespace detail
691
692struct AllocatorWithDefaultOptions;
693struct Env;
694struct EpDevice;
695struct Graph;
696struct Model;
697struct Node;
698struct ModelMetadata;
699struct TypeInfo;
700struct Value;
701struct ValueInfo;
702
707using AllocatedStringPtr = std::unique_ptr<char, detail::AllocatedFree>;
708
713struct Status : detail::Base<OrtStatus> {
715 using Base::Base;
716
717 explicit Status(std::nullptr_t) noexcept {}
718 explicit Status(OrtStatus* status) noexcept;
719 explicit Status(const Exception&) noexcept;
720 explicit Status(const std::exception&) noexcept;
721 Status(const char* message, OrtErrorCode code) noexcept;
722 std::string GetErrorMessage() const;
724 bool IsOK() const noexcept;
725};
726
756
757namespace detail {
758template <typename T>
761 using B::B;
762
763 const char* GetValue(const char* key) const;
764
765 // get the pairs in unordered_map. needs to copy to std::string so the hash works as expected
766 std::unordered_map<std::string, std::string> GetKeyValuePairs() const;
767 // get the pairs in two vectors. entries will be 1:1 between keys and values. avoids copying to std::string
768 void GetKeyValuePairs(std::vector<const char*>& keys, std::vector<const char*>& values) const;
769};
770} // namespace detail
771
772// Const object holder that does not own the underlying object
774
776struct KeyValuePairs : detail::KeyValuePairsImpl<OrtKeyValuePairs> {
777 explicit KeyValuePairs(std::nullptr_t) {}
779 explicit KeyValuePairs(OrtKeyValuePairs* p) : KeyValuePairsImpl<OrtKeyValuePairs>{p} {}
780
782 explicit KeyValuePairs();
783
785 explicit KeyValuePairs(const std::unordered_map<std::string, std::string>& kv_pairs);
786
788 void Add(const char* key, const char* value);
789
791 void Remove(const char* key);
792
793 ConstKeyValuePairs GetConst() const { return ConstKeyValuePairs{this->p_}; }
794};
795
796namespace detail {
797template <typename T>
800 using B::B;
801
803 uint32_t VendorId() const;
804 uint32_t DeviceId() const;
805 const char* Vendor() const;
807};
808} // namespace detail
809
814
815namespace detail {
816template <typename T>
819 using B::B;
820
821 const char* EpName() const;
822 const char* EpVendor() const;
826};
827} // namespace detail
828
833
836struct EpDevice : detail::EpDeviceImpl<OrtEpDevice> {
837 explicit EpDevice(std::nullptr_t) {}
838 explicit EpDevice(OrtEpDevice* p) : EpDeviceImpl<OrtEpDevice>{p} {}
839
841 EpDevice(OrtEpFactory& ep_factory, ConstHardwareDevice& hardware_device,
842 ConstKeyValuePairs ep_metadata = {}, ConstKeyValuePairs ep_options = {});
843};
844
850struct Env : detail::Base<OrtEnv> {
851 explicit Env(std::nullptr_t) {}
852
854 Env(OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
855
857 Env(OrtLoggingLevel logging_level, const char* logid, OrtLoggingFunction logging_function, void* logger_param);
858
860 Env(const OrtThreadingOptions* tp_options, OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
861
863 Env(const OrtThreadingOptions* tp_options, OrtLoggingFunction logging_function, void* logger_param,
864 OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
865
867 explicit Env(OrtEnv* p) : Base<OrtEnv>{p} {}
868
871
873
874 Env& CreateAndRegisterAllocator(const OrtMemoryInfo* mem_info, const OrtArenaCfg* arena_cfg);
875
876 Env& CreateAndRegisterAllocatorV2(const std::string& provider_type, const OrtMemoryInfo* mem_info,
877 const std::unordered_map<std::string, std::string>& options,
878 const OrtArenaCfg* arena_cfg);
879
880 Env& RegisterExecutionProviderLibrary(const char* registration_name, const std::basic_string<ORTCHAR_T>& path);
881 Env& UnregisterExecutionProviderLibrary(const char* registration_name);
882
883 std::vector<ConstEpDevice> GetEpDevices() const;
884};
885
889struct CustomOpDomain : detail::Base<OrtCustomOpDomain> {
891 using Base::Base;
892
893 explicit CustomOpDomain(std::nullptr_t) {}
894
896 explicit CustomOpDomain(const char* domain);
897
898 // This does not take ownership of the op, simply registers it.
899 void Add(const OrtCustomOp* op);
900};
901
903struct LoraAdapter : detail::Base<OrtLoraAdapter> {
905 using Base::Base;
906
907 explicit LoraAdapter(std::nullptr_t) {}
914 static LoraAdapter CreateLoraAdapter(const std::basic_string<ORTCHAR_T>& adapter_path,
915 OrtAllocator* allocator);
916
924 static LoraAdapter CreateLoraAdapterFromArray(const void* bytes, size_t num_bytes,
925 OrtAllocator* allocator);
926};
927
931struct RunOptions : detail::Base<OrtRunOptions> {
932 explicit RunOptions(std::nullptr_t) {}
934
937
940
941 RunOptions& SetRunTag(const char* run_tag);
942 const char* GetRunTag() const;
943
944 RunOptions& AddConfigEntry(const char* config_key, const char* config_value);
945
952
958
966};
967
968namespace detail {
969// Utility function that returns a SessionOption config entry key for a specific custom operator.
970// Ex: custom_op.[custom_op_name].[config]
971std::string MakeCustomOpConfigEntryKey(const char* custom_op_name, const char* config);
972} // namespace detail
973
984 CustomOpConfigs() = default;
985 ~CustomOpConfigs() = default;
990
999 CustomOpConfigs& AddConfig(const char* custom_op_name, const char* config_key, const char* config_value);
1000
1009 const std::unordered_map<std::string, std::string>& GetFlattenedConfigs() const;
1010
1011 private:
1012 std::unordered_map<std::string, std::string> flat_configs_;
1013};
1014
1020struct SessionOptions;
1021
1022namespace detail {
1023// we separate const-only methods because passing const ptr to non-const methods
1024// is only discovered when inline methods are compiled which is counter-intuitive
1025template <typename T>
1026struct ConstSessionOptionsImpl : Base<T> {
1027 using B = Base<T>;
1028 using B::B;
1029
1030 SessionOptions Clone() const;
1031
1032 std::string GetConfigEntry(const char* config_key) const;
1033 bool HasConfigEntry(const char* config_key) const;
1034 std::string GetConfigEntryOrDefault(const char* config_key, const std::string& def) const;
1035};
1036
1037template <typename T>
1038struct SessionOptionsImpl : ConstSessionOptionsImpl<T> {
1039 using B = ConstSessionOptionsImpl<T>;
1040 using B::B;
1041
1042 SessionOptionsImpl& SetIntraOpNumThreads(int intra_op_num_threads);
1043 SessionOptionsImpl& SetInterOpNumThreads(int inter_op_num_threads);
1044 SessionOptionsImpl& SetGraphOptimizationLevel(GraphOptimizationLevel graph_optimization_level);
1045 SessionOptionsImpl& SetDeterministicCompute(bool value);
1046
1047 SessionOptionsImpl& EnableCpuMemArena();
1048 SessionOptionsImpl& DisableCpuMemArena();
1049
1050 SessionOptionsImpl& SetOptimizedModelFilePath(const ORTCHAR_T* optimized_model_file);
1051
1052 SessionOptionsImpl& EnableProfiling(const ORTCHAR_T* profile_file_prefix);
1053 SessionOptionsImpl& DisableProfiling();
1054
1055 SessionOptionsImpl& EnableOrtCustomOps();
1056
1057 SessionOptionsImpl& EnableMemPattern();
1058 SessionOptionsImpl& DisableMemPattern();
1059
1060 SessionOptionsImpl& SetExecutionMode(ExecutionMode execution_mode);
1061
1062 SessionOptionsImpl& SetLoadCancellationFlag(bool value);
1063
1064 SessionOptionsImpl& SetLogId(const char* logid);
1065 SessionOptionsImpl& SetLogSeverityLevel(int level);
1066
1067 SessionOptionsImpl& Add(OrtCustomOpDomain* custom_op_domain);
1068
1069 SessionOptionsImpl& DisablePerSessionThreads();
1070
1071 SessionOptionsImpl& AddConfigEntry(const char* config_key, const char* config_value);
1072
1073 SessionOptionsImpl& AddInitializer(const char* name, const OrtValue* ort_val);
1074 SessionOptionsImpl& AddExternalInitializers(const std::vector<std::string>& names, const std::vector<Value>& ort_values);
1075 SessionOptionsImpl& AddExternalInitializersFromFilesInMemory(const std::vector<std::basic_string<ORTCHAR_T>>& external_initializer_file_names,
1076 const std::vector<char*>& external_initializer_file_buffer_array,
1077 const std::vector<size_t>& external_initializer_file_lengths);
1078
1079 SessionOptionsImpl& AppendExecutionProvider_CUDA(const OrtCUDAProviderOptions& provider_options);
1080 SessionOptionsImpl& AppendExecutionProvider_CUDA_V2(const OrtCUDAProviderOptionsV2& provider_options);
1081 SessionOptionsImpl& AppendExecutionProvider_ROCM(const OrtROCMProviderOptions& provider_options);
1082 SessionOptionsImpl& AppendExecutionProvider_OpenVINO(const OrtOpenVINOProviderOptions& provider_options);
1084 SessionOptionsImpl& AppendExecutionProvider_OpenVINO_V2(const std::unordered_map<std::string, std::string>& provider_options = {});
1085 SessionOptionsImpl& AppendExecutionProvider_TensorRT(const OrtTensorRTProviderOptions& provider_options);
1086 SessionOptionsImpl& AppendExecutionProvider_TensorRT_V2(const OrtTensorRTProviderOptionsV2& provider_options);
1087 SessionOptionsImpl& AppendExecutionProvider_MIGraphX(const OrtMIGraphXProviderOptions& provider_options);
1089 SessionOptionsImpl& AppendExecutionProvider_CANN(const OrtCANNProviderOptions& provider_options);
1091 SessionOptionsImpl& AppendExecutionProvider_Dnnl(const OrtDnnlProviderOptions& provider_options);
1093 SessionOptionsImpl& AppendExecutionProvider(const std::string& provider_name,
1094 const std::unordered_map<std::string, std::string>& provider_options = {});
1095
1098 SessionOptionsImpl& AppendExecutionProvider_V2(Env& env, const std::vector<ConstEpDevice>& ep_devices,
1099 const KeyValuePairs& ep_options);
1102 SessionOptionsImpl& AppendExecutionProvider_V2(Env& env, const std::vector<ConstEpDevice>& ep_devices,
1103 const std::unordered_map<std::string, std::string>& ep_options);
1104
1106 SessionOptionsImpl& SetEpSelectionPolicy(OrtExecutionProviderDevicePolicy policy);
1107
1109 SessionOptionsImpl& SetEpSelectionPolicy(EpSelectionDelegate delegate, void* state = nullptr);
1110
1111 SessionOptionsImpl& SetCustomCreateThreadFn(OrtCustomCreateThreadFn ort_custom_create_thread_fn);
1112 SessionOptionsImpl& SetCustomThreadCreationOptions(void* ort_custom_thread_creation_options);
1113 SessionOptionsImpl& SetCustomJoinThreadFn(OrtCustomJoinThreadFn ort_custom_join_thread_fn);
1114
1118 SessionOptionsImpl& RegisterCustomOpsLibrary(const ORTCHAR_T* library_name, const CustomOpConfigs& custom_op_configs = {});
1119
1120 SessionOptionsImpl& RegisterCustomOpsUsingFunction(const char* function_name);
1121
1123 SessionOptionsImpl& AppendExecutionProvider_VitisAI(const std::unordered_map<std::string, std::string>& provider_options = {});
1124};
1125} // namespace detail
1126
1127using UnownedSessionOptions = detail::SessionOptionsImpl<detail::Unowned<OrtSessionOptions>>;
1128using ConstSessionOptions = detail::ConstSessionOptionsImpl<detail::Unowned<const OrtSessionOptions>>;
1129
1133struct SessionOptions : detail::SessionOptionsImpl<OrtSessionOptions> {
1134 explicit SessionOptions(std::nullptr_t) {}
1136 explicit SessionOptions(OrtSessionOptions* p) : SessionOptionsImpl<OrtSessionOptions>{p} {}
1139};
1140
1145struct ModelCompilationOptions : detail::Base<OrtModelCompilationOptions> {
1147 using Base::Base;
1148
1149 explicit ModelCompilationOptions(std::nullptr_t) {}
1150
1151 ModelCompilationOptions(const Env& env, const SessionOptions& session_options);
1152 ModelCompilationOptions(const Env& env, ConstSessionOptions session_options);
1153
1154 ModelCompilationOptions& SetInputModelPath(const ORTCHAR_T* input_model_path);
1156 size_t input_model_data_size);
1157 ModelCompilationOptions& SetEpContextEmbedMode(bool embed_ep_context_in_model);
1158 ModelCompilationOptions& SetOutputModelPath(const ORTCHAR_T* output_model_path);
1160 size_t initializer_size_threshold);
1161 ModelCompilationOptions& SetOutputModelBuffer(OrtAllocator* allocator, void** output_model_buffer_ptr,
1162 size_t* output_model_buffer_size_ptr);
1164};
1165
1172Status CompileModel(const Env& env, const ModelCompilationOptions& model_compilation_options);
1173
1177struct ModelMetadata : detail::Base<OrtModelMetadata> {
1179 using Base::Base;
1180
1181 explicit ModelMetadata(std::nullptr_t) {}
1182
1190
1198
1206
1214
1222
1229 std::vector<AllocatedStringPtr> GetCustomMetadataMapKeysAllocated(OrtAllocator* allocator) const;
1230
1241
1242 int64_t GetVersion() const;
1243};
1244
1245struct IoBinding;
1246
1247namespace detail {
1248
1249// we separate const-only methods because passing const ptr to non-const methods
1250// is only discovered when inline methods are compiled which is counter-intuitive
1251template <typename T>
1253 using B = Base<T>;
1254 using B::B;
1255
1256 size_t GetInputCount() const;
1257 size_t GetOutputCount() const;
1259
1260 std::vector<std::string> GetInputNames() const;
1261 std::vector<std::string> GetOutputNames() const;
1262 std::vector<std::string> GetOverridableInitializerNames() const;
1263
1272
1281
1290
1291 uint64_t GetProfilingStartTimeNs() const;
1293
1294 TypeInfo GetInputTypeInfo(size_t index) const;
1295 TypeInfo GetOutputTypeInfo(size_t index) const;
1297
1298 int GetOpset(const std::string& domain) const;
1299
1300 // Will move before checkin if that's the case.
1301 std::vector<ValueInfo> GetInputs() const;
1302 std::vector<ValueInfo> GetOutputs() const;
1303};
1304
1305template <typename T>
1308 using B::B;
1309
1327 std::vector<Value> Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
1328 const char* const* output_names, size_t output_count);
1329
1333 void Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
1334 const char* const* output_names, Value* output_values, size_t output_count);
1335
1336 void Run(const RunOptions& run_options, const IoBinding&);
1337
1357 void RunAsync(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
1358 const char* const* output_names, Value* output_values, size_t output_count, RunAsyncCallbackFn callback, void* user_data);
1359
1367
1379 void SetEpDynamicOptions(const char* const* keys, const char* const* values, size_t kv_len);
1380
1381 void FinalizeModelEditorSession(const Model& model, const SessionOptions& options,
1382 OrtPrepackedWeightsContainer* prepacked_weights_container = nullptr);
1383};
1384
1385} // namespace detail
1386
1389
1393struct Session : detail::SessionImpl<OrtSession> {
1395 explicit Session(std::nullptr_t) {}
1396 explicit Session(OrtSession* p) : SessionImpl{p} {}
1397
1398 Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
1399
1401 Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options,
1402 OrtPrepackedWeightsContainer* prepacked_weights_container);
1403
1405 Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options);
1406
1408 Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options,
1409 OrtPrepackedWeightsContainer* prepacked_weights_container);
1410
1411#if !defined(ORT_MINIMAL_BUILD)
1413 Session(const Env& env, const Model& model, const SessionOptions& options);
1414
1416 static Session CreateModelEditorSession(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
1417
1419 static Session CreateModelEditorSession(const Env& env, const void* model_data, size_t model_data_length,
1420 const SessionOptions& options);
1421#endif // !defined(ORT_MINIMAL_BUILD)
1422
1423 ConstSession GetConst() const { return ConstSession{this->p_}; }
1424 UnownedSession GetUnowned() const { return UnownedSession{this->p_}; }
1425};
1426
1427namespace detail {
1428template <typename T>
1430 using B = Base<T>;
1431 using B::B;
1432
1433 std::string GetAllocatorName() const;
1435 int GetDeviceId() const;
1438
1439 template <typename U>
1440 bool operator==(const MemoryInfoImpl<U>& o) const;
1441};
1442} // namespace detail
1443
1444// Const object holder that does not own the underlying object
1446
1450struct MemoryInfo : detail::MemoryInfoImpl<OrtMemoryInfo> {
1452 explicit MemoryInfo(std::nullptr_t) {}
1453 explicit MemoryInfo(OrtMemoryInfo* p) : MemoryInfoImpl<OrtMemoryInfo>{p} {}
1454 MemoryInfo(const char* name, OrtAllocatorType type, int id, OrtMemType mem_type);
1455 ConstMemoryInfo GetConst() const { return ConstMemoryInfo{this->p_}; }
1456};
1457
1458namespace detail {
1459template <typename T>
1461 using B = Base<T>;
1462 using B::B;
1463
1465 size_t GetElementCount() const;
1466
1467 size_t GetDimensionsCount() const;
1468
1473 [[deprecated("use GetShape()")]] void GetDimensions(int64_t* values, size_t values_count) const;
1474
1475 void GetSymbolicDimensions(const char** values, size_t values_count) const;
1476 std::vector<const char*> GetSymbolicDimensions() const;
1477
1478 std::vector<int64_t> GetShape() const;
1479};
1480
1481} // namespace detail
1482
1484
1490 using Base::Base;
1491
1493 explicit TensorTypeAndShapeInfo(std::nullptr_t) {}
1495 explicit TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* p) : TensorTypeAndShapeInfoImpl{p} {}
1496
1497 // Create a TensorTypeAndShapeInfo object with the specified element type and dimensions
1498 // symbolic_dims are optional, but should be 1:1 with dims.
1499 // The value in symbolic_dims will be used for all entries in dims that are -1.
1501 const std::vector<int64_t>& dims,
1502 const std::vector<std::string>* symbolic_dims = nullptr);
1503
1505};
1506
1507namespace detail {
1508template <typename T>
1510 using B = Base<T>;
1511 using B::B;
1513};
1514
1515} // namespace detail
1516
1518
1522struct SequenceTypeInfo : detail::SequenceTypeInfoImpl<OrtSequenceTypeInfo> {
1524 using Base::Base;
1525
1526 explicit SequenceTypeInfo(std::nullptr_t) {}
1527 explicit SequenceTypeInfo(OrtSequenceTypeInfo* p) : SequenceTypeInfoImpl<OrtSequenceTypeInfo>{p} {}
1529};
1530
1531namespace detail {
1532template <typename T>
1534 using B = Base<T>;
1535 using B::B;
1537};
1538
1539} // namespace detail
1540
1541// This is always owned by the TypeInfo and can only be obtained from it.
1543
1544namespace detail {
1545template <typename T>
1552
1553} // namespace detail
1554
1556
1560struct MapTypeInfo : detail::MapTypeInfoImpl<OrtMapTypeInfo> {
1562 using Base::Base;
1563
1564 explicit MapTypeInfo(std::nullptr_t) {}
1565 explicit MapTypeInfo(OrtMapTypeInfo* p) : MapTypeInfoImpl<OrtMapTypeInfo>{p} {}
1566 ConstMapTypeInfo GetConst() const { return ConstMapTypeInfo{this->p_}; }
1567};
1568
1569namespace detail {
1570template <typename T>
1582} // namespace detail
1583
1589
1594struct TypeInfo : detail::TypeInfoImpl<OrtTypeInfo> {
1596 using Base::Base;
1597
1599 explicit TypeInfo(std::nullptr_t) {}
1600 explicit TypeInfo(OrtTypeInfo* p) : TypeInfoImpl<OrtTypeInfo>{p} {}
1601
1602#if !defined(ORT_MINIMAL_BUILD)
1608#endif // !defined(ORT_MINIMAL_BUILD)
1609
1610 ConstTypeInfo GetConst() const { return ConstTypeInfo{this->p_}; }
1611};
1612
1613namespace detail {
1614// This structure is used to feed sparse tensor values
1615// information for use with FillSparseTensor<Format>() API
1616// if the data type for the sparse tensor values is numeric
1617// use data.p_data, otherwise, use data.str pointer to feed
1618// values. data.str is an array of const char* that are zero terminated.
1619// number of strings in the array must match shape size.
1620// For fully sparse tensors use shape {0} and set p_data/str
1621// to nullptr.
1623 const int64_t* values_shape;
1625 union {
1626 const void* p_data;
1627 const char** str;
1628 } data;
1629};
1630
1631// Provides a way to pass shape in a single
1632// argument
1633struct Shape {
1634 const int64_t* shape;
1636};
1637
1638template <typename T>
1640 using B = Base<T>;
1641 using B::B;
1642
1646 template <typename R>
1647 void GetOpaqueData(const char* domain, const char* type_name, R&) const;
1648
1649 bool IsTensor() const;
1650 bool HasValue() const;
1651
1652 size_t GetCount() const; // If a non tensor, returns 2 for map and N for sequence, where N is the number of elements
1653 Value GetValue(int index, OrtAllocator* allocator) const;
1654
1662
1677 void GetStringTensorContent(void* buffer, size_t buffer_length, size_t* offsets, size_t offsets_count) const;
1678
1685 template <typename R>
1686 const R* GetTensorData() const;
1687
1692 const void* GetTensorRawData() const;
1693
1701
1709
1715
1724 void GetStringTensorElement(size_t buffer_length, size_t element_index, void* buffer) const;
1725
1732 std::string GetStringTensorElement(size_t element_index) const;
1733
1740 size_t GetStringTensorElementLength(size_t element_index) const;
1741
1748 size_t GetTensorSizeInBytes() const;
1749
1750#if !defined(DISABLE_SPARSE_TENSORS)
1758
1765
1774
1784 template <typename R>
1785 const R* GetSparseTensorIndicesData(OrtSparseIndicesFormat indices_format, size_t& num_indices) const;
1786
1791 bool IsSparseTensor() const;
1792
1801 template <typename R>
1802 const R* GetSparseTensorValues() const;
1803
1804#endif
1805};
1806
1807template <typename T>
1810 using B::B;
1811
1817 template <typename R>
1819
1825
1827 // Obtain a reference to an element of data at the location specified
1833 template <typename R>
1834 R& At(const std::vector<int64_t>& location);
1835
1841 void FillStringTensor(const char* const* s, size_t s_len);
1842
1848 void FillStringTensorElement(const char* s, size_t index);
1849
1862 char* GetResizedStringTensorElementBuffer(size_t index, size_t buffer_length);
1863
1864#if !defined(DISABLE_SPARSE_TENSORS)
1873 void UseCooIndices(int64_t* indices_data, size_t indices_num);
1874
1885 void UseCsrIndices(int64_t* inner_data, size_t inner_num, int64_t* outer_data, size_t outer_num);
1886
1895 void UseBlockSparseIndices(const Shape& indices_shape, int32_t* indices_data);
1896
1906 void FillSparseTensorCoo(const OrtMemoryInfo* data_mem_info, const OrtSparseValuesParam& values_param,
1907 const int64_t* indices_data, size_t indices_num);
1908
1920 void FillSparseTensorCsr(const OrtMemoryInfo* data_mem_info,
1921 const OrtSparseValuesParam& values,
1922 const int64_t* inner_indices_data, size_t inner_indices_num,
1923 const int64_t* outer_indices_data, size_t outer_indices_num);
1924
1935 const OrtSparseValuesParam& values,
1936 const Shape& indices_shape,
1937 const int32_t* indices_data);
1938
1939#endif
1940};
1941
1942} // namespace detail
1943
1946
1950struct Value : detail::ValueImpl<OrtValue> {
1952 using Base::Base;
1955
1956 explicit Value(std::nullptr_t) {}
1957 Value(Value&&) = default;
1958 Value& operator=(Value&&) = default;
1959
1960 ConstValue GetConst() const { return ConstValue{this->p_}; }
1961 UnownedValue GetUnowned() const { return UnownedValue{this->p_}; }
1962
1971 template <typename T>
1972 static Value CreateTensor(const OrtMemoryInfo* info, T* p_data, size_t p_data_element_count,
1973 const int64_t* shape, size_t shape_len);
1974
1984 static Value CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count,
1985 const int64_t* shape, size_t shape_len,
1987
1997 static Value CreateTensor(OrtAllocator* deleter, void* p_data, size_t p_data_byte_count,
1998 const int64_t* shape, size_t shape_len,
2000
2012 template <typename T>
2013 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len);
2014
2026 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len,
2028
2037 static Value CreateMap(const Value& keys, const Value& values);
2038
2046 static Value CreateSequence(const std::vector<Value>& values);
2047
2056 template <typename T>
2057 static Value CreateOpaque(const char* domain, const char* type_name, const T& value);
2058
2059#if !defined(DISABLE_SPARSE_TENSORS)
2070 template <typename T>
2071 static Value CreateSparseTensor(const OrtMemoryInfo* info, T* p_data, const Shape& dense_shape,
2072 const Shape& values_shape);
2073
2090 static Value CreateSparseTensor(const OrtMemoryInfo* info, void* p_data, const Shape& dense_shape,
2091 const Shape& values_shape, ONNXTensorElementDataType type);
2092
2102 template <typename T>
2103 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape);
2104
2116 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape, ONNXTensorElementDataType type);
2117
2118#endif // !defined(DISABLE_SPARSE_TENSORS)
2119};
2120
2128 MemoryAllocation(OrtAllocator* allocator, void* p, size_t size);
2133 MemoryAllocation& operator=(MemoryAllocation&&) noexcept;
2134
2135 void* get() { return p_; }
2136 size_t size() const { return size_; }
2137
2138 private:
2139 OrtAllocator* allocator_;
2140 void* p_;
2141 size_t size_;
2142};
2143
2144namespace detail {
2145template <typename T>
2146struct AllocatorImpl : Base<T> {
2147 using B = Base<T>;
2148 using B::B;
2149
2150 void* Alloc(size_t size);
2151 MemoryAllocation GetAllocation(size_t size);
2152 void Free(void* p);
2153 ConstMemoryInfo GetInfo() const;
2154
2159 KeyValuePairs GetStats() const;
2160};
2161
2162} // namespace detail
2163
2167struct AllocatorWithDefaultOptions : detail::AllocatorImpl<detail::Unowned<OrtAllocator>> {
2168 explicit AllocatorWithDefaultOptions(std::nullptr_t) {}
2170};
2171
2175struct Allocator : detail::AllocatorImpl<OrtAllocator> {
2176 explicit Allocator(std::nullptr_t) {}
2177 Allocator(const Session& session, const OrtMemoryInfo*);
2178};
2179
2180using UnownedAllocator = detail::AllocatorImpl<detail::Unowned<OrtAllocator>>;
2181
2182namespace detail {
2183namespace binding_utils {
2184// Bring these out of template
2185std::vector<std::string> GetOutputNamesHelper(const OrtIoBinding* binding, OrtAllocator*);
2186std::vector<Value> GetOutputValuesHelper(const OrtIoBinding* binding, OrtAllocator*);
2187} // namespace binding_utils
2188
2189template <typename T>
2191 using B = Base<T>;
2192 using B::B;
2193
2194 std::vector<std::string> GetOutputNames() const;
2195 std::vector<std::string> GetOutputNames(OrtAllocator*) const;
2196 std::vector<Value> GetOutputValues() const;
2197 std::vector<Value> GetOutputValues(OrtAllocator*) const;
2198};
2199
2200template <typename T>
2203 using B::B;
2204
2205 void BindInput(const char* name, const Value&);
2206 void BindOutput(const char* name, const Value&);
2207 void BindOutput(const char* name, const OrtMemoryInfo*);
2212};
2213
2214} // namespace detail
2215
2218
2222struct IoBinding : detail::IoBindingImpl<OrtIoBinding> {
2223 explicit IoBinding(std::nullptr_t) {}
2224 explicit IoBinding(Session& session);
2225 ConstIoBinding GetConst() const { return ConstIoBinding{this->p_}; }
2226 UnownedIoBinding GetUnowned() const { return UnownedIoBinding{this->p_}; }
2227};
2228
2233struct ArenaCfg : detail::Base<OrtArenaCfg> {
2234 explicit ArenaCfg(std::nullptr_t) {}
2243 ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk);
2244};
2245
2246//
2247// Custom OPs (only needed to implement custom OPs)
2248//
2249
2253struct OpAttr : detail::Base<OrtOpAttr> {
2255 using Base::Base;
2256
2257 explicit OpAttr(std::nullptr_t) {}
2258 OpAttr(const char* name, const void* data, int len, OrtOpAttrType type);
2259};
2260
2269#define ORT_CXX_LOG(logger, message_severity, message) \
2270 do { \
2271 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2272 Ort::ThrowOnError(logger.LogMessage(message_severity, ORT_FILE, __LINE__, \
2273 static_cast<const char*>(__FUNCTION__), message)); \
2274 } \
2275 } while (false)
2276
2285#define ORT_CXX_LOG_NOEXCEPT(logger, message_severity, message) \
2286 do { \
2287 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2288 static_cast<void>(logger.LogMessage(message_severity, ORT_FILE, __LINE__, \
2289 static_cast<const char*>(__FUNCTION__), message)); \
2290 } \
2291 } while (false)
2292
2304#define ORT_CXX_LOGF(logger, message_severity, /*format,*/...) \
2305 do { \
2306 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2307 Ort::ThrowOnError(logger.LogFormattedMessage(message_severity, ORT_FILE, __LINE__, \
2308 static_cast<const char*>(__FUNCTION__), __VA_ARGS__)); \
2309 } \
2310 } while (false)
2311
2323#define ORT_CXX_LOGF_NOEXCEPT(logger, message_severity, /*format,*/...) \
2324 do { \
2325 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2326 static_cast<void>(logger.LogFormattedMessage(message_severity, ORT_FILE, __LINE__, \
2327 static_cast<const char*>(__FUNCTION__), __VA_ARGS__)); \
2328 } \
2329 } while (false)
2330
2341struct Logger {
2345 Logger() = default;
2346
2350 explicit Logger(std::nullptr_t) {}
2351
2358 explicit Logger(const OrtLogger* logger);
2359
2360 ~Logger() = default;
2361
2362 Logger(const Logger&) = default;
2363 Logger& operator=(const Logger&) = default;
2364
2365 Logger(Logger&& v) noexcept = default;
2366 Logger& operator=(Logger&& v) noexcept = default;
2367
2374
2387 Status LogMessage(OrtLoggingLevel log_severity_level, const ORTCHAR_T* file_path, int line_number,
2388 const char* func_name, const char* message) const noexcept;
2389
2404 template <typename... Args>
2405 Status LogFormattedMessage(OrtLoggingLevel log_severity_level, const ORTCHAR_T* file_path, int line_number,
2406 const char* func_name, const char* format, Args&&... args) const noexcept;
2407
2408 private:
2409 const OrtLogger* logger_{};
2410 OrtLoggingLevel cached_severity_level_{};
2411};
2412
2421 size_t GetInputCount() const;
2422 size_t GetOutputCount() const;
2423 // If input is optional and is not present, the method returns an empty ConstValue
2424 // which can be compared to nullptr.
2425 ConstValue GetInput(size_t index) const;
2426 // If output is optional and is not present, the method returns an empty UnownedValue
2427 // which can be compared to nullptr.
2428 UnownedValue GetOutput(size_t index, const int64_t* dim_values, size_t dim_count) const;
2429 UnownedValue GetOutput(size_t index, const std::vector<int64_t>& dims) const;
2430 void* GetGPUComputeStream() const;
2432 OrtAllocator* GetAllocator(const OrtMemoryInfo& memory_info) const;
2433 OrtKernelContext* GetOrtKernelContext() const { return ctx_; }
2434 void ParallelFor(void (*fn)(void*, size_t), size_t total, size_t num_batch, void* usr_data) const;
2435
2436 private:
2437 OrtKernelContext* ctx_;
2438};
2439
2440struct KernelInfo;
2441
2442namespace detail {
2443namespace attr_utils {
2444void GetAttr(const OrtKernelInfo* p, const char* name, float&);
2445void GetAttr(const OrtKernelInfo* p, const char* name, int64_t&);
2446void GetAttr(const OrtKernelInfo* p, const char* name, std::string&);
2447void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<float>&);
2448void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<int64_t>&);
2449} // namespace attr_utils
2450
2451template <typename T>
2452struct KernelInfoImpl : Base<T> {
2453 using B = Base<T>;
2454 using B::B;
2455
2456 KernelInfo Copy() const;
2457
2458 template <typename R> // R is only implemented for float, int64_t, and string
2459 R GetAttribute(const char* name) const {
2460 R val;
2461 attr_utils::GetAttr(this->p_, name, val);
2462 return val;
2463 }
2464
2465 template <typename R> // R is only implemented for std::vector<float>, std::vector<int64_t>
2466 std::vector<R> GetAttributes(const char* name) const {
2467 std::vector<R> result;
2468 attr_utils::GetAttrs(this->p_, name, result);
2469 return result;
2470 }
2471
2472 Value GetTensorAttribute(const char* name, OrtAllocator* allocator) const;
2473
2474 size_t GetInputCount() const;
2475 size_t GetOutputCount() const;
2476
2477 std::string GetInputName(size_t index) const;
2478 std::string GetOutputName(size_t index) const;
2479
2480 TypeInfo GetInputTypeInfo(size_t index) const;
2481 TypeInfo GetOutputTypeInfo(size_t index) const;
2482
2483 ConstValue GetTensorConstantInput(size_t index, int* is_constant) const;
2484
2485 std::string GetNodeName() const;
2486 Logger GetLogger() const;
2487};
2488
2489} // namespace detail
2490
2491using ConstKernelInfo = detail::KernelInfoImpl<detail::Unowned<const OrtKernelInfo>>;
2492
2499struct KernelInfo : detail::KernelInfoImpl<OrtKernelInfo> {
2500 using Base = detail::KernelInfoImpl<OrtKernelInfo>;
2501 using Base::Base;
2502 explicit KernelInfo(std::nullptr_t) {}
2503 explicit KernelInfo(OrtKernelInfo* info);
2504 ConstKernelInfo GetConst() const { return ConstKernelInfo{this->p_}; }
2505};
2506
2510struct Op : detail::Base<OrtOp> {
2512 using Base::Base;
2513
2514 explicit Op(std::nullptr_t) {}
2515
2516 explicit Op(OrtOp*);
2517
2518 static Op Create(const OrtKernelInfo* info, const char* op_name, const char* domain,
2519 int version, const char** type_constraint_names,
2520 const ONNXTensorElementDataType* type_constraint_values,
2521 size_t type_constraint_count,
2522 const OpAttr* attr_values,
2523 size_t attr_count,
2524 size_t input_count, size_t output_count);
2525
2526 void Invoke(const OrtKernelContext* context,
2527 const Value* input_values,
2528 size_t input_count,
2529 Value* output_values,
2530 size_t output_count);
2531
2532 // For easier refactoring
2533 void Invoke(const OrtKernelContext* context,
2534 const OrtValue* const* input_values,
2535 size_t input_count,
2536 OrtValue* const* output_values,
2537 size_t output_count);
2538};
2539
2545 SymbolicInteger(int64_t i) : i_(i), is_int_(true) {};
2546 SymbolicInteger(const char* s) : s_(s), is_int_(false) {};
2549
2552
2553 bool operator==(const SymbolicInteger& dim) const {
2554 if (is_int_ == dim.is_int_) {
2555 if (is_int_) {
2556 return i_ == dim.i_;
2557 } else {
2558 return std::string{s_} == std::string{dim.s_};
2559 }
2560 }
2561 return false;
2562 }
2563
2564 bool IsInt() const { return is_int_; }
2565 int64_t AsInt() const { return i_; }
2566 const char* AsSym() const { return s_; }
2567
2568 static constexpr int INVALID_INT_DIM = -2;
2569
2570 private:
2571 union {
2572 int64_t i_;
2573 const char* s_;
2574 };
2575 bool is_int_;
2576 };
2577
2578 using Shape = std::vector<SymbolicInteger>;
2579
2581
2582 const Shape& GetInputShape(size_t indice) const { return input_shapes_.at(indice); }
2583
2584 size_t GetInputCount() const { return input_shapes_.size(); }
2585
2587
2588 int64_t GetAttrInt(const char* attr_name);
2589
2590 using Ints = std::vector<int64_t>;
2591 Ints GetAttrInts(const char* attr_name);
2592
2593 float GetAttrFloat(const char* attr_name);
2594
2595 using Floats = std::vector<float>;
2596 Floats GetAttrFloats(const char* attr_name);
2597
2598 std::string GetAttrString(const char* attr_name);
2599
2600 using Strings = std::vector<std::string>;
2601 Strings GetAttrStrings(const char* attr_name);
2602
2603 private:
2604 const OrtOpAttr* GetAttrHdl(const char* attr_name) const;
2605 const OrtApi* ort_api_;
2607 std::vector<Shape> input_shapes_;
2608};
2609
2611
2612#define MAX_CUSTOM_OP_END_VER (1UL << 31) - 1
2613
2614template <typename TOp, typename TKernel, bool WithStatus = false>
2618 OrtCustomOp::GetName = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetName(); };
2619
2620 OrtCustomOp::GetExecutionProviderType = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetExecutionProviderType(); };
2621
2622 OrtCustomOp::GetInputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetInputTypeCount(); };
2623 OrtCustomOp::GetInputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputType(index); };
2624 OrtCustomOp::GetInputMemoryType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputMemoryType(index); };
2625
2626 OrtCustomOp::GetOutputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetOutputTypeCount(); };
2627 OrtCustomOp::GetOutputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputType(index); };
2628
2629#if defined(_MSC_VER) && !defined(__clang__)
2630#pragma warning(push)
2631#pragma warning(disable : 26409)
2632#endif
2633 OrtCustomOp::KernelDestroy = [](void* op_kernel) { delete static_cast<TKernel*>(op_kernel); };
2634#if defined(_MSC_VER) && !defined(__clang__)
2635#pragma warning(pop)
2636#endif
2637 OrtCustomOp::GetInputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputCharacteristic(index); };
2638 OrtCustomOp::GetOutputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputCharacteristic(index); };
2639
2640 OrtCustomOp::GetVariadicInputMinArity = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetVariadicInputMinArity(); };
2641 OrtCustomOp::GetVariadicInputHomogeneity = [](const OrtCustomOp* this_) { return static_cast<int>(static_cast<const TOp*>(this_)->GetVariadicInputHomogeneity()); };
2642 OrtCustomOp::GetVariadicOutputMinArity = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetVariadicOutputMinArity(); };
2643 OrtCustomOp::GetVariadicOutputHomogeneity = [](const OrtCustomOp* this_) { return static_cast<int>(static_cast<const TOp*>(this_)->GetVariadicOutputHomogeneity()); };
2644#ifdef __cpp_if_constexpr
2645 if constexpr (WithStatus) {
2646#else
2647 if (WithStatus) {
2648#endif
2649 OrtCustomOp::CreateKernelV2 = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info, void** op_kernel) -> OrtStatusPtr {
2650 return static_cast<const TOp*>(this_)->CreateKernelV2(*api, info, op_kernel);
2651 };
2652 OrtCustomOp::KernelComputeV2 = [](void* op_kernel, OrtKernelContext* context) -> OrtStatusPtr {
2653 return static_cast<TKernel*>(op_kernel)->ComputeV2(context);
2654 };
2655 } else {
2658
2659 OrtCustomOp::CreateKernel = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info) { return static_cast<const TOp*>(this_)->CreateKernel(*api, info); };
2660 OrtCustomOp::KernelCompute = [](void* op_kernel, OrtKernelContext* context) {
2661 static_cast<TKernel*>(op_kernel)->Compute(context);
2662 };
2663 }
2664
2665 SetShapeInferFn<TOp>(0);
2666
2667 OrtCustomOp::GetStartVersion = [](const OrtCustomOp* this_) {
2668 return static_cast<const TOp*>(this_)->start_ver_;
2669 };
2670
2671 OrtCustomOp::GetEndVersion = [](const OrtCustomOp* this_) {
2672 return static_cast<const TOp*>(this_)->end_ver_;
2673 };
2674
2677 OrtCustomOp::GetAliasMap = nullptr;
2679 }
2680
2681 // Default implementation of GetExecutionProviderType that returns nullptr to default to the CPU provider
2682 const char* GetExecutionProviderType() const { return nullptr; }
2683
2684 // Default implementations of GetInputCharacteristic() and GetOutputCharacteristic() below
2685 // (inputs and outputs are required by default)
2687 return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED;
2688 }
2689
2691 return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED;
2692 }
2693
2694 // Default implementation of GetInputMemoryType() that returns OrtMemTypeDefault
2695 OrtMemType GetInputMemoryType(size_t /*index*/) const {
2696 return OrtMemTypeDefault;
2697 }
2698
2699 // Default implementation of GetVariadicInputMinArity() returns 1 to specify that a variadic input
2700 // should expect at least 1 argument.
2702 return 1;
2703 }
2704
2705 // Default implementation of GetVariadicInputHomegeneity() returns true to specify that all arguments
2706 // to a variadic input should be of the same type.
2708 return true;
2709 }
2710
2711 // Default implementation of GetVariadicOutputMinArity() returns 1 to specify that a variadic output
2712 // should produce at least 1 output value.
2714 return 1;
2715 }
2716
2717 // Default implementation of GetVariadicOutputHomegeneity() returns true to specify that all output values
2718 // produced by a variadic output should be of the same type.
2720 return true;
2721 }
2722
2723 // Declare list of session config entries used by this Custom Op.
2724 // Implement this function in order to get configs from CustomOpBase::GetSessionConfigs().
2725 // This default implementation returns an empty vector of config entries.
2726 std::vector<std::string> GetSessionConfigKeys() const {
2727 return std::vector<std::string>{};
2728 }
2729
2730 // Ort::CustomOpBase derived class should provide the following static method with the type/shape inferencing
2731 // implementation if needed:
2732 // static OrtStatusPtr InferOutputShape(Ort::ShapeInferContext& context)
2733 template <typename C>
2734 decltype(&C::InferOutputShape) SetShapeInferFn(decltype(&C::InferOutputShape)) {
2736 ShapeInferContext ctx(&GetApi(), ort_ctx);
2737 return C::InferOutputShape(ctx);
2738 };
2739 return {};
2740 }
2741
2742 template <typename C>
2746
2747 protected:
2748 // Helper function that returns a map of session config entries specified by CustomOpBase::GetSessionConfigKeys.
2749 void GetSessionConfigs(std::unordered_map<std::string, std::string>& out, ConstSessionOptions options) const;
2750
2751 int start_ver_ = 1;
2752 int end_ver_ = MAX_CUSTOM_OP_END_VER;
2753};
2754
2755namespace detail {
2756template <typename T>
2759 using B::B;
2760
2761 std::string Name() const;
2763};
2764} // namespace detail
2765
2766// Const object holder that does not own the underlying object
2768
2772struct ValueInfo : detail::ValueInfoImpl<OrtValueInfo> {
2773 explicit ValueInfo(std::nullptr_t) {}
2775 explicit ValueInfo(OrtValueInfo* p) : ValueInfoImpl<OrtValueInfo>{p} {}
2776
2777 // Create ValueInfo for a tensor
2778 explicit ValueInfo(const std::string& name, const ConstTypeInfo& type_info);
2779
2780 ConstValueInfo GetConst() const { return ConstValueInfo{this->p_}; }
2781};
2782
2783namespace detail {
2784template <typename T>
2787 using B::B;
2788};
2789} // namespace detail
2790
2794struct Node : detail::NodeImpl<OrtNode> {
2795 explicit Node(std::nullptr_t) {}
2796 explicit Node(OrtNode* p) : NodeImpl<OrtNode>{p} {}
2797
2798#if !defined(ORT_MINIMAL_BUILD)
2799 Node(const std::string& operator_name, const std::string& operator_domain,
2800 const std::string& node_name,
2801 const std::vector<std::string>& input_names,
2802 const std::vector<std::string>& output_names);
2803
2807 Node(const std::string& operator_name, const std::string& operator_domain,
2808 const std::string& node_name,
2809 const std::vector<std::string>& input_names,
2810 const std::vector<std::string>& output_names,
2811 std::vector<OpAttr>& attributes);
2812
2813 private:
2814 static void Init(const std::string& operator_name, const std::string& operator_domain,
2815 const std::string& node_name,
2816 const std::vector<std::string>& input_names,
2817 const std::vector<std::string>& output_names,
2818 std::vector<OpAttr>& attributes,
2819 OrtNode*& node);
2820#endif // !defined(ORT_MINIMAL_BUILD)
2821};
2822
2823namespace detail {
2824template <typename T>
2825struct GraphImpl : Ort::detail::Base<T> {
2826 using B = Ort::detail::Base<T>;
2827 using B::B;
2828
2829#if !defined(ORT_MINIMAL_BUILD)
2830 void SetInputs(std::vector<ValueInfo>& inputs);
2831 void SetOutputs(std::vector<ValueInfo>& outputs);
2832 void AddInitializer(const std::string& name, Value& initializer, bool data_is_external); // Graph takes ownership of Value
2833 void AddNode(Node& node); // Graph takes ownership of Node
2834#endif // !defined(ORT_MINIMAL_BUILD)
2835};
2836} // namespace detail
2837
2841struct Graph : detail::GraphImpl<OrtGraph> {
2842 explicit Graph(std::nullptr_t) {}
2843 explicit Graph(OrtGraph* p) : GraphImpl<OrtGraph>{p} {}
2844#if !defined(ORT_MINIMAL_BUILD)
2846#endif
2847};
2848
2849namespace detail {
2850template <typename T>
2853 using B::B;
2854
2855#if !defined(ORT_MINIMAL_BUILD)
2856 void AddGraph(Graph& graph);
2857#endif
2858};
2859} // namespace detail
2860
2861// Const object holder that does not own the underlying object
2863
2867struct Model : detail::ModelImpl<OrtModel> {
2868 using DomainOpsetPair = std::pair<std::string, int>;
2869
2870 explicit Model(std::nullptr_t) {}
2871 explicit Model(OrtModel* p) : ModelImpl<OrtModel>{p} {}
2872
2873#if !defined(ORT_MINIMAL_BUILD)
2874 explicit Model(const std::vector<DomainOpsetPair>& opsets);
2875#endif
2876
2877 ConstModel GetConst() const { return ConstModel{this->p_}; }
2878};
2879} // namespace Ort
2880#include "onnxruntime_cxx_inline.h"
struct OrtMemoryInfo OrtMemoryInfo
Definition onnxruntime_c_api.h:284
struct OrtKernelInfo OrtKernelInfo
Definition onnxruntime_c_api.h:401
struct OrtNode OrtNode
Definition onnxruntime_c_api.h:312
OrtLoggingLevel
Logging severity levels.
Definition onnxruntime_c_api.h:237
OrtMemoryInfoDeviceType
This mimics OrtDevice type constants so they can be returned in the API.
Definition onnxruntime_c_api.h:425
struct OrtShapeInferContext OrtShapeInferContext
Definition onnxruntime_c_api.h:309
void(* OrtLoggingFunction)(void *param, OrtLoggingLevel severity, const char *category, const char *logid, const char *code_location, const char *message)
Definition onnxruntime_c_api.h:365
void(* OrtCustomJoinThreadFn)(OrtCustomThreadHandle ort_custom_thread_handle)
Custom thread join function.
Definition onnxruntime_c_api.h:825
OrtCustomOpInputOutputCharacteristic
Definition onnxruntime_c_api.h:5348
struct OrtTensorRTProviderOptionsV2 OrtTensorRTProviderOptionsV2
Definition onnxruntime_c_api.h:301
struct OrtOpAttr OrtOpAttr
Definition onnxruntime_c_api.h:307
struct OrtThreadingOptions OrtThreadingOptions
Definition onnxruntime_c_api.h:298
struct OrtSequenceTypeInfo OrtSequenceTypeInfo
Definition onnxruntime_c_api.h:292
struct OrtValueInfo OrtValueInfo
Definition onnxruntime_c_api.h:311
struct OrtDnnlProviderOptions OrtDnnlProviderOptions
Definition onnxruntime_c_api.h:305
OrtSparseIndicesFormat
Definition onnxruntime_c_api.h:226
struct OrtPrepackedWeightsContainer OrtPrepackedWeightsContainer
Definition onnxruntime_c_api.h:300
struct OrtSession OrtSession
Definition onnxruntime_c_api.h:286
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:468
struct OrtCustomOpDomain OrtCustomOpDomain
Definition onnxruntime_c_api.h:295
struct OrtIoBinding OrtIoBinding
Definition onnxruntime_c_api.h:285
OrtAllocatorType
Definition onnxruntime_c_api.h:407
struct OrtOp OrtOp
Definition onnxruntime_c_api.h:306
struct OrtTypeInfo OrtTypeInfo
Definition onnxruntime_c_api.h:289
struct OrtTensorTypeAndShapeInfo OrtTensorTypeAndShapeInfo
Definition onnxruntime_c_api.h:290
struct OrtCUDAProviderOptionsV2 OrtCUDAProviderOptionsV2
Definition onnxruntime_c_api.h:303
struct OrtKernelContext OrtKernelContext
Definition onnxruntime_c_api.h:403
struct OrtCANNProviderOptions OrtCANNProviderOptions
Definition onnxruntime_c_api.h:304
struct OrtEpDevice OrtEpDevice
Definition onnxruntime_c_api.h:317
void(* RunAsyncCallbackFn)(void *user_data, OrtValue **outputs, size_t num_outputs, OrtStatusPtr status)
Callback function for RunAsync.
Definition onnxruntime_c_api.h:836
OrtHardwareDeviceType
Definition onnxruntime_c_api.h:431
struct OrtModel OrtModel
Definition onnxruntime_c_api.h:314
struct OrtGraph OrtGraph
Definition onnxruntime_c_api.h:313
struct OrtSessionOptions OrtSessionOptions
Definition onnxruntime_c_api.h:294
struct OrtValue OrtValue
Definition onnxruntime_c_api.h:287
GraphOptimizationLevel
Graph optimization level.
Definition onnxruntime_c_api.h:374
struct OrtKeyValuePairs OrtKeyValuePairs
Definition onnxruntime_c_api.h:318
OrtStatus * OrtStatusPtr
Definition onnxruntime_c_api.h:323
OrtMemType
Memory types for allocated memory, execution provider specific types should be extended in each provi...
Definition onnxruntime_c_api.h:416
OrtSparseFormat
Definition onnxruntime_c_api.h:218
ONNXType
Definition onnxruntime_c_api.h:206
struct OrtEnv OrtEnv
Definition onnxruntime_c_api.h:282
OrtErrorCode
Definition onnxruntime_c_api.h:245
struct OrtStatus OrtStatus
Definition onnxruntime_c_api.h:283
#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:308
struct OrtMapTypeInfo OrtMapTypeInfo
Definition onnxruntime_c_api.h:291
struct OrtArenaCfg OrtArenaCfg
Definition onnxruntime_c_api.h:299
ExecutionMode
Definition onnxruntime_c_api.h:382
OrtOpAttrType
Definition onnxruntime_c_api.h:262
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:818
ONNXTensorElementDataType
Definition onnxruntime_c_api.h:177
OrtExecutionProviderDevicePolicy
These are the default EP selection policies used by ORT when doing automatic EP selection.
Definition onnxruntime_c_api.h:439
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:240
@ OrtMemTypeDefault
The default allocator for execution provider.
Definition onnxruntime_c_api.h:420
@ ORT_FAIL
Definition onnxruntime_c_api.h:247
@ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT
Definition onnxruntime_c_api.h:179
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:551
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:151
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:707
detail::ConstSessionOptionsImpl< detail::Unowned< const OrtSessionOptions > > ConstSessionOptions
Definition onnxruntime_cxx_api.h:1128
detail::KernelInfoImpl< detail::Unowned< const OrtKernelInfo > > ConstKernelInfo
Definition onnxruntime_cxx_api.h:2491
const OrtApi & GetApi() noexcept
This returns a reference to the ORT C API.
Definition onnxruntime_cxx_api.h:125
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:165
detail::AllocatorImpl< detail::Unowned< OrtAllocator > > UnownedAllocator
Definition onnxruntime_cxx_api.h:2180
detail::SessionOptionsImpl< detail::Unowned< OrtSessionOptions > > UnownedSessionOptions
Definition onnxruntime_cxx_api.h:1127
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:179
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:2610
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:2175
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:2176
Wrapper around OrtAllocator default instance that is owned by Onnxruntime.
Definition onnxruntime_cxx_api.h:2167
AllocatorWithDefaultOptions(std::nullptr_t)
Convenience to create a class member and then replace with an instance.
Definition onnxruntime_cxx_api.h:2168
it is a structure that represents the configuration of an arena based allocator
Definition onnxruntime_cxx_api.h:2233
ArenaCfg(std::nullptr_t)
Create an empty ArenaCfg object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:2234
ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk)
bfloat16 (Brain Floating Point) data type
Definition onnxruntime_cxx_api.h:349
bool operator==(const BFloat16_t &rhs) const noexcept
onnxruntime_float16::BFloat16Impl< BFloat16_t > Base
Definition onnxruntime_cxx_api.h:361
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:370
bool operator!=(const BFloat16_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:468
BFloat16_t(float v) noexcept
__ctor from float. Float is converted into bfloat16 16-bit representation.
Definition onnxruntime_cxx_api.h:376
float ToFloat() const noexcept
Converts bfloat16 to float.
Definition onnxruntime_cxx_api.h:382
bool operator<(const BFloat16_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:2615
OrtCustomOpInputOutputCharacteristic GetOutputCharacteristic(size_t) const
Definition onnxruntime_cxx_api.h:2690
OrtCustomOpInputOutputCharacteristic GetInputCharacteristic(size_t) const
Definition onnxruntime_cxx_api.h:2686
OrtMemType GetInputMemoryType(size_t) const
Definition onnxruntime_cxx_api.h:2695
std::vector< std::string > GetSessionConfigKeys() const
Definition onnxruntime_cxx_api.h:2726
bool GetVariadicInputHomogeneity() const
Definition onnxruntime_cxx_api.h:2707
int GetVariadicInputMinArity() const
Definition onnxruntime_cxx_api.h:2701
void SetShapeInferFn(...)
Definition onnxruntime_cxx_api.h:2743
CustomOpBase()
Definition onnxruntime_cxx_api.h:2616
bool GetVariadicOutputHomogeneity() const
Definition onnxruntime_cxx_api.h:2719
int GetVariadicOutputMinArity() const
Definition onnxruntime_cxx_api.h:2713
decltype(&C::InferOutputShape) SetShapeInferFn(decltype(&C::InferOutputShape))
Definition onnxruntime_cxx_api.h:2734
const char * GetExecutionProviderType() const
Definition onnxruntime_cxx_api.h:2682
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:983
~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:889
CustomOpDomain(std::nullptr_t)
Create an empty CustomOpDomain object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:893
CustomOpDomain(const char *domain)
Wraps OrtApi::CreateCustomOpDomain.
void Add(const OrtCustomOp *op)
Wraps CustomOpDomain_Add.
The Env (Environment)
Definition onnxruntime_cxx_api.h:850
Env & EnableTelemetryEvents()
Wraps OrtApi::EnableTelemetryEvents.
Env(OrtEnv *p)
C Interop Helper.
Definition onnxruntime_cxx_api.h:867
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(std::nullptr_t)
Create an empty Env object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:851
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(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.
Env & RegisterExecutionProviderLibrary(const char *registration_name, const std::basic_string< char > &path)
Wraps OrtApi::RegisterExecutionProviderLibrary.
Env & UpdateEnvWithCustomLogLevel(OrtLoggingLevel log_severity_level)
Wraps OrtApi::UpdateEnvWithCustomLogLevel.
Env & DisableTelemetryEvents()
Wraps OrtApi::DisableTelemetryEvents.
Mutable EpDevice that is created by EpApi users.
Definition onnxruntime_cxx_api.h:836
EpDevice(OrtEpDevice *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:838
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:837
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:58
OrtErrorCode GetOrtErrorCode() const
Definition onnxruntime_cxx_api.h:57
Exception(std::string &&string, OrtErrorCode code)
Definition onnxruntime_cxx_api.h:55
IEEE 754 half-precision floating point data type.
Definition onnxruntime_cxx_api.h:207
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:235
onnxruntime_float16::Float16Impl< Float16_t > Base
Definition onnxruntime_cxx_api.h:217
float ToFloat() const noexcept
Converts float16 to float.
Definition onnxruntime_cxx_api.h:241
static constexpr Float16_t FromBits(uint16_t v) noexcept
Explicit conversion to uint16_t representation of float16.
Definition onnxruntime_cxx_api.h:229
float8e4m3fn (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:479
uint8_t value
Definition onnxruntime_cxx_api.h:480
constexpr Float8E4M3FN_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:482
constexpr bool operator==(const Float8E4M3FN_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:485
constexpr Float8E4M3FN_t() noexcept
Definition onnxruntime_cxx_api.h:481
constexpr bool operator!=(const Float8E4M3FN_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:486
float8e4m3fnuz (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:496
constexpr bool operator==(const Float8E4M3FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:502
uint8_t value
Definition onnxruntime_cxx_api.h:497
constexpr Float8E4M3FNUZ_t() noexcept
Definition onnxruntime_cxx_api.h:498
constexpr bool operator!=(const Float8E4M3FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:503
constexpr Float8E4M3FNUZ_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:499
float8e5m2 (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:513
constexpr Float8E5M2_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:516
uint8_t value
Definition onnxruntime_cxx_api.h:514
constexpr bool operator!=(const Float8E5M2_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:520
constexpr Float8E5M2_t() noexcept
Definition onnxruntime_cxx_api.h:515
constexpr bool operator==(const Float8E5M2_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:519
float8e5m2fnuz (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:530
constexpr Float8E5M2FNUZ_t() noexcept
Definition onnxruntime_cxx_api.h:532
constexpr Float8E5M2FNUZ_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:533
constexpr bool operator!=(const Float8E5M2FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:537
constexpr bool operator==(const Float8E5M2FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:536
uint8_t value
Definition onnxruntime_cxx_api.h:531
Definition onnxruntime_cxx_api.h:86
static const OrtApi * api_
Definition onnxruntime_cxx_api.h:87
Wrapper around OrtGraph.
Definition onnxruntime_cxx_api.h:2841
Graph(OrtGraph *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:2843
Graph(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:2842
Wrapper around OrtIoBinding.
Definition onnxruntime_cxx_api.h:2222
UnownedIoBinding GetUnowned() const
Definition onnxruntime_cxx_api.h:2226
ConstIoBinding GetConst() const
Definition onnxruntime_cxx_api.h:2225
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:2223
This class wraps a raw pointer OrtKernelContext* that is being passed to the custom kernel Compute() ...
Definition onnxruntime_cxx_api.h:2419
KernelContext(OrtKernelContext *context)
Logger GetLogger() const
ConstValue GetInput(size_t index) const
OrtKernelContext * GetOrtKernelContext() const
Definition onnxruntime_cxx_api.h:2433
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:2499
KernelInfo(OrtKernelInfo *info)
Take ownership of the instance.
ConstKernelInfo GetConst() const
Definition onnxruntime_cxx_api.h:2504
detail::KernelInfoImpl< OrtKernelInfo > Base
Definition onnxruntime_cxx_api.h:2500
KernelInfo(std::nullptr_t)
Create an empty instance to initialize later.
Definition onnxruntime_cxx_api.h:2502
Wrapper around OrtKeyValuePairs.
Definition onnxruntime_cxx_api.h:776
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:777
ConstKeyValuePairs GetConst() const
Definition onnxruntime_cxx_api.h:793
KeyValuePairs(OrtKeyValuePairs *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:779
This class represents an ONNX Runtime logger that can be used to log information with an associated s...
Definition onnxruntime_cxx_api.h:2341
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:2350
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:903
static LoraAdapter CreateLoraAdapter(const std::basic_string< char > &adapter_path, OrtAllocator *allocator)
Wraps OrtApi::CreateLoraAdapter.
LoraAdapter(std::nullptr_t)
Definition onnxruntime_cxx_api.h:907
static LoraAdapter CreateLoraAdapterFromArray(const void *bytes, size_t num_bytes, OrtAllocator *allocator)
Wraps OrtApi::CreateLoraAdapterFromArray.
Wrapper around OrtMapTypeInfo.
Definition onnxruntime_cxx_api.h:1560
ConstMapTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:1566
MapTypeInfo(OrtMapTypeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1565
MapTypeInfo(std::nullptr_t)
Create an empty MapTypeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1564
Represents native memory allocation coming from one of the OrtAllocators registered with OnnxRuntime....
Definition onnxruntime_cxx_api.h:2127
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:2136
Wrapper around OrtMemoryInfo.
Definition onnxruntime_cxx_api.h:1450
MemoryInfo(const char *name, OrtAllocatorType type, int id, OrtMemType mem_type)
MemoryInfo(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:1452
MemoryInfo(OrtMemoryInfo *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:1453
static MemoryInfo CreateCpu(OrtAllocatorType type, OrtMemType mem_type1)
ConstMemoryInfo GetConst() const
Definition onnxruntime_cxx_api.h:1455
Options object used when compiling a model.
Definition onnxruntime_cxx_api.h:1145
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 & 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:1149
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(const Env &env, const SessionOptions &session_options)
Wraps OrtApi::CreateModelCompilationOptionsFromSessionOptions.
ModelCompilationOptions & SetFlags(size_t flags)
Wraps OrtApi::ModelCompilationOptions_SetFlags.
Wrapper around OrtModel.
Definition onnxruntime_cxx_api.h:2867
Model(const std::vector< DomainOpsetPair > &opsets)
Model(OrtModel *p)
Take ownership of a pointer created by C API.
Definition onnxruntime_cxx_api.h:2871
std::pair< std::string, int > DomainOpsetPair
Definition onnxruntime_cxx_api.h:2868
Model(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:2870
ConstModel GetConst() const
Definition onnxruntime_cxx_api.h:2877
Wrapper around OrtModelMetadata.
Definition onnxruntime_cxx_api.h:1177
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:1181
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:2794
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(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:2795
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:2796
This struct provides life time management for custom op attribute.
Definition onnxruntime_cxx_api.h:2253
OpAttr(const char *name, const void *data, int len, OrtOpAttrType type)
OpAttr(std::nullptr_t)
Definition onnxruntime_cxx_api.h:2257
Create and own custom defined operation.
Definition onnxruntime_cxx_api.h:2510
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:2514
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)
RunOptions.
Definition onnxruntime_cxx_api.h:931
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:932
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.
Wrapper around OrtSequenceTypeInfo.
Definition onnxruntime_cxx_api.h:1522
SequenceTypeInfo(std::nullptr_t)
Create an empty SequenceTypeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1526
ConstSequenceTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:1528
SequenceTypeInfo(OrtSequenceTypeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1527
Wrapper around OrtSession.
Definition onnxruntime_cxx_api.h:1393
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:1395
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:1424
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:1396
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:1423
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:1133
SessionOptions(std::nullptr_t)
Create an empty SessionOptions object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1134
UnownedSessionOptions GetUnowned() const
Definition onnxruntime_cxx_api.h:1137
SessionOptions()
Wraps OrtApi::CreateSessionOptions.
ConstSessionOptions GetConst() const
Definition onnxruntime_cxx_api.h:1138
SessionOptions(OrtSessionOptions *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1136
Definition onnxruntime_cxx_api.h:2544
SymbolicInteger & operator=(const SymbolicInteger &)=default
SymbolicInteger(const SymbolicInteger &)=default
int64_t AsInt() const
Definition onnxruntime_cxx_api.h:2565
int64_t i_
Definition onnxruntime_cxx_api.h:2572
const char * s_
Definition onnxruntime_cxx_api.h:2573
bool operator==(const SymbolicInteger &dim) const
Definition onnxruntime_cxx_api.h:2553
SymbolicInteger & operator=(SymbolicInteger &&)=default
SymbolicInteger(SymbolicInteger &&)=default
const char * AsSym() const
Definition onnxruntime_cxx_api.h:2566
SymbolicInteger(int64_t i)
Definition onnxruntime_cxx_api.h:2545
SymbolicInteger(const char *s)
Definition onnxruntime_cxx_api.h:2546
bool IsInt() const
Definition onnxruntime_cxx_api.h:2564
Provide access to per-node attributes and input shapes, so one could compute and set output shapes.
Definition onnxruntime_cxx_api.h:2543
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:2578
std::vector< float > Floats
Definition onnxruntime_cxx_api.h:2595
std::string GetAttrString(const char *attr_name)
std::vector< int64_t > Ints
Definition onnxruntime_cxx_api.h:2590
ShapeInferContext(const OrtApi *ort_api, OrtShapeInferContext *ctx)
int64_t GetAttrInt(const char *attr_name)
size_t GetInputCount() const
Definition onnxruntime_cxx_api.h:2584
std::vector< std::string > Strings
Definition onnxruntime_cxx_api.h:2600
Floats GetAttrFloats(const char *attr_name)
const Shape & GetInputShape(size_t indice) const
Definition onnxruntime_cxx_api.h:2582
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:713
OrtErrorCode GetErrorCode() const
Status(const char *message, OrtErrorCode code) noexcept
Creates status instance out of null-terminated string message.
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(const Exception &) noexcept
Creates status instance out of exception.
Status(const std::exception &) noexcept
Creates status instance out of exception.
detail::Base< OrtStatus > Base
Definition onnxruntime_cxx_api.h:714
Status(std::nullptr_t) noexcept
Create an empty object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:717
Wrapper around OrtTensorTypeAndShapeInfo.
Definition onnxruntime_cxx_api.h:1488
TensorTypeAndShapeInfo(std::nullptr_t)
Create an empty TensorTypeAndShapeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1493
ConstTensorTypeAndShapeInfo GetConst() const
Definition onnxruntime_cxx_api.h:1504
TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1495
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:731
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:1594
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:1599
static TypeInfo CreateMapTypeInfo(ONNXTensorElementDataType key_type, ConstTypeInfo value_type)
ConstTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:1610
TypeInfo(OrtTypeInfo *p)
C API Interop.
Definition onnxruntime_cxx_api.h:1600
Wrapper around OrtValue.
Definition onnxruntime_cxx_api.h:1950
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:1956
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:1961
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:1960
Wrapper around OrtValueInfo.
Definition onnxruntime_cxx_api.h:2772
ConstValueInfo GetConst() const
Definition onnxruntime_cxx_api.h:2780
ValueInfo(std::nullptr_t)
Definition onnxruntime_cxx_api.h:2773
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:2775
Definition onnxruntime_cxx_api.h:681
AllocatedFree(OrtAllocator *allocator)
Definition onnxruntime_cxx_api.h:683
OrtAllocator * allocator_
Definition onnxruntime_cxx_api.h:682
void operator()(void *ptr) const
Definition onnxruntime_cxx_api.h:685
Base & operator=(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:668
typename Unowned< T >::Type contained_type
Definition onnxruntime_cxx_api.h:657
Base(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:667
Base(const Base &)=default
constexpr Base(contained_type *p) noexcept
Definition onnxruntime_cxx_api.h:660
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:611
Base(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:623
constexpr Base()=default
contained_type * release()
Relinquishes ownership of the contained C object pointer The underlying object is not destroyed.
Definition onnxruntime_cxx_api.h:634
Base(const Base &)=delete
constexpr Base(contained_type *p) noexcept
Definition onnxruntime_cxx_api.h:615
Base & operator=(const Base &)=delete
Base & operator=(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:624
contained_type * p_
Definition onnxruntime_cxx_api.h:641
~Base()
Definition onnxruntime_cxx_api.h:616
T contained_type
Definition onnxruntime_cxx_api.h:612
Definition onnxruntime_cxx_api.h:2190
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:1252
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.
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.
AllocatedStringPtr GetInputNameAllocated(size_t index, OrtAllocator *allocator) const
Returns a copy of input name at the specified index.
std::vector< ValueInfo > GetInputs() const
TypeInfo GetOverridableInitializerTypeInfo(size_t index) const
Wraps OrtApi::SessionGetOverridableInitializerTypeInfo.
Definition onnxruntime_cxx_api.h:1639
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:817
const char * EpName() const
const char * EpVendor() const
ConstKeyValuePairs EpOptions() const
ConstHardwareDevice Device() const
ConstKeyValuePairs EpMetadata() const
Definition onnxruntime_cxx_api.h:798
OrtHardwareDeviceType Type() const
const char * Vendor() const
ConstKeyValuePairs Metadata() const
Definition onnxruntime_cxx_api.h:2201
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:759
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:1546
ONNXTensorElementDataType GetMapKeyType() const
Wraps OrtApi::GetMapKeyType.
TypeInfo GetMapValueType() const
Wraps OrtApi::GetMapValueType.
Definition onnxruntime_cxx_api.h:1429
std::string GetAllocatorName() const
OrtMemType GetMemoryType() const
OrtMemoryInfoDeviceType GetDeviceType() const
OrtAllocatorType GetAllocatorType() const
bool operator==(const MemoryInfoImpl< U > &o) const
Definition onnxruntime_cxx_api.h:2851
void AddGraph(Graph &graph)
Definition onnxruntime_cxx_api.h:2785
Definition onnxruntime_cxx_api.h:1533
TypeInfo GetOptionalElementType() const
Wraps OrtApi::CastOptionalTypeToContainedTypeInfo.
Definition onnxruntime_cxx_api.h:1622
const char ** str
Definition onnxruntime_cxx_api.h:1627
const int64_t * values_shape
Definition onnxruntime_cxx_api.h:1623
size_t values_shape_len
Definition onnxruntime_cxx_api.h:1624
const void * p_data
Definition onnxruntime_cxx_api.h:1626
Definition onnxruntime_cxx_api.h:1509
TypeInfo GetSequenceElementType() const
Wraps OrtApi::GetSequenceElementType.
Definition onnxruntime_cxx_api.h:1306
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:1633
const int64_t * shape
Definition onnxruntime_cxx_api.h:1634
size_t shape_len
Definition onnxruntime_cxx_api.h:1635
Definition onnxruntime_cxx_api.h:1460
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.
Definition onnxruntime_cxx_api.h:1571
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:587
T Type
Definition onnxruntime_cxx_api.h:588
Definition onnxruntime_cxx_api.h:1808
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...
Definition onnxruntime_cxx_api.h:2757
ConstTypeInfo TypeInfo() const
std::string Name() const
Memory allocation interface.
Definition onnxruntime_c_api.h:332
void(* Free)(struct OrtAllocator *this_, void *p)
Free a block of memory previously allocated with OrtAllocator::Alloc.
Definition onnxruntime_c_api.h:335
const OrtApi *(* GetApi)(uint32_t version)
Get a pointer to the requested version of the OrtApi.
Definition onnxruntime_c_api.h:785
The C API.
Definition onnxruntime_c_api.h:845
const OrtCompileApi *(* GetCompileApi)()
Get the Compile API instance.
Definition onnxruntime_c_api.h:5033
const OrtModelEditorApi *(* GetModelEditorApi)()
Get the Model Editor API instance.
Definition onnxruntime_c_api.h:4975
const OrtEpApi *(* GetEpApi)()
Get the OrtEpApi instance for implementing an execution provider.
Definition onnxruntime_c_api.h:5299
CUDA Provider Options.
Definition onnxruntime_c_api.h:489
The OrtCompileApi struct provides functions to compile ONNX models.
Definition onnxruntime_c_api.h:5885
Definition onnxruntime_c_api.h:5358
int(* GetVariadicInputHomogeneity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:5404
OrtCustomOpInputOutputCharacteristic(* GetOutputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:5388
size_t(* GetInputTypeCount)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:5376
int(* GetVariadicOutputMinArity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:5408
size_t(* GetAliasMap)(int **input_index, int **output_index)
Definition onnxruntime_c_api.h:5441
int(* GetStartVersion)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:5426
void(* ReleaseMayInplace)(int *input_index, int *output_index)
Definition onnxruntime_c_api.h:5438
const char *(* GetName)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:5369
size_t(* GetOutputTypeCount)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:5378
void(* KernelDestroy)(void *op_kernel)
Definition onnxruntime_c_api.h:5384
int(* GetVariadicOutputHomogeneity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:5413
OrtMemType(* GetInputMemoryType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:5395
void *(* CreateKernel)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info)
Definition onnxruntime_c_api.h:5365
uint32_t version
Definition onnxruntime_c_api.h:5359
ONNXTensorElementDataType(* GetInputType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:5375
void(* ReleaseAliasMap)(int *input_index, int *output_index)
Definition onnxruntime_c_api.h:5442
OrtCustomOpInputOutputCharacteristic(* GetInputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:5387
const char *(* GetExecutionProviderType)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:5372
ONNXTensorElementDataType(* GetOutputType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:5377
int(* GetVariadicInputMinArity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:5399
OrtStatusPtr(* InferOutputShapeFn)(const struct OrtCustomOp *op, OrtShapeInferContext *)
Definition onnxruntime_c_api.h:5423
int(* GetEndVersion)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:5427
OrtStatusPtr(* CreateKernelV2)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info, void **kernel)
Definition onnxruntime_c_api.h:5416
size_t(* GetMayInplace)(int **input_index, int **output_index)
Definition onnxruntime_c_api.h:5434
OrtStatusPtr(* KernelComputeV2)(void *op_kernel, OrtKernelContext *context)
Definition onnxruntime_c_api.h:5421
void(* KernelCompute)(void *op_kernel, OrtKernelContext *context)
Definition onnxruntime_c_api.h:5383
Definition onnxruntime_c_api.h:6061
The OrtEpFactory provides functions to create and manage execution providers.
Definition onnxruntime_c_api.h:6157
MIGraphX Provider Options.
Definition onnxruntime_c_api.h:693
The OrtModelEditorApi struct provides functions to create or edit an ONNX model.
Definition onnxruntime_c_api.h:5456
OpenVINO Provider Options.
Definition onnxruntime_c_api.h:731
ROCM Provider Options.
Definition onnxruntime_c_api.h:576
TensorRT Provider Options.
Definition onnxruntime_c_api.h:665