Skip to main content

BufferPool

Struct BufferPool 

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

A pool of reusable GPU buffers, organized by size buckets

§Design Rationale

GPU buffer allocation is expensive (involves driver calls and memory mapping). This pool enables buffer reuse to:

  1. Reduce allocation overhead for repeated operations
  2. Minimize memory fragmentation
  3. Prevent memory exhaustion during benchmarking/training

Buffers are bucketed by size (rounded up to power-of-2) for efficient matching. A 5000-byte request gets a buffer from the 8192-byte bucket.

§Thread Safety

All operations are protected by a Mutex, making the pool safe for concurrent access (though Volta is currently single-threaded, this future-proofs the design).

Implementations§

Source§

impl BufferPool

Source

pub fn new(config: BufferPoolConfig) -> Self

Create a new buffer pool with the given configuration

Source

pub fn with_defaults() -> Self

Create a buffer pool with default configuration

Source

pub fn allocation_size(min_size: usize) -> usize

Get the allocation size for a given minimum size

This rounds up to the next power of 2, ensuring all buffers in a bucket have the same size and can be safely reused.

Source

pub fn acquire(&self, min_size: usize) -> Option<Buffer>

Try to acquire a buffer from the pool

Returns Some(buffer) if a suitable buffer is available, None if the pool is empty for that size or the size is too large.

§Arguments
  • min_size - Minimum required size in bytes
Source

pub fn release(&self, buffer: Buffer, size: usize) -> bool

Return a buffer to the pool for reuse

Returns true if the buffer was pooled, false if it was rejected (e.g., pool full or buffer too large). Rejected buffers should be dropped normally.

§Arguments
  • buffer - The GPU buffer to return
  • size - The buffer size in bytes
Source

pub fn clear(&self)

Clear all buffers from the pool

This immediately frees all GPU memory held by the pool. Useful for reducing memory pressure or before shutdown.

Source

pub fn stats(&self) -> BufferPoolStats

Get statistics about pool usage

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

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,