Skip to main content

PoolScalar

Trait PoolScalar 

Source
pub trait PoolScalar:
    Copy
    + Sized
    + Send
    + Sealed {
    // Required methods
    unsafe fn pool_acquire(pool: &mut BufferPool, len: usize) -> Vec<Self>;
    fn pool_release(pool: &mut BufferPool, buf: Vec<Self>);
}
Expand description

Scalar types supported by BufferPool.

The trait is sealed to the scalar dtypes that tenferro currently pools for CPU execution.

§Examples

use tenferro_tensor::buffer_pool::{BufferPool, PoolScalar};

let mut pool = BufferPool::new();
let mut buf = unsafe { <f64 as PoolScalar>::pool_acquire(&mut pool, 2) };
buf.copy_from_slice(&[3.0, 4.0]);
<f64 as PoolScalar>::pool_release(&mut pool, buf);

Required Methods§

Source

unsafe fn pool_acquire(pool: &mut BufferPool, len: usize) -> Vec<Self>

Acquire a buffer with length len.

The vector length is set without initializing its contents. Callers must overwrite every element before any read.

§Safety

The returned vector may contain uninitialized elements. Reading any element before writing it is undefined behavior.

§Examples
use tenferro_tensor::buffer_pool::{BufferPool, PoolScalar};

let mut pool = BufferPool::new();
let mut buf = unsafe { <f64 as PoolScalar>::pool_acquire(&mut pool, 2) };
buf.copy_from_slice(&[1.0, 2.0]);
assert_eq!(buf, vec![1.0, 2.0]);
Source

fn pool_release(pool: &mut BufferPool, buf: Vec<Self>)

Return a buffer to the typed pool for later reuse.

Zero-capacity buffers are ignored.

§Examples
use tenferro_tensor::buffer_pool::{BufferPool, PoolScalar};

let mut pool = BufferPool::new();
let buf = vec![1.0_f32; 4];
<f32 as PoolScalar>::pool_release(&mut pool, buf);
assert_eq!(pool.len(), 1);

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.

Implementations on Foreign Types§

Source§

impl PoolScalar for f32

Source§

unsafe fn pool_acquire(pool: &mut BufferPool, len: usize) -> Vec<Self>

Source§

fn pool_release(pool: &mut BufferPool, buf: Vec<Self>)

Source§

impl PoolScalar for f64

Source§

unsafe fn pool_acquire(pool: &mut BufferPool, len: usize) -> Vec<Self>

Source§

fn pool_release(pool: &mut BufferPool, buf: Vec<Self>)

Source§

impl PoolScalar for Complex32

Source§

unsafe fn pool_acquire(pool: &mut BufferPool, len: usize) -> Vec<Self>

Source§

fn pool_release(pool: &mut BufferPool, buf: Vec<Self>)

Source§

impl PoolScalar for Complex64

Source§

unsafe fn pool_acquire(pool: &mut BufferPool, len: usize) -> Vec<Self>

Source§

fn pool_release(pool: &mut BufferPool, buf: Vec<Self>)

Implementors§