Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6d34481
save work
edgchen1 Oct 17, 2025
790ba41
update comment
edgchen1 Oct 17, 2025
81c7d95
update autoep tests to build/run on Android
edgchen1 Oct 17, 2025
2e14060
update comment in CMakeLists.txt
edgchen1 Oct 17, 2025
e52f862
replace ProviderSharedLibrary oid Ensure() with Status Initialize(),…
edgchen1 Oct 17, 2025
ff569c6
remove newlines
edgchen1 Oct 17, 2025
ff3ed18
pass by ref in for loop
edgchen1 Oct 17, 2025
6a81526
try to fix GCC warning about maybe_unused on data members
edgchen1 Oct 17, 2025
9f41ebd
fix formatting
edgchen1 Oct 17, 2025
f5a6655
use Ort::MemoryInfo in ep_factory.cc
edgchen1 Oct 17, 2025
160b06e
fix example_plugin_ep library path on Apple platforms
edgchen1 Oct 21, 2025
c291c6a
example_plugin_ep - derive allocators from BaseAllocator which has a …
edgchen1 Oct 21, 2025
b39b442
delete ExampleNodeComputeInfo* instead of base class OrtNodeComputeIn…
edgchen1 Oct 21, 2025
27c6790
Merge remote-tracking branch 'origin/main' into edgchen1/plugin_ep_an…
edgchen1 Oct 21, 2025
7a4c849
add libexample_plugin_ep.so to files copied to Android device, sort f…
edgchen1 Oct 21, 2025
e3f372e
add include, update comment
edgchen1 Oct 22, 2025
c12b722
try to implement GetRuntimePath() for posix env.
edgchen1 Oct 24, 2025
45ef29d
update posix GetRuntimePath
edgchen1 Oct 24, 2025
18c062e
update autoep cuda EP test
edgchen1 Oct 24, 2025
0894421
only check one address from posix env GetRuntimePath
edgchen1 Oct 25, 2025
6f0e6b0
add PlatformEnvTest.GetRuntimePath test
edgchen1 Oct 25, 2025
d0aae1e
enable QNN autoep tests
edgchen1 Oct 25, 2025
9f6e5bb
fix path arg
edgchen1 Oct 27, 2025
59bc088
Revert "enable QNN autoep tests"
edgchen1 Oct 27, 2025
b48ef8e
skip PlatformEnvTest.GetRuntimePath in WebAssembly build
edgchen1 Oct 27, 2025
af31522
add test for GetRuntimePath() call from shared library
edgchen1 Oct 29, 2025
2081235
add CMAKE_DL_LIBS to onnxruntime_runtime_path_test_shared_library lin…
edgchen1 Oct 30, 2025
5b395fb
print exception info from OrtTestGetSharedLibraryRuntimePath
edgchen1 Oct 30, 2025
7b5e0ee
fix build issue
edgchen1 Oct 30, 2025
a382d5f
reorder path update calls - absolute(remove_filename(path)) -> remove…
edgchen1 Oct 31, 2025
348a954
add readme
edgchen1 Oct 31, 2025
21815fa
add copyright comments, update shared lib test
edgchen1 Oct 31, 2025
2d42cba
remove GetRuntimePath test that tests statically linked function
edgchen1 Oct 31, 2025
d4cad75
Merge remote-tracking branch 'origin/main' into edgchen1/plugin_ep_an…
edgchen1 Oct 31, 2025
873bda0
remove unused EpFactoryVirtualGpu::default_logger_ data member
edgchen1 Nov 1, 2025
7305296
remove unused EpVirtualGpu::factory_ data member
edgchen1 Nov 1, 2025
95f0d0b
use lambda capture [&] to avoid clang warning
edgchen1 Nov 1, 2025
657ddae
add libonnxruntime_runtime_path_test_shared_library.so to shared libs…
edgchen1 Nov 1, 2025
f889090
add GSL to example_plugin_ep_virt_gpu link libraries
edgchen1 Nov 1, 2025
c4b05b9
loop var const ref
edgchen1 Nov 1, 2025
88a5e1c
remove .dll from base shared lib name
edgchen1 Nov 1, 2025
5cabd69
uncomment factory parameter - oops
edgchen1 Nov 1, 2025
64c2cec
handle no exception build
edgchen1 Nov 1, 2025
b8368f0
add example_plugin_ep_virt_gpu to shared lib list
edgchen1 Nov 1, 2025
6d25cb1
cast to AddNodeComputeInfo* before delete
edgchen1 Nov 3, 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
22 changes: 19 additions & 3 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1654,9 +1654,25 @@ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
endif()
endif()

