com.github.asus4.onnxruntime 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/Plugins/Android/onnxruntime.aar +0 -0
  2. package/Plugins/Linux/x64/libonnxruntime.so +0 -0
  3. package/Plugins/Windows/arm64/onnxruntime.dll +0 -0
  4. package/Plugins/Windows/x64/onnxruntime.dll +0 -0
  5. package/Plugins/Windows/x86/onnxruntime.dll +0 -0
  6. package/Plugins/iOS~/onnxruntime.xcframework/Info.plist +11 -5
  7. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/onnxruntime_c_api.h +1307 -64
  8. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/onnxruntime_cxx_api.h +425 -24
  9. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/onnxruntime_cxx_inline.h +614 -6
  10. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/onnxruntime_run_options_config_keys.h +3 -0
  11. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/onnxruntime_session_options_config_keys.h +29 -5
  12. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Info.plist +2 -2
  13. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/onnxruntime +0 -0
  14. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst/onnxruntime.framework/Versions/A/Headers/onnxruntime_c_api.h +1307 -64
  15. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst/onnxruntime.framework/Versions/A/Headers/onnxruntime_cxx_api.h +425 -24
  16. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst/onnxruntime.framework/Versions/A/Headers/onnxruntime_cxx_inline.h +614 -6
  17. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst/onnxruntime.framework/Versions/A/Headers/onnxruntime_run_options_config_keys.h +3 -0
  18. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst/onnxruntime.framework/Versions/A/Headers/onnxruntime_session_options_config_keys.h +29 -5
  19. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst/onnxruntime.framework/Versions/A/Resources/Info.plist +2 -2
  20. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst/onnxruntime.framework/Versions/A/onnxruntime +0 -0
  21. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Headers/onnxruntime_c_api.h +1307 -64
  22. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Headers/onnxruntime_cxx_api.h +425 -24
  23. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Headers/onnxruntime_cxx_inline.h +614 -6
  24. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Headers/onnxruntime_run_options_config_keys.h +3 -0
  25. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Headers/onnxruntime_session_options_config_keys.h +29 -5
  26. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Info.plist +2 -2
  27. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/onnxruntime +0 -0
  28. package/Plugins/macOS/arm64/libonnxruntime.dylib +0 -0
  29. package/Plugins/macOS/x64/libonnxruntime.dylib +0 -0
  30. package/README.md +7 -6
  31. package/Runtime/ManagedProjections.shared.cs +1 -2
  32. package/Runtime/NativeMethods.shared.cs +20 -2
  33. package/Runtime/OrtValue.shared.cs +1 -1
  34. package/Runtime/SessionOptions.shared.cs +10 -0
  35. package/Runtime/Training/NativeTrainingMethods.shared.cs +1 -1
  36. package/package.json +1 -1
@@ -26,16 +26,17 @@
26
26
  #include "onnxruntime_c_api.h"
27
27
  #include "onnxruntime_float16.h"
28
28
 
29
+ #include <array>
29
30
  #include <cstddef>
30
31
  #include <cstdio>
31
- #include <array>
32
32
  #include <memory>
33
33
  #include <stdexcept>
34
34
  #include <string>
35
- #include <vector>
35
+ #include <type_traits>
36
36
  #include <unordered_map>
37
37
  #include <utility>
38
- #include <type_traits>
38
+ #include <variant>
39
+ #include <vector>
39
40
 
40
41
  #ifdef ORT_NO_EXCEPTIONS
41
42
  #include <iostream>
@@ -120,7 +121,7 @@ const OrtApi* Global<T>::api_ = OrtGetApiBase()->GetApi(ORT_API_VERSION);
120
121
  #endif
121
122
  #endif
122
123
 
123
- /// This returns a reference to the OrtApi interface in use
124
+ /// This returns a reference to the ORT C API.
124
125
  inline const OrtApi& GetApi() noexcept { return *Global<void>::api_; }
125
126
 
126
127
  /// <summary>
@@ -143,6 +144,48 @@ std::string GetBuildInfoString();
143
144
  /// <returns>vector of strings</returns>
144
145
  std::vector<std::string> GetAvailableProviders();
145
146
 
