Repository navigation
Add EP device memory capacity query API with CUDA support - #33447
Open
Selena Yang (selenayang888) wants to merge 4 commits into
Open
Selena Yang (selenayang888) wants to merge 4 commits into
Selena Yang (selenayang888) wants to merge 4 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The minimal CUDA build lacks the required driver-library dependency, and the new mock capacities overflow on 32-bit targets.
2 open issues
What changed in this PR
Adds a provider-independent API for querying device memory capacity, giving downstream consumers access to total and currently available memory through ONNX Runtime.
Changes:
- Adds C and C++ query APIs with an optional execution-provider factory callback.
- Implements CUDA queries through shared logic that manages context switching and preserves outputs on failure.
- Adds example-plugin coverage and deterministic regression tests.
| File | Description |
|---|---|
onnxruntime/test/autoep/test_registration.cc |
Adds API, context, and failure-path tests. |
onnxruntime/test/autoep/library/example_plugin_ep/ep_factory.h |
Declares the example callback. |
onnxruntime/test/autoep/library/example_plugin_ep/ep_factory.cc |
Provides synthetic memory capacities. |
onnxruntime/core/session/plugin_ep/forward_to_factory_impl.h |
Forwards queries to internal factories. |
onnxruntime/core/session/plugin_ep/ep_factory_provider_bridge.h |
Adds version-checked provider forwarding. |
onnxruntime/core/session/plugin_ep/ep_factory_internal.h |
Exposes internal query forwarding. |
onnxruntime/core/session/plugin_ep/ep_factory_internal.cc |
Registers the forwarding callback. |
onnxruntime/core/session/plugin_ep/ep_factory_internal_impl.h |
Supplies the unsupported-query default. |
onnxruntime/core/session/ort_apis.h |
Declares the C API implementation. |
onnxruntime/core/session/onnxruntime_c_api.cc |
Validates, dispatches, and registers queries. |
onnxruntime/core/providers/cuda/shared_inc/device_memory_capacity.h |
Adds testable query and cleanup logic. |
onnxruntime/core/providers/cuda/shared_inc/cuda_memory_capacity.h |
Wraps CUDA Driver API calls. |
onnxruntime/core/providers/cuda/plugin/cuda_ep_factory.h |
Declares the CUDA plugin callback. |
onnxruntime/core/providers/cuda/plugin/cuda_ep_factory.cc |
Implements CUDA plugin queries. |
onnxruntime/core/providers/cuda/cuda_provider_factory.cc |
Implements shared-provider CUDA queries. |
include/onnxruntime/core/session/onnxruntime_ep_c_api.h |
Appends and documents the optional callback. |
include/onnxruntime/core/session/onnxruntime_cxx_inline.h |
Implements the C++ wrapper. |
include/onnxruntime/core/session/onnxruntime_cxx_api.h |
Declares the C++ wrapper. |
include/onnxruntime/core/session/onnxruntime_c_api.h |
Appends and documents the public query API. |
Review effort: Balanced
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Add an authoritative EP/device API for querying total and currently available device memory. This provides capacity information for downstream consumers such as Foundry Local and ONNX Runtime GenAI without requiring provider-specific memory queries in those consumers.
Changes
OrtApi::EpDevice_GetMemoryCapacityand a C++GetMemoryCapacity()wrapper.OrtEpFactory::GetDeviceMemoryCapacitycallback, with internal factory and provider-bridge forwarding.ORT_NOT_IMPLEMENTEDwhen an EP does not support the query.cuDeviceTotalMemfor device-global capacity andcuMemGetInfofor current free memory.noexceptquery error paths.API Semantics
Total memory is the device-global capacity exposed for the specific EP device, not a per-process or per-context allocation budget. For partitioned or virtual devices, it reflects the exposed device rather than the entire physical board.
Available memory is a current free-memory estimate. It is not a reservation or a guarantee that an allocation of that size will succeed.
Validation
OrtEpLibrary.*: 66 passed, 1 GPU-dependent test skipped.CUDA-enabled compilation and real GPU validation remain outstanding because the local environment has no CUDA toolkit. The deterministic tests exercise the shared query logic without a CUDA dependency.
Scope
This PR provides the ORT/EP capacity-reporting foundation. It does not change Foundry Local catalog filtering or migrate GenAI runtime-profile selection to the new API.