Skip to content
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
732f29a
Create IExecutionProvider wrapper for OrtEp
adrianlizarraga May 28, 2025
9c39966
Add OrtEp::GetCapability and stub implementation in dummy ep
adrianlizarraga May 28, 2025
db2cda3
Simplify GetCapability for OrtEp (no allocator). Make OrtGraph compat…
adrianlizarraga May 29, 2025
93900ba
Add API OrtGraph_GetNodes()
adrianlizarraga May 29, 2025
5676355
Derive from OrtNode and OrtGraph instead of using variant (reduce str…
adrianlizarraga May 29, 2025
353fdb8
Separate model-editor and ep-api graph types into different files
adrianlizarraga May 29, 2025
62eb132
Revert variable name change to reduce diff
adrianlizarraga May 29, 2025
38b5398
Add some comments
adrianlizarraga May 29, 2025
09cea7a
Add unit test that adds the example plugin ep to a session.
adrianlizarraga May 30, 2025
a659a80
Merge branch 'main' into adrianl/ep-abi
adrianlizarraga May 30, 2025
9f45c18
Add C APIs to get a node's name and op_type
adrianlizarraga May 30, 2025
7cac7d1
Update error message when user passes in the wrong kind of OrtNode/Or…
adrianlizarraga May 30, 2025
5b38f4b
Add ToInternal() methods to convert from OrtNode to its derived classes
adrianlizarraga May 30, 2025
8abe39e
clean up
adrianlizarraga May 30, 2025
9abc3ff
Rename AddSupportedNodes api func. Dont force eps to provide a subgra…
adrianlizarraga May 30, 2025
df0636d
Add OrtEp::Compile()
adrianlizarraga May 31, 2025
177828a
Fill out Compile() wrapper function more
adrianlizarraga May 31, 2025
0206de9
Fix annotation
adrianlizarraga May 31, 2025
a3ab415
Update NodeComputeInfo handling
adrianlizarraga May 31, 2025
59b5367
Merge branch 'main' into adrianl/ep-abi
adrianlizarraga May 31, 2025
77b3037
Finish making Mul work in example plugin EP
adrianlizarraga May 31, 2025
1b616d8
rename file
adrianlizarraga May 31, 2025
217aca1
Apply suggestions from code review
adrianlizarraga May 31, 2025
2adb618
Update onnxruntime/test/autoep/library/example_plugin_ep.cc
adrianlizarraga May 31, 2025
e144c80
hide reinterpret_cast with a ToInternal call
adrianlizarraga May 31, 2025
9031bd5
Use only one enum to differentiate between the ModelEditorApi and EpA…
adrianlizarraga Jun 2, 2025
37dd688
Add many more graph apis for traversing edges
adrianlizarraga Jun 2, 2025
ee354a4
Move graph apis to OrtApi struct
adrianlizarraga Jun 2, 2025
3a99ff2
ifdef out stuff for minimal build
adrianlizarraga Jun 2, 2025
d969d11
More ifdef for minimal builds
adrianlizarraga Jun 2, 2025
deb145d
Rename API to GetValueInfoUses to account for multiple OrtNode instan…
adrianlizarraga Jun 3, 2025
ac95834
Fix call to GetUses
adrianlizarraga Jun 3, 2025
dfc4f48
Make returning the producer's output index optional
adrianlizarraga Jun 3, 2025
c58ec9d
Return error status from GetValueInfoTypeInfo if type info is not valid
adrianlizarraga Jun 3, 2025
d7dc6db
Add a test executable for testing use of OrtGraph APIs
adrianlizarraga Jun 3, 2025
c1ada2f
Add nv lib to test; clean up
adrianlizarraga Jun 4, 2025
4443f2e
Cleanup: add includes, update some comments
adrianlizarraga Jun 4, 2025
c219e56
Merge main and fix conflicts
adrianlizarraga Jun 4, 2025
2cf5e59
Add fused nodes back into OrtEp::Compile()
adrianlizarraga Jun 4, 2025
66f78e5
Remove 'Get' from APIs that look like field/property getters
adrianlizarraga Jun 4, 2025
8641558
Add remaining OrtGraph apis to get inputs/outputs
adrianlizarraga Jun 4, 2025
b34b83c
Set missing optional node outputs to a null OrtValueInfo
adrianlizarraga Jun 4, 2025
ef49e54
Rename some GetValueInfo* apis. Add ability to specify a single suppo…
adrianlizarraga Jun 5, 2025
a55988d
Fix GetValueConsumers() to return a negative input index for consumer…
adrianlizarraga Jun 5, 2025
66044f2
Add Node_GetSinceVersion C API
adrianlizarraga Jun 5, 2025
05166d2
Add C APIs: Node_GetNumSubgraphs, Node_GetSubgraphs, Node_GetParentGraph
adrianlizarraga Jun 6, 2025
55e43e0
initialize var to fix warning/error on linux. set input index to -1 f…
adrianlizarraga Jun 6, 2025
c1e63cd
Remove OrtHardwareDevice passing from GetCapability
adrianlizarraga Jun 6, 2025
bc445f9
Add C APIs: Node_GetNumImplicitInputs(), Node_GetImplicitInputs()
adrianlizarraga Jun 6, 2025
dd1efdb
minor clean up on comments
adrianlizarraga Jun 6, 2025
89e50eb
more efficient node_index_to_ep_node map
adrianlizarraga Jun 6, 2025
4282be6
Merge branch 'main' into adrianl/ep-abi
adrianlizarraga Jun 6, 2025
e755b84
Add C API: Graph_GetParentNode(). Split up test_ep_graph.cc into anot…
adrianlizarraga Jun 6, 2025
28eec29
Add C APIs to query whether an OrtValueInfo is a graph input, a graph…
adrianlizarraga Jun 9, 2025
4ca1f37
Merge branch 'main' into adrianl/ep-abi
adrianlizarraga Jun 9, 2025
4348e73
Address review comments and update graph ir tests
adrianlizarraga Jun 9, 2025
a96fc71
Merge branch 'main' into adrianl/ep-abi
adrianlizarraga Jun 9, 2025
e2a5b8e
Address more review comments
adrianlizarraga Jun 9, 2025
a9d8956
Add C API Node_Id() and sample Kahns topological sort that uses only …
adrianlizarraga Jun 9, 2025
e03ec4f
Merge branch 'main' into adrianl/ep-abi
adrianlizarraga Jun 12, 2025
0d36505
Split up files
adrianlizarraga Jun 12, 2025
c6aaf40
Address review comments: factory creation in loop, delete OrtStatus
adrianlizarraga Jun 12, 2025
9d0e2ae
Delete OrtStatus in provider_policy_context.cc
adrianlizarraga Jun 12, 2025
3927442
Remove intermediate variable
adrianlizarraga Jun 12, 2025
410e7df
Add C APIs to get initializer OrtValues
adrianlizarraga Jun 13, 2025
edb3b2d
Allow getting OrtValue for initializer defined in an outer scope
adrianlizarraga Jun 13, 2025
35a31a0
Remove 'order' parameter from Graph_GetNodes()
adrianlizarraga Jun 13, 2025
f7f4043
Merge main and fix conflicts
adrianlizarraga Jun 13, 2025
4772ee8
Fix warnings as errors
adrianlizarraga Jun 13, 2025
be4e86c
Add new c api header (for eps) to cmakes list of headers
adrianlizarraga Jun 13, 2025
3f77e03
Graph_GetNodes() directly return internal order (already sorted); Mak…
adrianlizarraga Jun 13, 2025
5c4af97
Python unit test that runs simple model with EP plugin
adrianlizarraga Jun 14, 2025
0011333
Update include/onnxruntime/core/session/onnxruntime_c_ep_api.h
adrianlizarraga Jun 14, 2025
ea41d12
Update include/onnxruntime/core/session/onnxruntime_c_ep_api.h
adrianlizarraga Jun 14, 2025
52d0332
Use GraphViewer's parent node/subgraph information to get initializer…
adrianlizarraga Jun 15, 2025
d10335e
Address many review comments
adrianlizarraga Jun 16, 2025
a446ca0
Merge branch 'adrianl/ep-abi' of github.com:microsoft/onnxruntime int…
adrianlizarraga Jun 16, 2025
f078b93
merge main and fix conflicts
adrianlizarraga Jun 16, 2025
9a993c5
Apply suggestions from code review
adrianlizarraga Jun 16, 2025
079add6
Add documentation for OrtConstPointerArray API functions
adrianlizarraga Jun 16, 2025
32de043
Clean up
adrianlizarraga Jun 16, 2025
ff85323
Apply suggestions from code review
adrianlizarraga Jun 16, 2025
93c6769
Add unit test for a graph with 3 layers of nested subgraphs
adrianlizarraga Jun 17, 2025
e072a2d
Improve OrtArrayOfConstObjects to allow api user to create
adrianlizarraga Jun 18, 2025
c40baba
Clean up
adrianlizarraga Jun 18, 2025
74d3b4e
Add ArrayOfConstObjects_GetConstData
adrianlizarraga Jun 18, 2025
bae384d
Apply suggestions from code review
adrianlizarraga Jun 18, 2025
981726f
Adjust naming and description of OrtArrayOfConstObjects
adrianlizarraga Jun 18, 2025
910cd5e
wording: object vs element
adrianlizarraga Jun 18, 2025
5be3304
Renamed GetData -> GetMutableData, GetConstData -> GetData
adrianlizarraga Jun 19, 2025
e1fe569
Merge branch 'main' into adrianl/ep-abi
adrianlizarraga Jun 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ set (ONNXRUNTIME_GLOBAL_THREAD_POOLS_TEST_SRC_DIR "${TEST_SRC_DIR}/global_thread
set (ONNXRUNTIME_CUSTOM_OP_REGISTRATION_TEST_SRC_DIR "${TEST_SRC_DIR}/custom_op_registration")
set (ONNXRUNTIME_LOGGING_APIS_TEST_SRC_DIR "${TEST_SRC_DIR}/logging_apis")
set (ONNXRUNTIME_AUTOEP_TEST_SRC_DIR "${TEST_SRC_DIR}/autoep")
set (ONNXRUNTIME_EP_GRAPH_TEST_SRC_DIR "${TEST_SRC_DIR}/ep_graph")

set (onnxruntime_shared_lib_test_SRC
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_fixture.h
Expand Down Expand Up @@ -1977,4 +1978,34 @@ if (onnxruntime_USE_WEBGPU AND WIN32 AND onnxruntime_BUILD_SHARED_LIB AND NOT CM
)
endif()

# onnxruntime_ep_graph_test tests the implementation of the public OrtGraph APIs for use in plugin EPs (OrtEp).
if (onnxruntime_BUILD_SHARED_LIB AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten" AND NOT onnxruntime_MINIMAL_BUILD)
file(GLOB_RECURSE onnxruntime_ep_graph_test_SRC "${ONNXRUNTIME_EP_GRAPH_TEST_SRC_DIR}/*.h"
"${ONNXRUNTIME_EP_GRAPH_TEST_SRC_DIR}/*.cc")

set(onnxruntime_ep_graph_test_LIBS ${ONNXRUNTIME_TEST_LIBS} onnxruntime_test_utils ${onnxruntime_EXTERNAL_LIBRARIES})
if (CMAKE_SYSTEM_NAME MATCHES "AIX")
list(APPEND onnxruntime_ep_graph_test_LIBS onnxruntime_session onnxruntime_util onnxruntime_lora onnxruntime_framework
onnxruntime_common onnxruntime_graph onnxruntime_providers onnxruntime_mlas
onnxruntime_optimizer onnxruntime_flatbuffers iconv re2
${PROTOBUF_LIB} onnx onnx_proto)
endif()

if(NOT WIN32)
list(APPEND onnxruntime_ep_graph_test_LIBS ${CMAKE_DL_LIBS})
endif()

if (onnxruntime_USE_TENSORRT OR onnxruntime_USE_NV)
# Need this because unittest_main_src defines a global nvinfer1::IBuilder variable.
list(APPEND onnxruntime_ep_graph_test_LIBS ${TENSORRT_LIBRARY_INFER})
endif()

AddTest(DYN
TARGET onnxruntime_ep_graph_test
SOURCES ${onnxruntime_ep_graph_test_SRC} ${onnxruntime_unittest_main_src}
LIBS ${onnxruntime_ep_graph_test_LIBS}
DEPENDS ${all_dependencies}
)
endif()

include(onnxruntime_fuzz_test.cmake)
387 changes: 380 additions & 7 deletions include/onnxruntime/core/session/onnxruntime_c_api.h

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions onnxruntime/core/graph/abi_graph_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#pragma once

#include <memory>
#include <string>
#include <vector>
#include "core/common/inlined_containers_fwd.h"
#include "core/framework/onnxruntime_typeinfo.h"
#include "core/graph/onnx_protobuf.h"

#define DEFINE_ORT_GRAPH_IR_TO_EXTERNAL_INTERNAL_FUNCS(external_type, internal_type, internal_api) \
external_type* ToExternal() { return static_cast<external_type*>(this); } \
const external_type* ToExternal() const { return static_cast<const external_type*>(this); } \
static internal_type* ToInternal(external_type* e) { \
return e->graph_ir_api == (internal_api) ? static_cast<internal_type*>(e) : nullptr; \
} \
static const internal_type* ToInternal(const external_type* e) { \
return e->graph_ir_api == (internal_api) ? static_cast<const internal_type*>(e) : nullptr; \
}

// The public ORT graph IR types (e.g., OrtGraph, OrtNode, etc.) have different implementations for the
// ModelEditor API and EP API. This enum allows a user of the base class (e.g., OrtGraph) to determine
// the API for which the derived class was created.
enum class OrtGraphIrApi {
kInvalid = 0,
kModelEditorApi,
kEpApi,
};

/// <summary>
/// Public type that represents an ONNX value info.
/// </summary>
struct OrtValueInfo {
explicit OrtValueInfo(OrtGraphIrApi graph_ir_api) : graph_ir_api(graph_ir_api) {}
virtual ~OrtValueInfo() = default;

virtual const std::string& Name() const = 0;
virtual const OrtTypeInfo* TypeInfo() const = 0;

struct ProducerInfo {
ProducerInfo() = default;
ProducerInfo(const OrtNode* node, size_t output_index) : node(node), output_index(output_index) {}
const OrtNode* node = nullptr;
size_t output_index = 0;
};
virtual onnxruntime::Status GetProducerInfo(ProducerInfo& producer_info) const = 0;

struct UseInfo {
UseInfo() = default;
UseInfo(const OrtNode* node, size_t input_index) : node(node), input_index(input_index) {}
const OrtNode* node = nullptr;
size_t input_index = 0;
};
virtual onnxruntime::Status GetUses(std::vector<UseInfo>& uses) const = 0;
virtual onnxruntime::Status GetNumUses(size_t& num_consumers) const = 0;

OrtGraphIrApi graph_ir_api = OrtGraphIrApi::kInvalid;
};

/// <summary>
/// Public type that represents an ONNX attribute. Currently, an OrtOpAttr is interchangeable with AttributeProto.
/// </summary>
struct OrtOpAttr {
ONNX_NAMESPACE::AttributeProto attr_proto;
};

/// <summary>
/// Public type that represents an ONNX node.
/// </summary>
struct OrtNode {
explicit OrtNode(OrtGraphIrApi graph_ir_api) : graph_ir_api(graph_ir_api) {}
virtual ~OrtNode() = default;

virtual const std::string& Name() const = 0;
virtual const std::string& OpType() const = 0;
virtual const std::string& Domain() const = 0;
virtual size_t NumInputs() const = 0;
virtual size_t NumOutputs() const = 0;
virtual onnxruntime::Status GetInputs(onnxruntime::InlinedVector<const OrtValueInfo*>& inputs) const = 0;
virtual onnxruntime::Status GetOutputs(onnxruntime::InlinedVector<const OrtValueInfo*>& outputs) const = 0;

OrtGraphIrApi graph_ir_api = OrtGraphIrApi::kInvalid;
};

/// <summary>
/// Public type that represents an ONNX graph.
/// </summary>
struct OrtGraph {
explicit OrtGraph(OrtGraphIrApi graph_ir_api) : graph_ir_api(graph_ir_api) {}
virtual ~OrtGraph() = default;

virtual const std::string& Name() const = 0;
virtual size_t NumInputs() const = 0;
virtual size_t NumOutputs() const = 0;
virtual onnxruntime::Status GetInputs(onnxruntime::InlinedVector<const OrtValueInfo*>& inputs) const = 0;
virtual onnxruntime::Status GetOutputs(onnxruntime::InlinedVector<const OrtValueInfo*>& outputs) const = 0;
virtual size_t NumNodes() const = 0;
virtual std::vector<const OrtNode*> GetNodes(int order) const = 0;

OrtGraphIrApi graph_ir_api = OrtGraphIrApi::kInvalid;
};
Loading
Loading