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 <cstddef>
30#include <cstdio>
31#include <array>
32#include <memory>
33#include <stdexcept>
34#include <string>
35#include <vector>
36#include <unordered_map>
37#include <utility>
38#include <type_traits>
39
40#ifdef ORT_NO_EXCEPTIONS
41#include <iostream>
42#endif
43
47namespace Ort {
48
53struct Exception : std::exception {
54 Exception(std::string&& string, OrtErrorCode code) : message_{std::move(string)}, code_{code} {}
55
56 OrtErrorCode GetOrtErrorCode() const { return code_; }
57 const char* what() const noexcept override { return message_.c_str(); }
58
59 private:
60 std::string message_;
61 OrtErrorCode code_;
62};
63
64#ifdef ORT_NO_EXCEPTIONS
65// The #ifndef is for the very special case where the user of this library wants to define their own way of handling errors.
66// NOTE: This header expects control flow to not continue after calling ORT_CXX_API_THROW
67#ifndef ORT_CXX_API_THROW
68#define ORT_CXX_API_THROW(string, code) \
69 do { \
70 std::cerr << Ort::Exception(string, code) \
71 .what() \
72 << std::endl; \
73 abort(); \
74 } while (false)
75#endif
76#else
77#define ORT_CXX_API_THROW(string, code) \
78 throw Ort::Exception(string, code)
79#endif
80
81// This is used internally by the C++ API. This class holds the global variable that points to the OrtApi,
82// it's in a template so that we can define a global variable in a header and make
83// it transparent to the users of the API.
84template <typename T>
85struct Global {
86 static const OrtApi* api_;
87};
88
89// If macro ORT_API_MANUAL_INIT is defined, no static initialization will be performed. Instead, user must call InitApi() before using it.
90template <typename T>
91#ifdef ORT_API_MANUAL_INIT
92const OrtApi* Global<T>::api_{};
93inline void InitApi() noexcept { Global<void>::api_ = OrtGetApiBase()->GetApi(ORT_API_VERSION); }
94
95// Used by custom operator libraries that are not linked to onnxruntime. Sets the global API object, which is
96// required by C++ APIs.
97//
98// Example mycustomop.cc:
99//
100// #define ORT_API_MANUAL_INIT
101// #include <onnxruntime_cxx_api.h>
102// #undef ORT_API_MANUAL_INIT
103//
104// OrtStatus* ORT_API_CALL RegisterCustomOps(OrtSessionOptions* options, const OrtApiBase* api_base) {
105// Ort::InitApi(api_base->GetApi(ORT_API_VERSION));
106// // ...
107// }
108//
109inline void InitApi(const OrtApi* api) noexcept { Global<void>::api_ = api; }
110#else
111#if defined(_MSC_VER) && !defined(__clang__)
112#pragma warning(push)
113// "Global initializer calls a non-constexpr function." Therefore you can't use ORT APIs in the other global initializers.
114// Please define ORT_API_MANUAL_INIT if it conerns you.
115#pragma warning(disable : 26426)
116#endif
118#if defined(_MSC_VER) && !defined(__clang__)
119#pragma warning(pop)
120#endif
121#endif
122
124inline const OrtApi& GetApi() noexcept { return *Global<void>::api_; }
125
130std::string GetVersionString();
131
137std::string GetBuildInfoString();
138
144std::vector<std::string> GetAvailableProviders();
145
164struct Float16_t : onnxruntime_float16::Float16Impl<Float16_t> {
165 private:
171 constexpr explicit Float16_t(uint16_t v) noexcept { val = v; }
172
173 public:
174 using Base = onnxruntime_float16::Float16Impl<Float16_t>;
175
179 Float16_t() = default;
180
186 constexpr static Float16_t FromBits(uint16_t v) noexcept { return Float16_t(v); }
187
192 explicit Float16_t(float v) noexcept { val = Base::ToUint16Impl(v); }
193
198 float ToFloat() const noexcept { return Base::ToFloatImpl(); }
199
204 using Base::IsNegative;
205
210 using Base::IsNaN;
211
216 using Base::IsFinite;
217
222 using Base::IsPositiveInfinity;
223
228 using Base::IsNegativeInfinity;
229
234 using Base::IsInfinity;
235
240 using Base::IsNaNOrZero;
241
246 using Base::IsNormal;
247
252 using Base::IsSubnormal;
253
258 using Base::Abs;
259
264 using Base::Negate;
265
274 using Base::AreZero;
275
279 explicit operator float() const noexcept { return ToFloat(); }
280
281 using Base::operator==;
282 using Base::operator!=;
283 using Base::operator<;
284};
285
286static_assert(sizeof(Float16_t) == sizeof(uint16_t), "Sizes must match");
287
306struct BFloat16_t : onnxruntime_float16::BFloat16Impl<BFloat16_t> {
307 private:
315 constexpr explicit BFloat16_t(uint16_t v) noexcept { val = v; }
316
317 public:
318 using Base = onnxruntime_float16::BFloat16Impl<BFloat16_t>;
319
320 BFloat16_t() = default;
321
327 static constexpr BFloat16_t FromBits(uint16_t v) noexcept { return BFloat16_t(v); }
328
333 explicit BFloat16_t(float v) noexcept { val = Base::ToUint16Impl(v); }
334
339 float ToFloat() const noexcept { return Base::ToFloatImpl(); }
340
345 using Base::IsNegative;
346
351 using Base::IsNaN;
352
357 using Base::IsFinite;
358
363 using Base::IsPositiveInfinity;
364
369 using Base::IsNegativeInfinity;
370
375 using Base::IsInfinity;
376
381 using Base::IsNaNOrZero;
382
387 using Base::IsNormal;
388
393 using Base::IsSubnormal;
394
399 using Base::Abs;
400
405 using Base::Negate;
406
415 using Base::AreZero;
416
420 explicit operator float() const noexcept { return ToFloat(); }
421
422 // We do not have an inherited impl for the below operators
423 // as the internal class implements them a little differently
424 bool operator==(const BFloat16_t& rhs) const noexcept;
425 bool operator!=(const BFloat16_t& rhs) const noexcept { return !(*this == rhs); }
426 bool operator<(const BFloat16_t& rhs) const noexcept;
427};
428
429static_assert(sizeof(BFloat16_t) == sizeof(uint16_t), "Sizes must match");
430
437 uint8_t value;
438 constexpr Float8E4M3FN_t() noexcept : value(0) {}
439 constexpr Float8E4M3FN_t(uint8_t v) noexcept : value(v) {}
440 constexpr operator uint8_t() const noexcept { return value; }
441 // nan values are treated like any other value for operator ==, !=
442 constexpr bool operator==(const Float8E4M3FN_t& rhs) const noexcept { return value == rhs.value; };
443 constexpr bool operator!=(const Float8E4M3FN_t& rhs) const noexcept { return value != rhs.value; };
444};
445
446static_assert(sizeof(Float8E4M3FN_t) == sizeof(uint8_t), "Sizes must match");
447
454 uint8_t value;
455 constexpr Float8E4M3FNUZ_t() noexcept : value(0) {}
456 constexpr Float8E4M3FNUZ_t(uint8_t v) noexcept : value(v) {}
457 constexpr operator uint8_t() const noexcept { return value; }
458 // nan values are treated like any other value for operator ==, !=
459 constexpr bool operator==(const Float8E4M3FNUZ_t& rhs) const noexcept { return value == rhs.value; };
460 constexpr bool operator!=(const Float8E4M3FNUZ_t& rhs) const noexcept { return value != rhs.value; };
461};
462
463static_assert(sizeof(Float8E4M3FNUZ_t) == sizeof(uint8_t), "Sizes must match");
464
471 uint8_t value;
472 constexpr Float8E5M2_t() noexcept : value(0) {}
473 constexpr Float8E5M2_t(uint8_t v) noexcept : value(v) {}
474 constexpr operator uint8_t() const noexcept { return value; }
475 // nan values are treated like any other value for operator ==, !=
476 constexpr bool operator==(const Float8E5M2_t& rhs) const noexcept { return value == rhs.value; };
477 constexpr bool operator!=(const Float8E5M2_t& rhs) const noexcept { return value != rhs.value; };
478};
479
480static_assert(sizeof(Float8E5M2_t) == sizeof(uint8_t), "Sizes must match");
481
488 uint8_t value;
489 constexpr Float8E5M2FNUZ_t() noexcept : value(0) {}
490 constexpr Float8E5M2FNUZ_t(uint8_t v) noexcept : value(v) {}
491 constexpr operator uint8_t() const noexcept { return value; }
492 // nan values are treated like any other value for operator ==, !=
493 constexpr bool operator==(const Float8E5M2FNUZ_t& rhs) const noexcept { return value == rhs.value; };
494 constexpr bool operator!=(const Float8E5M2FNUZ_t& rhs) const noexcept { return value != rhs.value; };
495};
496
497static_assert(sizeof(Float8E5M2FNUZ_t) == sizeof(uint8_t), "Sizes must match");
498
499namespace detail {
500// 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
501// This can't be done in the C API since C doesn't have function overloading.
502#define ORT_DEFINE_RELEASE(NAME) \
503 inline void OrtRelease(Ort##NAME* ptr) { GetApi().Release##NAME(ptr); }
504
505ORT_DEFINE_RELEASE(Allocator);
506ORT_DEFINE_RELEASE(MemoryInfo);
507ORT_DEFINE_RELEASE(CustomOpDomain);
508ORT_DEFINE_RELEASE(ThreadingOptions);
509ORT_DEFINE_RELEASE(Env);
510ORT_DEFINE_RELEASE(RunOptions);
511ORT_DEFINE_RELEASE(LoraAdapter);
512ORT_DEFINE_RELEASE(Session);
513ORT_DEFINE_RELEASE(SessionOptions);
514ORT_DEFINE_RELEASE(TensorTypeAndShapeInfo);
515ORT_DEFINE_RELEASE(SequenceTypeInfo);
516ORT_DEFINE_RELEASE(MapTypeInfo);
517ORT_DEFINE_RELEASE(TypeInfo);
518ORT_DEFINE_RELEASE(Value);
519ORT_DEFINE_RELEASE(ModelMetadata);
520ORT_DEFINE_RELEASE(IoBinding);
521ORT_DEFINE_RELEASE(ArenaCfg);
522ORT_DEFINE_RELEASE(Status);
523ORT_DEFINE_RELEASE(OpAttr);
524ORT_DEFINE_RELEASE(Op);
525ORT_DEFINE_RELEASE(KernelInfo);
526
527#undef ORT_DEFINE_RELEASE
528
532template <typename T>
533struct Unowned {
534 using Type = T;
535};
536
556template <typename T>
557struct Base {
558 using contained_type = T;
559
560 constexpr Base() = default;
561 constexpr explicit Base(contained_type* p) noexcept : p_{p} {}
563
564 Base(const Base&) = delete;
565 Base& operator=(const Base&) = delete;
566
567 Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }
568 Base& operator=(Base&& v) noexcept {
569 OrtRelease(p_);
570 p_ = v.release();
571 return *this;
572 }
573
574 constexpr operator contained_type*() const noexcept { return p_; }
575
579 T* p = p_;
580 p_ = nullptr;
581 return p;
582 }
583
584 protected:
586};
587
588// Undefined. For const types use Base<Unowned<const T>>
589template <typename T>
590struct Base<const T>;
591
599template <typename T>
600struct Base<Unowned<T>> {
602
603 constexpr Base() = default;
604 constexpr explicit Base(contained_type* p) noexcept : p_{p} {}
605
606 ~Base() = default;
607
608 Base(const Base&) = default;
609 Base& operator=(const Base&) = default;
610
611 Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }
612 Base& operator=(Base&& v) noexcept {
613 p_ = nullptr;
614 std::swap(p_, v.p_);
615 return *this;
616 }
617
618 constexpr operator contained_type*() const noexcept { return p_; }
619
620 protected:
622};
623
624// Light functor to release memory with OrtAllocator
627 explicit AllocatedFree(OrtAllocator* allocator)
628 : allocator_(allocator) {}
629 void operator()(void* ptr) const {
630 if (ptr) allocator_->Free(allocator_, ptr);
631 }
632};
633
634} // namespace detail
635
636struct AllocatorWithDefaultOptions;
637struct Env;
638struct TypeInfo;
639struct Value;
640struct ModelMetadata;
641
646using AllocatedStringPtr = std::unique_ptr<char, detail::AllocatedFree>;
647
652struct Status : detail::Base<OrtStatus> {
654 using Base::Base;
655
656 explicit Status(std::nullptr_t) noexcept {}
657 explicit Status(OrtStatus* status) noexcept;
658 explicit Status(const Exception&) noexcept;
659 explicit Status(const std::exception&) noexcept;
660 Status(const char* message, OrtErrorCode code) noexcept;
661 std::string GetErrorMessage() const;
663 bool IsOK() const noexcept;
664};
665
695
701struct Env : detail::Base<OrtEnv> {
702 explicit Env(std::nullptr_t) {}
703
705 Env(OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
706
708 Env(OrtLoggingLevel logging_level, const char* logid, OrtLoggingFunction logging_function, void* logger_param);
709
711 Env(const OrtThreadingOptions* tp_options, OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
712
714 Env(const OrtThreadingOptions* tp_options, OrtLoggingFunction logging_function, void* logger_param,
715 OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");
716
718 explicit Env(OrtEnv* p) : Base<OrtEnv>{p} {}
719
722
724
725 Env& CreateAndRegisterAllocator(const OrtMemoryInfo* mem_info, const OrtArenaCfg* arena_cfg);
726
727 Env& CreateAndRegisterAllocatorV2(const std::string& provider_type, const OrtMemoryInfo* mem_info, const std::unordered_map<std::string, std::string>& options, const OrtArenaCfg* arena_cfg);
728};
729
733struct CustomOpDomain : detail::Base<OrtCustomOpDomain> {
735 using Base::Base;
736
737 explicit CustomOpDomain(std::nullptr_t) {}
738
740 explicit CustomOpDomain(const char* domain);
741
742 // This does not take ownership of the op, simply registers it.
743 void Add(const OrtCustomOp* op);
744};
745
747struct LoraAdapter : detail::Base<OrtLoraAdapter> {
749 using Base::Base;
750
751 explicit LoraAdapter(std::nullptr_t) {}
758 static LoraAdapter CreateLoraAdapter(const std::basic_string<ORTCHAR_T>& adapter_path,
759 OrtAllocator* allocator);
760
768 static LoraAdapter CreateLoraAdapterFromArray(const void* bytes, size_t num_bytes,
769 OrtAllocator* allocator);
770};
771
775struct RunOptions : detail::Base<OrtRunOptions> {
776 explicit RunOptions(std::nullptr_t) {}
778
781
784
785 RunOptions& SetRunTag(const char* run_tag);
786 const char* GetRunTag() const;
787
788 RunOptions& AddConfigEntry(const char* config_key, const char* config_value);
789
796
802
810};
811
812namespace detail {
813// Utility function that returns a SessionOption config entry key for a specific custom operator.
814// Ex: custom_op.[custom_op_name].[config]
815std::string MakeCustomOpConfigEntryKey(const char* custom_op_name, const char* config);
816} // namespace detail
817
828 CustomOpConfigs() = default;
829 ~CustomOpConfigs() = default;
834
843 CustomOpConfigs& AddConfig(const char* custom_op_name, const char* config_key, const char* config_value);
844
853 const std::unordered_map<std::string, std::string>& GetFlattenedConfigs() const;
854
855 private:
856 std::unordered_map<std::string, std::string> flat_configs_;
857};
858
864struct SessionOptions;
865
866namespace detail {
867// we separate const-only methods because passing const ptr to non-const methods
868// is only discovered when inline methods are compiled which is counter-intuitive
869template <typename T>
870struct ConstSessionOptionsImpl : Base<T> {
871 using B = Base<T>;
872 using B::B;
873
874 SessionOptions Clone() const;
875
876 std::string GetConfigEntry(const char* config_key) const;
877 bool HasConfigEntry(const char* config_key) const;
878 std::string GetConfigEntryOrDefault(const char* config_key, const std::string& def);
879};
880
881template <typename T>
882struct SessionOptionsImpl : ConstSessionOptionsImpl<T> {
883 using B = ConstSessionOptionsImpl<T>;
884 using B::B;
885
886 SessionOptionsImpl& SetIntraOpNumThreads(int intra_op_num_threads);
887 SessionOptionsImpl& SetInterOpNumThreads(int inter_op_num_threads);
888 SessionOptionsImpl& SetGraphOptimizationLevel(GraphOptimizationLevel graph_optimization_level);
889 SessionOptionsImpl& SetDeterministicCompute(bool value);
890
891 SessionOptionsImpl& EnableCpuMemArena();
892 SessionOptionsImpl& DisableCpuMemArena();
893
894 SessionOptionsImpl& SetOptimizedModelFilePath(const ORTCHAR_T* optimized_model_file);
895
896 SessionOptionsImpl& EnableProfiling(const ORTCHAR_T* profile_file_prefix);
897 SessionOptionsImpl& DisableProfiling();
898
899 SessionOptionsImpl& EnableOrtCustomOps();
900
901 SessionOptionsImpl& EnableMemPattern();
902 SessionOptionsImpl& DisableMemPattern();
903
904 SessionOptionsImpl& SetExecutionMode(ExecutionMode execution_mode);
905
906 SessionOptionsImpl& SetLogId(const char* logid);
907 SessionOptionsImpl& SetLogSeverityLevel(int level);
908
909 SessionOptionsImpl& Add(OrtCustomOpDomain* custom_op_domain);
910
911 SessionOptionsImpl& DisablePerSessionThreads();
912
913 SessionOptionsImpl& AddConfigEntry(const char* config_key, const char* config_value);
914
915 SessionOptionsImpl& AddInitializer(const char* name, const OrtValue* ort_val);
916 SessionOptionsImpl& AddExternalInitializers(const std::vector<std::string>& names, const std::vector<Value>& ort_values);
917 SessionOptionsImpl& AddExternalInitializersFromFilesInMemory(const std::vector<std::basic_string<ORTCHAR_T>>& external_initializer_file_names,
918 const std::vector<char*>& external_initializer_file_buffer_array,
919 const std::vector<size_t>& external_initializer_file_lengths);
920
921 SessionOptionsImpl& AppendExecutionProvider_CUDA(const OrtCUDAProviderOptions& provider_options);
922 SessionOptionsImpl& AppendExecutionProvider_CUDA_V2(const OrtCUDAProviderOptionsV2& provider_options);
923 SessionOptionsImpl& AppendExecutionProvider_ROCM(const OrtROCMProviderOptions& provider_options);
924 SessionOptionsImpl& AppendExecutionProvider_OpenVINO(const OrtOpenVINOProviderOptions& provider_options);
926 SessionOptionsImpl& AppendExecutionProvider_OpenVINO_V2(const std::unordered_map<std::string, std::string>& provider_options = {});
927 SessionOptionsImpl& AppendExecutionProvider_TensorRT(const OrtTensorRTProviderOptions& provider_options);
928 SessionOptionsImpl& AppendExecutionProvider_TensorRT_V2(const OrtTensorRTProviderOptionsV2& provider_options);
929 SessionOptionsImpl& AppendExecutionProvider_MIGraphX(const OrtMIGraphXProviderOptions& provider_options);
931 SessionOptionsImpl& AppendExecutionProvider_CANN(const OrtCANNProviderOptions& provider_options);
933 SessionOptionsImpl& AppendExecutionProvider_Dnnl(const OrtDnnlProviderOptions& provider_options);
935 SessionOptionsImpl& AppendExecutionProvider(const std::string& provider_name,
936 const std::unordered_map<std::string, std::string>& provider_options = {});
937
938 SessionOptionsImpl& SetCustomCreateThreadFn(OrtCustomCreateThreadFn ort_custom_create_thread_fn);
939 SessionOptionsImpl& SetCustomThreadCreationOptions(void* ort_custom_thread_creation_options);
940 SessionOptionsImpl& SetCustomJoinThreadFn(OrtCustomJoinThreadFn ort_custom_join_thread_fn);
941
945 SessionOptionsImpl& RegisterCustomOpsLibrary(const ORTCHAR_T* library_name, const CustomOpConfigs& custom_op_configs = {});
946
947 SessionOptionsImpl& RegisterCustomOpsUsingFunction(const char* function_name);
948
950 SessionOptionsImpl& AppendExecutionProvider_VitisAI(const std::unordered_map<std::string, std::string>& provider_options = {});
951};
952} // namespace detail
953
954using UnownedSessionOptions = detail::SessionOptionsImpl<detail::Unowned<OrtSessionOptions>>;
955using ConstSessionOptions = detail::ConstSessionOptionsImpl<detail::Unowned<const OrtSessionOptions>>;
956
960struct SessionOptions : detail::SessionOptionsImpl<OrtSessionOptions> {
961 explicit SessionOptions(std::nullptr_t) {}
963 explicit SessionOptions(OrtSessionOptions* p) : SessionOptionsImpl<OrtSessionOptions>{p} {}
966};
967
971struct ModelMetadata : detail::Base<OrtModelMetadata> {
973 using Base::Base;
974
975 explicit ModelMetadata(std::nullptr_t) {}
976
984
992
1000
1008
1016
1023 std::vector<AllocatedStringPtr> GetCustomMetadataMapKeysAllocated(OrtAllocator* allocator) const;
1024
1035
1036 int64_t GetVersion() const;
1037};
1038
1039struct IoBinding;
1040
1041namespace detail {
1042
1043// we separate const-only methods because passing const ptr to non-const methods
1044// is only discovered when inline methods are compiled which is counter-intuitive
1045template <typename T>
1047 using B = Base<T>;
1048 using B::B;
1049
1050 size_t GetInputCount() const;
1051 size_t GetOutputCount() const;
1053
1062
1071
1080
1081 uint64_t GetProfilingStartTimeNs() const;
1083
1084 TypeInfo GetInputTypeInfo(size_t index) const;
1085 TypeInfo GetOutputTypeInfo(size_t index) const;
1087};
1088
1089template <typename T>
1092 using B::B;
1093
1111 std::vector<Value> Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
1112 const char* const* output_names, size_t output_count);
1113
1117 void Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
1118 const char* const* output_names, Value* output_values, size_t output_count);
1119
1120 void Run(const RunOptions& run_options, const IoBinding&);
1121
1141 void RunAsync(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
1142 const char* const* output_names, Value* output_values, size_t output_count, RunAsyncCallbackFn callback, void* user_data);
1143
1151
1163 void SetEpDynamicOptions(const char* const* keys, const char* const* values, size_t kv_len);
1164};
1165
1166} // namespace detail
1167
1170
1174struct Session : detail::SessionImpl<OrtSession> {
1175 explicit Session(std::nullptr_t) {}
1176 Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
1177 Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options,
1178 OrtPrepackedWeightsContainer* prepacked_weights_container);
1179 Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options);
1180 Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options,
1181 OrtPrepackedWeightsContainer* prepacked_weights_container);
1182
1183 ConstSession GetConst() const { return ConstSession{this->p_}; }
1184 UnownedSession GetUnowned() const { return UnownedSession{this->p_}; }
1185};
1186
1187namespace detail {
1188template <typename T>
1190 using B = Base<T>;
1191 using B::B;
1192
1193 std::string GetAllocatorName() const;
1195 int GetDeviceId() const;
1198
1199 template <typename U>
1200 bool operator==(const MemoryInfoImpl<U>& o) const;
1201};
1202} // namespace detail
1203
1204// Const object holder that does not own the underlying object
1206
1210struct MemoryInfo : detail::MemoryInfoImpl<OrtMemoryInfo> {
1212 explicit MemoryInfo(std::nullptr_t) {}
1213 explicit MemoryInfo(OrtMemoryInfo* p) : MemoryInfoImpl<OrtMemoryInfo>{p} {}
1214 MemoryInfo(const char* name, OrtAllocatorType type, int id, OrtMemType mem_type);
1215 ConstMemoryInfo GetConst() const { return ConstMemoryInfo{this->p_}; }
1216};
1217
1218namespace detail {
1219template <typename T>
1221 using B = Base<T>;
1222 using B::B;
1223
1225 size_t GetElementCount() const;
1226
1227 size_t GetDimensionsCount() const;
1228
1233 [[deprecated("use GetShape()")]] void GetDimensions(int64_t* values, size_t values_count) const;
1234
1235 void GetSymbolicDimensions(const char** values, size_t values_count) const;
1236
1237 std::vector<int64_t> GetShape() const;
1238};
1239
1240} // namespace detail
1241
1243
1249 using Base::Base;
1250
1251 explicit TensorTypeAndShapeInfo(std::nullptr_t) {}
1252 explicit TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* p) : TensorTypeAndShapeInfoImpl{p} {}
1254};
1255
1256namespace detail {
1257template <typename T>
1259 using B = Base<T>;
1260 using B::B;
1262};
1263
1264} // namespace detail
1265
1267
1271struct SequenceTypeInfo : detail::SequenceTypeInfoImpl<OrtSequenceTypeInfo> {
1273 using Base::Base;
1274
1275 explicit SequenceTypeInfo(std::nullptr_t) {}
1276 explicit SequenceTypeInfo(OrtSequenceTypeInfo* p) : SequenceTypeInfoImpl<OrtSequenceTypeInfo>{p} {}
1278};
1279
1280namespace detail {
1281template <typename T>
1283 using B = Base<T>;
1284 using B::B;
1286};
1287
1288} // namespace detail
1289
1290// This is always owned by the TypeInfo and can only be obtained from it.
1292
1293namespace detail {
1294template <typename T>
1301
1302} // namespace detail
1303
1305
1309struct MapTypeInfo : detail::MapTypeInfoImpl<OrtMapTypeInfo> {
1311 using Base::Base;
1312
1313 explicit MapTypeInfo(std::nullptr_t) {}
1314 explicit MapTypeInfo(OrtMapTypeInfo* p) : MapTypeInfoImpl<OrtMapTypeInfo>{p} {}
1315 ConstMapTypeInfo GetConst() const { return ConstMapTypeInfo{this->p_}; }
1316};
1317
1318namespace detail {
1319template <typename T>
1331} // namespace detail
1332
1338
1343struct TypeInfo : detail::TypeInfoImpl<OrtTypeInfo> {
1345 using Base::Base;
1346
1347 explicit TypeInfo(std::nullptr_t) {}
1348 explicit TypeInfo(OrtTypeInfo* p) : TypeInfoImpl<OrtTypeInfo>{p} {}
1349
1350 ConstTypeInfo GetConst() const { return ConstTypeInfo{this->p_}; }
1351};
1352
1353namespace detail {
1354// This structure is used to feed sparse tensor values
1355// information for use with FillSparseTensor<Format>() API
1356// if the data type for the sparse tensor values is numeric
1357// use data.p_data, otherwise, use data.str pointer to feed
1358// values. data.str is an array of const char* that are zero terminated.
1359// number of strings in the array must match shape size.
1360// For fully sparse tensors use shape {0} and set p_data/str
1361// to nullptr.
1363 const int64_t* values_shape;
1365 union {
1366 const void* p_data;
1367 const char** str;
1368 } data;
1369};
1370
1371// Provides a way to pass shape in a single
1372// argument
1373struct Shape {
1374 const int64_t* shape;
1376};
1377
1378template <typename T>
1380 using B = Base<T>;
1381 using B::B;
1382
1386 template <typename R>
1387 void GetOpaqueData(const char* domain, const char* type_name, R&) const;
1388
1389 bool IsTensor() const;
1390 bool HasValue() const;
1391
1392 size_t GetCount() const; // If a non tensor, returns 2 for map and N for sequence, where N is the number of elements
1393 Value GetValue(int index, OrtAllocator* allocator) const;
1394
1402
1417 void GetStringTensorContent(void* buffer, size_t buffer_length, size_t* offsets, size_t offsets_count) const;
1418
1425 template <typename R>
1426 const R* GetTensorData() const;
1427
1432 const void* GetTensorRawData() const;
1433
1441
1449
1455
1464 void GetStringTensorElement(size_t buffer_length, size_t element_index, void* buffer) const;
1465
1472 std::string GetStringTensorElement(size_t element_index) const;
1473
1480 size_t GetStringTensorElementLength(size_t element_index) const;
1481
1482#if !defined(DISABLE_SPARSE_TENSORS)
1490
1497
1506
1516 template <typename R>
1517 const R* GetSparseTensorIndicesData(OrtSparseIndicesFormat indices_format, size_t& num_indices) const;
1518
1523 bool IsSparseTensor() const;
1524
1533 template <typename R>
1534 const R* GetSparseTensorValues() const;
1535
1536#endif
1537};
1538
1539template <typename T>
1542 using B::B;
1543
1549 template <typename R>
1551
1557
1559 // Obtain a reference to an element of data at the location specified
1565 template <typename R>
1566 R& At(const std::vector<int64_t>& location);
1567
1573 void FillStringTensor(const char* const* s, size_t s_len);
1574
1580 void FillStringTensorElement(const char* s, size_t index);
1581
1594 char* GetResizedStringTensorElementBuffer(size_t index, size_t buffer_length);
1595
1596#if !defined(DISABLE_SPARSE_TENSORS)
1605 void UseCooIndices(int64_t* indices_data, size_t indices_num);
1606
1617 void UseCsrIndices(int64_t* inner_data, size_t inner_num, int64_t* outer_data, size_t outer_num);
1618
1627 void UseBlockSparseIndices(const Shape& indices_shape, int32_t* indices_data);
1628
1638 void FillSparseTensorCoo(const OrtMemoryInfo* data_mem_info, const OrtSparseValuesParam& values_param,
1639 const int64_t* indices_data, size_t indices_num);
1640
1652 void FillSparseTensorCsr(const OrtMemoryInfo* data_mem_info,
1653 const OrtSparseValuesParam& values,
1654 const int64_t* inner_indices_data, size_t inner_indices_num,
1655 const int64_t* outer_indices_data, size_t outer_indices_num);
1656
1667 const OrtSparseValuesParam& values,
1668 const Shape& indices_shape,
1669 const int32_t* indices_data);
1670
1671#endif
1672};
1673
1674} // namespace detail
1675
1678
1682struct Value : detail::ValueImpl<OrtValue> {
1684 using Base::Base;
1687
1688 explicit Value(std::nullptr_t) {}
1689 Value(Value&&) = default;
1690 Value& operator=(Value&&) = default;
1691
1692 ConstValue GetConst() const { return ConstValue{this->p_}; }
1693 UnownedValue GetUnowned() const { return UnownedValue{this->p_}; }
1694
1703 template <typename T>
1704 static Value CreateTensor(const OrtMemoryInfo* info, T* p_data, size_t p_data_element_count, const int64_t* shape, size_t shape_len);
1705
1715 static Value CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count, const int64_t* shape, size_t shape_len,
1717
1729 template <typename T>
1730 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len);
1731
1743 static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type);
1744
1753 static Value CreateMap(const Value& keys, const Value& values);
1754
1762 static Value CreateSequence(const std::vector<Value>& values);
1763
1772 template <typename T>
1773 static Value CreateOpaque(const char* domain, const char* type_name, const T& value);
1774
1775#if !defined(DISABLE_SPARSE_TENSORS)
1786 template <typename T>
1787 static Value CreateSparseTensor(const OrtMemoryInfo* info, T* p_data, const Shape& dense_shape,
1788 const Shape& values_shape);
1789
1806 static Value CreateSparseTensor(const OrtMemoryInfo* info, void* p_data, const Shape& dense_shape,
1807 const Shape& values_shape, ONNXTensorElementDataType type);
1808
1818 template <typename T>
1819 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape);
1820
1832 static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape, ONNXTensorElementDataType type);
1833
1834#endif // !defined(DISABLE_SPARSE_TENSORS)
1835};
1836
1844 MemoryAllocation(OrtAllocator* allocator, void* p, size_t size);
1849 MemoryAllocation& operator=(MemoryAllocation&&) noexcept;
1850
1851 void* get() { return p_; }
1852 size_t size() const { return size_; }
1853
1854 private:
1855 OrtAllocator* allocator_;
1856 void* p_;
1857 size_t size_;
1858};
1859
1860namespace detail {
1861template <typename T>
1862struct AllocatorImpl : Base<T> {
1863 using B = Base<T>;
1864 using B::B;
1865
1866 void* Alloc(size_t size);
1867 MemoryAllocation GetAllocation(size_t size);
1868 void Free(void* p);
1869 ConstMemoryInfo GetInfo() const;
1870};
1871
1872} // namespace detail
1873
1877struct AllocatorWithDefaultOptions : detail::AllocatorImpl<detail::Unowned<OrtAllocator>> {
1878 explicit AllocatorWithDefaultOptions(std::nullptr_t) {}
1880};
1881
1885struct Allocator : detail::AllocatorImpl<OrtAllocator> {
1886 explicit Allocator(std::nullptr_t) {}
1887 Allocator(const Session& session, const OrtMemoryInfo*);
1888};
1889
1890using UnownedAllocator = detail::AllocatorImpl<detail::Unowned<OrtAllocator>>;
1891
1892namespace detail {
1893namespace binding_utils {
1894// Bring these out of template
1895std::vector<std::string> GetOutputNamesHelper(const OrtIoBinding* binding, OrtAllocator*);
1896std::vector<Value> GetOutputValuesHelper(const OrtIoBinding* binding, OrtAllocator*);
1897} // namespace binding_utils
1898
1899template <typename T>
1901 using B = Base<T>;
1902 using B::B;
1903
1904 std::vector<std::string> GetOutputNames() const;
1905 std::vector<std::string> GetOutputNames(OrtAllocator*) const;
1906 std::vector<Value> GetOutputValues() const;
1907 std::vector<Value> GetOutputValues(OrtAllocator*) const;
1908};
1909
1910template <typename T>
1913 using B::B;
1914
1915 void BindInput(const char* name, const Value&);
1916 void BindOutput(const char* name, const Value&);
1917 void BindOutput(const char* name, const OrtMemoryInfo*);
1922};
1923
1924} // namespace detail
1925
1928
1932struct IoBinding : detail::IoBindingImpl<OrtIoBinding> {
1933 explicit IoBinding(std::nullptr_t) {}
1934 explicit IoBinding(Session& session);
1935 ConstIoBinding GetConst() const { return ConstIoBinding{this->p_}; }
1936 UnownedIoBinding GetUnowned() const { return UnownedIoBinding{this->p_}; }
1937};
1938
1943struct ArenaCfg : detail::Base<OrtArenaCfg> {
1944 explicit ArenaCfg(std::nullptr_t) {}
1953 ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk);
1954};
1955
1956//
1957// Custom OPs (only needed to implement custom OPs)
1958//
1959
1963struct OpAttr : detail::Base<OrtOpAttr> {
1965 using Base::Base;
1966
1967 explicit OpAttr(std::nullptr_t) {}
1968 OpAttr(const char* name, const void* data, int len, OrtOpAttrType type);
1969};
1970
1979#define ORT_CXX_LOG(logger, message_severity, message) \
1980 do { \
1981 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
1982 Ort::ThrowOnError(logger.LogMessage(message_severity, ORT_FILE, __LINE__, \
1983 static_cast<const char*>(__FUNCTION__), message)); \
1984 } \
1985 } while (false)
1986
1995#define ORT_CXX_LOG_NOEXCEPT(logger, message_severity, message) \
1996 do { \
1997 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
1998 static_cast<void>(logger.LogMessage(message_severity, ORT_FILE, __LINE__, \
1999 static_cast<const char*>(__FUNCTION__), message)); \
2000 } \
2001 } while (false)
2002
2014#define ORT_CXX_LOGF(logger, message_severity, /*format,*/...) \
2015 do { \
2016 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2017 Ort::ThrowOnError(logger.LogFormattedMessage(message_severity, ORT_FILE, __LINE__, \
2018 static_cast<const char*>(__FUNCTION__), __VA_ARGS__)); \
2019 } \
2020 } while (false)
2021
2033#define ORT_CXX_LOGF_NOEXCEPT(logger, message_severity, /*format,*/...) \
2034 do { \
2035 if (message_severity >= logger.GetLoggingSeverityLevel()) { \
2036 static_cast<void>(logger.LogFormattedMessage(message_severity, ORT_FILE, __LINE__, \
2037 static_cast<const char*>(__FUNCTION__), __VA_ARGS__)); \
2038 } \
2039 } while (false)
2040
2051struct Logger {
2055 Logger() = default;
2056
2060 explicit Logger(std::nullptr_t) {}
2061
2068 explicit Logger(const OrtLogger* logger);
2069
2070 ~Logger() = default;
2071
2072 Logger(const Logger&) = default;
2073 Logger& operator=(const Logger&) = default;
2074
2075 Logger(Logger&& v) noexcept = default;
2076 Logger& operator=(Logger&& v) noexcept = default;
2077
2084
2097 Status LogMessage(OrtLoggingLevel log_severity_level, const ORTCHAR_T* file_path, int line_number,
2098 const char* func_name, const char* message) const noexcept;
2099
2114 template <typename... Args>
2115 Status LogFormattedMessage(OrtLoggingLevel log_severity_level, const ORTCHAR_T* file_path, int line_number,
2116 const char* func_name, const char* format, Args&&... args) const noexcept;
2117
2118 private:
2119 const OrtLogger* logger_{};
2120 OrtLoggingLevel cached_severity_level_{};
2121};
2122
2131 size_t GetInputCount() const;
2132 size_t GetOutputCount() const;
2133 // If input is optional and is not present, the method returns en empty ConstValue
2134 // which can be compared to nullptr.
2135 ConstValue GetInput(size_t index) const;
2136 // If outout is optional and is not present, the method returns en empty UnownedValue
2137 // which can be compared to nullptr.
2138 UnownedValue GetOutput(size_t index, const int64_t* dim_values, size_t dim_count) const;
2139 UnownedValue GetOutput(size_t index, const std::vector<int64_t>& dims) const;
2140 void* GetGPUComputeStream() const;
2142 OrtAllocator* GetAllocator(const OrtMemoryInfo& memory_info) const;
2143 OrtKernelContext* GetOrtKernelContext() const { return ctx_; }
2144 void ParallelFor(void (*fn)(void*, size_t), size_t total, size_t num_batch, void* usr_data) const;
2145
2146 private:
2147 OrtKernelContext* ctx_;
2148};
2149
2150struct KernelInfo;
2151
2152namespace detail {
2153namespace attr_utils {
2154void GetAttr(const OrtKernelInfo* p, const char* name, float&);
2155void GetAttr(const OrtKernelInfo* p, const char* name, int64_t&);
2156void GetAttr(const OrtKernelInfo* p, const char* name, std::string&);
2157void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<float>&);
2158void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector<int64_t>&);
2159} // namespace attr_utils
2160
2161template <typename T>
2162struct KernelInfoImpl : Base<T> {
2163 using B = Base<T>;
2164 using B::B;
2165
2166 KernelInfo Copy() const;
2167
2168 template <typename R> // R is only implemented for float, int64_t, and string
2169 R GetAttribute(const char* name) const {
2170 R val;
2171 attr_utils::GetAttr(this->p_, name, val);
2172 return val;
2173 }
2174
2175 template <typename R> // R is only implemented for std::vector<float>, std::vector<int64_t>
2176 std::vector<R> GetAttributes(const char* name) const {
2177 std::vector<R> result;
2178 attr_utils::GetAttrs(this->p_, name, result);
2179 return result;
2180 }
2181
2182 Value GetTensorAttribute(const char* name, OrtAllocator* allocator) const;
2183
2184 size_t GetInputCount() const;
2185 size_t GetOutputCount() const;
2186
2187 std::string GetInputName(size_t index) const;
2188 std::string GetOutputName(size_t index) const;
2189
2190 TypeInfo GetInputTypeInfo(size_t index) const;
2191 TypeInfo GetOutputTypeInfo(size_t index) const;
2192
2193 ConstValue GetTensorConstantInput(size_t index, int* is_constant) const;
2194
2195 std::string GetNodeName() const;
2196 Logger GetLogger() const;
2197};
2198
2199} // namespace detail
2200
2201using ConstKernelInfo = detail::KernelInfoImpl<detail::Unowned<const OrtKernelInfo>>;
2202
2209struct KernelInfo : detail::KernelInfoImpl<OrtKernelInfo> {
2210 using Base = detail::KernelInfoImpl<OrtKernelInfo>;
2211 using Base::Base;
2212 explicit KernelInfo(std::nullptr_t) {}
2213 explicit KernelInfo(OrtKernelInfo* info);
2214 ConstKernelInfo GetConst() const { return ConstKernelInfo{this->p_}; }
2215};
2216
2220struct Op : detail::Base<OrtOp> {
2222 using Base::Base;
2223
2224 explicit Op(std::nullptr_t) {}
2225
2226 explicit Op(OrtOp*);
2227
2228 static Op Create(const OrtKernelInfo* info, const char* op_name, const char* domain,
2229 int version, const char** type_constraint_names,
2230 const ONNXTensorElementDataType* type_constraint_values,
2231 size_t type_constraint_count,
2232 const OpAttr* attr_values,
2233 size_t attr_count,
2234 size_t input_count, size_t output_count);
2235
2236 void Invoke(const OrtKernelContext* context,
2237 const Value* input_values,
2238 size_t input_count,
2239 Value* output_values,
2240 size_t output_count);
2241
2242 // For easier refactoring
2243 void Invoke(const OrtKernelContext* context,
2244 const OrtValue* const* input_values,
2245 size_t input_count,
2246 OrtValue* const* output_values,
2247 size_t output_count);
2248};
2249
2255 SymbolicInteger(int64_t i) : i_(i), is_int_(true) {};
2256 SymbolicInteger(const char* s) : s_(s), is_int_(false) {};
2259
2262
2263 bool operator==(const SymbolicInteger& dim) const {
2264 if (is_int_ == dim.is_int_) {
2265 if (is_int_) {
2266 return i_ == dim.i_;
2267 } else {
2268 return std::string{s_} == std::string{dim.s_};
2269 }
2270 }
2271 return false;
2272 }
2273
2274 bool IsInt() const { return is_int_; }
2275 int64_t AsInt() const { return i_; }
2276 const char* AsSym() const { return s_; }
2277
2278 static constexpr int INVALID_INT_DIM = -2;
2279
2280 private:
2281 union {
2282 int64_t i_;
2283 const char* s_;
2284 };
2285 bool is_int_;
2286 };
2287
2288 using Shape = std::vector<SymbolicInteger>;
2289
2291
2292 const Shape& GetInputShape(size_t indice) const { return input_shapes_.at(indice); }
2293
2294 size_t GetInputCount() const { return input_shapes_.size(); }
2295
2297
2298 int64_t GetAttrInt(const char* attr_name);
2299
2300 using Ints = std::vector<int64_t>;
2301 Ints GetAttrInts(const char* attr_name);
2302
2303 float GetAttrFloat(const char* attr_name);
2304
2305 using Floats = std::vector<float>;
2306 Floats GetAttrFloats(const char* attr_name);
2307
2308 std::string GetAttrString(const char* attr_name);
2309
2310 using Strings = std::vector<std::string>;
2311 Strings GetAttrStrings(const char* attr_name);
2312
2313 private:
2314 const OrtOpAttr* GetAttrHdl(const char* attr_name) const;
2315 const OrtApi* ort_api_;
2317 std::vector<Shape> input_shapes_;
2318};
2319
2321
2322#define MAX_CUSTOM_OP_END_VER (1UL << 31) - 1
2323
2324template <typename TOp, typename TKernel, bool WithStatus = false>
2328 OrtCustomOp::GetName = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetName(); };
2329
2330 OrtCustomOp::GetExecutionProviderType = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetExecutionProviderType(); };
2331
2332 OrtCustomOp::GetInputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetInputTypeCount(); };
2333 OrtCustomOp::GetInputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputType(index); };
2334 OrtCustomOp::GetInputMemoryType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputMemoryType(index); };
2335
2336 OrtCustomOp::GetOutputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetOutputTypeCount(); };
2337 OrtCustomOp::GetOutputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputType(index); };
2338
2339#if defined(_MSC_VER) && !defined(__clang__)
2340#pragma warning(push)
2341#pragma warning(disable : 26409)
2342#endif
2343 OrtCustomOp::KernelDestroy = [](void* op_kernel) { delete static_cast<TKernel*>(op_kernel); };
2344#if defined(_MSC_VER) && !defined(__clang__)
2345#pragma warning(pop)
2346#endif
2347 OrtCustomOp::GetInputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputCharacteristic(index); };
2348 OrtCustomOp::GetOutputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputCharacteristic(index); };
2349
2350 OrtCustomOp::GetVariadicInputMinArity = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetVariadicInputMinArity(); };
2351 OrtCustomOp::GetVariadicInputHomogeneity = [](const OrtCustomOp* this_) { return static_cast<int>(static_cast<const TOp*>(this_)->GetVariadicInputHomogeneity()); };
2352 OrtCustomOp::GetVariadicOutputMinArity = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetVariadicOutputMinArity(); };
2353 OrtCustomOp::GetVariadicOutputHomogeneity = [](const OrtCustomOp* this_) { return static_cast<int>(static_cast<const TOp*>(this_)->GetVariadicOutputHomogeneity()); };
2354#ifdef __cpp_if_constexpr
2355 if constexpr (WithStatus) {
2356#else
2357 if (WithStatus) {
2358#endif
2359 OrtCustomOp::CreateKernelV2 = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info, void** op_kernel) -> OrtStatusPtr {
2360 return static_cast<const TOp*>(this_)->CreateKernelV2(*api, info, op_kernel);
2361 };
2362 OrtCustomOp::KernelComputeV2 = [](void* op_kernel, OrtKernelContext* context) -> OrtStatusPtr {
2363 return static_cast<TKernel*>(op_kernel)->ComputeV2(context);
2364 };
2365 } else {
2368
2369 OrtCustomOp::CreateKernel = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info) { return static_cast<const TOp*>(this_)->CreateKernel(*api, info); };
2370 OrtCustomOp::KernelCompute = [](void* op_kernel, OrtKernelContext* context) {
2371 static_cast<TKernel*>(op_kernel)->Compute(context);
2372 };
2373 }
2374
2375 SetShapeInferFn<TOp>(0);
2376
2377 OrtCustomOp::GetStartVersion = [](const OrtCustomOp* this_) {
2378 return static_cast<const TOp*>(this_)->start_ver_;
2379 };
2380
2381 OrtCustomOp::GetEndVersion = [](const OrtCustomOp* this_) {
2382 return static_cast<const TOp*>(this_)->end_ver_;
2383 };
2384
2387 OrtCustomOp::GetAliasMap = nullptr;
2389 }
2390
2391 // Default implementation of GetExecutionProviderType that returns nullptr to default to the CPU provider
2392 const char* GetExecutionProviderType() const { return nullptr; }
2393
2394 // Default implementations of GetInputCharacteristic() and GetOutputCharacteristic() below
2395 // (inputs and outputs are required by default)
2397 return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED;
2398 }
2399
2401 return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED;
2402 }
2403
2404 // Default implemention of GetInputMemoryType() that returns OrtMemTypeDefault
2405 OrtMemType GetInputMemoryType(size_t /*index*/) const {
2406 return OrtMemTypeDefault;
2407 }
2408
2409 // Default implementation of GetVariadicInputMinArity() returns 1 to specify that a variadic input
2410 // should expect at least 1 argument.
2412 return 1;
2413 }
2414
2415 // Default implementation of GetVariadicInputHomegeneity() returns true to specify that all arguments
2416 // to a variadic input should be of the same type.
2418 return true;
2419 }
2420
2421 // Default implementation of GetVariadicOutputMinArity() returns 1 to specify that a variadic output
2422 // should produce at least 1 output value.
2424 return 1;
2425 }
2426
2427 // Default implementation of GetVariadicOutputHomegeneity() returns true to specify that all output values
2428 // produced by a variadic output should be of the same type.
2430 return true;
2431 }
2432
2433 // Declare list of session config entries used by this Custom Op.
2434 // Implement this function in order to get configs from CustomOpBase::GetSessionConfigs().
2435 // This default implementation returns an empty vector of config entries.
2436 std::vector<std::string> GetSessionConfigKeys() const {
2437 return std::vector<std::string>{};
2438 }
2439
2440 template <typename C>
2441 decltype(&C::InferOutputShape) SetShapeInferFn(decltype(&C::InferOutputShape)) {
2443 ShapeInferContext ctx(&GetApi(), ort_ctx);
2444 return C::InferOutputShape(ctx);
2445 };
2446 return {};
2447 }
2448
2449 template <typename C>
2453
2454 protected:
2455 // Helper function that returns a map of session config entries specified by CustomOpBase::GetSessionConfigKeys.
2456 void GetSessionConfigs(std::unordered_map<std::string, std::string>& out, ConstSessionOptions options) const;
2457
2458 int start_ver_ = 1;
2459 int end_ver_ = MAX_CUSTOM_OP_END_VER;
2460};
2461
2462} // namespace Ort
2463
2464#include "onnxruntime_cxx_inline.h"
struct OrtMemoryInfo OrtMemoryInfo
Definition onnxruntime_c_api.h:282
struct OrtKernelInfo OrtKernelInfo
Definition onnxruntime_c_api.h:369
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:393
struct OrtShapeInferContext OrtShapeInferContext
Definition onnxruntime_c_api.h:306
void(* OrtLoggingFunction)(void *param, OrtLoggingLevel severity, const char *category, const char *logid, const char *code_location, const char *message)
Definition onnxruntime_c_api.h:334
void(* OrtCustomJoinThreadFn)(OrtCustomThreadHandle ort_custom_thread_handle)
Custom thread join function.
Definition onnxruntime_c_api.h:722
OrtCustomOpInputOutputCharacteristic
Definition onnxruntime_c_api.h:4776
struct OrtTensorRTProviderOptionsV2 OrtTensorRTProviderOptionsV2
Definition onnxruntime_c_api.h:299
struct OrtOpAttr OrtOpAttr
Definition onnxruntime_c_api.h:304
struct OrtThreadingOptions OrtThreadingOptions
Definition onnxruntime_c_api.h:296
struct OrtSequenceTypeInfo OrtSequenceTypeInfo
Definition onnxruntime_c_api.h:290
struct OrtDnnlProviderOptions OrtDnnlProviderOptions
Definition onnxruntime_c_api.h:302
OrtSparseIndicesFormat
Definition onnxruntime_c_api.h:226
struct OrtPrepackedWeightsContainer OrtPrepackedWeightsContainer
Definition onnxruntime_c_api.h:298
struct OrtCustomOpDomain OrtCustomOpDomain
Definition onnxruntime_c_api.h:293
struct OrtIoBinding OrtIoBinding
Definition onnxruntime_c_api.h:283
OrtAllocatorType
Definition onnxruntime_c_api.h:375
struct OrtOp OrtOp
Definition onnxruntime_c_api.h:303
struct OrtTypeInfo OrtTypeInfo
Definition onnxruntime_c_api.h:287
struct OrtTensorTypeAndShapeInfo OrtTensorTypeAndShapeInfo
Definition onnxruntime_c_api.h:288
struct OrtCUDAProviderOptionsV2 OrtCUDAProviderOptionsV2
Definition onnxruntime_c_api.h:300
struct OrtKernelContext OrtKernelContext
Definition onnxruntime_c_api.h:371
struct OrtCANNProviderOptions OrtCANNProviderOptions
Definition onnxruntime_c_api.h:301
void(* RunAsyncCallbackFn)(void *user_data, OrtValue **outputs, size_t num_outputs, OrtStatusPtr status)
Callback function for RunAsync.
Definition onnxruntime_c_api.h:733
struct OrtSessionOptions OrtSessionOptions
Definition onnxruntime_c_api.h:292
struct OrtValue OrtValue
Definition onnxruntime_c_api.h:285
GraphOptimizationLevel
Graph optimization level.
Definition onnxruntime_c_api.h:343
OrtStatus * OrtStatusPtr
Definition onnxruntime_c_api.h:312
OrtMemType
Memory types for allocated memory, execution provider specific types should be extended in each provi...
Definition onnxruntime_c_api.h:384
OrtSparseFormat
Definition onnxruntime_c_api.h:218
ONNXType
Definition onnxruntime_c_api.h:206
struct OrtEnv OrtEnv
Definition onnxruntime_c_api.h:280
OrtErrorCode
Definition onnxruntime_c_api.h:245
struct OrtStatus OrtStatus
Definition onnxruntime_c_api.h:281
#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:305
struct OrtMapTypeInfo OrtMapTypeInfo
Definition onnxruntime_c_api.h:289
struct OrtArenaCfg OrtArenaCfg
Definition onnxruntime_c_api.h:297
ExecutionMode
Definition onnxruntime_c_api.h:350
OrtOpAttrType
Definition onnxruntime_c_api.h:260
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:715
ONNXTensorElementDataType
Definition onnxruntime_c_api.h:177
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:388
@ 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:505
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:47
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:646
detail::ConstSessionOptionsImpl< detail::Unowned< const OrtSessionOptions > > ConstSessionOptions
Definition onnxruntime_cxx_api.h:955
detail::KernelInfoImpl< detail::Unowned< const OrtKernelInfo > > ConstKernelInfo
Definition onnxruntime_cxx_api.h:2201
const OrtApi & GetApi() noexcept
This returns a reference to the OrtApi interface in use.
Definition onnxruntime_cxx_api.h:124
detail::AllocatorImpl< detail::Unowned< OrtAllocator > > UnownedAllocator
Definition onnxruntime_cxx_api.h:1890
detail::SessionOptionsImpl< detail::Unowned< OrtSessionOptions > > UnownedSessionOptions
Definition onnxruntime_cxx_api.h:954
std::string GetBuildInfoString()
This function returns the onnxruntime build information: including git branch, git commit id,...
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:2320
Wrapper around OrtAllocator.
Definition onnxruntime_cxx_api.h:1885
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:1886
Wrapper around OrtAllocator default instance that is owned by Onnxruntime.
Definition onnxruntime_cxx_api.h:1877
AllocatorWithDefaultOptions(std::nullptr_t)
Convenience to create a class member and then replace with an instance.
Definition onnxruntime_cxx_api.h:1878
it is a structure that represents the configuration of an arena based allocator
Definition onnxruntime_cxx_api.h:1943
ArenaCfg(std::nullptr_t)
Create an empty ArenaCfg object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1944
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:306
bool operator==(const BFloat16_t &rhs) const noexcept
onnxruntime_float16::BFloat16Impl< BFloat16_t > Base
Definition onnxruntime_cxx_api.h:318
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:327
bool operator!=(const BFloat16_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:425
BFloat16_t(float v) noexcept
__ctor from float. Float is converted into bfloat16 16-bit representation.
Definition onnxruntime_cxx_api.h:333
float ToFloat() const noexcept
Converts bfloat16 to float.
Definition onnxruntime_cxx_api.h:339
bool operator<(const BFloat16_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:2325
OrtCustomOpInputOutputCharacteristic GetOutputCharacteristic(size_t) const
Definition onnxruntime_cxx_api.h:2400
OrtCustomOpInputOutputCharacteristic GetInputCharacteristic(size_t) const
Definition onnxruntime_cxx_api.h:2396
OrtMemType GetInputMemoryType(size_t) const
Definition onnxruntime_cxx_api.h:2405
std::vector< std::string > GetSessionConfigKeys() const
Definition onnxruntime_cxx_api.h:2436
bool GetVariadicInputHomogeneity() const
Definition onnxruntime_cxx_api.h:2417
int GetVariadicInputMinArity() const
Definition onnxruntime_cxx_api.h:2411
void SetShapeInferFn(...)
Definition onnxruntime_cxx_api.h:2450
CustomOpBase()
Definition onnxruntime_cxx_api.h:2326
bool GetVariadicOutputHomogeneity() const
Definition onnxruntime_cxx_api.h:2429
int GetVariadicOutputMinArity() const
Definition onnxruntime_cxx_api.h:2423
decltype(&C::InferOutputShape) SetShapeInferFn(decltype(&C::InferOutputShape))
Definition onnxruntime_cxx_api.h:2441
const char * GetExecutionProviderType() const
Definition onnxruntime_cxx_api.h:2392
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:827
~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:733
CustomOpDomain(std::nullptr_t)
Create an empty CustomOpDomain object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:737
CustomOpDomain(const char *domain)
Wraps OrtApi::CreateCustomOpDomain.
void Add(const OrtCustomOp *op)
Wraps CustomOpDomain_Add.
The Env (Environment)
Definition onnxruntime_cxx_api.h:701
Env & EnableTelemetryEvents()
Wraps OrtApi::EnableTelemetryEvents.
Env(OrtEnv *p)
C Interop Helper.
Definition onnxruntime_cxx_api.h:718
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(std::nullptr_t)
Create an empty Env object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:702
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:53
const char * what() const noexcept override
Definition onnxruntime_cxx_api.h:57
OrtErrorCode GetOrtErrorCode() const
Definition onnxruntime_cxx_api.h:56
Exception(std::string &&string, OrtErrorCode code)
Definition onnxruntime_cxx_api.h:54
IEEE 754 half-precision floating point data type.
Definition onnxruntime_cxx_api.h:164
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:192
onnxruntime_float16::Float16Impl< Float16_t > Base
Definition onnxruntime_cxx_api.h:174
float ToFloat() const noexcept
Converts float16 to float.
Definition onnxruntime_cxx_api.h:198
static constexpr Float16_t FromBits(uint16_t v) noexcept
Explicit conversion to uint16_t representation of float16.
Definition onnxruntime_cxx_api.h:186
float8e4m3fn (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:436
uint8_t value
Definition onnxruntime_cxx_api.h:437
constexpr Float8E4M3FN_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:439
constexpr bool operator==(const Float8E4M3FN_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:442
constexpr Float8E4M3FN_t() noexcept
Definition onnxruntime_cxx_api.h:438
constexpr bool operator!=(const Float8E4M3FN_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:443
float8e4m3fnuz (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:453
constexpr bool operator==(const Float8E4M3FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:459
uint8_t value
Definition onnxruntime_cxx_api.h:454
constexpr Float8E4M3FNUZ_t() noexcept
Definition onnxruntime_cxx_api.h:455
constexpr bool operator!=(const Float8E4M3FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:460
constexpr Float8E4M3FNUZ_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:456
float8e5m2 (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:470
constexpr Float8E5M2_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:473
uint8_t value
Definition onnxruntime_cxx_api.h:471
constexpr bool operator!=(const Float8E5M2_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:477
constexpr Float8E5M2_t() noexcept
Definition onnxruntime_cxx_api.h:472
constexpr bool operator==(const Float8E5M2_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:476
float8e5m2fnuz (Float8 Floating Point) data type
Definition onnxruntime_cxx_api.h:487
constexpr Float8E5M2FNUZ_t() noexcept
Definition onnxruntime_cxx_api.h:489
constexpr Float8E5M2FNUZ_t(uint8_t v) noexcept
Definition onnxruntime_cxx_api.h:490
constexpr bool operator!=(const Float8E5M2FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:494
constexpr bool operator==(const Float8E5M2FNUZ_t &rhs) const noexcept
Definition onnxruntime_cxx_api.h:493
uint8_t value
Definition onnxruntime_cxx_api.h:488
Definition onnxruntime_cxx_api.h:85
static const OrtApi * api_
Definition onnxruntime_cxx_api.h:86
Wrapper around OrtIoBinding.
Definition onnxruntime_cxx_api.h:1932
UnownedIoBinding GetUnowned() const
Definition onnxruntime_cxx_api.h:1936
ConstIoBinding GetConst() const
Definition onnxruntime_cxx_api.h:1935
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:1933
This class wraps a raw pointer OrtKernelContext* that is being passed to the custom kernel Compute() ...
Definition onnxruntime_cxx_api.h:2129
KernelContext(OrtKernelContext *context)
Logger GetLogger() const
ConstValue GetInput(size_t index) const
OrtKernelContext * GetOrtKernelContext() const
Definition onnxruntime_cxx_api.h:2143
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:2209
KernelInfo(OrtKernelInfo *info)
Take ownership of the instance.
ConstKernelInfo GetConst() const
Definition onnxruntime_cxx_api.h:2214
detail::KernelInfoImpl< OrtKernelInfo > Base
Definition onnxruntime_cxx_api.h:2210
KernelInfo(std::nullptr_t)
Create an empty instance to initialize later.
Definition onnxruntime_cxx_api.h:2212
This class represents an ONNX Runtime logger that can be used to log information with an associated s...
Definition onnxruntime_cxx_api.h:2051
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:2060
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:747
static LoraAdapter CreateLoraAdapter(const std::basic_string< char > &adapter_path, OrtAllocator *allocator)
Wraps OrtApi::CreateLoraAdapter.
LoraAdapter(std::nullptr_t)
Definition onnxruntime_cxx_api.h:751
static LoraAdapter CreateLoraAdapterFromArray(const void *bytes, size_t num_bytes, OrtAllocator *allocator)
Wraps OrtApi::CreateLoraAdapterFromArray.
Wrapper around OrtMapTypeInfo.
Definition onnxruntime_cxx_api.h:1309
ConstMapTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:1315
MapTypeInfo(OrtMapTypeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1314
MapTypeInfo(std::nullptr_t)
Create an empty MapTypeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1313
Represents native memory allocation coming from one of the OrtAllocators registered with OnnxRuntime....
Definition onnxruntime_cxx_api.h:1843
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:1852
Wrapper around OrtMemoryInfo.
Definition onnxruntime_cxx_api.h:1210
MemoryInfo(const char *name, OrtAllocatorType type, int id, OrtMemType mem_type)
MemoryInfo(std::nullptr_t)
No instance is created.
Definition onnxruntime_cxx_api.h:1212
MemoryInfo(OrtMemoryInfo *p)
Take ownership of a pointer created by C Api.
Definition onnxruntime_cxx_api.h:1213
static MemoryInfo CreateCpu(OrtAllocatorType type, OrtMemType mem_type1)
ConstMemoryInfo GetConst() const
Definition onnxruntime_cxx_api.h:1215
Wrapper around OrtModelMetadata.
Definition onnxruntime_cxx_api.h:971
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:975
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.
This struct provides life time management for custom op attribute.
Definition onnxruntime_cxx_api.h:1963
OpAttr(const char *name, const void *data, int len, OrtOpAttrType type)
OpAttr(std::nullptr_t)
Definition onnxruntime_cxx_api.h:1967
Create and own custom defined operation.
Definition onnxruntime_cxx_api.h:2220
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:2224
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:775
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:776
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:1271
SequenceTypeInfo(std::nullptr_t)
Create an empty SequenceTypeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1275
ConstSequenceTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:1277
SequenceTypeInfo(OrtSequenceTypeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1276
Wrapper around OrtSession.
Definition onnxruntime_cxx_api.h:1174
Session(std::nullptr_t)
Create an empty Session object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1175
UnownedSession GetUnowned() const
Definition onnxruntime_cxx_api.h:1184
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:1183
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:960
SessionOptions(std::nullptr_t)
Create an empty SessionOptions object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:961
UnownedSessionOptions GetUnowned() const
Definition onnxruntime_cxx_api.h:964
SessionOptions()
Wraps OrtApi::CreateSessionOptions.
ConstSessionOptions GetConst() const
Definition onnxruntime_cxx_api.h:965
SessionOptions(OrtSessionOptions *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:963
Definition onnxruntime_cxx_api.h:2254
SymbolicInteger & operator=(const SymbolicInteger &)=default
SymbolicInteger(const SymbolicInteger &)=default
int64_t AsInt() const
Definition onnxruntime_cxx_api.h:2275
int64_t i_
Definition onnxruntime_cxx_api.h:2282
const char * s_
Definition onnxruntime_cxx_api.h:2283
bool operator==(const SymbolicInteger &dim) const
Definition onnxruntime_cxx_api.h:2263
SymbolicInteger & operator=(SymbolicInteger &&)=default
SymbolicInteger(SymbolicInteger &&)=default
const char * AsSym() const
Definition onnxruntime_cxx_api.h:2276
SymbolicInteger(int64_t i)
Definition onnxruntime_cxx_api.h:2255
SymbolicInteger(const char *s)
Definition onnxruntime_cxx_api.h:2256
bool IsInt() const
Definition onnxruntime_cxx_api.h:2274
Provide access to per-node attributes and input shapes, so one could compute and set output shapes.
Definition onnxruntime_cxx_api.h:2253
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:2288
std::vector< float > Floats
Definition onnxruntime_cxx_api.h:2305
std::string GetAttrString(const char *attr_name)
std::vector< int64_t > Ints
Definition onnxruntime_cxx_api.h:2300
ShapeInferContext(const OrtApi *ort_api, OrtShapeInferContext *ctx)
int64_t GetAttrInt(const char *attr_name)
size_t GetInputCount() const
Definition onnxruntime_cxx_api.h:2294
std::vector< std::string > Strings
Definition onnxruntime_cxx_api.h:2310
Floats GetAttrFloats(const char *attr_name)
const Shape & GetInputShape(size_t indice) const
Definition onnxruntime_cxx_api.h:2292
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:652
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:653
Status(std::nullptr_t) noexcept
Create an empty object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:656
Wrapper around OrtTensorTypeAndShapeInfo.
Definition onnxruntime_cxx_api.h:1247
TensorTypeAndShapeInfo(std::nullptr_t)
Create an empty TensorTypeAndShapeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1251
ConstTensorTypeAndShapeInfo GetConst() const
Definition onnxruntime_cxx_api.h:1253
TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo *p)
Used for interop with the C API.
Definition onnxruntime_cxx_api.h:1252
The ThreadingOptions.
Definition onnxruntime_cxx_api.h:670
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:1343
TypeInfo(std::nullptr_t)
Create an empty TypeInfo object, must be assigned a valid one to be used.
Definition onnxruntime_cxx_api.h:1347
ConstTypeInfo GetConst() const
Definition onnxruntime_cxx_api.h:1350
TypeInfo(OrtTypeInfo *p)
C API Interop.
Definition onnxruntime_cxx_api.h:1348
Wrapper around OrtValue.
Definition onnxruntime_cxx_api.h:1682
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:1688
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:1693
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...
ConstValue GetConst() const
Definition onnxruntime_cxx_api.h:1692
Definition onnxruntime_cxx_api.h:625
AllocatedFree(OrtAllocator *allocator)
Definition onnxruntime_cxx_api.h:627
OrtAllocator * allocator_
Definition onnxruntime_cxx_api.h:626
void operator()(void *ptr) const
Definition onnxruntime_cxx_api.h:629
Base & operator=(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:612
typename Unowned< T >::Type contained_type
Definition onnxruntime_cxx_api.h:601
Base(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:611
Base(const Base &)=default
constexpr Base(contained_type *p) noexcept
Definition onnxruntime_cxx_api.h:604
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:557
Base(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:567
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:578
Base(const Base &)=delete
constexpr Base(contained_type *p) noexcept
Definition onnxruntime_cxx_api.h:561
Base & operator=(const Base &)=delete
Base & operator=(Base &&v) noexcept
Definition onnxruntime_cxx_api.h:568
contained_type * p_
Definition onnxruntime_cxx_api.h:585
~Base()
Definition onnxruntime_cxx_api.h:562
T contained_type
Definition onnxruntime_cxx_api.h:558
Definition onnxruntime_cxx_api.h:1900
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:1046
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:1379
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.
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:1911
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:1295
ONNXTensorElementDataType GetMapKeyType() const
Wraps OrtApi::GetMapKeyType.
TypeInfo GetMapValueType() const
Wraps OrtApi::GetMapValueType.
Definition onnxruntime_cxx_api.h:1189
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:1282
TypeInfo GetOptionalElementType() const
Wraps OrtApi::CastOptionalTypeToContainedTypeInfo.
Definition onnxruntime_cxx_api.h:1362
const char ** str
Definition onnxruntime_cxx_api.h:1367
const int64_t * values_shape
Definition onnxruntime_cxx_api.h:1363
size_t values_shape_len
Definition onnxruntime_cxx_api.h:1364
const void * p_data
Definition onnxruntime_cxx_api.h:1366
Definition onnxruntime_cxx_api.h:1258
TypeInfo GetSequenceElementType() const
Wraps OrtApi::GetSequenceElementType.
Definition onnxruntime_cxx_api.h:1090
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 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:1373
const int64_t * shape
Definition onnxruntime_cxx_api.h:1374
size_t shape_len
Definition onnxruntime_cxx_api.h:1375
Definition onnxruntime_cxx_api.h:1220
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:1320
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:533
T Type
Definition onnxruntime_cxx_api.h:534
Definition onnxruntime_cxx_api.h:1540
void FillStringTensorElement(const char *s, size_t index)
Set a single string in a string tensor.
R * GetTensorMutableData()
Returns a non-const typed pointer to an OrtValue/Tensor contained buffer No type checking is performe...
R & At(const std::vector< int64_t > &location)
void UseBlockSparseIndices(const Shape &indices_shape, int32_t *indices_data)
Supplies BlockSparse format specific indices and marks the contained sparse tensor as being a BlockSp...
void FillSparseTensorBlockSparse(const OrtMemoryInfo *data_mem_info, const OrtSparseValuesParam &values, const Shape &indices_shape, const int32_t *indices_data)
The API will allocate memory using the allocator instance supplied to the CreateSparseTensor() API an...
void * GetTensorMutableRawData()
Returns a non-typed non-const pointer to a tensor contained data.
void UseCooIndices(int64_t *indices_data, size_t indices_num)
Supplies COO format specific indices and marks the contained sparse tensor as being a COO format tens...
void FillSparseTensorCoo(const OrtMemoryInfo *data_mem_info, const OrtSparseValuesParam &values_param, const int64_t *indices_data, size_t indices_num)
The API will allocate memory using the allocator instance supplied to the CreateSparseTensor() API an...
void FillStringTensor(const char *const *s, size_t s_len)
Set all strings at once in a string tensor.
void UseCsrIndices(int64_t *inner_data, size_t inner_num, int64_t *outer_data, size_t outer_num)
Supplies CSR format specific indices and marks the contained sparse tensor as being a CSR format tens...
void FillSparseTensorCsr(const OrtMemoryInfo *data_mem_info, const OrtSparseValuesParam &values, const int64_t *inner_indices_data, size_t inner_indices_num, const int64_t *outer_indices_data, size_t outer_indices_num)
The API will allocate memory using the allocator instance supplied to the CreateSparseTensor() API an...
char * GetResizedStringTensorElementBuffer(size_t index, size_t buffer_length)
Allocate if necessary and obtain a pointer to a UTF-8 encoded string element buffer indexed by the fl...
Memory allocation interface.
Definition onnxruntime_c_api.h:321
void(* Free)(struct OrtAllocator *this_, void *p)
Free a block of memory previously allocated with OrtAllocator::Alloc.
Definition onnxruntime_c_api.h:324
const OrtApi *(* GetApi)(uint32_t version)
Get a pointer to the requested version of the OrtApi.
Definition onnxruntime_c_api.h:682
The C API.
Definition onnxruntime_c_api.h:742
CUDA Provider Options.
Definition onnxruntime_c_api.h:411
Definition onnxruntime_c_api.h:4786
int(* GetVariadicInputHomogeneity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:4832
OrtCustomOpInputOutputCharacteristic(* GetOutputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:4816
size_t(* GetInputTypeCount)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:4804
int(* GetVariadicOutputMinArity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:4836
size_t(* GetAliasMap)(int **input_index, int **output_index)
Definition onnxruntime_c_api.h:4869
int(* GetStartVersion)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:4854
void(* ReleaseMayInplace)(int *input_index, int *output_index)
Definition onnxruntime_c_api.h:4866
const char *(* GetName)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:4797
size_t(* GetOutputTypeCount)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:4806
void(* KernelDestroy)(void *op_kernel)
Definition onnxruntime_c_api.h:4812
int(* GetVariadicOutputHomogeneity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:4841
OrtMemType(* GetInputMemoryType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:4823
void *(* CreateKernel)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info)
Definition onnxruntime_c_api.h:4793
uint32_t version
Definition onnxruntime_c_api.h:4787
ONNXTensorElementDataType(* GetInputType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:4803
void(* ReleaseAliasMap)(int *input_index, int *output_index)
Definition onnxruntime_c_api.h:4870
OrtCustomOpInputOutputCharacteristic(* GetInputCharacteristic)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:4815
const char *(* GetExecutionProviderType)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:4800
ONNXTensorElementDataType(* GetOutputType)(const struct OrtCustomOp *op, size_t index)
Definition onnxruntime_c_api.h:4805
int(* GetVariadicInputMinArity)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:4827
OrtStatusPtr(* InferOutputShapeFn)(const struct OrtCustomOp *op, OrtShapeInferContext *)
Definition onnxruntime_c_api.h:4851
int(* GetEndVersion)(const struct OrtCustomOp *op)
Definition onnxruntime_c_api.h:4855
OrtStatusPtr(* CreateKernelV2)(const struct OrtCustomOp *op, const OrtApi *api, const OrtKernelInfo *info, void **kernel)
Definition onnxruntime_c_api.h:4844
size_t(* GetMayInplace)(int **input_index, int **output_index)
Definition onnxruntime_c_api.h:4862
OrtStatusPtr(* KernelComputeV2)(void *op_kernel, OrtKernelContext *context)
Definition onnxruntime_c_api.h:4849
void(* KernelCompute)(void *op_kernel, OrtKernelContext *context)
Definition onnxruntime_c_api.h:4811
MIGraphX Provider Options.
Definition onnxruntime_c_api.h:615
OpenVINO Provider Options.
Definition onnxruntime_c_api.h:637
ROCM Provider Options.
Definition onnxruntime_c_api.h:498
TensorRT Provider Options.
Definition onnxruntime_c_api.h:587