Skip to content

Commit 72aa066

Browse files
committed
Merge branch 'main' into pad
2 parents 8540e1a + 30c6825 commit 72aa066

File tree

134 files changed

+7878
-5166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+7878
-5166
lines changed

.gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
[submodule "cmake/external/emsdk"]
88
path = cmake/external/emsdk
99
url = https://github.com/emscripten-core/emsdk.git
10-
branch = 4.0.3
10+
branch = 4.0.4

cmake/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,11 @@ if (onnxruntime_USE_OPENVINO)
15121512

15131513
endif()
15141514

1515+
if (onnxruntime_USE_OPENVINO_INTERFACE AND (NOT onnxruntime_USE_OPENVINO))
1516+
add_definitions(-DUSE_OPENVINO=1)
1517+
add_definitions(-DOPENVINO_CONFIG_NPU=1)
1518+
endif()
1519+
15151520
if (onnxruntime_USE_VITISAI)
15161521
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_LIST_DIR}")
15171522
endif()

cmake/deps.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ mimalloc;https://github.com/microsoft/mimalloc/archive/refs/tags/v2.1.1.zip;d5ee
3737
mp11;https://github.com/boostorg/mp11/archive/refs/tags/boost-1.82.0.zip;9bc9e01dffb64d9e0773b2e44d2f22c51aace063
3838
onnx;https://github.com/onnx/onnx/archive/refs/tags/v1.17.0.zip;13a60ac5217c104139ce0fd024f48628e7bcf5bc
3939
# Use the latest commit of 10.8-GA
40-
onnx_tensorrt;https://github.com/onnx/onnx-tensorrt/archive/118ed0aea197fa9a7d3ea66180a1d5ddb9deecc3.zip;b78aed3728ad4daf6dc47ea10c1d243dee1d95b1
40+
onnx_tensorrt;https://github.com/onnx/onnx-tensorrt/archive/c5ca8912f30e9ad630a0ef565e3d5f4bd5e91563.zip;588b294aaa9e84679ed5815cea1d399210ac98c2
4141
protobuf;https://github.com/protocolbuffers/protobuf/archive/refs/tags/v21.12.zip;7cf2733949036c7d52fda017badcab093fe73bfa
4242
protoc_win64;https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protoc-21.12-win64.zip;b4521f7ada5b260380f94c4bd7f1b7684c76969a
4343
protoc_win32;https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protoc-21.12-win32.zip;3688010318192c46ce73213cdfb6b3e5656da874

cmake/external/onnxruntime_external_deps.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ if(NOT TARGET Boost::mp11)
301301
onnxruntime_fetchcontent_declare(
302302
mp11
303303
URL ${DEP_URL_mp11}
304+
EXCLUDE_FROM_ALL
304305
FIND_PACKAGE_ARGS NAMES Boost
305306
)
306307
onnxruntime_fetchcontent_makeavailable(mp11)

cmake/onnxruntime_session.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ endif()
2222
if (onnxruntime_MINIMAL_BUILD)
2323
set(onnxruntime_session_src_exclude
2424
"${ONNXRUNTIME_ROOT}/core/session/provider_bridge_ort.cc"
25+
"${ONNXRUNTIME_ROOT}/core/session/model_builder_c_api.cc"
2526
)
2627

2728
list(REMOVE_ITEM onnxruntime_session_srcs ${onnxruntime_session_src_exclude})

