TensorAllocator

Trait TensorAllocator 

Source
pub trait TensorAllocator: Clone {
    // Required methods
    fn alloc(&self, layout: Layout) -> Result<*mut u8, TensorAllocatorError>;
    fn dealloc(&self, ptr: *mut u8, layout: Layout);
}
Expand description

A trait for allocating and deallocating memory for tensors.

§Safety

The tensor allocator must be thread-safe.

§Methods

  • alloc - Allocates memory for a tensor with the given layout.
  • dealloc - Deallocates memory for a tensor with the given layout.

Required Methods§

Source

fn alloc(&self, layout: Layout) -> Result<*mut u8, TensorAllocatorError>

Allocates memory for a tensor with the given layout.

Source

fn dealloc(&self, ptr: *mut u8, layout: Layout)

Deallocates memory for a tensor with the given layout.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl TensorAllocator for CpuAllocator

Implement the TensorAllocator trait for the CpuAllocator struct.