147
+ /// <summary>
148
+ /// This returns a reference to the ORT C Model Editor API. Used if building or augmenting a model at runtime.
149
+ /// </summary>
150
+ /// <returns>ORT C Model Editor API reference</returns>
151
+ inline const OrtModelEditorApi& GetModelEditorApi() {
152
+ auto* api = GetApi().GetModelEditorApi();
153
+ if (api == nullptr) {
154
+ // minimal build
155
+ ORT_CXX_API_THROW("Model Editor API is not available in this build", ORT_FAIL);
156
+ }
157
+
158
+ return *api;
159
+ }
160
+
161
+ /// <summary>
162
+ /// This returns a reference to the ORT C Compile API. Used if compiling a model at runtime.
163
+ /// </summary>
164
+ /// <returns>ORT C Compile API reference</returns>
165
+ inline const OrtCompileApi& GetCompileApi() {
166
+ auto* api = GetApi().GetCompileApi();
167
+ if (api == nullptr) {
168
+ // minimal build
169
+ ORT_CXX_API_THROW("Compile API is not available in this build", ORT_FAIL);
170
+ }
171
+
172
+ return *api;
173
+ }
174
+
175
+ /// <summary>
176
+ /// This returns a reference to the ORT C EP API. Used if authoring a plugin execution provider.
177
+ /// </summary>
178
+ /// <returns>ORT C EP API reference</returns>
179
+ inline const OrtEpApi& GetEpApi() {
180
+ auto* api = GetApi().GetEpApi();
181
+ if (api == nullptr) {
182
+ // minimal build
183
+ ORT_CXX_API_THROW("EP API is not available in this build", ORT_FAIL);
184
+ }
185
+
186
+ return *api;
187
+ }
188
+
146
189
  /** \brief IEEE 754 half-precision floating point data type
147
190
  *
148
191
  * \details This struct is used for converting float to float16 and back
@@ -502,6 +545,9 @@ namespace detail {
502
545
  #define ORT_DEFINE_RELEASE(NAME) \
503
546
  inline void OrtRelease(Ort##NAME* ptr) { GetApi().Release##NAME(ptr); }
504
547
 
548
+ #define ORT_DEFINE_RELEASE_FROM_API_STRUCT(NAME, API_GETTER) \
549
+ inline void OrtRelease(Ort##NAME* ptr) { API_GETTER().Release##NAME(ptr); }
550
+
505
551
  ORT_DEFINE_RELEASE(Allocator);
506
552
  ORT_DEFINE_RELEASE(MemoryInfo);
507
553
  ORT_DEFINE_RELEASE(CustomOpDomain);
@@ -523,8 +569,16 @@ ORT_DEFINE_RELEASE(Status);
523
569
  ORT_DEFINE_RELEASE(OpAttr);
524
570
  ORT_DEFINE_RELEASE(Op);
525
571
  ORT_DEFINE_RELEASE(KernelInfo);
572
+ ORT_DEFINE_RELEASE(ValueInfo);
573
+ ORT_DEFINE_RELEASE(Node);
574
+ ORT_DEFINE_RELEASE(Graph);
575
+ ORT_DEFINE_RELEASE(Model);
576
+ ORT_DEFINE_RELEASE(KeyValuePairs)
577
+ ORT_DEFINE_RELEASE_FROM_API_STRUCT(ModelCompilationOptions, GetCompileApi);
578
+ ORT_DEFINE_RELEASE_FROM_API_STRUCT(EpDevice, GetEpApi);
526
579
 
527
580
  #undef ORT_DEFINE_RELEASE
581
+ #undef ORT_DEFINE_RELEASE_FROM_API_STRUCT
528
582
 
529
583
  /** \brief This is a tagging template type. Use it with Base<T> to indicate that the C++ interface object
530
584
  * has no ownership of the underlying C object.
@@ -559,7 +613,9 @@ struct Base {
559
613
 
560
614
  constexpr Base() = default;
561
615
  constexpr explicit Base(contained_type* p) noexcept : p_{p} {}
562
- ~Base() { OrtRelease(p_); }
616
+ ~Base() {
617
+ OrtRelease(p_);
618
+ }
563
619
 
564
620
  Base(const Base&) = delete;
565
621
  Base& operator=(const Base&) = delete;
@@ -635,9 +691,14 @@ struct AllocatedFree {
635
691
 
636
692
  struct AllocatorWithDefaultOptions;
637
693
  struct Env;
694
+ struct EpDevice;
695
+ struct Graph;
696
+ struct Model;
697
+ struct Node;
698
+ struct ModelMetadata;
638
699
  struct TypeInfo;
639
700
  struct Value;
640
- struct ModelMetadata;
701
+ struct ValueInfo;
641
702
 
642
703
  /** \brief unique_ptr typedef used to own strings allocated by OrtAllocators
643
704
  * and release them at the end of the scope. The lifespan of the given allocator
@@ -693,6 +754,94 @@ struct ThreadingOptions : detail::Base<OrtThreadingOptions> {
693
754
  ThreadingOptions& SetGlobalCustomJoinThreadFn(OrtCustomJoinThreadFn ort_custom_join_thread_fn);
694
755
  };
695
756
 
757
+ namespace detail {
758
+ template <typename T>
759
+ struct KeyValuePairsImpl : Ort::detail::Base<T> {
760
+ using B = Ort::detail::Base<T>;
761
+ using B::B;
762
+
763
+ const char* GetValue(const char* key) const;
764
+
765
+ // get the pairs in unordered_map. needs to copy to std::string so the hash works as expected
766
+ std::unordered_map<std::string, std::string> GetKeyValuePairs() const;
767
+ // get the pairs in two vectors. entries will be 1:1 between keys and values. avoids copying to std::string
768
+ void GetKeyValuePairs(std::vector<const char*>& keys, std::vector<const char*>& values) const;
769
+ };
770
+ } // namespace detail
771
+
772
+ // Const object holder that does not own the underlying object
773
+ using ConstKeyValuePairs = detail::KeyValuePairsImpl<Ort::detail::Unowned<const OrtKeyValuePairs>>;
774
+
775
+ /** \brief Wrapper around ::OrtKeyValuePair */
776
+ struct KeyValuePairs : detail::KeyValuePairsImpl<OrtKeyValuePairs> {
777
+ explicit KeyValuePairs(std::nullptr_t) {} ///< No instance is created
778
+ /// Take ownership of a pointer created by C API
779
+ explicit KeyValuePairs(OrtKeyValuePairs* p) : KeyValuePairsImpl<OrtKeyValuePairs>{p} {}
780
+
781
+ /// \brief Wraps OrtApi::CreateKeyValuePairs
782
+ explicit KeyValuePairs();
783
+
784
+ /// \brief Wraps OrtApi::CreateKeyValuePairs and OrtApi::AddKeyValuePair
785
+ explicit KeyValuePairs(const std::unordered_map<std::string, std::string>& kv_pairs);
786
+
787
+ /// \brief Wraps OrtApi::AddKeyValuePair
788
+ void Add(const char* key, const char* value);
789
+
790
+ /// \brief Wraps OrtApi::RemoveKeyValuePair
791
+ void Remove(const char* key);
792
+
793
+ ConstKeyValuePairs GetConst() const { return ConstKeyValuePairs{this->p_}; }
794
+ };
795
+
796
+ namespace detail {
797
+ template <typename T>
798
+ struct HardwareDeviceImpl : Ort::detail::Base<T> {
799
+ using B = Ort::detail::Base<T>;
800
+ using B::B;
801
+
802
+ OrtHardwareDeviceType Type() const;
803
+ uint32_t VendorId() const;
804
+ uint32_t DeviceId() const;
805
+ const char* Vendor() const;
806
+ ConstKeyValuePairs Metadata() const;
807
+ };
808
+ } // namespace detail
809
+
810
+ /** \brief Wrapper around ::OrtHardwareDevice
811
+ * \remarks HardwareDevice is always read-only for API users.
812
+ */
813
+ using ConstHardwareDevice = detail::HardwareDeviceImpl<Ort::detail::Unowned<const OrtHardwareDevice>>;
814
+
815
+ namespace detail {
816
+ template <typename T>
817
+ struct EpDeviceImpl : Ort::detail::Base<T> {
818
+ using B = Ort::detail::Base<T>;
819
+ using B::B;
820
+
821
+ const char* EpName() const;
822
+ const char* EpVendor() const;
823
+ ConstKeyValuePairs EpMetadata() const;
824
+ ConstKeyValuePairs EpOptions() const;
825
+ ConstHardwareDevice Device() const;
826
+ };
827
+ } // namespace detail
828
+
829
+ /** \brief Wrapper around ::OrtEpDevice
830
+ * \remarks EpDevice is always read-only for ORT API users.
831
+ */
832
+ using ConstEpDevice = detail::EpDeviceImpl<Ort::detail::Unowned<const OrtEpDevice>>;
833
+
834
+ /** \brief Mutable EpDevice that is created by EpApi users.
835
+ */
836
+ struct EpDevice : detail::EpDeviceImpl<OrtEpDevice> {
837
+ explicit EpDevice(std::nullptr_t) {} ///< No instance is created
838
+ explicit EpDevice(OrtEpDevice* p) : EpDeviceImpl<OrtEpDevice>{p} {} ///< Take ownership of a pointer created by C API
839
+
840
+ /// \brief Wraps OrtEpApi::CreateEpDevice
841
+ EpDevice(OrtEpFactory& ep_factory, ConstHardwareDevice& hardware_device,
842
+ ConstKeyValuePairs ep_metadata = {}, ConstKeyValuePairs ep_options = {});
843
+ };
844
+
696
845
  /** \brief The Env (Environment)
697
846
  *
698
847
  * The Env holds the logging state used by all other objects.
@@ -724,7 +873,14 @@ struct Env : detail::Base<OrtEnv> {
724
873
 
725
874
  Env& CreateAndRegisterAllocator(const OrtMemoryInfo* mem_info, const OrtArenaCfg* arena_cfg); ///< Wraps OrtApi::CreateAndRegisterAllocator
726
875
 
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); ///< Wraps OrtApi::CreateAndRegisterAllocatorV2
876
+ Env& CreateAndRegisterAllocatorV2(const std::string& provider_type, const OrtMemoryInfo* mem_info,
877
+ const std::unordered_map<std::string, std::string>& options,
878
+ const OrtArenaCfg* arena_cfg); ///< Wraps OrtApi::CreateAndRegisterAllocatorV2
879
+
880
+ Env& RegisterExecutionProviderLibrary(const char* registration_name, const std::basic_string<ORTCHAR_T>& path); ///< Wraps OrtApi::RegisterExecutionProviderLibrary
881
+ Env& UnregisterExecutionProviderLibrary(const char* registration_name); ///< Wraps OrtApi::UnregisterExecutionProviderLibrary
882
+
883
+ std::vector<ConstEpDevice> GetEpDevices() const;
728
884
  };
729
885
 
730
886
  /** \brief Custom Op Domain
@@ -875,7 +1031,7 @@ struct ConstSessionOptionsImpl : Base<T> {
875
1031
 
876
1032
  std::string GetConfigEntry(const char* config_key) const; ///< Wraps OrtApi::GetSessionConfigEntry
877
1033
  bool HasConfigEntry(const char* config_key) const; ///< Wraps OrtApi::HasSessionConfigEntry
878
- std::string GetConfigEntryOrDefault(const char* config_key, const std::string& def);
1034
+ std::string GetConfigEntryOrDefault(const char* config_key, const std::string& def) const;
879
1035
  };
880
1036
 
881
1037
  template <typename T>
@@ -903,6 +1059,8 @@ struct SessionOptionsImpl : ConstSessionOptionsImpl<T> {
903
1059
 
904
1060
  SessionOptionsImpl& SetExecutionMode(ExecutionMode execution_mode); ///< Wraps OrtApi::SetSessionExecutionMode
905
1061
 
1062
+ SessionOptionsImpl& SetLoadCancellationFlag(bool value); ///< Wraps OrtApi::SessionOptionsSetLoadCancellationFlag
1063
+
906
1064
  SessionOptionsImpl& SetLogId(const char* logid); ///< Wraps OrtApi::SetSessionLogId
907
1065
  SessionOptionsImpl& SetLogSeverityLevel(int level); ///< Wraps OrtApi::SetSessionLogSeverityLevel
908
1066
 
@@ -927,14 +1085,29 @@ struct SessionOptionsImpl : ConstSessionOptionsImpl<T> {
927
1085
  SessionOptionsImpl& AppendExecutionProvider_TensorRT(const OrtTensorRTProviderOptions& provider_options); ///< Wraps OrtApi::SessionOptionsAppendExecutionProvider_TensorRT
928
1086
  SessionOptionsImpl& AppendExecutionProvider_TensorRT_V2(const OrtTensorRTProviderOptionsV2& provider_options); ///< Wraps OrtApi::SessionOptionsAppendExecutionProvider_TensorRT
929
1087
  SessionOptionsImpl& AppendExecutionProvider_MIGraphX(const OrtMIGraphXProviderOptions& provider_options); ///< Wraps OrtApi::SessionOptionsAppendExecutionProvider_MIGraphX
930
- ///< Wraps OrtApi::SessionOptionsAppendExecutionProvider_CANN
1088
+ /// Wraps OrtApi::SessionOptionsAppendExecutionProvider_CANN
931
1089
  SessionOptionsImpl& AppendExecutionProvider_CANN(const OrtCANNProviderOptions& provider_options);
932
- ///< Wraps OrtApi::SessionOptionsAppendExecutionProvider_Dnnl
1090
+ /// Wraps OrtApi::SessionOptionsAppendExecutionProvider_Dnnl
933
1091
  SessionOptionsImpl& AppendExecutionProvider_Dnnl(const OrtDnnlProviderOptions& provider_options);
934
1092
  /// Wraps OrtApi::SessionOptionsAppendExecutionProvider. Currently supports QNN, SNPE and XNNPACK.
935
1093
  SessionOptionsImpl& AppendExecutionProvider(const std::string& provider_name,
936
1094
  const std::unordered_map<std::string, std::string>& provider_options = {});
937
1095
 
1096
+ /// Append EPs that have been registered previously with the OrtEnv.
1097
+ /// Wraps OrtApi::SessionOptionsAppendExecutionProvider_V2
1098
+ SessionOptionsImpl& AppendExecutionProvider_V2(Env& env, const std::vector<ConstEpDevice>& ep_devices,
1099
+ const KeyValuePairs& ep_options);
1100
+ /// Append EPs that have been registered previously with the OrtEnv.
1101
+ /// Wraps OrtApi::SessionOptionsAppendExecutionProvider_V2
1102
+ SessionOptionsImpl& AppendExecutionProvider_V2(Env& env, const std::vector<ConstEpDevice>& ep_devices,
1103
+ const std::unordered_map<std::string, std::string>& ep_options);
1104
+
1105
+ /// Wraps OrtApi::SessionOptionsSetEpSelectionPolicy
1106
+ SessionOptionsImpl& SetEpSelectionPolicy(OrtExecutionProviderDevicePolicy policy);
1107
+
1108
+ /// Wraps OrtApi::SessionOptionsSetEpSelectionPolicyDelegate
1109
+ SessionOptionsImpl& SetEpSelectionPolicy(EpSelectionDelegate delegate, void* state = nullptr);
1110
+
938
1111
  SessionOptionsImpl& SetCustomCreateThreadFn(OrtCustomCreateThreadFn ort_custom_create_thread_fn); ///< Wraps OrtApi::SessionOptionsSetCustomCreateThreadFn
939
1112
  SessionOptionsImpl& SetCustomThreadCreationOptions(void* ort_custom_thread_creation_options); ///< Wraps OrtApi::SessionOptionsSetCustomThreadCreationOptions
940
1113
  SessionOptionsImpl& SetCustomJoinThreadFn(OrtCustomJoinThreadFn ort_custom_join_thread_fn); ///< Wraps OrtApi::SessionOptionsSetCustomJoinThreadFn
@@ -965,6 +1138,38 @@ struct SessionOptions : detail::SessionOptionsImpl<OrtSessionOptions> {
965
1138
  ConstSessionOptions GetConst() const { return ConstSessionOptions{this->p_}; }
966
1139
  };
967
1140
 
1141
+ /** \brief Options object used when compiling a model.
1142
+ *
1143
+ * Wraps ::OrtModelCompilationOptions object and methods
1144
+ */
1145
+ struct ModelCompilationOptions : detail::Base<OrtModelCompilationOptions> {
1146
+ using Base = detail::Base<OrtModelCompilationOptions>;
1147
+ using Base::Base;
1148
+
1149
+ explicit ModelCompilationOptions(std::nullptr_t) {} ///< Create an empty ModelCompilationOptions object, must be assigned a valid one to be used.
1150
+
1151
+ ModelCompilationOptions(const Env& env, const SessionOptions& session_options); ///< Wraps OrtApi::CreateModelCompilationOptionsFromSessionOptions
1152
+ ModelCompilationOptions(const Env& env, ConstSessionOptions session_options); ///< Wraps OrtApi::CreateModelCompilationOptionsFromSessionOptions
1153
+
1154
+ ModelCompilationOptions& SetInputModelPath(const ORTCHAR_T* input_model_path); ///< Wraps OrtApi::ModelCompilationOptions_SetInputModelPath
1155
+ ModelCompilationOptions& SetInputModelFromBuffer(const void* input_model_data,
1156
+ size_t input_model_data_size); ///< Wraps OrtApi::ModelCompilationOptions_SetInputModelFromBuffer
1157
+ ModelCompilationOptions& SetEpContextEmbedMode(bool embed_ep_context_in_model); ///< Wraps OrtApi::ModelCompilationOptions_SetEpContextEmbedMode
1158
+ ModelCompilationOptions& SetOutputModelPath(const ORTCHAR_T* output_model_path); ///< Wraps OrtApi::ModelCompilationOptions_SetOutputModelPath
1159
+ ModelCompilationOptions& SetOutputModelExternalInitializersFile(const ORTCHAR_T* file_path,
1160
+ size_t initializer_size_threshold); ///< Wraps OrtApi::ModelCompilationOptions_SetOutputModelExternalInitializersFile
1161
+ ModelCompilationOptions& SetOutputModelBuffer(OrtAllocator* allocator, void** output_model_buffer_ptr,
1162
+ size_t* output_model_buffer_size_ptr); ///< Wraps OrtApi::ModelCompilationOptions_SetOutputModelBuffer
1163
+ };
1164
+
1165
+ /** \brief Compiles an input model to generate a model with EPContext nodes that execute EP-specific kernels. Wraps OrtApi::CompileModels.
1166
+ *
1167
+ * \param env: ORT environment object.
1168
+ * \param model_compilation_options: Compilation options for a model.
1169
+ * \return A Status indicating success or failure.
1170
+ */
1171
+ Status CompileModel(const Env& env, const ModelCompilationOptions& model_compilation_options);
1172
+
968
1173
  /** \brief Wrapper around ::OrtModelMetadata
969
1174
  *
970
1175
  */
