pub trait Backend: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn is_available(&self) -> bool;
fn capabilities(&self) -> DeviceCapabilities;
fn allocate(&self, size: usize) -> *mut u8;
fn deallocate(&self, ptr: *mut u8, size: usize);
fn copy_to_device(&self, dst: *mut u8, src: *const u8, size: usize);
fn copy_to_host(&self, dst: *mut u8, src: *const u8, size: usize);
fn copy_device_to_device(&self, dst: *mut u8, src: *const u8, size: usize);
fn synchronize(&self);
}Expand description
Common trait for all compute backends.
This trait defines the interface that all backends must implement, enabling device-agnostic tensor operations.
Required Methods§
Sourcefn is_available(&self) -> bool
fn is_available(&self) -> bool
Returns whether this backend is available on the current system.
Sourcefn capabilities(&self) -> DeviceCapabilities
fn capabilities(&self) -> DeviceCapabilities
Returns the device capabilities.
Sourcefn deallocate(&self, ptr: *mut u8, size: usize)
fn deallocate(&self, ptr: *mut u8, size: usize)
Deallocates memory on this backend.
Sourcefn copy_to_device(&self, dst: *mut u8, src: *const u8, size: usize)
fn copy_to_device(&self, dst: *mut u8, src: *const u8, size: usize)
Copies data from host to device.
Sourcefn copy_to_host(&self, dst: *mut u8, src: *const u8, size: usize)
fn copy_to_host(&self, dst: *mut u8, src: *const u8, size: usize)
Copies data from device to host.
Sourcefn copy_device_to_device(&self, dst: *mut u8, src: *const u8, size: usize)
fn copy_device_to_device(&self, dst: *mut u8, src: *const u8, size: usize)
Copies data within the device.
Sourcefn synchronize(&self)
fn synchronize(&self)
Synchronizes the device (waits for all operations to complete).