OnnxRuntime
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 <cstddef>
28#include <array>
29#include <memory>
30#include <stdexcept>
31#include <string>
32#include <vector>
33#include <unordered_map>
34#include <utility>
35#include <type_traits>
36
37#ifdef ORT_NO_EXCEPTIONS
38#include <iostream>
39#endif
40
44namespace Ort {
45
50struct Exception : std::exception {
51 Exception(std::string&& string, OrtErrorCode code) : message_{std::move(string)}, code_{code} {}
52
53 OrtErrorCode GetOrtErrorCode() const { return code_; }
54 const char* what() const noexcept override { return message_.c_str(); }
55
56 private:
57 std::string message_;
58 OrtErrorCode code_;
59};
60
61#ifdef ORT_NO_EXCEPTIONS
62// The #ifndef is for the very special case where the user of this library wants to define their own way of handling errors.
63// NOTE: This header expects control flow to not continue after calling ORT_CXX_API_THROW
64#ifndef ORT_CXX_API_THROW
65#define ORT_CXX_API_THROW(string, code) \
66 do { \
67 std::cerr << Ort::Exception(string, code) \
68 .what() \
69 << std::endl; \
70 abort(); \
71 } while (false)
72#endif
73#else
74#define ORT_CXX_API_THROW(string, code) \
75 throw Ort::Exception(string, code)
76#endif
77
78// This is used internally by the C++ API. This class holds the global variable that points to the OrtApi,
79// it's in a template so that we can define a global variable in a header and make
80// it transparent to the users of the API.
81template <typename T>
82struct Global {
83 static const OrtApi* api_;
84};
85
86// If macro ORT_API_MANUAL_INIT is defined, no static initialization will be performed. Instead, user must call InitApi() before using it.
87template <typename T>
88#ifdef ORT_API_MANUAL_INIT
89const OrtApi* Global<T>::api_{};
90inline void InitApi() { Global<void>::api_ = OrtGetApiBase()->GetApi(ORT_API_VERSION); }
91
92// Used by custom operator libraries that are not linked to onnxruntime. Sets the global API object, which is
93// required by C++ APIs.
94//
95// Example mycustomop.cc:
96//
97// #define ORT_API_MANUAL_INIT
98// #include <onnxruntime_cxx_api.h>
99// #undef ORT_API_MANUAL_INIT
100//
101// OrtStatus* ORT_API_CALL RegisterCustomOps(OrtSessionOptions* options, const OrtApiBase* api_base) {
102// Ort::InitApi(api_base->GetApi(ORT_API_VERSION));
103// // ...
104// }
105//
106inline void InitApi(const OrtApi* api) { Global<void>::api_ = api; }
107#else
108#if defined(_MSC_VER) && !defined(__clang__)
109#pragma warning(push)
110// "Global initializer calls a non-constexpr function." Therefore you can't use ORT APIs in the other global initializers.
111// Please define ORT_API_MANUAL_INIT if it conerns you.
112#pragma warning(disable : 26426)
113#endif
115#if defined(_MSC_VER) && !defined(__clang__)
116#pragma warning(pop)
117#endif
118#endif
119
121inline const OrtApi& GetApi() { return *Global<void>::api_; }
122
128std::vector<std::string> GetAvailableProviders();
129
169struct Float16_t {
170 uint16_t value;
171 constexpr Float16_t() noexcept : value(0) {}
172 constexpr Float16_t(uint16_t v) noexcept : value(v) {}
173 constexpr operator uint16_t() const noexcept { return value; }
174 constexpr bool operator==(const Float16_t& rhs) const noexcept { return value == rhs.value; };
175 constexpr bool operator!=(const Float16_t& rhs) const noexcept { return value != rhs.value; };
176};
177
178static_assert(sizeof(Float16_t) == sizeof(uint16_t), "Sizes must match");
179
189 uint16_t value;
190 constexpr BFloat16_t() noexcept : value(0) {}
191 constexpr BFloat16_t(uint16_t v) noexcept : value(v) {}
192 constexpr operator uint16_t() const noexcept { return value; }
193 constexpr bool operator==(const BFloat16_t& rhs) const noexcept { return value == rhs.value; };
194 constexpr bool operator!=(const BFloat16_t& rhs) const noexcept { return value != rhs.value; };
195};
196
197static_assert(sizeof(BFloat16_t) == sizeof(uint16_t), "Sizes must match");
198
199namespace detail {
200// 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
201// This can't be done in the C API since C doesn't have function overloading.
202#define ORT_DEFINE_RELEASE(NAME) \
203 inline void OrtRelease(Ort##NAME* ptr) { GetApi().Release##NAME(ptr); }
204
205ORT_DEFINE_RELEASE(Allocator);
206ORT_DEFINE_RELEASE(MemoryInfo);
207ORT_DEFINE_RELEASE(CustomOpDomain);
208ORT_DEFINE_RELEASE(ThreadingOptions);
209ORT_DEFINE_RELEASE(Env);
210ORT_DEFINE_RELEASE(RunOptions);
211ORT_DEFINE_RELEASE(Session);
212ORT_DEFINE_RELEASE(SessionOptions);
213ORT_DEFINE_RELEASE(TensorTypeAndShapeInfo);
214ORT_DEFINE_RELEASE(SequenceTypeInfo);
215ORT_DEFINE_RELEASE(MapTypeInfo);
216ORT_DEFINE_RELEASE(TypeInfo);
217ORT_DEFINE_RELEASE(Value);
218ORT_DEFINE_RELEASE(ModelMetadata);
219ORT_DEFINE_RELEASE(IoBinding);
220ORT_DEFINE_RELEASE(ArenaCfg);
221ORT_DEFINE_RELEASE(Status);
222ORT_DEFINE_RELEASE(OpAttr);
223ORT_DEFINE_RELEASE(Op);
224ORT_DEFINE_RELEASE(KernelInfo);
225
226#undef ORT_DEFINE_RELEASE
227
231template <typename T>
232struct Unowned {
233 using Type = T;
234};
235
255template <typename T>
256struct Base {
257 using contained_type = T;
258
259 constexpr Base() = default;
260 constexpr explicit Base(contained_type* p) noexcept : p_{p} {}
262
263 Base(const Base&) = delete;
264 Base& operator=(const Base&) = delete;
265
266 Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }
267 Base& operator=(Base&& v) noexcept {
268 OrtRelease(p_);
269 p_ = v.release();
270 return *this;
271 }
272
273 constexpr operator contained_type*() const noexcept { return p_; }
274
278 T* p = p_;
279 p_ = nullptr;
280 return p;
281 }
282
283 protected:
285};
286
287// Undefined. For const types use Base<Unowned<const T>>
288template <typename T>
289struct Base<const T>;
290
298template <typename T>
299struct Base<Unowned<T>> {
301
302 constexpr Base() = default;
303 constexpr explicit Base(contained_type* p) noexcept : p_{p} {}
304
305 ~Base() = default;
306
307 Base(const Base&) = default;
308 Base& operator=(const Base&) = default;
309
310 Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }
311 Base& operator=(Base&& v) noexcept {
312 p_ = nullptr;
313 std::swap(p_, v.p_);
314 return *this;
315 }
316
317 constexpr operator contained_type*() const noexcept { return p_; }
318
319 protected:
321};
322
323// Light functor to release memory with OrtAllocator
326 explicit AllocatedFree(OrtAllocator* allocator)
327 : allocator_(allocator) {}
328 void operator()(void* ptr) const {
329 if (ptr) allocator_->Free(allocator_, ptr);
330 }
331};
332
333} // namespace detail
334
335struct AllocatorWithDefaultOptions;
336struct Env;
337struct TypeInfo;
338struct Value;
339struct ModelMetadata;
340
345using AllocatedStringPtr = std::unique_ptr<char, detail::AllocatedFree>;
346
351struct Status : detail::Base<OrtStatus> {
352 explicit Status(std::nullptr_t) {}
353 explicit Status(OrtStatus* status);
354 explicit Status(const Exception&);
355 explicit Status(const std::exception&);
356 std::string GetErrorMessage() const;
358};
359
364struct ThreadingOptions : detail::Base<OrtThreadingOptions> {
367
370
373
376
379
382
384 ThreadingOptions& SetGlobalCustomThreadCreationOptions(void* ort_custom_thread_creation_options);
385
388};
389
395struct Env : detail::Base<OrtEnv> {
396 explicit Env(std::nullptr_t) {}
397
399 Env(OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
400
402 Env(OrtLoggingLevel logging_level, const char* logid, OrtLoggingFunction logging_function, void* logger_param);
403
405 Env(const OrtThreadingOptions* tp_options, OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
406
408 Env(const OrtThreadingOptions* tp_options, OrtLoggingFunction logging_function, void* logger_param,
409 OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
410
412 explicit Env(OrtEnv* p) : Base<OrtEnv>{p} {}
413
416
418
419 Env& CreateAndRegisterAllocator(const OrtMemoryInfo* mem_info, const OrtArenaCfg* arena_cfg);
420};
421
425struct CustomOpDomain : detail::Base<OrtCustomOpDomain> {
426 explicit CustomOpDomain(std::nullptr_t) {}
427
429 explicit CustomOpDomain(const char* domain);
430
431 // This does not take ownership of the op, simply registers it.
432 void Add(const OrtCustomOp* op);
433};
434
438struct RunOptions : detail::Base<OrtRunOptions> {
439 explicit RunOptions(std::nullptr_t) {}
441
444
447
448 RunOptions& SetRunTag(const char* run_tag);
449 const char* GetRunTag() const;
450
451 RunOptions& AddConfigEntry(const char* config_key, const char* config_value);
452
459
465};
466
467
468namespace detail {
469// Utility function that returns a SessionOption config entry key for a specific custom operator.
470// Ex: custom_op.[custom_op_name].[config]
471std::string MakeCustomOpConfigEntryKey(const char* custom_op_name, const char* config);
472} // namespace detail
473
484 CustomOpConfigs() = default;
485 ~CustomOpConfigs() = default;
490
499 CustomOpConfigs& AddConfig(const char* custom_op_name, const char* config_key, const char* config_value);
500
509 const std::unordered_map<std::string, std::string>& GetFlattenedConfigs() const;
510
511 private:
512 std::unordered_map<std::string, std::string> flat_configs_;
513};
514
520struct SessionOptions;
521
522namespace detail {
523// we separate const-only methods because passing const ptr to non-const methods
524// is only discovered when inline methods are compiled which is counter-intuitive
525template <typename T>
527 using B = Base<T>;
528 using B::B;
529
531
532 std::string GetConfigEntry(const char* config_key) const;
533 bool HasConfigEntry(const char* config_key) const;
534 std::string GetConfigEntryOrDefault(const char* config_key, const std::string& def);
535};
536
537template <typename T>
540 using B::B;
541
542 SessionOptionsImpl& SetIntraOpNumThreads(int intra_op_num_threads);
543 SessionOptionsImpl& SetInterOpNumThreads(int inter_op_num_threads);
545
548
549 SessionOptionsImpl& SetOptimizedModelFilePath(const ORTCHAR_T* optimized_model_file);
550
551 SessionOptionsImpl& EnableProfiling(const ORTCHAR_T* profile_file_prefix);
553
555
558
560
561 SessionOptionsImpl& SetLogId(const char* logid);
563
565
567
568 SessionOptionsImpl& AddConfigEntry(const char* config_key, const char* config_value);
569
570 SessionOptionsImpl& AddInitializer(const char* name, const OrtValue* ort_val);
571 SessionOptionsImpl& AddExternalInitializers(const std::vector<std::string>& names, const std::vector<Value>& ort_values);
572
585 SessionOptionsImpl& AppendExecutionProvider(const std::string& provider_name,
586 const std::unordered_map<std::string, std::string>& provider_options = {});
587
589 SessionOptionsImpl& SetCustomThreadCreationOptions(void* ort_custom_thread_creation_options);
591
595 SessionOptionsImpl& RegisterCustomOpsLibrary(const ORTCHAR_T* library_name, const CustomOpConfigs& custom_op_configs = {});
596
598};
599} // namespace detail
600
603
607struct SessionOptions : detail::SessionOptionsImpl<OrtSessionOptions> {
608 explicit SessionOptions(std::nullptr_t) {}
610 explicit SessionOptions(OrtSessionOptions* p) : SessionOptionsImpl<OrtSessionOptions>{p} {}
613};
614
618struct ModelMetadata : detail::Base<OrtModelMetadata> {
619 explicit ModelMetadata(std::nullptr_t) {}
621
629
637
645
653
661
668 std::vector<AllocatedStringPtr> GetCustomMetadataMapKeysAllocated(OrtAllocator* allocator) const;
669
680
681 int64_t GetVersion() const;
682};
683
684struct IoBinding;
685
686namespace detail {
687
688// we separate const-only methods because passing const ptr to non-const methods
689// is only discovered when inline methods are compiled which is counter-intuitive
690template <typename T>
692 using B = Base<T>;
693 using B::B;
694
695 size_t GetInputCount() const;
696 size_t GetOutputCount() const;
698
707
716
725
726 uint64_t GetProfilingStartTimeNs() const;
728
729 TypeInfo GetInputTypeInfo(size_t index) const;
730 TypeInfo GetOutputTypeInfo(size_t index) const;
732};
733
734template <typename T>
737 using B::B;
738
756 std::vector<Value> Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
757 const char* const* output_names, size_t output_count);
758
762 void Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
763 const char* const* output_names, Value* output_values, size_t output_count);
764
765 void Run(const RunOptions& run_options, const IoBinding&);
766
774};
775
776} // namespace detail
777
780
784struct Session : detail::SessionImpl<OrtSession> {
785 explicit Session(std::nullptr_t) {}
786 Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
787 Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options,
788 OrtPrepackedWeightsContainer* prepacked_weights_container);
789 Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options);
790 Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options,
791 OrtPrepackedWeightsContainer* prepacked_weights_container);
792
793 ConstSession GetConst() const { return ConstSession{this->p_}; }
794 UnownedSession GetUnowned() const { return UnownedSession{this->p_}; }
795};
796
797namespace detail {
798template <typename T>
799struct MemoryInfoImpl : Base<T> {
800 using B = Base<T>;
801 using B::B;
802
803 std::string GetAllocatorName() const;
805 int GetDeviceId() const;
808
809 template <typename U>
810 bool operator==(const MemoryInfoImpl<U>& o) const;
811};
812} // namespace detail
813
814// Const object holder that does not own the underlying object
816
820struct MemoryInfo : detail::MemoryInfoImpl<OrtMemoryInfo> {
822 explicit MemoryInfo(std::nullptr_t) {}
823 explicit MemoryInfo(OrtMemoryInfo* p) : MemoryInfoImpl<OrtMemoryInfo>{p} {}
824 MemoryInfo(const char* name, OrtAllocatorType type, int id, OrtMemType mem_type);
825 ConstMemoryInfo GetConst() const { return ConstMemoryInfo{this->p_}; }
826};
827
828namespace detail {
829template <typename T>
831 using B = Base<T>;
832 using B::B;
833
835 size_t GetElementCount() const;
836
837 size_t GetDimensionsCount() const;
838
843 [[deprecated("use GetShape()")]] void GetDimensions(int64_t* values, size_t values_count) const;
844
845 void GetSymbolicDimensions(const char** values, size_t values_count) const;
846
847 std::vector<int64_t> GetShape() const;
848};
849
850} // namespace detail
851
853
858 explicit TensorTypeAndShapeInfo(std::nullptr_t) {}
859 explicit TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* p) : TensorTypeAndShapeInfoImpl{p} {}
861};
862
863namespace detail {
864template <typename T>
866 using B = Base<T>;
867 using B::B;
869};
870
871} // namespace detail
872
874
878struct SequenceTypeInfo : detail::SequenceTypeInfoImpl<OrtSequenceTypeInfo> {
879 explicit SequenceTypeInfo(std::nullptr_t) {}
880 explicit SequenceTypeInfo(OrtSequenceTypeInfo* p) : SequenceTypeInfoImpl<OrtSequenceTypeInfo>{p} {}
882};
883
884namespace detail {
885template <typename T>
887 using B = Base<T>;
888 using B::B;
891};
892
893} // namespace detail
894
896
900struct MapTypeInfo : detail::MapTypeInfoImpl<OrtMapTypeInfo> {
901 explicit MapTypeInfo(std::nullptr_t) {}
902 explicit MapTypeInfo(OrtMapTypeInfo* p) : MapTypeInfoImpl<OrtMapTypeInfo>{p} {}
903 ConstMapTypeInfo GetConst() const { return ConstMapTypeInfo{this->p_}; }
904};
905
906namespace detail {
907template <typename T>
909 using B = Base<T>;
910 using B::B;
911
915
917};
918} // namespace detail
919
925
930struct TypeInfo : detail::TypeInfoImpl<OrtTypeInfo> {
931 explicit TypeInfo(std::nullptr_t) {}
932 explicit TypeInfo(OrtTypeInfo* p) : TypeInfoImpl<OrtTypeInfo>{p} {}
933
934 ConstTypeInfo GetConst() const { return ConstTypeInfo{this->p_}; }
935};
936
937namespace detail {
938// This structure is used to feed sparse tensor values
939// information for use with FillSparseTensor<Format>() API
940// if the data type for the sparse tensor values is numeric
941// use data.p_data, otherwise, use data.str pointer to feed
942// values. data.str is an array of const char* that are zero terminated.
943// number of strings in the array must match shape size.
944// For fully sparse tensors use shape {0} and set p_data/str
945// to nullptr.
947 const int64_t* values_shape;
949 union {
950 const void* p_data;
951 const char** str;
953};
954
955// Provides a way to pass shape in a single
956// argument
957struct Shape {
958 const int64_t* shape;
959 size_t shape_len;
960};
961
962template <typename T>
963struct ConstValueImpl : Base<T> {
964 using B = Base<T>;
965 using B::B;
966
970 template <typename R>
971 void GetOpaqueData(const char* domain, const char* type_name, R&) const;
972
973 bool IsTensor() const;
974 bool HasValue() const;
975
976 size_t GetCount() const; // If a non tensor, returns 2 for map and N for sequence, where N is the number of elements
977 Value GetValue(int index, OrtAllocator* allocator) const;
978
986
1001 void GetStringTensorContent(void* buffer, size_t buffer_length, size_t* offsets, size_t offsets_count) const;
1002
1009 template <typename R>
1010 const R* GetTensorData() const;
1011
1016 const void* GetTensorRawData() const;
1017
1025
1033
1039
1048 void GetStringTensorElement(size_t buffer_length, size_t element_index, void* buffer) const;
1049
1056 size_t GetStringTensorElementLength(size_t element_index) const;
1057
1058#if !defined(DISABLE_SPARSE_TENSORS)
1066
1073
1082
1092 template <typename R>
1093 const R* GetSparseTensorIndicesData(OrtSparseIndicesFormat indices_format, size_t& num_indices) const;
1094
1099 bool IsSparseTensor() const;
1100
1109 template <typename R>
1110 const R* GetSparseTensorValues() const;
1111
1112#endif
1113};
1114
1115template <typename T>
1118 using B::B;
1119
1125 template <typename R>
1127
1133
1135 // Obtain a reference to an element of data at the location specified
1141 template <typename R>
1142 R& At(const std::vector<int64_t>& location);
1143
1149 void FillStringTensor(const char* const* s, size_t s_len);
1150
1156 void FillStringTensorElement(const char* s, size_t index);
1157
1158#if !defined(DISABLE_SPARSE_TENSORS)
1167 void UseCooIndices(int64_t* indices_data, size_t indices_num);
1168
1179 void UseCsrIndices(int64_t* inner_data, size_t inner_num, int64_t* outer_data, size_t outer_num);
1180
1189 void UseBlockSparseIndices(const Shape& indices_shape, int32_t* indices_data);
1190
1200 void FillSparseTensorCoo(const OrtMemoryInfo* data_mem_info, const OrtSparseValuesParam& values_param,
1201 const int64_t* indices_data, size_t indices_num);
1202
1214 void FillSparseTensorCsr(const OrtMemoryInfo* data_mem_info,
1215 const OrtSparseValuesParam& values,
1216 const int64_t* inner_indices_data, size_t inner_indices_num,
1217 const int64_t* outer_indices_data, size_t outer_indices_num);
1218
1229 const OrtSparseValuesParam& values,
1230 const Shape& indices_shape,
1231 const int32_t* indices_data);
1232
1233#endif
1234};
1235
1236} // namespace detail
1237
1240
1244struct Value : detail::ValueImpl<OrtValue> {
1248
1249 explicit Value(std::nullptr_t) {}
1250 explicit Value(OrtValue* p) : Base{p} {}
1251 Value(Value&&) = default;
1252 Value& operator=(Value&&) = default;
1253
1254 ConstValue GetConst() const { return ConstValue{this->p_}; }
1255 UnownedValue GetUnowned() const { return UnownedValue{this->p_}; }
1256
1265 template <typename T>
1266 static Value CreateTensor(const OrtMemoryInfo* info, T* p_data, size_t p_data_element_count, const int64_t* shape, size_t shape_len);
1267
1276 static Value CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count, const int64_t* shape, size_t shape_len,
1278
1285 template <typename T>
1286 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len);
1287
1294 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type);
1295
1296 static Value CreateMap(Value& keys, Value& values);
1297 static Value CreateSequence(std::vector<Value>& values);
1298
1299 template <typename T>
1300 static Value CreateOpaque(const char* domain, const char* type_name, const T&);
1301
1302#if !defined(DISABLE_SPARSE_TENSORS)
1313 template <typename T>
1314 static Value CreateSparseTensor(const OrtMemoryInfo* info, T* p_data, const Shape& dense_shape,
1315 const Shape& values_shape);
1316
1333 static Value CreateSparseTensor(const OrtMemoryInfo* info, void* p_data, const Shape& dense_shape,
1334 const Shape& values_shape, ONNXTensorElementDataType type);
1335
1345 template <typename T>
1346 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape);
1347
1359 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape, ONNXTensorElementDataType type);
1360
1361#endif // !defined(DISABLE_SPARSE_TENSORS)
1362};
1363
1371 MemoryAllocation(OrtAllocator* allocator, void* p, size_t size);
1376 MemoryAllocation& operator=(MemoryAllocation&&) noexcept;
1377
1378 void* get() { return p_; }
1379 size_t size() const { return size_; }
1380
1381 private:
1382 OrtAllocator* allocator_;
1383 void* p_;
1384 size_t size_;
1385};
1386
1387namespace detail {
1388template <typename T>
1389struct AllocatorImpl : Base<T> {
1390 using B = Base<T>;
1391 using B::B;
1392
1393 void* Alloc(size_t size);
1395 void Free(void* p);
1397};
1398
1399} // namespace detail
1400
1404struct AllocatorWithDefaultOptions : detail::AllocatorImpl<detail::Unowned<OrtAllocator>> {
1405 explicit AllocatorWithDefaultOptions(std::nullptr_t) {}
1407};
1408
1412struct Allocator : detail::AllocatorImpl<OrtAllocator> {
1413 explicit Allocator(std::nullptr_t) {}
1414 Allocator(const Session& session, const OrtMemoryInfo*);
1415};
1416
1418
1419namespace detail {
1420namespace binding_utils {
1421// Bring these out of template
1422std::vector<std::string> GetOutputNamesHelper(const OrtIoBinding* binding, OrtAllocator*);
1423std::vector<Value> GetOutputValuesHelper(const OrtIoBinding* binding, OrtAllocator*);
1424} // namespace binding_utils
1425
1426template <typename T>
1428 using B = Base<T>;
1429 using B::B;
1430
1431 std::vector<std::string> GetOutputNames() const;
1432 std::vector<std::string> GetOutputNames(OrtAllocator*) const;
1433 std::vector<Value> GetOutputValues() const;
1434 std::vector<Value> GetOutputValues(OrtAllocator*) const;
1435};
1436
1437template <typename T>
1440 using B::B;
1441
1442 void BindInput(const char* name, const Value&);
1443 void BindOutput(const char* name, const Value&);
1444 void BindOutput(const char* name, const OrtMemoryInfo*);
1449};
1450
1451} // namespace detail
1452
1455
1459struct IoBinding : detail::IoBindingImpl<OrtIoBinding> {
1460 explicit IoBinding(std::nullptr_t) {}
1461 explicit IoBinding(Session& session);
1462 ConstIoBinding GetConst() const { return ConstIoBinding{this->p_}; }
1464};
1465
1470struct ArenaCfg : detail::Base<OrtArenaCfg> {
1471 explicit ArenaCfg(std::nullptr_t) {}
1480 ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk);
1481};
1482
1483//
1484// Custom OPs (only needed to implement custom OPs)
1485//
1486
1490struct OpAttr : detail::Base<OrtOpAttr> {
1491 OpAttr(const char* name, const void* data, int len, OrtOpAttrType type);
1492};
1493
1502 size_t GetInputCount() const;
1503 size_t GetOutputCount() const;
1504 ConstValue GetInput(size_t index) const;
1505 UnownedValue GetOutput(size_t index, const int64_t* dim_values, size_t dim_count) const;
1506 UnownedValue GetOutput(size_t index, const std::vector<int64_t>& dims) const;
1507 void* GetGPUComputeStream() const;
1508
1509 private:
1510 OrtKernelContext* ctx_;
1511};
1512
1513struct KernelInfo;
1514
1515namespace detail {
1516namespace attr_utils {
1517void GetAttr(const OrtKernelInfo* p, const char* name, float&);
1518void GetAttr(const OrtKernelInfo* p, const char* name, int64_t&);
1519void GetAttr(const OrtKernelInfo* p, const char* name, std::string&);
1520void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<float>&);
1521void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<int64_t>&);
1522} // namespace attr_utils
1523
1524template <typename T>
1526 using B = Base<T>;
1527 using B::B;
1528
1530
1531 template <typename R> // R is only implemented for float, int64_t, and string
1532 R GetAttribute(const char* name) const {
1533 R val;
1534 attr_utils::GetAttr(this->p_, name, val);
1535 return val;
1536 }
1537
1538 template <typename R> // R is only implemented for std::vector<float>, std::vector<int64_t>
1539 std::vector<R> GetAttributes(const char* name) const {
1540 std::vector<R> result;
1541 attr_utils::GetAttrs(this->p_, name, result);
1542 return result;
1543 }
1544
1545 Value GetTensorAttribute(const char* name, OrtAllocator* allocator) const;
1546
1547 size_t GetInputCount() const;
1548 size_t GetOutputCount() const;
1549
1550 std::string GetInputName(size_t index) const;
1551 std::string GetOutputName(size_t index) const;
1552
1553 TypeInfo GetInputTypeInfo(size_t index) const;
1554 TypeInfo GetOutputTypeInfo(size_t index) const;
1555};
1556
1557} // namespace detail
1558
1560
1567struct KernelInfo : detail::KernelInfoImpl<OrtKernelInfo> {
1568 explicit KernelInfo(std::nullptr_t) {}
1569 explicit KernelInfo(OrtKernelInfo* info);
1570 ConstKernelInfo GetConst() const { return ConstKernelInfo{this->p_}; }
1571};
1572
1576struct Op : detail::Base<OrtOp> {
1577 explicit Op(std::nullptr_t) {}
1578
1579 explicit Op(OrtOp*);
1580
1581 static Op Create(const OrtKernelInfo* info, const char* op_name, const char* domain,
1582 int version, const char** type_constraint_names,
1583 const ONNXTensorElementDataType* type_constraint_values,
1584 size_t type_constraint_count,
1585 const OpAttr* attr_values,
1586 size_t attr_count,
1587 size_t input_count, size_t output_count);
1588
1589 void Invoke(const OrtKernelContext* context,
1590 const Value* input_values,
1591 size_t input_count,
1592 Value* output_values,
1593 size_t output_count);
1594
1595 // For easier refactoring
1596 void Invoke(const OrtKernelContext* context,
1597 const OrtValue* const* input_values,
1598 size_t input_count,
1599 OrtValue* const* output_values,
1600 size_t output_count);
1601};
1602
1608 CustomOpApi(const OrtApi& api) : api_(api) {}
1609
1614 [[deprecated("use Ort::Value::GetTensorTypeAndShape()")]] OrtTensorTypeAndShapeInfo* GetTensorTypeAndShape(_In_ const OrtValue* value);
1615
1620 [[deprecated("use Ort::TensorTypeAndShapeInfo::GetElementCount()")]] size_t GetTensorShapeElementCount(_In_ const OrtTensorTypeAndShapeInfo* info);
1621
1626 [[deprecated("use Ort::TensorTypeAndShapeInfo::GetElementType()")]] ONNXTensorElementDataType GetTensorElementType(const OrtTensorTypeAndShapeInfo* info);
1627
1632 [[deprecated("use Ort::TensorTypeAndShapeInfo::GetDimensionsCount()")]] size_t GetDimensionsCount(_In_ const OrtTensorTypeAndShapeInfo* info);
1633
1638 [[deprecated("use Ort::TensorTypeAndShapeInfo::GetShape()")]] void GetDimensions(_In_ const OrtTensorTypeAndShapeInfo* info, _Out_ int64_t* dim_values, size_t dim_values_length);
1639
1644 [[deprecated("Do not use")]] void SetDimensions(OrtTensorTypeAndShapeInfo* info, _In_ const int64_t* dim_values, size_t dim_count);
1645
1650 template <typename T>
1651 [[deprecated("use Ort::Value::GetTensorMutableData()")]] T* GetTensorMutableData(_Inout_ OrtValue* value);
1652
1657 template <typename T>
1658 [[deprecated("use Ort::Value::GetTensorData()")]] const T* GetTensorData(_Inout_ const OrtValue* value);
1659
1664 [[deprecated("use Ort::Value::GetTensorMemoryInfo()")]] const OrtMemoryInfo* GetTensorMemoryInfo(_In_ const OrtValue* value);
1665
1670 [[deprecated("use Ort::TensorTypeAndShapeInfo::GetShape()")]] std::vector<int64_t> GetTensorShape(const OrtTensorTypeAndShapeInfo* info);
1671
1676 [[deprecated("use TensorTypeAndShapeInfo")]] void ReleaseTensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* input);
1677
1682 [[deprecated("use Ort::KernelContext::GetInputCount")]] size_t KernelContext_GetInputCount(const OrtKernelContext* context);
1683
1688 [[deprecated("use Ort::KernelContext::GetInput")]] const OrtValue* KernelContext_GetInput(const OrtKernelContext* context, _In_ size_t index);
1689
1694 [[deprecated("use Ort::KernelContext::GetOutputCount")]] size_t KernelContext_GetOutputCount(const OrtKernelContext* context);
1695
1700 [[deprecated("use Ort::KernelContext::GetOutput")]] OrtValue* KernelContext_GetOutput(OrtKernelContext* context, _In_ size_t index, _In_ const int64_t* dim_values, size_t dim_count);
1701
1706 [[deprecated("use Ort::KernelContext::GetGPUComputeStream")]] void* KernelContext_GetGPUComputeStream(const OrtKernelContext* context);
1707
1712 [[deprecated("use Ort::ThrowOnError()")]] void ThrowOnError(OrtStatus* result);
1713
1718 [[deprecated("use Ort::OpAttr")]] OrtOpAttr* CreateOpAttr(_In_ const char* name,
1719 _In_ const void* data,
1720 _In_ int len,
1721 _In_ OrtOpAttrType type);
1722
1727 [[deprecated("use Ort::OpAttr")]] void ReleaseOpAttr(_Frees_ptr_opt_ OrtOpAttr* op_attr);
1728
1733 [[deprecated("use Ort::Op")]] OrtOp* CreateOp(_In_ const OrtKernelInfo* info,
1734 _In_ const char* op_name,
1735 _In_ const char* domain,
1736 _In_ int version,
1737 _In_opt_ const char** type_constraint_names,
1738 _In_opt_ const ONNXTensorElementDataType* type_constraint_values,
1739 _In_opt_ int type_constraint_count,
1740 _In_opt_ const OrtOpAttr* const* attr_values,
1741 _In_opt_ int attr_count,
1742 _In_ int input_count,
1743 _In_ int output_count);
1744
1749 [[deprecated("use Ort::Op::Invoke")]] void InvokeOp(_In_ const OrtKernelContext* context,
1750 _In_ const OrtOp* ort_op,
1751 _In_ const OrtValue* const* input_values,
1752 _In_ int input_count,
1753 _Inout_ OrtValue* const* output_values,
1754 _In_ int output_count);
1755
1760 [[deprecated("use Ort::Op")]] void ReleaseOp(_Frees_ptr_opt_ OrtOp* ort_op);
1761
1767 template <typename T> // T is only implemented for std::vector<float>, std::vector<int64_t>, float, int64_t, and string
1768 [[deprecated("use Ort::KernelInfo::GetAttribute")]] T KernelInfoGetAttribute(_In_ const OrtKernelInfo* info, _In_ const char* name);
1769
1775 [[deprecated("use Ort::KernelInfo::Copy")]] OrtKernelInfo* CopyKernelInfo(_In_ const OrtKernelInfo* info);
1776
1782 [[deprecated("use Ort::KernelInfo")]] void ReleaseKernelInfo(_Frees_ptr_opt_ OrtKernelInfo* info_copy);
1783
1784 private:
1785 const OrtApi& api_;
1786};
1787
1788template <typename TOp, typename TKernel>
1792 OrtCustomOp::CreateKernel = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info) { return static_cast<const TOp*>(this_)->CreateKernel(*api, info); };
1793 OrtCustomOp::GetName = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetName(); };
1794
1795 OrtCustomOp::GetExecutionProviderType = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetExecutionProviderType(); };
1796
1797 OrtCustomOp::GetInputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetInputTypeCount(); };
1798 OrtCustomOp::GetInputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputType(index); };
1799 OrtCustomOp::GetInputMemoryType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputMemoryType(index); };
1800
1801 OrtCustomOp::GetOutputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetOutputTypeCount(); };
1802 OrtCustomOp::GetOutputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputType(index); };
1803
1804 OrtCustomOp::KernelCompute = [](void* op_kernel, OrtKernelContext* context) { static_cast<TKernel*>(op_kernel)->Compute(context); };
1805#if defined(_MSC_VER) && !defined(__clang__)
1806#pragma warning(push)
1807#pragma warning(disable : 26409)
1808#endif
1809 OrtCustomOp::KernelDestroy = [](void* op_kernel) { delete static_cast<TKernel*>(op_kernel); };
1810#if defined(_MSC_VER) && !defined(__clang__)
1811#pragma warning(pop)
1812#endif
1813 OrtCustomOp::GetInputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputCharacteristic(index); };
1814 OrtCustomOp::GetOutputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputCharacteristic(index); };
1815
1816 OrtCustomOp::GetVariadicInputMinArity = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetVariadicInputMinArity(); };
1817 OrtCustomOp::GetVariadicInputHomogeneity = [](const OrtCustomOp* this_) { return static_cast<int>(static_cast<const TOp*>(this_)->GetVariadicInputHomogeneity()); };
1818 OrtCustomOp::GetVariadicOutputMinArity = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetVariadicOutputMinArity(); };
1819 OrtCustomOp::GetVariadicOutputHomogeneity = [](const OrtCustomOp* this_) { return static_cast<int>(static_cast<const TOp*>(this_)->GetVariadicOutputHomogeneity()); };
1820 }
1821
1822 // Default implementation of GetExecutionProviderType that returns nullptr to default to the CPU provider
1823 const char* GetExecutionProviderType() const { return nullptr; }
1824
1825 // Default implementations of GetInputCharacteristic() and GetOutputCharacteristic() below
1826 // (inputs and outputs are required by default)
1828 return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED;
1829 }
1830
1832 return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED;
1833 }
1834
1835 // Default implemention of GetInputMemoryType() that returns OrtMemTypeDefault
1836 OrtMemType GetInputMemoryType(size_t /*index*/) const {
1837 return OrtMemTypeDefault;
1838 }
1839
1840 // Default implementation of GetVariadicInputMinArity() returns 1 to specify that a variadic input
1841 // should expect at least 1 argument.
1843 return 1;
1844 }
1845
1846 // Default implementation of GetVariadicInputHomegeneity() returns true to specify that all arguments
1847 // to a variadic input should be of the same type.
1849 return true;
1850 }
1851
1852 // Default implementation of GetVariadicOutputMinArity() returns 1 to specify that a variadic output
1853 // should produce at least 1 output value.
1855 return 1;
1856 }
1857
1858 // Default implementation of GetVariadicOutputHomegeneity() returns true to specify that all output values
1859 // produced by a variadic output should be of the same type.
1861 return true;
1862 }
1863
1864 // Declare list of session config entries used by this Custom Op.
1865 // Implement this function in order to get configs from CustomOpBase::GetSessionConfigs().
1866 // This default implementation returns an empty vector of config entries.
1867 std::vector<std::string> GetSessionConfigKeys() const {
1868 return std::vector<std::string>{};
1869 }
1870
1871 protected:
1872 // Helper function that returns a map of session config entries specified by CustomOpBase::GetSessionConfigKeys.
1873 void GetSessionConfigs(std::unordered_map<std::string, std::string>& out, ConstSessionOptions options) const;
1874};
1875
1876} // namespace Ort
1877
1878#include "onnxruntime_cxx_inline.h"
struct OrtMemoryInfo OrtMemoryInfo
Definition: onnxruntime_c_api.h:252
struct OrtKernelInfo OrtKernelInfo
Definition: onnxruntime_c_api.h:329
OrtLoggingLevel
Logging severity levels.
Definition: onnxruntime_c_api.h:207
OrtMemoryInfoDeviceType
This mimics OrtDevice type constants so they can be returned in the API.
Definition: onnxruntime_c_api.h:353
void(* OrtLoggingFunction)(void *param, OrtLoggingLevel severity, const char *category, const char *logid, const char *code_location, const char *message)
Definition: onnxruntime_c_api.h:294
void(* OrtCustomJoinThreadFn)(OrtCustomThreadHandle ort_custom_thread_handle)
Custom thread join function.
Definition: onnxruntime_c_api.h:627
OrtCustomOpInputOutputCharacteristic
Definition: onnxruntime_c_api.h:3979
struct OrtTensorRTProviderOptionsV2 OrtTensorRTProviderOptionsV2
Definition: onnxruntime_c_api.h:268
struct OrtOpAttr OrtOpAttr
Definition: onnxruntime_c_api.h:273
struct OrtThreadingOptions OrtThreadingOptions
Definition: onnxruntime_c_api.h:265
struct OrtSequenceTypeInfo OrtSequenceTypeInfo
Definition: onnxruntime_c_api.h:262
struct OrtDnnlProviderOptions OrtDnnlProviderOptions
Definition: onnxruntime_c_api.h:271
OrtSparseIndicesFormat
Definition: onnxruntime_c_api.h:196
struct OrtPrepackedWeightsContainer OrtPrepackedWeightsContainer
Definition: onnxruntime_c_api.h:267
struct OrtCustomOpDomain OrtCustomOpDomain
Definition: onnxruntime_c_api.h:260
struct OrtIoBinding OrtIoBinding
Definition: onnxruntime_c_api.h:253
OrtAllocatorType
Definition: onnxruntime_c_api.h:335
struct OrtOp OrtOp
Definition: onnxruntime_c_api.h:272
struct OrtModelMetadata OrtModelMetadata
Definition: onnxruntime_c_api.h:263
struct OrtTypeInfo OrtTypeInfo
Definition: onnxruntime_c_api.h:257
struct OrtTensorTypeAndShapeInfo OrtTensorTypeAndShapeInfo
Definition: onnxruntime_c_api.h:258
struct OrtCUDAProviderOptionsV2 OrtCUDAProviderOptionsV2
Definition: onnxruntime_c_api.h:269
struct OrtKernelContext OrtKernelContext
Definition: onnxruntime_c_api.h:331
struct OrtCANNProviderOptions OrtCANNProviderOptions
Definition: onnxruntime_c_api.h:270
struct OrtSessionOptions OrtSessionOptions
Definition: onnxruntime_c_api.h:259
struct OrtValue OrtValue
Definition: onnxruntime_c_api.h:255
GraphOptimizationLevel
Graph optimization level.
Definition: onnxruntime_c_api.h:303
OrtMemType
Memory types for allocated memory, execution provider specific types should be extended in each provi...
Definition: onnxruntime_c_api.h:344
OrtSparseFormat
Definition: onnxruntime_c_api.h:188
ONNXType
Definition: onnxruntime_c_api.h:176
struct OrtEnv OrtEnv
Definition: onnxruntime_c_api.h:250
OrtErrorCode
Definition: onnxruntime_c_api.h:215
struct OrtStatus OrtStatus
Definition: onnxruntime_c_api.h:251
#define ORT_API_VERSION
The API version defined in this header.
Definition: onnxruntime_c_api.h:33
struct OrtMapTypeInfo OrtMapTypeInfo
Definition: onnxruntime_c_api.h:261
struct OrtArenaCfg OrtArenaCfg
Definition: onnxruntime_c_api.h:266
ExecutionMode
Definition: onnxruntime_c_api.h:310
OrtOpAttrType
Definition: onnxruntime_c_api.h:230
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:620
ONNXTensorElementDataType
Definition: onnxruntime_c_api.h:155
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:210
@ OrtMemTypeDefault
The default allocator for execution provider.
Definition: onnxruntime_c_api.h:348
void GetAttr(const OrtKernelInfo *p, const char *name, float &)
void GetAttrs(const OrtKernelInfo *p, const char *name, std::vector< float > &)
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:205
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:44
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:345
const OrtApi & GetApi()
This returns a reference to the OrtApi interface in use.
Definition: onnxruntime_cxx_api.h:121
std::vector< std::string > GetAvailableProviders()
This is a C++ wrapper for OrtApi::GetAvailableProviders() and returns a vector of strings representin...
Wrapper around OrtAllocator.
Definition: onnxruntime_cxx_api.h:1412
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:1413
Wrapper around OrtAllocator default instance that is owned by Onnxruntime.
Definition: onnxruntime_cxx_api.h:1404
AllocatorWithDefaultOptions(std::nullptr_t)
Convenience to create a class member and then replace with an instance.
Definition: onnxruntime_cxx_api.h:1405
it is a structure that represents the configuration of an arena based allocator
Definition: onnxruntime_cxx_api.h:1470
ArenaCfg(std::nullptr_t)
Create an empty ArenaCfg object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:1471
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:188
uint16_t value
Definition: onnxruntime_cxx_api.h:189
constexpr bool operator!=(const BFloat16_t &rhs) const noexcept
Definition: onnxruntime_cxx_api.h:194
constexpr BFloat16_t(uint16_t v) noexcept
Definition: onnxruntime_cxx_api.h:191
constexpr bool operator==(const BFloat16_t &rhs) const noexcept
Definition: onnxruntime_cxx_api.h:193
constexpr BFloat16_t() noexcept
Definition: onnxruntime_cxx_api.h:190
This entire structure is deprecated, but we not marking it as a whole yet since we want to preserve f...
Definition: onnxruntime_cxx_api.h:1607
size_t KernelContext_GetOutputCount(const OrtKernelContext *context)
size_t GetDimensionsCount(const OrtTensorTypeAndShapeInfo *info)
void * KernelContext_GetGPUComputeStream(const OrtKernelContext *context)
size_t KernelContext_GetInputCount(const OrtKernelContext *context)
void InvokeOp(const OrtKernelContext *context, const OrtOp *ort_op, const OrtValue *const *input_values, int input_count, OrtValue *const *output_values, int output_count)
OrtOpAttr * CreateOpAttr(const char *name, const void *data, int len, OrtOpAttrType type)
void ReleaseOp(OrtOp *ort_op)
OrtValue * KernelContext_GetOutput(OrtKernelContext *context, size_t index, const int64_t *dim_values, size_t dim_count)
void ReleaseTensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo *input)
T KernelInfoGetAttribute(const OrtKernelInfo *info, const char *name)
OrtTensorTypeAndShapeInfo * GetTensorTypeAndShape(const OrtValue *value)
std::vector< int64_t > GetTensorShape(const OrtTensorTypeAndShapeInfo *info)
void GetDimensions(const OrtTensorTypeAndShapeInfo *info, int64_t *dim_values, size_t dim_values_length)
void ReleaseOpAttr(OrtOpAttr *op_attr)
void ThrowOnError(OrtStatus *result)
size_t GetTensorShapeElementCount(const OrtTensorTypeAndShapeInfo *info)
ONNXTensorElementDataType GetTensorElementType(const OrtTensorTypeAndShapeInfo *info)
OrtOp * CreateOp(const OrtKernelInfo *info, const char *op_name, const char *domain, int version, const char **type_constraint_names, const ONNXTensorElementDataType *type_constraint_values, int type_constraint_count, const OrtOpAttr *const *attr_values, int attr_count, int input_count, int output_count)
CustomOpApi(const OrtApi &api)
Definition: onnxruntime_cxx_api.h:1608
void SetDimensions(OrtTensorTypeAndShapeInfo *info, const int64_t *dim_values, size_t dim_count)
OrtKernelInfo * CopyKernelInfo(const OrtKernelInfo *info)
void ReleaseKernelInfo(OrtKernelInfo *info_copy)
T * GetTensorMutableData(OrtValue *value)
const OrtValue * KernelContext_GetInput(const OrtKernelContext *context, size_t index)
const OrtMemoryInfo * GetTensorMemoryInfo(const OrtValue *value)
const T * GetTensorData(const OrtValue *value)
Definition: onnxruntime_cxx_api.h:1789
std::vector< std::string > GetSessionConfigKeys() const
Definition: onnxruntime_cxx_api.h:1867
OrtCustomOpInputOutputCharacteristic GetOutputCharacteristic(size_t) const
Definition: onnxruntime_cxx_api.h:1831
bool GetVariadicInputHomogeneity() const
Definition: onnxruntime_cxx_api.h:1848
CustomOpBase()
Definition: onnxruntime_cxx_api.h:1790
bool GetVariadicOutputHomogeneity() const
Definition: onnxruntime_cxx_api.h:1860
OrtMemType GetInputMemoryType(size_t) const
Definition: onnxruntime_cxx_api.h:1836
int GetVariadicInputMinArity() const
Definition: onnxruntime_cxx_api.h:1842
const char * GetExecutionProviderType() const
Definition: onnxruntime_cxx_api.h:1823
int GetVariadicOutputMinArity() const
Definition: onnxruntime_cxx_api.h:1854
OrtCustomOpInputOutputCharacteristic GetInputCharacteristic(size_t) const
Definition: onnxruntime_cxx_api.h:1827
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:483
~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:425
CustomOpDomain(std::nullptr_t)
Create an empty CustomOpDomain object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:426
CustomOpDomain(const char *domain)
Wraps OrtApi::CreateCustomOpDomain.
void Add(const OrtCustomOp *op)
Wraps CustomOpDomain_Add.
The Env (Environment)
Definition: onnxruntime_cxx_api.h:395
Env & EnableTelemetryEvents()
Wraps OrtApi::EnableTelemetryEvents.
Env(OrtEnv *p)
C Interop Helper.
Definition: onnxruntime_cxx_api.h:412
Env(std::nullptr_t)
Create an empty Env object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:396
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 & UpdateEnvWithCustomLogLevel(OrtLoggingLevel log_severity_level)
Wraps OrtApi::UpdateEnvWithCustomLogLevel.
Env & DisableTelemetryEvents()
Wraps OrtApi::DisableTelemetryEvents.
All C++ methods that can fail will throw an exception of this type.
Definition: onnxruntime_cxx_api.h:50
const char * what() const noexcept override
Definition: onnxruntime_cxx_api.h:54
OrtErrorCode GetOrtErrorCode() const
Definition: onnxruntime_cxx_api.h:53
Exception(std::string &&string, OrtErrorCode code)
Definition: onnxruntime_cxx_api.h:51
IEEE 754 half-precision floating point data type.
Definition: onnxruntime_cxx_api.h:169
constexpr bool operator!=(const Float16_t &rhs) const noexcept
Definition: onnxruntime_cxx_api.h:175
constexpr Float16_t(uint16_t v) noexcept
Definition: onnxruntime_cxx_api.h:172
uint16_t value
Definition: onnxruntime_cxx_api.h:170
constexpr bool operator==(const Float16_t &rhs) const noexcept
Definition: onnxruntime_cxx_api.h:174
constexpr Float16_t() noexcept
Definition: onnxruntime_cxx_api.h:171
Definition: onnxruntime_cxx_api.h:82
static const OrtApi * api_
Definition: onnxruntime_cxx_api.h:83
Wrapper around OrtIoBinding.
Definition: onnxruntime_cxx_api.h:1459
UnownedIoBinding GetUnowned() const
Definition: onnxruntime_cxx_api.h:1463
ConstIoBinding GetConst() const
Definition: onnxruntime_cxx_api.h:1462
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:1460
This class wraps a raw pointer OrtKernelContext* that is being passed to the custom kernel Compute() ...
Definition: onnxruntime_cxx_api.h:1500
KernelContext(OrtKernelContext *context)
ConstValue GetInput(size_t index) 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:1567
KernelInfo(OrtKernelInfo *info)
Take ownership of the instance.
ConstKernelInfo GetConst() const
Definition: onnxruntime_cxx_api.h:1570
KernelInfo(std::nullptr_t)
Create an empty instance to initialize later.
Definition: onnxruntime_cxx_api.h:1568
Wrapper around OrtMapTypeInfo.
Definition: onnxruntime_cxx_api.h:900
ConstMapTypeInfo GetConst() const
Definition: onnxruntime_cxx_api.h:903
MapTypeInfo(OrtMapTypeInfo *p)
Used for interop with the C API.
Definition: onnxruntime_cxx_api.h:902
MapTypeInfo(std::nullptr_t)
Create an empty MapTypeInfo object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:901
Represents native memory allocation coming from one of the OrtAllocators registered with OnnxRuntime....
Definition: onnxruntime_cxx_api.h:1370
MemoryAllocation(MemoryAllocation &&) noexcept
MemoryAllocation & operator=(const MemoryAllocation &)=delete
void * get()
Definition: onnxruntime_cxx_api.h:1378
MemoryAllocation(const MemoryAllocation &)=delete
MemoryAllocation(OrtAllocator *allocator, void *p, size_t size)
size_t size() const
Definition: onnxruntime_cxx_api.h:1379
Wrapper around OrtMemoryInfo.
Definition: onnxruntime_cxx_api.h:820
MemoryInfo(const char *name, OrtAllocatorType type, int id, OrtMemType mem_type)
MemoryInfo(std::nullptr_t)
No instance is created.
Definition: onnxruntime_cxx_api.h:822
MemoryInfo(OrtMemoryInfo *p)
Take ownership of a pointer created by C Api.
Definition: onnxruntime_cxx_api.h:823
static MemoryInfo CreateCpu(OrtAllocatorType type, OrtMemType mem_type1)
ConstMemoryInfo GetConst() const
Definition: onnxruntime_cxx_api.h:825
Wrapper around OrtModelMetadata.
Definition: onnxruntime_cxx_api.h:618
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:619
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.
ModelMetadata(OrtModelMetadata *p)
Used for interop with the C API.
Definition: onnxruntime_cxx_api.h:620
AllocatedStringPtr GetDomainAllocated(OrtAllocator *allocator) const
Returns a copy of the domain name.
int64_t GetVersion() const
Wraps OrtApi::ModelMetadataGetVersion.
This struct provides life time management for custom op attribute.
Definition: onnxruntime_cxx_api.h:1490
OpAttr(const char *name, const void *data, int len, OrtOpAttrType type)
Create and own custom defined operation.
Definition: onnxruntime_cxx_api.h:1576
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:1577
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:438
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 & 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:439
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:878
SequenceTypeInfo(std::nullptr_t)
Create an empty SequenceTypeInfo object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:879
ConstSequenceTypeInfo GetConst() const
Definition: onnxruntime_cxx_api.h:881
SequenceTypeInfo(OrtSequenceTypeInfo *p)
Used for interop with the C API.
Definition: onnxruntime_cxx_api.h:880
Wrapper around OrtSession.
Definition: onnxruntime_cxx_api.h:784
Session(std::nullptr_t)
Create an empty Session object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:785
UnownedSession GetUnowned() const
Definition: onnxruntime_cxx_api.h:794
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 char *model_path, const SessionOptions &options)
Wraps OrtApi::CreateSession.
ConstSession GetConst() const
Definition: onnxruntime_cxx_api.h:793
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:607
SessionOptions(std::nullptr_t)
Create an empty SessionOptions object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:608
UnownedSessionOptions GetUnowned() const
Definition: onnxruntime_cxx_api.h:611
SessionOptions()
Wraps OrtApi::CreateSessionOptions.
ConstSessionOptions GetConst() const
Definition: onnxruntime_cxx_api.h:612
SessionOptions(OrtSessionOptions *p)
Used for interop with the C API.
Definition: onnxruntime_cxx_api.h:610
The Status that holds ownership of OrtStatus received from C API Use it to safely destroy OrtStatus* ...
Definition: onnxruntime_cxx_api.h:351
OrtErrorCode GetErrorCode() const
Status(const Exception &)
Creates status instance out of exception.
Status(OrtStatus *status)
Takes ownership of OrtStatus instance returned from the C API. Must be non-null.
std::string GetErrorMessage() const
Status(const std::exception &)
Creates status instance out of exception.
Status(std::nullptr_t)
Create an empty object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:352
Wrapper around OrtTensorTypeAndShapeInfo.
Definition: onnxruntime_cxx_api.h:857
TensorTypeAndShapeInfo(std::nullptr_t)
Create an empty TensorTypeAndShapeInfo object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:858
ConstTensorTypeAndShapeInfo GetConst() const
Definition: onnxruntime_cxx_api.h:860
TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo *p)
Used for interop with the C API.
Definition: onnxruntime_cxx_api.h:859
The ThreadingOptions.
Definition: onnxruntime_cxx_api.h:364
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:930
TypeInfo(std::nullptr_t)
Create an empty TypeInfo object, must be assigned a valid one to be used.
Definition: onnxruntime_cxx_api.h:931
ConstTypeInfo GetConst() const
Definition: onnxruntime_cxx_api.h:934
TypeInfo(OrtTypeInfo *p)
C API Interop.
Definition: onnxruntime_cxx_api.h:932
Wrapper around OrtValue.
Definition: onnxruntime_cxx_api.h:1244
static Value CreateMap(Value &keys, Value &values)
Wraps OrtApi::CreateValue.
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:1249
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.
Value(OrtValue *p)
Used for interop with the C API.
Definition: onnxruntime_cxx_api.h:1250
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 a tensor using a supplied OrtAllocator. Wraps OrtApi::CreateTensorAsOrtValue.
UnownedValue GetUnowned() const
Definition: onnxruntime_cxx_api.h:1255
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 CreateOpaque(const char *domain, const char *type_name, const T &)
Wraps OrtApi::CreateOpaqueValue.
static Value CreateTensor(OrtAllocator *allocator, const int64_t *shape, size_t shape_len)
Creates a tensor using a supplied OrtAllocator. Wraps OrtApi::CreateTensorAsOrtValue.
static Value CreateSequence(std::vector< Value > &values)
Wraps OrtApi::CreateValue.
ConstValue GetConst() const
Definition: onnxruntime_cxx_api.h:1254
Definition: onnxruntime_cxx_api.h:324
AllocatedFree(OrtAllocator *allocator)
Definition: onnxruntime_cxx_api.h:326
OrtAllocator * allocator_
Definition: onnxruntime_cxx_api.h:325
void operator()(void *ptr) const
Definition: onnxruntime_cxx_api.h:328
Definition: onnxruntime_cxx_api.h:1389
ConstMemoryInfo GetInfo() const
void * Alloc(size_t size)
MemoryAllocation GetAllocation(size_t size)
Base & operator=(Base &&v) noexcept
Definition: onnxruntime_cxx_api.h:311
typename Unowned< T >::Type contained_type
Definition: onnxruntime_cxx_api.h:300
Base(Base &&v) noexcept
Definition: onnxruntime_cxx_api.h:310
Base(const Base &)=default
constexpr Base(contained_type *p) noexcept
Definition: onnxruntime_cxx_api.h:303
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:256
Base(Base &&v) noexcept
Definition: onnxruntime_cxx_api.h:266
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:277
Base(const Base &)=delete
constexpr Base(contained_type *p) noexcept
Definition: onnxruntime_cxx_api.h:260
Base & operator=(const Base &)=delete
Base & operator=(Base &&v) noexcept
Definition: onnxruntime_cxx_api.h:267
contained_type * p_
Definition: onnxruntime_cxx_api.h:284
~Base()
Definition: onnxruntime_cxx_api.h:261
T contained_type
Definition: onnxruntime_cxx_api.h:257
Definition: onnxruntime_cxx_api.h:1427
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:691
TypeInfo GetInputTypeInfo(size_t index) const
Wraps OrtApi::SessionGetInputTypeInfo.
size_t GetOutputCount() const
Returns the number of model outputs.
uint64_t GetProfilingStartTimeNs() const
Wraps OrtApi::SessionGetProfilingStartTimeNs.
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.
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.
TypeInfo GetOverridableInitializerTypeInfo(size_t index) const
Wraps OrtApi::SessionGetOverridableInitializerTypeInfo.
Definition: onnxruntime_cxx_api.h:526
std::string GetConfigEntry(const char *config_key) const
Wraps OrtApi::GetSessionConfigEntry.
std::string GetConfigEntryOrDefault(const char *config_key, const std::string &def)
SessionOptions Clone() const
Creates and returns a copy of this SessionOptions object. Wraps OrtApi::CloneSessionOptions.
bool HasConfigEntry(const char *config_key) const
Wraps OrtApi::HasSessionConfigEntry.
Definition: onnxruntime_cxx_api.h:963
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.
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.
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:1438
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:1525
Value GetTensorAttribute(const char *name, OrtAllocator *allocator) const
TypeInfo GetInputTypeInfo(size_t index) const
std::vector< R > GetAttributes(const char *name) const
Definition: onnxruntime_cxx_api.h:1539
R GetAttribute(const char *name) const
Definition: onnxruntime_cxx_api.h:1532
TypeInfo GetOutputTypeInfo(size_t index) const
KernelInfo Copy() const
std::string GetInputName(size_t index) const
size_t GetOutputCount() const
size_t GetInputCount() const
std::string GetOutputName(size_t index) const
Definition: onnxruntime_cxx_api.h:886
ONNXTensorElementDataType GetMapKeyType() const
Wraps OrtApi::GetMapKeyType.
TypeInfo GetMapValueType() const
Wraps OrtApi::GetMapValueType.
Definition: onnxruntime_cxx_api.h:799
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:946
union Ort::detail::OrtSparseValuesParam::@0 data
const char ** str
Definition: onnxruntime_cxx_api.h:951
const int64_t * values_shape
Definition: onnxruntime_cxx_api.h:947
size_t values_shape_len
Definition: onnxruntime_cxx_api.h:948
const void * p_data
Definition: onnxruntime_cxx_api.h:950
Definition: onnxruntime_cxx_api.h:865
TypeInfo GetSequenceElementType() const
Wraps OrtApi::GetSequenceElementType.
Definition: onnxruntime_cxx_api.h:735
AllocatedStringPtr EndProfilingAllocated(OrtAllocator *allocator)
End profiling and return a copy of the profiling file name.
void Run(const RunOptions &run_options, const IoBinding &)
Wraps OrtApi::RunWithBinding.
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:538
SessionOptionsImpl & DisableMemPattern()
Wraps OrtApi::DisableMemPattern.
SessionOptionsImpl & SetCustomJoinThreadFn(OrtCustomJoinThreadFn ort_custom_join_thread_fn)
Wraps OrtApi::SessionOptionsSetCustomJoinThreadFn.
SessionOptionsImpl & SetLogSeverityLevel(int level)
Wraps OrtApi::SetSessionLogSeverityLevel.
SessionOptionsImpl & AppendExecutionProvider(const std::string &provider_name, const std::unordered_map< std::string, std::string > &provider_options={})
Wraps OrtApi::SessionOptionsAppendExecutionProvider. Currently supports SNPE and XNNPACK.
SessionOptionsImpl & EnableOrtCustomOps()
Wraps OrtApi::EnableOrtCustomOps.
SessionOptionsImpl & SetCustomCreateThreadFn(OrtCustomCreateThreadFn ort_custom_create_thread_fn)
Wraps OrtApi::SessionOptionsSetCustomCreateThreadFn.
SessionOptionsImpl & AppendExecutionProvider_CANN(const OrtCANNProviderOptions &provider_options)
Wraps OrtApi::SessionOptionsAppendExecutionProvider_Dnnl.
SessionOptionsImpl & SetGraphOptimizationLevel(GraphOptimizationLevel graph_optimization_level)
Wraps OrtApi::SetSessionGraphOptimizationLevel.
SessionOptionsImpl & AppendExecutionProvider_MIGraphX(const OrtMIGraphXProviderOptions &provider_options)
Wraps OrtApi::SessionOptionsAppendExecutionProvider_CANN.
SessionOptionsImpl & DisableCpuMemArena()
Wraps OrtApi::DisableCpuMemArena.
SessionOptionsImpl & Add(OrtCustomOpDomain *custom_op_domain)
Wraps OrtApi::AddCustomOpDomain.
SessionOptionsImpl & AddConfigEntry(const char *config_key, const char *config_value)
Wraps OrtApi::AddSessionConfigEntry.
SessionOptionsImpl & EnableMemPattern()
Wraps OrtApi::EnableMemPattern.
SessionOptionsImpl & AppendExecutionProvider_Dnnl(const OrtDnnlProviderOptions &provider_options)
SessionOptionsImpl & SetCustomThreadCreationOptions(void *ort_custom_thread_creation_options)
Wraps OrtApi::SessionOptionsSetCustomThreadCreationOptions.
SessionOptionsImpl & AddExternalInitializers(const std::vector< std::string > &names, const std::vector< Value > &ort_values)
Wraps OrtApi::AddExternalInitializers.
SessionOptionsImpl & SetLogId(const char *logid)
Wraps OrtApi::SetSessionLogId.
SessionOptionsImpl & AppendExecutionProvider_CUDA_V2(const OrtCUDAProviderOptionsV2 &provider_options)
Wraps OrtApi::SessionOptionsAppendExecutionProvider_CUDA_V2.
SessionOptionsImpl & SetExecutionMode(ExecutionMode execution_mode)
Wraps OrtApi::SetSessionExecutionMode.
SessionOptionsImpl & DisablePerSessionThreads()
Wraps OrtApi::DisablePerSessionThreads.
SessionOptionsImpl & RegisterCustomOpsLibrary(const char *library_name, const CustomOpConfigs &custom_op_configs={})
SessionOptionsImpl & AppendExecutionProvider_TensorRT_V2(const OrtTensorRTProviderOptionsV2 &provider_options)
Wraps OrtApi::SessionOptionsAppendExecutionProvider_TensorRT.
SessionOptionsImpl & RegisterCustomOpsUsingFunction(const char *function_name)
Wraps OrtApi::RegisterCustomOpsUsingFunction.
SessionOptionsImpl & DisableProfiling()
Wraps OrtApi::DisableProfiling.
SessionOptionsImpl & SetIntraOpNumThreads(int intra_op_num_threads)
Wraps OrtApi::SetIntraOpNumThreads.
SessionOptionsImpl & AppendExecutionProvider_ROCM(const OrtROCMProviderOptions &provider_options)
Wraps OrtApi::SessionOptionsAppendExecutionProvider_ROCM.
SessionOptionsImpl & AppendExecutionProvider_OpenVINO(const OrtOpenVINOProviderOptions &provider_options)
Wraps OrtApi::SessionOptionsAppendExecutionProvider_OpenVINO.
SessionOptionsImpl & EnableCpuMemArena()
Wraps OrtApi::EnableCpuMemArena.
SessionOptionsImpl & AddInitializer(const char *name, const OrtValue *ort_val)
Wraps OrtApi::AddInitializer.
SessionOptionsImpl & SetInterOpNumThreads(int inter_op_num_threads)
Wraps OrtApi::SetInterOpNumThreads.
SessionOptionsImpl & EnableProfiling(const char *profile_file_prefix)
Wraps OrtApi::EnableProfiling.
SessionOptionsImpl & SetOptimizedModelFilePath(const char *optimized_model_file)
Wraps OrtApi::SetOptimizedModelFilePath.
SessionOptionsImpl & AppendExecutionProvider_TensorRT(const OrtTensorRTProviderOptions &provider_options)
Wraps OrtApi::SessionOptionsAppendExecutionProvider_TensorRT.
SessionOptionsImpl & AppendExecutionProvider_CUDA(const OrtCUDAProviderOptions &provider_options)
Wraps OrtApi::SessionOptionsAppendExecutionProvider_CUDA.
Definition: onnxruntime_cxx_api.h:957
const int64_t * shape
Definition: onnxruntime_cxx_api.h:958
size_t shape_len
Definition: onnxruntime_cxx_api.h:959
Definition: onnxruntime_cxx_api.h:830
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.
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:908
ONNXType GetONNXType() const
ConstSequenceTypeInfo GetSequenceTypeInfo() const
Wraps OrtApi::CastTypeInfoToSequenceTypeInfo.
ConstMapTypeInfo GetMapTypeInfo() const
Wraps OrtApi::CastTypeInfoToMapTypeInfo.
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:232
T Type
Definition: onnxruntime_cxx_api.h:233
Definition: onnxruntime_cxx_api.h:1116
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...
Memory allocation interface.
Definition: onnxruntime_c_api.h:287
void(* Free)(struct OrtAllocator *this_, void *p)
Free a block of memory previously allocated with OrtAllocator::Alloc.
Definition: onnxruntime_c_api.h:290
const OrtApi *(* GetApi)(uint32_t version)
Get a pointer to the requested version of the OrtApi.
Definition: onnxruntime_c_api.h:593
The C API.
Definition: onnxruntime_c_api.h:638
CUDA Provider Options.
Definition: onnxruntime_c_api.h:371
Definition: onnxruntime_c_api.h:3989
int(* GetVariadicInputHomogeneity)(const struct OrtCustomOp *op)
Definition: onnxruntime_c_api.h:4030
OrtCustomOpInputOutputCharacteristic(* GetOutputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition: onnxruntime_c_api.h:4014
size_t(* GetInputTypeCount)(const struct OrtCustomOp *op)
Definition: onnxruntime_c_api.h:4004
int(* GetVariadicOutputMinArity)(const struct OrtCustomOp *op)
Definition: onnxruntime_c_api.h:4034
const char *(* GetName)(const struct OrtCustomOp *op)
Definition: onnxruntime_c_api.h:3997
size_t(* GetOutputTypeCount)(const struct OrtCustomOp *op)
Definition: onnxruntime_c_api.h:4006
void(* KernelDestroy)(void *op_kernel)
Definition: onnxruntime_c_api.h:4010
int(* GetVariadicOutputHomogeneity)(const struct OrtCustomOp *op)
Definition: onnxruntime_c_api.h:4039
OrtMemType(* GetInputMemoryType)(const struct OrtCustomOp *op, size_t index)
Definition: onnxruntime_c_api.h:4021
void *(* CreateKernel)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info)
Definition: onnxruntime_c_api.h:3993
uint32_t version
Definition: onnxruntime_c_api.h:3990
ONNXTensorElementDataType(* GetInputType)(const struct OrtCustomOp *op, size_t index)
Definition: onnxruntime_c_api.h:4003
OrtCustomOpInputOutputCharacteristic(* GetInputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition: onnxruntime_c_api.h:4013
const char *(* GetExecutionProviderType)(const struct OrtCustomOp *op)
Definition: onnxruntime_c_api.h:4000
ONNXTensorElementDataType(* GetOutputType)(const struct OrtCustomOp *op, size_t index)
Definition: onnxruntime_c_api.h:4005
int(* GetVariadicInputMinArity)(const struct OrtCustomOp *op)
Definition: onnxruntime_c_api.h:4025
void(* KernelCompute)(void *op_kernel, OrtKernelContext *context)
Definition: onnxruntime_c_api.h:4009
MIGraphX Provider Options.
Definition: onnxruntime_c_api.h:546
OpenVINO Provider Options.
Definition: onnxruntime_c_api.h:556
ROCM Provider Options.
Definition: onnxruntime_c_api.h:445
TensorRT Provider Options.
Definition: onnxruntime_c_api.h:518