@@ -1051,6 +1256,10 @@ struct ConstSessionImpl : Base<T> {
1051
1256
  size_t GetOutputCount() const; ///< Returns the number of model outputs
1052
1257
  size_t GetOverridableInitializerCount() const; ///< Returns the number of inputs that have defaults that can be overridden
1053
1258
 
1259
+ std::vector<std::string> GetInputNames() const;
1260
+ std::vector<std::string> GetOutputNames() const;
1261
+ std::vector<std::string> GetOverridableInitializerNames() const;
1262
+
1054
1263
  /** \brief Returns a copy of input name at the specified index.
1055
1264
  *
1056
1265
  * \param index must less than the value returned by GetInputCount()
@@ -1084,6 +1293,12 @@ struct ConstSessionImpl : Base<T> {
1084
1293
  TypeInfo GetInputTypeInfo(size_t index) const; ///< Wraps OrtApi::SessionGetInputTypeInfo
1085
1294
  TypeInfo GetOutputTypeInfo(size_t index) const; ///< Wraps OrtApi::SessionGetOutputTypeInfo
1086
1295
  TypeInfo GetOverridableInitializerTypeInfo(size_t index) const; ///< Wraps OrtApi::SessionGetOverridableInitializerTypeInfo
1296
+
1297
+ int GetOpset(const std::string& domain) const; ///< Wraps OrtApi::SessionGetOpsetForDomain
1298
+
1299
+ // Will move before checkin if that's the case.
1300
+ std::vector<ValueInfo> GetInputs() const;
1301
+ std::vector<ValueInfo> GetOutputs() const;
1087
1302
  };
1088
1303
 
1089
1304
  template <typename T>
@@ -1161,6 +1376,9 @@ struct SessionImpl : ConstSessionImpl<T> {
1161
1376
  * \param[in] kv_len Number of elements in the keys and values arrays
1162
1377
  */
1163
1378
  void SetEpDynamicOptions(const char* const* keys, const char* const* values, size_t kv_len);
1379
+
1380
+ void FinalizeModelEditorSession(const Model& model, const SessionOptions& options,
1381
+ OrtPrepackedWeightsContainer* prepacked_weights_container = nullptr);
1164
1382
  };
