Skip to main content

BackendRegistry

Struct BackendRegistry 

Source
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

Source

pub fn new() -> Self

An empty registry.

Source

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).

Source

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.

Source

pub fn len(&self) -> usize

Number of registered backends.

Source

pub fn is_empty(&self) -> bool

true if no backend is registered.

Source

pub fn get(&self, kind: BackendKind) -> Option<&BackendEntry>

Borrow the entry for kind, if registered.

Source

pub fn set_available(&mut self, kind: BackendKind, available: bool) -> bool

Mark kind’s availability, returning true if the kind was present.

Source

pub fn set_capabilities( &mut self, kind: BackendKind, caps: Capabilities, ) -> bool

Update kind’s capability report, returning true if present.

Source

pub fn available_kinds(&self) -> Vec<BackendKind>

All currently-available backend kinds.

Source

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.

Source

pub fn select_best(&self) -> BackendResult<BackendKind>

Convenience: select the best available backend with no constraints, preferring a GPU but accepting the CPU fallback.

Source

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.

Source

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

Source§

fn clone(&self) -> BackendRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BackendRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BackendRegistry

Source§

fn default() -> BackendRegistry

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.