#Now the 'onnxruntime_EXTERNAL_LIBRARIES' variable should be sealed. It will be used in onnxruntime.cmake which will be included in the next.
#The order of the following targets matters. Right depends on left. If target A appears before target B. Then A.cmake can not use variables defined in B.cmake.
set(ONNXRUNTIME_CMAKE_FILES onnxruntime_flatbuffers onnxruntime_common onnxruntime_mlas onnxruntime_graph onnxruntime_lora onnxruntime_framework onnxruntime_util onnxruntime_providers onnxruntime_optimizer onnxruntime_session ${ONNXRUNTIME_EAGER_CMAKE_FILE_NAME})
# From this point on, onnxruntime_EXTERNAL_LIBRARIES should be no longer be modified. It will be used in
# onnxruntime.cmake which will be included next.

# The order of the CMake file names (which exclude the ".cmake" suffix) in ONNXRUNTIME_CMAKE_FILES matters. Later CMake
# files may depend on earlier ones but earlier ones cannot depend on later ones. For example, if A appears before B,
# then A.cmake cannot use variables defined in B.cmake.
set(ONNXRUNTIME_CMAKE_FILES
onnxruntime_flatbuffers
onnxruntime_common
onnxruntime_mlas
onnxruntime_graph
onnxruntime_lora
onnxruntime_framework
onnxruntime_util
onnxruntime_providers
onnxruntime_optimizer
onnxruntime_session
${ONNXRUNTIME_EAGER_CMAKE_FILE_NAME}
)