1165
1383
 
1166
1384
  } // namespace detail
@@ -1172,13 +1390,34 @@ using UnownedSession = detail::SessionImpl<detail::Unowned<OrtSession>>;
1172
1390
  *
1173
1391
  */
1174
1392
  struct Session : detail::SessionImpl<OrtSession> {
1175
- explicit Session(std::nullptr_t) {} ///< Create an empty Session object, must be assigned a valid one to be used
1176
- Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options); ///< Wraps OrtApi::CreateSession
1393
+ /// Create an empty Session object, must be assigned a valid one to be used. Wraps OrtApi::CreateSession
1394
+ explicit Session(std::nullptr_t) {}
1395
+ explicit Session(OrtSession* p) : SessionImpl{p} {} ///< C API Interop
1396
+
1397
+ Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
1398
+
1399
+ /// Wraps OrtApi::CreateSessionWithPrepackedWeightsContainer
1177
1400
  Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options,
1178
- OrtPrepackedWeightsContainer* prepacked_weights_container); ///< Wraps OrtApi::CreateSessionWithPrepackedWeightsContainer
1179
- Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options); ///< Wraps OrtApi::CreateSessionFromArray
1401
+ OrtPrepackedWeightsContainer* prepacked_weights_container);
1402
+
1403
+ /// Wraps OrtApi::CreateSessionFromArray
1404
+ Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options);
1405
+
1406
+ /// Wraps OrtApi::CreateSessionFromArrayWithPrepackedWeightsContainer
1180
1407
  Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options,
