Skip to main content

BufferPool

Struct BufferPool 

Source
pub struct BufferPool { /* private fields */ }
Expand description

Typed buffer pool keyed by element capacity and separated by scalar type.

Each supported dtype has an independent best-fit pool. Acquired buffers are returned without zero-initialization so kernels can avoid redundant writes when they fully overwrite the output. Use PoolScalar::pool_acquire_zeroed when the caller may read the buffer before writing every element.

§Examples

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

let mut pool = BufferPool::new();
let buf = pool.acquire_zeroed::<f32>(8);
<f32 as PoolScalar>::pool_release(&mut pool, buf);
assert_eq!(pool.len(), 1);

Implementations§

Source§

impl BufferPool

Source

pub fn new() -> BufferPool

Create an empty typed buffer pool.

§Examples
use tenferro_cpu_basic::buffer_pool::BufferPool;

let pool = BufferPool::new();
assert!(pool.is_empty());
Source

pub fn with_max_retained_capacity_bytes( max_retained_capacity_bytes: usize, ) -> BufferPool

Create an empty typed buffer pool with a specific retention cap.

A cap of zero disables retention. Use BufferPool::unbounded only for diagnostics or workloads that are externally memory-limited.

§Examples
use tenferro_cpu_basic::buffer_pool::BufferPool;

let pool = BufferPool::with_max_retained_capacity_bytes(1024);
assert_eq!(pool.max_retained_capacity_bytes(), 1024);
Source

pub fn unbounded() -> BufferPool

Create an empty typed buffer pool without a retention cap.

This preserves the historical behavior and is mainly useful for diagnostics or controlled benchmarks.

§Examples
use tenferro_cpu_basic::buffer_pool::BufferPool;

let pool = BufferPool::unbounded();
assert_eq!(pool.max_retained_capacity_bytes(), usize::MAX);
Source

pub fn max_retained_capacity_bytes(&self) -> usize

Maximum retained typed host-buffer capacity in bytes.

§Examples
use tenferro_cpu_basic::buffer_pool::BufferPool;

let pool = BufferPool::with_max_retained_capacity_bytes(4096);
assert_eq!(pool.max_retained_capacity_bytes(), 4096);
Source

pub fn set_max_retained_capacity_bytes( &mut self, max_retained_capacity_bytes: usize, )

Update the maximum retained typed host-buffer capacity in bytes.

Shrinking below the currently retained capacity immediately evicts retained buffers until the new cap is satisfied. A cap of zero disables retention.

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

let mut pool = BufferPool::with_max_retained_capacity_bytes(1024);
<f64 as PoolScalar>::pool_release(&mut pool, Vec::with_capacity(128));
pool.set_max_retained_capacity_bytes(0);
assert_eq!(pool.max_retained_capacity_bytes(), 0);
assert!(pool.is_empty());
Source

pub fn len(&self) -> usize

Number of retained buffers across all typed pools.

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

let mut pool = BufferPool::new();
<f64 as PoolScalar>::pool_release(&mut pool, vec![0.0; 2]);
assert_eq!(pool.len(), 1);
Source

pub fn retained_capacity_bytes(&self) -> usize

Total retained typed host-buffer capacity in bytes.

This counts capacity that is still live in the pool. The operating system RSS may remain high after clearing the pool because the process allocator can keep freed pages for future allocations.

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

let mut pool = BufferPool::new();
<f64 as PoolScalar>::pool_release(&mut pool, Vec::with_capacity(2));
assert_eq!(pool.retained_capacity_bytes(), 16);
Source

pub fn stats(&self) -> BufferPoolStats

Snapshot retained-buffer count and capacity.

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

let mut pool = BufferPool::new();
<f32 as PoolScalar>::pool_release(&mut pool, Vec::with_capacity(4));
let stats = pool.stats();
assert_eq!(stats.buffers, 1);
assert_eq!(stats.capacity_bytes, 16);
Source

pub fn cache_stats(&self) -> CacheStats

Return cache-style stats for the buffers retained by this pool.

entries is the number of retained buffers, and retained_bytes is the total retained vector capacity in bytes.

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

let mut pool = BufferPool::new();
<f32 as PoolScalar>::pool_release(&mut pool, Vec::with_capacity(4));
let stats = pool.cache_stats();
assert_eq!(stats.entries, 1);
assert_eq!(stats.retained_bytes, 16);
Source

pub fn acquire_with_capacity<T>(&mut self, cap: usize) -> Vec<T>
where T: PoolScalar,

Acquire a typed vector with length 0 and at least cap capacity.

Returned buffers come from the typed pool when possible and are ready for push-based population.

§Examples
use tenferro_cpu_basic::buffer_pool::BufferPool;

let mut pool = BufferPool::new();
let mut buf = pool.acquire_with_capacity::<f64>(4);
buf.extend_from_slice(&[1.0, 2.0]);
assert_eq!(buf.len(), 2);
assert!(buf.capacity() >= 4);
Source

pub fn acquire_zeroed<T>(&mut self, len: usize) -> Vec<T>
where T: PoolScalar,

Acquire a typed vector with length len initialized to zero.

Use this only when the caller may read elements before overwriting the entire buffer. Full-overwrite kernels should use crate::PooledUninitOutput to avoid the initialization cost.

§Examples
use tenferro_cpu_basic::buffer_pool::BufferPool;

let mut pool = BufferPool::new();
let buf = pool.acquire_zeroed::<f32>(3);
assert_eq!(buf, vec![0.0, 0.0, 0.0]);
Source

pub fn is_empty(&self) -> bool

Whether all typed pools are empty.

§Examples
use tenferro_cpu_basic::buffer_pool::BufferPool;

let pool = BufferPool::new();
assert!(pool.is_empty());
Source

pub fn clear(&mut self)

Drop all retained buffers from the pool.

This releases the vectors owned by the pool. The process allocator may still keep freed pages mapped for reuse, so operating-system RSS is not guaranteed to fall immediately.

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

let mut pool = BufferPool::new();
<f64 as PoolScalar>::pool_release(&mut pool, Vec::with_capacity(8));
pool.clear();
assert!(pool.is_empty());

Trait Implementations§

Source§

impl Debug for BufferPool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for BufferPool

Source§

fn default() -> BufferPool

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.