Skip to content

Commit 0ef8213

Browse files
adrianlizarragaCopilotedgchen1
authored
Add GetCapability/Compile infrastructure for EP ABI (microsoft#24887)
### Description This PRs sets the foundation for the EP ABI, which allows plugin-EPs to interface with ORT using a binary stable interface. A plugin-EP can be built separately from ORT and is not tied to a specific commit of ORT. Currently, this PR adds basic APIs necessary to allow an example plugin-EP to compile and run a simple model with a single `Mul` node. - Example plugin-EP implementation: https://github.com/microsoft/onnxruntime/blob/adrianl/ep-abi/onnxruntime/test/autoep/library/example_plugin_ep.cc - APIs: - Graph IR: https://github.com/microsoft/onnxruntime/blob/adrianl/ep-abi/include/onnxruntime/core/session/onnxruntime_c_api.h#L5290-L5439 - Plugin EP: https://github.com/microsoft/onnxruntime/blob/adrianl/ep-abi/include/onnxruntime/core/session/onnxruntime_c_api.h#L6177-L6481 - Example app code (from unit tests): https://github.com/microsoft/onnxruntime/blob/adrianl/ep-abi/onnxruntime/test/autoep/test_autoep_selection.cc#L614 ### Motivation and Context Based on microsoft#21450 --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Edward Chen <[email protected]>
1 parent 0385779 commit 0ef8213

37 files changed

+4934
-290
lines changed

cmake/onnxruntime.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ endif()
2222
function(get_c_cxx_api_headers HEADERS_VAR)
2323
set(_headers
2424
"${REPO_ROOT}/include/onnxruntime/core/session/onnxruntime_c_api.h"
25+
"${REPO_ROOT}/include/onnxruntime/core/session/onnxruntime_ep_c_api.h"
2526
"${REPO_ROOT}/include/onnxruntime/core/session/onnxruntime_cxx_api.h"
2627
"${REPO_ROOT}/include/onnxruntime/core/session/onnxruntime_cxx_inline.h"
2728
"${REPO_ROOT}/include/onnxruntime/core/session/onnxruntime_float16.h"

cmake/onnxruntime_unittests.cmake

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ set (ONNXRUNTIME_GLOBAL_THREAD_POOLS_TEST_SRC_DIR "${TEST_SRC_DIR}/global_thread
495495
set (ONNXRUNTIME_CUSTOM_OP_REGISTRATION_TEST_SRC_DIR "${TEST_SRC_DIR}/custom_op_registration")
496496
set (ONNXRUNTIME_LOGGING_APIS_TEST_SRC_DIR "${TEST_SRC_DIR}/logging_apis")
497497
set (ONNXRUNTIME_AUTOEP_TEST_SRC_DIR "${TEST_SRC_DIR}/autoep")
498+
set (ONNXRUNTIME_EP_GRAPH_TEST_SRC_DIR "${TEST_SRC_DIR}/ep_graph")
498499

499500
set (onnxruntime_shared_lib_test_SRC
500501
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_fixture.h
@@ -1848,8 +1849,8 @@ if (WIN32 AND onnxruntime_BUILD_SHARED_LIB AND
18481849
${ONNXRUNTIME_AUTOEP_LIB_LINK_FLAG})
18491850

18501851
# test library
1851-
file(GLOB_RECURSE onnxruntime_autoep_test_SRC "${ONNXRUNTIME_AUTOEP_TEST_SRC_DIR}/*.h"
1852-
"${ONNXRUNTIME_AUTOEP_TEST_SRC_DIR}/*.cc")
1852+
file(GLOB onnxruntime_autoep_test_SRC "${ONNXRUNTIME_AUTOEP_TEST_SRC_DIR}/*.h"
1853+
"${ONNXRUNTIME_AUTOEP_TEST_SRC_DIR}/*.cc")
18531854

18541855
set(onnxruntime_autoep_test_LIBS onnxruntime_mocked_allocator ${ONNXRUNTIME_TEST_LIBS} onnxruntime_test_utils
18551856
onnx_proto onnx ${onnxruntime_EXTERNAL_LIBRARIES})
@@ -1988,4 +1989,34 @@ if (onnxruntime_USE_WEBGPU AND WIN32 AND onnxruntime_BUILD_SHARED_LIB AND NOT CM
19881989
)
19891990
endif()
19901991

1992+
# onnxruntime_ep_graph_test tests the implementation of the public OrtGraph APIs for use in plugin EPs (OrtEp).
1993+
if (onnxruntime_BUILD_SHARED_LIB AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten" AND NOT onnxruntime_MINIMAL_BUILD)
1994+
file(GLOB_RECURSE onnxruntime_ep_graph_test_SRC "${ONNXRUNTIME_EP_GRAPH_TEST_SRC_DIR}/*.h"
1995+
"${ONNXRUNTIME_EP_GRAPH_TEST_SRC_DIR}/*.cc")
1996+
1997+
set(onnxruntime_ep_graph_test_LIBS ${ONNXRUNTIME_TEST_LIBS} onnxruntime_test_utils ${onnxruntime_EXTERNAL_LIBRARIES})
1998+
if (CMAKE_SYSTEM_NAME MATCHES "AIX")
1999+
list(APPEND onnxruntime_ep_graph_test_LIBS onnxruntime_session onnxruntime_util onnxruntime_lora onnxruntime_framework
2000+
onnxruntime_common onnxruntime_graph onnxruntime_providers onnxruntime_mlas
2001+
onnxruntime_optimizer onnxruntime_flatbuffers iconv re2
2002+
${PROTOBUF_LIB} onnx onnx_proto)
2003+
endif()
2004+
2005+
if(NOT WIN32)
2006+
list(APPEND onnxruntime_ep_graph_test_LIBS ${CMAKE_DL_LIBS})
2007+
endif()
2008+
2009+
if (onnxruntime_USE_TENSORRT OR onnxruntime_USE_NV)
2010+
# Need this because unittest_main_src defines a global nvinfer1::IBuilder variable.
2011+
list(APPEND onnxruntime_ep_graph_test_LIBS ${TENSORRT_LIBRARY_INFER})
2012+
endif()
2013+
2014+
AddTest(DYN
2015+
TARGET onnxruntime_ep_graph_test
2016+
SOURCES ${onnxruntime_ep_graph_test_SRC} ${onnxruntime_unittest_main_src}
2017+
LIBS ${onnxruntime_ep_graph_test_LIBS}
2018+
DEPENDS ${all_dependencies}
2019+
)
2020+
endif()
2021+
19912022
include(onnxruntime_fuzz_test.cmake)

include/onnxruntime/core/common/const_pointer_container.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ class ConstPointerContainer {
7979
return data_[index];
8080
}
8181

82+
const T* const* data() const {
83+
return data_.data();
84+
}
85+
8286
private:
8387
const Container& data_;
8488
};

include/onnxruntime/core/graph/graph.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,9 @@ class Graph { // NOLINT(clang-analyzer-optin.performance.Padding): preserve exi
797797
/** Returns true if an initializer value can be overridden by a graph input with the same name. */
798798
bool CanOverrideInitializer() const noexcept { return ir_version_ >= 4; }
799799

800+
/** Returns the ONNX IR version for the model. */
801+
Version GetOnnxIRVersion() const noexcept { return ir_version_; }
802+
800803
/** returns the initializer's TensorProto if 'name' is an initializer, is constant and
801804
cannot be overridden at runtime. If the initializer is not found or is not constant, a nullptr is returned.
802805
@param check_outer_scope If true and the graph is a subgraph,
@@ -812,6 +815,18 @@ class Graph { // NOLINT(clang-analyzer-optin.performance.Padding): preserve exi
812815
*/
813816
const ONNX_NAMESPACE::TensorProto* GetInitializer(const std::string& name, bool check_outer_scope) const;
814817

818+
/// <summary>
819+
/// Returns the initializer's TensorProto if 'name' is an initializer (either constant or overridable).
820+
/// If the initializer is not found, a nullptr is returned. An output parameter is set to true if the initializer
821+
/// is constant.
822+
/// </summary>
823+
/// <param name="name">The initializer's name.</param>
824+
/// <param name="check_outer_scope">Checks outer scope if set to true and the graph is a subgraph.</param>
825+
/// <param name="is_constant">Output parameter set to true if the initializer is a constant.</param>
826+
/// <returns>The initializer's TensorProto or nullptr.</returns>
827+
const ONNX_NAMESPACE::TensorProto* GetInitializer(const std::string& name, bool check_outer_scope,
828+
bool& is_constant) const;
829+
815830
/** Gets the Graph inputs excluding initializers.
816831
These are the required inputs to the Graph as the initializers can be optionally overridden via graph inputs.
817832
@remarks Contains no nullptr values. */

include/onnxruntime/core/graph/graph_viewer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class GraphViewer {
5757
/** Returns true if an initializer value can be overridden by a graph input with the same name. */
5858
bool CanOverrideInitializer() const noexcept;
5959

60+
/** Returns the ONNX IR version for the model. */
61+
Version GetOnnxIRVersion() const noexcept {
62+
return graph_->GetOnnxIRVersion();
63+
}
64+
6065
/**
6166
Gets the Graph inputs, excluding initializers.
6267
@returns Collection of NodeArg pointers for the graph inputs, excluding inputs that have matching initializers.

0 commit comments

Comments
 (0)