pub struct BackendRegistry { /* private fields */ }Expand description
A registry of compute backends with capability-aware selection.
Construction registers nothing; call register (or
with_defaults) to populate it. Selection is pure
and side-effect-free, so it is trivially unit-testable.
Implementations§
Source§impl BackendRegistry
impl BackendRegistry
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
A registry pre-populated with one entry per BackendKind, all
flagged unavailable except the CPU reference backend.
Concrete crates then flip the available flag (and refine the
capabilities) for backends they detect via
set_available /
set_capabilities. This guarantees there
is always at least one usable backend (the CPU fallback).
Sourcepub fn register(&mut self, entry: BackendEntry)
pub fn register(&mut self, entry: BackendEntry)
Register (or replace) an entry. If a backend of the same kind is already present, it is overwritten so a later, more-informed probe wins.
Sourcepub fn get(&self, kind: BackendKind) -> Option<&BackendEntry>
pub fn get(&self, kind: BackendKind) -> Option<&BackendEntry>
Borrow the entry for kind, if registered.
Sourcepub fn set_available(&mut self, kind: BackendKind, available: bool) -> bool
pub fn set_available(&mut self, kind: BackendKind, available: bool) -> bool
Mark kind’s availability, returning true if the kind was present.
Sourcepub fn set_capabilities(
&mut self,
kind: BackendKind,
caps: Capabilities,
) -> bool
pub fn set_capabilities( &mut self, kind: BackendKind, caps: Capabilities, ) -> bool
Update kind’s capability report, returning true if present.
Sourcepub fn available_kinds(&self) -> Vec<BackendKind>
pub fn available_kinds(&self) -> Vec<BackendKind>
All currently-available backend kinds.
Sourcepub fn select(&self, req: &SelectionRequest) -> BackendResult<BackendKind>
pub fn select(&self, req: &SelectionRequest) -> BackendResult<BackendKind>
Select the single best backend satisfying req, or
BackendError::Unsupported if none qualifies.
“Best” = highest priority among satisfying entries; ties break by
BackendKind::default_priority and then declaration order, so the
result is deterministic.
Sourcepub fn select_best(&self) -> BackendResult<BackendKind>
pub fn select_best(&self) -> BackendResult<BackendKind>
Convenience: select the best available backend with no constraints, preferring a GPU but accepting the CPU fallback.
Sourcepub fn fallback_chain(&self, req: &SelectionRequest) -> Vec<BackendKind>
pub fn fallback_chain(&self, req: &SelectionRequest) -> Vec<BackendKind>
The ordered fallback chain for req: every satisfying backend, most-
to least-preferred, with the CPU reference backend forced to the end
if it is available (even when it would also satisfy req earlier).
Consumers walk this chain, trying each backend until one initializes and runs the op, so a transient GPU failure degrades gracefully to the host.
Sourcepub fn route(&self, op: OpClass) -> BackendResult<BackendKind>
pub fn route(&self, op: OpClass) -> BackendResult<BackendKind>
Route an OpClass to the best backend.
For Tensor-Core-friendly classes the router first tries to find an available matrix-capable backend; if none exists it falls back to the plain best-available selection (so routing never fails when any backend is available).
Trait Implementations§
Source§impl Clone for BackendRegistry
impl Clone for BackendRegistry
Source§fn clone(&self) -> BackendRegistry
fn clone(&self) -> BackendRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more