if (onnxruntime_USE_WINML)
# WINML uses and depends on the shared lib. Note: You can build WINML without DML and you will get a
Expand Down
49 changes: 44 additions & 5 deletions cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ set (onnxruntime_shared_lib_test_SRC
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_nontensor_types.cc
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_ort_format_models.cc
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_run_options.cc
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_runtime_path.cc
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_session_options.cc
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/utils.h
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/utils.cc
Expand Down Expand Up @@ -1518,9 +1519,48 @@ endif()
target_link_libraries(onnxruntime_mocked_allocator PRIVATE ${GSL_TARGET})
set_target_properties(onnxruntime_mocked_allocator PROPERTIES FOLDER "ONNXRuntimeTest")

# onnxruntime_runtime_path_test_shared_library
block()
set(onnxruntime_runtime_path_test_shared_library_src
"${TEST_SRC_DIR}/shared_lib/runtime_path_test_shared_library/runtime_path_test_shared_library.h"
"${TEST_SRC_DIR}/shared_lib/runtime_path_test_shared_library/runtime_path_test_shared_library.cc")

onnxruntime_add_shared_library(onnxruntime_runtime_path_test_shared_library
${onnxruntime_runtime_path_test_shared_library_src})

target_link_libraries(onnxruntime_runtime_path_test_shared_library PRIVATE
onnxruntime_common cpuinfo ${CMAKE_DL_LIBS})
target_include_directories(onnxruntime_runtime_path_test_shared_library PRIVATE ${ONNXRUNTIME_ROOT})

if(UNIX)
if (APPLE)
set(onnxruntime_runtime_path_test_shared_library_link_flags "-Xlinker -dead_strip")
elseif (NOT CMAKE_SYSTEM_NAME MATCHES "AIX")
string(CONCAT onnxruntime_runtime_path_test_shared_library_link_flags
"-Xlinker --version-script=${TEST_SRC_DIR}/shared_lib/runtime_path_test_shared_library/runtime_path_test_shared_library.lds "
"-Xlinker --no-undefined -Xlinker --gc-sections -z noexecstack")
endif()
else()
set(onnxruntime_runtime_path_test_shared_library_link_flags
"-DEF:${TEST_SRC_DIR}/shared_lib/runtime_path_test_shared_library/runtime_path_test_shared_library.def")
endif()

set_property(TARGET onnxruntime_runtime_path_test_shared_library APPEND_STRING PROPERTY LINK_FLAGS
${onnxruntime_runtime_path_test_shared_library_link_flags})

set_target_properties(onnxruntime_runtime_path_test_shared_library PROPERTIES FOLDER "ONNXRuntimeTest")
source_group(TREE ${TEST_SRC_DIR} FILES ${onnxruntime_runtime_path_test_shared_library_src})
endblock()

#################################################################
# test inference using shared lib
set(onnxruntime_shared_lib_test_LIBS onnxruntime_mocked_allocator onnxruntime_test_utils onnxruntime_common onnx_proto)
set(onnxruntime_shared_lib_test_LIBS
onnxruntime_mocked_allocator
onnxruntime_test_utils
onnxruntime_common
onnx_proto
onnxruntime_runtime_path_test_shared_library)

if(NOT WIN32)
if(onnxruntime_USE_SNPE)
list(APPEND onnxruntime_shared_lib_test_LIBS onnxruntime_providers_snpe)
Expand Down Expand Up @@ -1978,8 +2018,7 @@ endif()

# Build library that can be used with RegisterExecutionProviderLibrary and automatic EP selection
# We need a shared lib build to use that as a dependency for the test library
# Currently we only have device discovery on Windows so no point building the test app on other platforms.
if (WIN32 AND onnxruntime_BUILD_SHARED_LIB AND
if (onnxruntime_BUILD_SHARED_LIB AND
NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten" AND
NOT onnxruntime_MINIMAL_BUILD)

Expand All @@ -1991,7 +2030,7 @@ if (WIN32 AND onnxruntime_BUILD_SHARED_LIB AND
"${TEST_SRC_DIR}/autoep/library/plugin_ep_utils.h")
onnxruntime_add_shared_library_module(example_plugin_ep ${onnxruntime_autoep_test_library_src})
target_include_directories(example_plugin_ep PRIVATE ${REPO_ROOT}/include/onnxruntime/core/session)
target_link_libraries(example_plugin_ep PRIVATE onnxruntime)
target_link_libraries(example_plugin_ep PRIVATE onnxruntime ${GSL_TARGET})

if(UNIX)
if (APPLE)
Expand Down Expand Up @@ -2024,7 +2063,7 @@ if (WIN32 AND onnxruntime_BUILD_SHARED_LIB AND
"${TEST_SRC_DIR}/autoep/library/example_plugin_ep_virt_gpu/ep.cc")
onnxruntime_add_shared_library_module(example_plugin_ep_virt_gpu ${onnxruntime_autoep_test_example_plugin_ep_virt_gpu_src})
target_include_directories(example_plugin_ep_virt_gpu PRIVATE ${REPO_ROOT}/include/onnxruntime/core/session)
target_link_libraries(example_plugin_ep_virt_gpu PRIVATE onnxruntime)
target_link_libraries(example_plugin_ep_virt_gpu PRIVATE onnxruntime ${GSL_TARGET})

if(UNIX)
if (APPLE)
Expand Down
6 changes: 3 additions & 3 deletions onnxruntime/core/platform/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ class Env {

// \brief Gets the file path of the onnx runtime code
//
// Used to help load other shared libraries that live in the same folder as the core code, for example
// The DNNL provider shared library. Without this path, the module won't be found on windows in all cases.
virtual PathString GetRuntimePath() const { return PathString(); }
// Used to help load other shared libraries that live in the same folder as the core code.
// For example, the DNNL provider shared library.
virtual PathString GetRuntimePath() const = 0;

// \brief Get a pointer to a symbol from a dynamic library.
//
Expand Down
18 changes: 18 additions & 0 deletions onnxruntime/core/platform/posix/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#endif
#include <unistd.h>

#include <filesystem>

Check warning on line 34 in onnxruntime/core/platform/posix/env.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 <filesystem> is an unapproved C++17 header. [build/c++17] [5] Raw Output: onnxruntime/core/platform/posix/env.cc:34: <filesystem> is an unapproved C++17 header. [build/c++17] [5]
#include <iostream>
#include <optional>
#include <thread>
Expand Down Expand Up @@ -554,6 +555,23 @@
return common::Status::OK();
}

PathString GetRuntimePath() const override {
// Use dladdr() to look up the file that contains an address from this binary.
const void* const address_from_this_binary = reinterpret_cast<const void*>(Env::Default);

if (Dl_info dl_info{};
dladdr(address_from_this_binary, &dl_info) != 0 && dl_info.dli_fname != nullptr) {
LOGS_DEFAULT(VERBOSE) << "Getting runtime path as parent directory of binary: " << dl_info.dli_fname;

auto runtime_path = std::filesystem::path{dl_info.dli_fname};
runtime_path = std::filesystem::absolute(runtime_path);
runtime_path.remove_filename();
return runtime_path;
}

return PathString{};
}

common::Status GetSymbolFromLibrary(void* handle, const std::string& symbol_name, void** symbol) const override {
dlerror(); // clear any old error str

Expand Down
2 changes: 2 additions & 0 deletions onnxruntime/core/providers/cuda/version_script.lds
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
VERS_1.0 {
global:
GetProvider;
CreateEpFactories;
ReleaseEpFactory;
_binary_*;

# Hide everything else.
Expand Down
21 changes: 12 additions & 9 deletions onnxruntime/core/session/provider_bridge_ort.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1775,24 +1775,27 @@
#if !defined(ORT_MINIMAL_BUILD) || defined(ORT_MINIMAL_BUILD_CUSTOM_OPS)
Status LoadDynamicLibrary(onnxruntime::PathString library_name) override { return LoadDynamicLibraryFromProvider(library_name); };
#endif
} provider_host_;
} g_provider_host;

#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(pop)
#endif
struct ProviderSharedLibrary {
void Ensure() {
if (handle_)
return;
Status Initialize() {
if (handle_) {
return Status::OK();
}

auto full_path = Env::Default().GetRuntimePath() +
PathString(LIBRARY_PREFIX ORT_TSTR("onnxruntime_providers_shared") LIBRARY_EXTENSION);
ORT_THROW_IF_ERROR(Env::Default().LoadDynamicLibrary(full_path, true /*shared_globals on unix*/, &handle_));
ORT_RETURN_IF_ERROR(Env::Default().LoadDynamicLibrary(full_path, true /*shared_globals on unix*/, &handle_));

void (*PProvider_SetHost)(void*);
ORT_THROW_IF_ERROR(Env::Default().GetSymbolFromLibrary(handle_, "Provider_SetHost", (void**)&PProvider_SetHost));
ORT_RETURN_IF_ERROR(Env::Default().GetSymbolFromLibrary(handle_, "Provider_SetHost", (void**)&PProvider_SetHost));

Check warning on line 1794 in onnxruntime/core/session/provider_bridge_ort.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Using C-style cast. Use reinterpret_cast<void**>(...) instead [readability/casting] [4] Raw Output: onnxruntime/core/session/provider_bridge_ort.cc:1794: Using C-style cast. Use reinterpret_cast<void**>(...) instead [readability/casting] [4]

PProvider_SetHost(&provider_host_);
PProvider_SetHost(&g_provider_host);

return Status::OK();
}

void Unload() {
Expand All @@ -1819,7 +1822,7 @@
static ProviderSharedLibrary s_library_shared;

bool InitProvidersSharedLibrary() try {
s_library_shared.Ensure();
ORT_THROW_IF_ERROR(s_library_shared.Initialize());
return true;
} catch (const std::exception&) {
return false;
Expand All @@ -1841,7 +1844,7 @@
try {
std::lock_guard<std::mutex> lock{mutex_};
if (!provider_) {
s_library_shared.Ensure();
ORT_RETURN_IF_ERROR(s_library_shared.Initialize());

if (absolute_) {
// If filename_ is not absolute it should not be loaded.
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/test/autoep/library/example_plugin_ep/ep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ void ORT_API_CALL ExampleEp::ReleaseNodeComputeInfosImpl(OrtEp* this_ptr,
size_t num_node_compute_infos) noexcept {
(void)this_ptr;
for (size_t i = 0; i < num_node_compute_infos; i++) {
delete node_compute_infos[i];
delete static_cast<ExampleNodeComputeInfo*>(node_compute_infos[i]);
}
}

Expand All @@ -399,7 +399,7 @@ OrtStatus* ExampleEp::CreateEpContextNodes(gsl::span<const OrtNode*> fused_nodes
std::vector<std::string> value_names;
value_names.reserve(value_infos.size());

for (const auto vi : value_infos) {
for (const auto& vi : value_infos) {
value_names.push_back(vi.GetName());
}

Expand Down
12 changes: 11 additions & 1 deletion onnxruntime/test/autoep/library/example_plugin_ep/ep_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "../plugin_ep_utils.h"

#include <memory>
#include <sstream>

// from onnxruntime/core/framework/allocator_stats.h
Expand Down Expand Up @@ -51,7 +52,16 @@ struct AllocatorStats {
}
};

struct CustomAllocator : OrtAllocator {
// `OrtAllocator` is a C API struct. `BaseAllocator` is a minimal C++ struct which inherits from `OrtAllocator`.
// Notably, `BaseAllocator` has a virtual destructor to enable a derived class to be deleted through a `BaseAllocator`
// pointer. Allocators which need to be deleted through a base class pointer should inherit from `BaseAllocator`.
struct BaseAllocator : OrtAllocator {
virtual ~BaseAllocator() = default;
};

using AllocatorUniquePtr = std::unique_ptr<BaseAllocator>;

struct CustomAllocator : BaseAllocator {
CustomAllocator(const OrtMemoryInfo* mem_info, const ApiPtrs& api_ptrs_in)
: memory_info{mem_info}, api_ptrs{api_ptrs_in} {
version = ORT_API_VERSION;
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/test/autoep/library/example_plugin_ep/ep_arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ class ArenaImpl {
// un-assign chunks when StreamImpl::OnSessionRunEnd is called.
std::unordered_map<const OrtSyncStreamImpl*, const OrtSyncStream*> impl_to_stream_;

AllocatorStats stats_;
AllocatorStats stats_{};

const OrtApi& api_;
const OrtEpApi& ep_api_;
Expand All @@ -563,7 +563,7 @@ class ArenaImpl {
ArenaImpl& operator=(ArenaImpl&&) = delete;
};

struct ArenaAllocator : OrtAllocator {
struct ArenaAllocator : BaseAllocator {
static OrtStatus* CreateOrtArenaAllocator(AllocatorUniquePtr allocator,
const OrtKeyValuePairs* options,
const OrtApi& api,
Expand Down
67 changes: 32 additions & 35 deletions onnxruntime/test/autoep/library/example_plugin_ep/ep_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
#include "ep_stream_support.h"

ExampleEpFactory::ExampleEpFactory(const char* ep_name, ApiPtrs apis, const OrtLogger& default_logger)
: OrtEpFactory{}, ApiPtrs(apis), default_logger_{default_logger}, ep_name_{ep_name} {
: OrtEpFactory{},
ApiPtrs(apis),
default_logger_{default_logger},
ep_name_{ep_name},
default_memory_info_{nullptr},
readonly_memory_info_{nullptr} {
ort_version_supported = ORT_API_VERSION; // set to the ORT version we were compiled with.
GetName = GetNameImpl;
GetVendor = GetVendorImpl;
Expand All @@ -34,43 +39,35 @@ ExampleEpFactory::ExampleEpFactory(const char* ep_name, ApiPtrs apis, const OrtL

// setup the OrtMemoryInfo instances required by the EP.
// We pretend the device the EP is running on is GPU.
OrtMemoryInfo* mem_info = nullptr;
auto* status = ort_api.CreateMemoryInfo_V2("ExampleEP GPU", OrtMemoryInfoDeviceType_GPU,
/*vendor*/ 0xBE57, /* device_id */ 0,
OrtDeviceMemoryType_DEFAULT,
/*alignment*/ 0,
// it is invalid to use OrtArenaAllocator as that is reserved for the
// internal ORT Arena implementation
OrtAllocatorType::OrtDeviceAllocator,
&mem_info);
assert(status == nullptr); // should never fail.
default_memory_info_ = MemoryInfoUniquePtr(mem_info, ort_api.ReleaseMemoryInfo);
default_memory_info_ = Ort::MemoryInfo{"ExampleEP GPU",
OrtMemoryInfoDeviceType_GPU,
/*vendor*/ 0xBE57, /* device_id */ 0,
OrtDeviceMemoryType_DEFAULT,
/*alignment*/ 0,
// it is invalid to use OrtArenaAllocator as that is reserved for the internal
// ORT Arena implementation
OrtAllocatorType::OrtDeviceAllocator};

// create data transfer for the device
const OrtMemoryDevice* device = ep_api.MemoryInfo_GetMemoryDevice(default_memory_info_.get());
const OrtMemoryDevice* device = ep_api.MemoryInfo_GetMemoryDevice(default_memory_info_);
data_transfer_impl_ = std::make_unique<ExampleDataTransfer>(apis, device);

// create read-only allocator for use with initializers. same info as DEFAULT memory apart from the allocator type.
status = ort_api.CreateMemoryInfo_V2("ExampleEP GPU readonly", OrtMemoryInfoDeviceType_GPU,
/*vendor*/ 0xBE57, /* device_id */ 0,
OrtDeviceMemoryType_DEFAULT,
/*alignment*/ 0,
OrtAllocatorType::OrtReadOnlyAllocator,
&mem_info);
assert(status == nullptr); // should never fail.

readonly_memory_info_ = MemoryInfoUniquePtr(mem_info, ort_api.ReleaseMemoryInfo);
readonly_memory_info_ = Ort::MemoryInfo{"ExampleEP GPU readonly",
OrtMemoryInfoDeviceType_GPU,
/*vendor*/ 0xBE57, /* device_id */ 0,
OrtDeviceMemoryType_DEFAULT,
/*alignment*/ 0,
OrtAllocatorType::OrtReadOnlyAllocator};

// HOST_ACCESSIBLE memory example. use the non-CPU device type so it's clear which device the memory is also
// accessible from. we infer from the type of HOST_ACCESSIBLE that it's CPU accessible.
mem_info = nullptr;
status = ort_api.CreateMemoryInfo_V2("ExampleEP GPU pinned", OrtMemoryInfoDeviceType_GPU,
/*vendor*/ 0xBE57, /* device_id */ 0,
OrtDeviceMemoryType_HOST_ACCESSIBLE,
/*alignment*/ 0,
OrtAllocatorType::OrtDeviceAllocator,
&mem_info);
ort_api.ReleaseMemoryInfo(mem_info);
auto host_accessible_memory_info = Ort::MemoryInfo{"ExampleEP GPU pinned",
OrtMemoryInfoDeviceType_GPU,
/*vendor*/ 0xBE57, /* device_id */ 0,
OrtDeviceMemoryType_HOST_ACCESSIBLE,
/*alignment*/ 0,
OrtAllocatorType::OrtDeviceAllocator};
}

/*static*/
Expand Down Expand Up @@ -136,8 +133,8 @@ OrtStatus* ORT_API_CALL ExampleEpFactory::GetSupportedDevicesImpl(OrtEpFactory*
// register the allocator info required by the EP.
// registering OrtMemoryInfo for host accessible memory would be done in an additional call.
// OrtReadOnlyAllocator + OrtDeviceMemoryType_DEFAULT allocator for use with initializers is optional.
RETURN_IF_ERROR(factory->ep_api.EpDevice_AddAllocatorInfo(ep_device, factory->default_memory_info_.get()));
RETURN_IF_ERROR(factory->ep_api.EpDevice_AddAllocatorInfo(ep_device, factory->readonly_memory_info_.get()));
RETURN_IF_ERROR(factory->ep_api.EpDevice_AddAllocatorInfo(ep_device, factory->default_memory_info_));
RETURN_IF_ERROR(factory->ep_api.EpDevice_AddAllocatorInfo(ep_device, factory->readonly_memory_info_));

ep_devices[num_ep_devices++] = ep_device;
}
Expand Down Expand Up @@ -215,8 +212,8 @@ OrtStatus* ORT_API_CALL ExampleEpFactory::CreateAllocatorImpl(OrtEpFactory* this
auto& factory = *static_cast<ExampleEpFactory*>(this_ptr);
*allocator = nullptr;

bool is_default_allocator = memory_info == factory.default_memory_info_.get();
bool is_readonly_allocator = memory_info == factory.readonly_memory_info_.get();
bool is_default_allocator = memory_info == factory.default_memory_info_;
bool is_readonly_allocator = memory_info == factory.readonly_memory_info_;

if (!is_default_allocator && !is_readonly_allocator) {
return factory.ort_api.CreateStatus(ORT_INVALID_ARGUMENT,
Expand Down Expand Up @@ -244,7 +241,7 @@ OrtStatus* ORT_API_CALL ExampleEpFactory::CreateAllocatorImpl(OrtEpFactory* this
std::lock_guard<std::mutex> lock{factory.mutex_};

if (!factory.arena_allocator_) {
std::unique_ptr<OrtAllocator> ep_allocator = std::make_unique<CustomAllocator>(memory_info, factory);
AllocatorUniquePtr ep_allocator = std::make_unique<CustomAllocator>(memory_info, factory);

// initial shared allocator in environment does not have allocator options.
// if the user calls CreateSharedAllocator they can provide options to configure the arena differently.
Expand Down
Loading
Loading