1181
- OrtPrepackedWeightsContainer* prepacked_weights_container); ///< Wraps OrtApi::CreateSessionFromArrayWithPrepackedWeightsContainer
1408
+ OrtPrepackedWeightsContainer* prepacked_weights_container);
1409
+
1410
+ #if !defined(ORT_MINIMAL_BUILD)
1411
+ /// Wraps OrtModelEditorApi::CreateSessionFromModel
1412
+ Session(const Env& env, const Model& model, const SessionOptions& options);
1413
+
1414
+ /// Wraps OrtModelEditorApi::CreateModelEditorSession
1415
+ static Session CreateModelEditorSession(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);
1416
+
1417
+ /// Wraps OrtModelEditorApi::CreateModelEditorSession
1418
+ static Session CreateModelEditorSession(const Env& env, const void* model_data, size_t model_data_length,
1419
+ const SessionOptions& options);
1420
+ #endif // !defined(ORT_MINIMAL_BUILD)
1182
1421
 
1183
1422
  ConstSession GetConst() const { return ConstSession{this->p_}; }
1184
1423
  UnownedSession GetUnowned() const { return UnownedSession{this->p_}; }
@@ -1210,7 +1449,7 @@ using ConstMemoryInfo = detail::MemoryInfoImpl<detail::Unowned<const OrtMemoryIn
1210
1449
  struct MemoryInfo : detail::MemoryInfoImpl<OrtMemoryInfo> {
1211
1450
  static MemoryInfo CreateCpu(OrtAllocatorType type, OrtMemType mem_type1);
1212
1451
  explicit MemoryInfo(std::nullptr_t) {} ///< No instance is created
1213
- explicit MemoryInfo(OrtMemoryInfo* p) : MemoryInfoImpl<OrtMemoryInfo>{p} {} ///< Take ownership of a pointer created by C Api
1452
+ explicit MemoryInfo(OrtMemoryInfo* p) : MemoryInfoImpl<OrtMemoryInfo>{p} {} ///< Take ownership of a pointer created by C API
1214
1453
  MemoryInfo(const char* name, OrtAllocatorType type, int id, OrtMemType mem_type);
1215
1454
  ConstMemoryInfo GetConst() const { return ConstMemoryInfo{this->p_}; }
1216
1455
  };
