Skip to main content

BackendBuffer

Trait BackendBuffer 

Source
pub trait BackendBuffer<T>:
    Debug
    + Send
    + Sync
    + 'static {
    // Required methods
    fn backend_family(&self) -> &'static str;
    fn len(&self) -> usize;
    fn as_any(&self) -> &dyn Any;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn allocation_domain(&self) -> Option<AllocationDomainId> { ... }
    fn allocation_id(&self) -> Option<AllocationId> { ... }
    fn map_read(&self) -> Result<HostReadGuard<'_, T>, HostAccessError> { ... }
    fn map_write(&self) -> Result<HostWriteGuard<'_, T>, HostAccessError> { ... }
}
Expand description

Opaque backend-owned tensor buffer.

Tensor core never inspects backend-native allocations directly. Backend crates store their own concrete handle types behind this trait and downcast inside the owning backend only.

§Examples

use std::sync::Arc;
use tenferro_tensor::{BackendBuffer, BufferHandle};

let buffer: Arc<dyn BackendBuffer<f64>> = Arc::new(BufferHandle::<f64>::new_with_len(7, 2));
assert_eq!(buffer.backend_family(), "opaque");
assert_eq!(buffer.len(), 2);

Required Methods§

Source

fn backend_family(&self) -> &'static str

Stable backend family identifier.

Source

fn len(&self) -> usize

Number of logical elements in the backend allocation.

Source

fn as_any(&self) -> &dyn Any

Type-erased access for the backend crate that owns the concrete handle.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true when the backend allocation is empty.

Source

fn allocation_domain(&self) -> Option<AllocationDomainId>

Return the shared-allocation domain, when this buffer belongs to one.

Source

fn allocation_id(&self) -> Option<AllocationId>

Return the stable physical allocation identity, when available.

Source

fn map_read(&self) -> Result<HostReadGuard<'_, T>, HostAccessError>

Map the allocation for closure-scoped host reads.

§Errors

The default returns HostAccessError::Unsupported. Host-visible backends return typed overlap, pending-GPU, or backend mapping failures.

Source

fn map_write(&self) -> Result<HostWriteGuard<'_, T>, HostAccessError>

Map the allocation for closure-scoped host writes.

§Errors

The default returns HostAccessError::Unsupported. Host-visible backends return typed overlap, pending-GPU, or backend mapping failures.

Implementors§

Source§

impl<T: Send + Sync + 'static> BackendBuffer<T> for BufferHandle<T>