pub struct DeviceFactoryRegistry { /* private fields */ }Expand description
Registry for full Device objects with caching and factory registration.
§Thread Safety
This registry uses parking_lot::RwLock for efficient concurrent access:
- Multiple readers can access cached devices simultaneously
- Writers acquire exclusive lock only when creating new devices
- Double-checked locking pattern prevents redundant device creation
§Example
ⓘ
// Get a device (creates if not cached)
let alloc_registry = svod_device::registry::registry();
let device = DEVICE_FACTORIES.device(&DeviceSpec::Cpu, alloc_registry)?;
// Register a custom factory
DEVICE_FACTORIES.register_factory("CUSTOM", Arc::new(|spec, reg| {
// Create custom device...
}));Implementations§
Source§impl DeviceFactoryRegistry
impl DeviceFactoryRegistry
Sourcepub fn register_factory(&self, device_type: &str, factory: DeviceFactory)
pub fn register_factory(&self, device_type: &str, factory: DeviceFactory)
Register a device factory for a device type.
The device type string is case-insensitive (converted to uppercase). This allows plugins or extensions to register new device types at runtime.
§Arguments
device_type- Device type identifier (e.g., “CPU”, “CUDA”, “METAL”)factory- Factory function that creates Device instances
Sourcepub fn device(
&self,
spec: &DeviceSpec,
alloc_registry: &DeviceRegistry,
) -> Result<Arc<Device>>
pub fn device( &self, spec: &DeviceSpec, alloc_registry: &DeviceRegistry, ) -> Result<Arc<Device>>
Get or create a Device for the given specification.
This method uses double-checked locking for efficiency:
- Fast path: Read lock to check cache
- Slow path: Write lock to create and cache new device
§Arguments
spec- Device specification (e.g.,DeviceSpec::Cpu)alloc_registry- Allocator registry for obtaining device allocators
§Returns
Arc-wrapped Device for the specification, or error if device type unsupported.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DeviceFactoryRegistry
impl !RefUnwindSafe for DeviceFactoryRegistry
impl Send for DeviceFactoryRegistry
impl Sync for DeviceFactoryRegistry
impl Unpin for DeviceFactoryRegistry
impl UnsafeUnpin for DeviceFactoryRegistry
impl !UnwindSafe for DeviceFactoryRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more