@@ -1233,6 +1472,7 @@ struct TensorTypeAndShapeInfoImpl : Base<T> {
1233
1472
  [[deprecated("use GetShape()")]] void GetDimensions(int64_t* values, size_t values_count) const; ///< Wraps OrtApi::GetDimensions
1234
1473
 
1235
1474
  void GetSymbolicDimensions(const char** values, size_t values_count) const; ///< Wraps OrtApi::GetSymbolicDimensions
1475
+ std::vector<const char*> GetSymbolicDimensions() const;
1236
1476
 
1237
1477
  std::vector<int64_t> GetShape() const; ///< Uses GetDimensionsCount & GetDimensions to return a std::vector of the shape
1238
1478
  };
@@ -1248,8 +1488,18 @@ struct TensorTypeAndShapeInfo : detail::TensorTypeAndShapeInfoImpl<OrtTensorType
1248
1488
  using Base = detail::TensorTypeAndShapeInfoImpl<OrtTensorTypeAndShapeInfo>;
1249
1489
  using Base::Base;
1250
1490
 
1251
- explicit TensorTypeAndShapeInfo(std::nullptr_t) {} ///< Create an empty TensorTypeAndShapeInfo object, must be assigned a valid one to be used
1252
- explicit TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* p) : TensorTypeAndShapeInfoImpl{p} {} ///< Used for interop with the C API
1491
+ /// Create an empty TensorTypeAndShapeInfo object, must be assigned a valid one to be used
1492
+ explicit TensorTypeAndShapeInfo(std::nullptr_t) {}
1493
+ /// Used for interop with the C API
1494
+ explicit TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* p) : TensorTypeAndShapeInfoImpl{p} {}
1495
+
1496
+ // Create a TensorTypeAndShapeInfo object with the specified element type and dimensions
1497
+ // symbolic_dims are optional, but should be 1:1 with dims.
1498
+ // The value in symbolic_dims will be used for all entries in dims that are -1.
1499
+ explicit TensorTypeAndShapeInfo(ONNXTensorElementDataType element_type,
1500
+ const std::vector<int64_t>& dims,
1501
+ const std::vector<std::string>* symbolic_dims = nullptr);
1502
+
1253
1503
  ConstTensorTypeAndShapeInfo GetConst() const { return ConstTensorTypeAndShapeInfo{this->p_}; }
1254
1504
  };
1255
1505
 