cmake/onnxruntime_unittests.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ set (onnxruntime_shared_lib_test_SRC
503503

504504
if (NOT onnxruntime_MINIMAL_BUILD)
505505
list(APPEND onnxruntime_shared_lib_test_SRC ${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_inference.cc)
506+
list(APPEND onnxruntime_shared_lib_test_SRC ${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_model_builder_api.cc)
506507
endif()
507508

508509
if(onnxruntime_RUN_ONNX_TESTS)
@@ -1359,14 +1360,19 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
13591360
LIBS ${onnxruntime_shared_lib_test_LIBS}
13601361
DEPENDS ${all_dependencies}
13611362
)
1363+
1364+
target_include_directories(onnxruntime_shared_lib_test PRIVATE ${ONNXRUNTIME_ROOT})
1365+
13621366
if (onnxruntime_USE_CUDA)
13631367
target_include_directories(onnxruntime_shared_lib_test PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
13641368
target_sources(onnxruntime_shared_lib_test PRIVATE ${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/cuda_ops.cu)
13651369
endif()
1370+
13661371
if (onnxruntime_USE_ROCM)
13671372
target_include_directories(onnxruntime_shared_lib_test PRIVATE ${onnxruntime_ROCM_HOME}/include)
13681373
target_compile_definitions(onnxruntime_shared_lib_test PRIVATE __HIP_PLATFORM_AMD__)
13691374
endif()
1375+
13701376
if (CMAKE_SYSTEM_NAME STREQUAL "Android")
13711377
target_sources(onnxruntime_shared_lib_test PRIVATE
13721378
"${ONNXRUNTIME_ROOT}/core/platform/android/cxa_demangle.cc"

csharp/src/Microsoft.ML.OnnxRuntime/ManagedProjections.shared.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal class ManagedTypeProjection
2525
/// </summary>
2626
/// <param name="namedOnnxValue"></param>
2727
/// <param name="metadata"></param>
28-
/// <returns>OrtValye created accoding to the metadata</returns>
28+
/// <returns>OrtValue created according to the metadata</returns>
2929
internal static OrtValue CreateProjection(NamedOnnxValue namedOnnxValue, NodeMetadata metadata)
3030
{
3131
OrtValue result;
@@ -191,4 +191,3 @@ private static OrtValue CreateTensorProjection(NamedOnnxValue node, NodeMetadata
191191
}
192192
}
193193
}
194-

csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.shared.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ internal class NativeLib
847847
/// Creates an instance of OrtSession with provided parameters
848848
/// </summary>
849849
/// <param name="environment">Native OrtEnv instance</param>
850-
/// <param name="modelData">Byte array correspoonding to the model</param>
850+
/// <param name="modelData">Byte array corresponding to the model</param>
851851
/// <param name="modelSize">Size of the model in bytes</param>
852852
/// <param name="sessionOptions">Native SessionOptions instance</param>
853853
/// <param name="prepackedWeightsContainer">Native OrtPrepackedWeightsContainer instance</param>
@@ -1258,7 +1258,7 @@ IntPtr[] outputValues /* An array of output value pointers. Array must be alloca
12581258
/// </summary>
12591259
/// <param name="options">Native SessionOptions instance</param>
12601260
/// <param name="name">Name of the initializer</param>
1261-
/// <param name="ortValue">Native OrtValue instnce</param>
1261+
/// <param name="ortValue">Native OrtValue instance</param>
12621262
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
12631263
public delegate IntPtr /*(OrtStatus*)*/ DOrtAddInitializer(IntPtr /*(OrtSessionOptions*)*/ options,
12641264
byte[] /*(const char*)*/ name,

include/onnxruntime/core/graph/graph.h

+30-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "core/common/span_utils.h"
2828
#include "core/common/status.h"
2929
#include "core/common/logging/logging.h"
30+
#include "core/framework/ort_value.h"
3031
#include "core/framework/prepacked_weights_container.h"
3132
#include "core/graph/onnx_protobuf.h"
3233
#include "core/graph/basic_types.h"
@@ -39,6 +40,9 @@
3940
#include "core/graph/node_arg.h"
4041
#include "core/graph/ort_format_load_options.h"
4142

43+
// Type from Model Editor API in ORT C API so can't be in a namespace
44+
struct OrtGraph;
45+
4246
namespace onnxruntime {
4347
class Graph;
4448
struct IndexedSubGraph;
@@ -763,6 +767,10 @@ class Graph { // NOLINT(clang-analyzer-optin.performance.Padding): preserve exi
763767
*/
764768
bool GetInitializedTensor(const std::string& tensor_name, const ONNX_NAMESPACE::TensorProto*& value) const;
765769

770+
/** Populate `value` if an externally allocated OrtValue exists for an initializer with the given name.
771+
*/
772+
bool GetOrtValueInitializer(const std::string& name, OrtValue& value) const;
773+
766774
/** Gets all the initializer tensors in this Graph. */
767775
const InitializedTensorSet& GetAllInitializedTensors() const noexcept { return name_to_initial_tensor_; }
768776

@@ -1430,6 +1438,16 @@ class Graph { // NOLINT(clang-analyzer-optin.performance.Padding): preserve exi
14301438
const OrtFormatLoadOptions& load_options,
14311439
const logging::Logger& logger, std::unique_ptr<Graph>& graph);
14321440

1441+
static Status LoadFromModelEditorApiModel(const OrtGraph& api_graph,
1442+
const Model& owning_model,
1443+
const std::unordered_map<std::string, int>& domain_to_version,
1444+
IOnnxRuntimeOpSchemaCollectionPtr schema_registry,
1445+
bool strict_shape_type_inference,
1446+
const logging::Logger& logger,
1447+
std::unique_ptr<Graph>& graph);
1448+
1449+
Status UpdateUsingModelEditorApiModel(const OrtModel& api_model);
1450+
14331451
#if !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD)
14341452
const RuntimeOptimizationRecordContainer& RuntimeOptimizations() const {
14351453
return runtime_optimizations_;
@@ -1630,7 +1648,8 @@ class Graph { // NOLINT(clang-analyzer-optin.performance.Padding): preserve exi
16301648
// Implementation for initializer replacement
16311649
Status ReplaceInitializedTensorImpl(ONNX_NAMESPACE::TensorProto new_initializer, bool is_external);
16321650

1633-
std::vector<NodeArg*> CreateNodeArgs(const google::protobuf::RepeatedPtrField<std::string>& names,
1651+
template <typename StringRange> // range-initializer returning std::string
1652+
std::vector<NodeArg*> CreateNodeArgs(const StringRange& names,
16341653
const ArgNameToTypeMap& name_to_type_map);
16351654

16361655
void ToGraphProtoInternal(ONNX_NAMESPACE::GraphProto& graph_proto) const;
@@ -1694,6 +1713,8 @@ class Graph { // NOLINT(clang-analyzer-optin.performance.Padding): preserve exi
16941713
return nodes_[node_index].get();
16951714
}
16961715

1716+
Status LoadFromModelEditorApiModel(const OrtGraph& api_graph, bool updating_existing_graph = false);
1717+
16971718
const Model& owning_model_;
16981719

16991720
// GraphProto to store name, version, initializer.
@@ -1708,6 +1729,12 @@ class Graph { // NOLINT(clang-analyzer-optin.performance.Padding): preserve exi
17081729

17091730
InitializedTensorSet name_to_initial_tensor_;
17101731

1732+
// Initializers that are external to the Graph.
1733+
// e.g. created from existing memory using CreateTensorWithDataAndDeleterAsOrtValue in the ORT API.
1734+
// As we need to convert to TensorProto for the optimizers to work and keep the deleter information we store them
1735+
// in the Graph instance and retrieve during session state finalization.
1736+
std::unordered_map<std::string, OrtValue> ortvalue_initializers_;
1737+
17111738
std::unordered_set<std::reference_wrapper<const std::string>,
17121739
std::hash<std::string>, std::equal_to<std::string>>
17131740
sparse_tensor_names_;
@@ -1744,6 +1771,7 @@ class Graph { // NOLINT(clang-analyzer-optin.performance.Padding): preserve exi
17441771
// in some case, a fused sub-graph will happens multiple times in one model, we use a map
17451772
// to store reusable-schema in lookup.
17461773
InlinedHashMap<std::string, std::reference_wrapper<ONNX_NAMESPACE::OpSchema>> reusable_fused_schema_map_;
1774+
17471775
#endif // !defined(ORT_MINIMAL_BUILD)
17481776

17491777
// Graph nodes.
@@ -1806,7 +1834,7 @@ class Graph { // NOLINT(clang-analyzer-optin.performance.Padding): preserve exi
18061834
std::unordered_map<std::string, std::unordered_set<NodeIndex>> node_arg_to_consumer_nodes_;
18071835
#endif // !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD)
18081836

1809-
const std::unordered_map<std::string, int> domain_to_version_;
1837+
std::unordered_map<std::string, int> domain_to_version_;
18101838

18111839
// Model IR version.
18121840
Version ir_version_{ONNX_NAMESPACE::Version::IR_VERSION};

include/onnxruntime/core/graph/graph_viewer.h

+6
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ class GraphViewer {
193193
IOnnxRuntimeOpSchemaCollectionPtr GetSchemaRegistry() const { return graph_->GetSchemaRegistry(); }
194194
#endif
195195

196+
/** Populate `value` if an externally allocated OrtValue exists for an initializer with the given name.
197+
*/
198+
bool GetOrtValueInitializer(const std::string& name, OrtValue& value) const {
199+
return graph_->GetOrtValueInitializer(name, value);
200+
}
201+
196202
private:
197203
ORT_DISALLOW_COPY_ASSIGNMENT_AND_MOVE(GraphViewer);
198204
GraphViewer(const Graph& graph, const IndexedSubGraph* filter_info);

0 commit comments

Comments
 (0)