@@ -1344,9 +1594,18 @@ struct TypeInfo : detail::TypeInfoImpl<OrtTypeInfo> {
1344
1594
  using Base = detail::TypeInfoImpl<OrtTypeInfo>;
1345
1595
  using Base::Base;
1346
1596
 
1347
- explicit TypeInfo(std::nullptr_t) {} ///< Create an empty TypeInfo object, must be assigned a valid one to be used
1597
+ /// Create an empty TypeInfo object, must be assigned a valid one to be used
1598
+ explicit TypeInfo(std::nullptr_t) {}
1348
1599
  explicit TypeInfo(OrtTypeInfo* p) : TypeInfoImpl<OrtTypeInfo>{p} {} ///< C API Interop
1349
1600
 
1601
+ #if !defined(ORT_MINIMAL_BUILD)
1602
+ static TypeInfo CreateTensorInfo(ConstTensorTypeAndShapeInfo tensor_info);
1603
+ static TypeInfo CreateSparseTensorInfo(ConstTensorTypeAndShapeInfo sparse_tensor_info);
1604
+ static TypeInfo CreateSequenceTypeInfo(ConstTypeInfo sequence_type);
1605
+ static TypeInfo CreateMapTypeInfo(ONNXTensorElementDataType key_type, ConstTypeInfo value_type);
1606
+ static TypeInfo CreateOptionalTypeInfo(ConstTypeInfo contained_type);
1607
+ #endif // !defined(ORT_MINIMAL_BUILD)
1608
+
1350
1609
  ConstTypeInfo GetConst() const { return ConstTypeInfo{this->p_}; }
1351
1610
  };
1352
1611
 
@@ -1701,7 +1960,8 @@ struct Value : detail::ValueImpl<OrtValue> {
1701
1960
  * \param shape_len The number of tensor shape dimensions.
1702
1961
  */
1703
1962
  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);
1963
+ static Value CreateTensor(const OrtMemoryInfo* info, T* p_data, size_t p_data_element_count,
1964
+ const int64_t* shape, size_t shape_len);
1705
1965
 
1706
1966
  /** \brief Creates a tensor with a user supplied buffer. Wraps OrtApi::CreateTensorWithDataAsOrtValue.
1707
1967
  *
@@ -1712,11 +1972,25 @@ struct Value : detail::ValueImpl<OrtValue> {
1712
1972
  * \param shape_len The number of tensor shape dimensions.
1713
1973
  * \param type The data type.
1714
1974
  */
1715
- static Value CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count, const int64_t* shape, size_t shape_len,
1975
+ static Value CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count,
1976
+ const int64_t* shape, size_t shape_len,
1977
+ ONNXTensorElementDataType type);
1978
+
1979
+ /** \brief Creates a tensor with a user supplied buffer. Wraps OrtApi::CreateTensorWithDataAndDeleterAsOrtValue.
1980
+ *
1981
+ * \param deleter OrtAllocator that will be used to free the buffer when no longer required.
1982
+ * \param p_data Pointer to the data buffer.
1983
+ * \param p_data_byte_count The number of bytes in the data buffer.
1984
+ * \param shape Pointer to the tensor shape dimensions.
1985
+ * \param shape_len The number of tensor shape dimensions.
1986
+ * \param type The data type.
1987
+ */
1988
+ static Value CreateTensor(OrtAllocator* deleter, void* p_data, size_t p_data_byte_count,
1989
+ const int64_t* shape, size_t shape_len,
1716
1990
  ONNXTensorElementDataType type);
1717
1991
 
1718
1992
  /** \brief Creates an OrtValue with a tensor using a supplied OrtAllocator. Wraps OrtApi::CreateTensorAsOrtValue.
1719
- * This overload will allocate the buffer for the tensor according to the supplied shape and data type.
1993
+ * This overload will allocate the buffer for the tensor according to the supplied shape and data type.
1720
1994
  * The allocated buffer will be owned by the returned OrtValue and will be freed when the OrtValue is released.
1721
1995
  * The input data would need to be copied into the allocated buffer.
1722
1996
  * This API is not suitable for strings.
@@ -1740,7 +2014,8 @@ struct Value : detail::ValueImpl<OrtValue> {
1740
2014
  * \param shape_len The number of tensor shape dimensions.
1741
2015
  * \param type The data type.
1742
2016
  */
1743
- static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type);
2017
+ static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len,
2018
+ ONNXTensorElementDataType type);
1744
2019
 
1745
2020
  /** \brief Creates an OrtValue with a Map Onnx type representation.
1746
2021
  * The API would ref-count the supplied OrtValues and they will be released
@@ -2437,6 +2712,9 @@ struct CustomOpBase : OrtCustomOp {
2437
2712
  return std::vector<std::string>{};
2438
2713
  }
2439
2714
 
2715
+ // Ort::CustomOpBase derived class should provide the following static method with the type/shape inferencing
2716
+ // implementation if needed:
2717
+ // static OrtStatusPtr InferOutputShape(Ort::ShapeInferContext& context)
2440
2718
  template <typename C>
2441
2719
  decltype(&C::InferOutputShape) SetShapeInferFn(decltype(&C::InferOutputShape)) {
2442
2720
  OrtCustomOp::InferOutputShapeFn = [](const OrtCustomOp*, OrtShapeInferContext* ort_ctx) -> OrtStatusPtr {
@@ -2459,6 +2737,129 @@ struct CustomOpBase : OrtCustomOp {
2459
2737
  int end_ver_ = MAX_CUSTOM_OP_END_VER;
2460
2738
  };
2461
2739
 
2462
- } // namespace Ort
2740
+ namespace detail {
2741
+ template <typename T>
2742
+ struct ValueInfoImpl : Ort::detail::Base<T> {
2743
+ using B = Ort::detail::Base<T>;
2744
+ using B::B;
2745
+
2746
+ std::string Name() const;
2747
+ ConstTypeInfo TypeInfo() const;
2748
+ };
2749
+ } // namespace detail
2750
+
2751
+ // Const object holder that does not own the underlying object
2752
+ using ConstValueInfo = detail::ValueInfoImpl<Ort::detail::Unowned<const OrtValueInfo>>;
2753
+
2754
+ /** \brief Wrapper around ::OrtValueInfo
2755
+ *
2756
+ */
2757
+ struct ValueInfo : detail::ValueInfoImpl<OrtValueInfo> {
2758
+ explicit ValueInfo(std::nullptr_t) {} ///< No instance is created
2759
+ /// Take ownership of a pointer created by C API
2760
+ explicit ValueInfo(OrtValueInfo* p) : ValueInfoImpl<OrtValueInfo>{p} {}
2761
+
2762
+ // Create ValueInfo for a tensor
2763
+ explicit ValueInfo(const std::string& name, const ConstTypeInfo& type_info);
2764
+
2765
+ ConstValueInfo GetConst() const { return ConstValueInfo{this->p_}; }
2766
+ };
2767
+
2768
+ namespace detail {
2769
+ template <typename T>
2770
+ struct NodeImpl : Ort::detail::Base<T> {
2771
+ using B = Ort::detail::Base<T>;
2772
+ using B::B;
2773
+ };
2774
+ } // namespace detail
2775
+
2776
+ /** \brief Wrapper around ::OrtNode
2777
+ *
2778
+ */
2779
+ struct Node : detail::NodeImpl<OrtNode> {
2780
+ explicit Node(std::nullptr_t) {} ///< No instance is created
2781
+ explicit Node(OrtNode* p) : NodeImpl<OrtNode>{p} {} ///< Take ownership of a pointer created by C API
2782
+
2783
+ #if !defined(ORT_MINIMAL_BUILD)
2784
+ Node(const std::string& operator_name, const std::string& operator_domain,
2785
+ const std::string& node_name,
2786
+ const std::vector<std::string>& input_names,
2787
+ const std::vector<std::string>& output_names);
2788
+
2789
+ /// <summary>
2790
+ /// Wraps CreateNode. Node takes ownership of attributes on success and updates the OpAttr in `attributes` to do so.
2791
+ /// </summary>
2792
+ Node(const std::string& operator_name, const std::string& operator_domain,
2793
+ const std::string& node_name,
2794
+ const std::vector<std::string>& input_names,
2795
+ const std::vector<std::string>& output_names,
2796
+ std::vector<OpAttr>& attributes);
2797
+
2798
+ private:
2799
+ static void Init(const std::string& operator_name, const std::string& operator_domain,
2800
+ const std::string& node_name,
2801
+ const std::vector<std::string>& input_names,
2802
+ const std::vector<std::string>& output_names,
2803
+ std::vector<OpAttr>& attributes,
2804
+ OrtNode*& node);
2805
+ #endif // !defined(ORT_MINIMAL_BUILD)
2806
+ };
2807
+
2808
+ namespace detail {
2809
+ template <typename T>
2810
+ struct GraphImpl : Ort::detail::Base<T> {
2811
+ using B = Ort::detail::Base<T>;
2812
+ using B::B;
2813
+
2814
+ #if !defined(ORT_MINIMAL_BUILD)
2815
+ void SetInputs(std::vector<ValueInfo>& inputs);
2816
+ void SetOutputs(std::vector<ValueInfo>& outputs);
2817
+ void AddInitializer(const std::string& name, Value& initializer, bool data_is_external); // Graph takes ownership of Value
2818
+ void AddNode(Node& node); // Graph takes ownership of Node
2819
+ #endif // !defined(ORT_MINIMAL_BUILD)
2820
+ };
2821
+ } // namespace detail
2822
+
2823
+ /** \brief Wrapper around ::OrtGraph
2824
+ *
2825
+ */
2826
+ struct Graph : detail::GraphImpl<OrtGraph> {
2827
+ explicit Graph(std::nullptr_t) {} ///< No instance is created
2828
+ explicit Graph(OrtGraph* p) : GraphImpl<OrtGraph>{p} {} ///< Take ownership of a pointer created by C API
2829
+ #if !defined(ORT_MINIMAL_BUILD)
2830
+ Graph();
2831
+ #endif
2832
+ };
2833
+
2834
+ namespace detail {
2835
+ template <typename T>
2836
+ struct ModelImpl : Ort::detail::Base<T> {
2837
+ using B = Ort::detail::Base<T>;
2838
+ using B::B;
2839
+
2840
+ #if !defined(ORT_MINIMAL_BUILD)
2841
+ void AddGraph(Graph& graph);
2842
+ #endif
2843
+ };
2844
+ } // namespace detail
2463
2845
 
2846
+ // Const object holder that does not own the underlying object
2847
+ using ConstModel = detail::ModelImpl<Ort::detail::Unowned<const OrtModel>>;
2848
+
2849
+ /** \brief Wrapper around ::OrtModel
2850
+ *
2851
+ */
2852
+ struct Model : detail::ModelImpl<OrtModel> {
2853
+ using DomainOpsetPair = std::pair<std::string, int>;
2854
+
2855
+ explicit Model(std::nullptr_t) {} ///< No instance is created
2856
+ explicit Model(OrtModel* p) : ModelImpl<OrtModel>{p} {} ///< Take ownership of a pointer created by C API
2857
+
2858
+ #if !defined(ORT_MINIMAL_BUILD)
2859
+ explicit Model(const std::vector<DomainOpsetPair>& opsets);
2860
+ #endif
2861
+
2862
+ ConstModel GetConst() const { return ConstModel{this->p_}; }
2863
+ };
2864
+ } // namespace Ort
2464
2865
  #include "onnxruntime_cxx_inline.h"