pub struct BufferPool { /* private fields */ }Expand description
Free lists of GPU buffers keyed by exact byte size.
Returned buffers are kept for reuse until the pool holds
max_pooled_bytes; beyond that they are released. Without the cap a
workload with many distinct tensor sizes (e.g. training on sequences of
varying length) would keep every buffer it ever freed.
Implementations§
Source§impl BufferPool
impl BufferPool
Sourcepub fn new(usage: BufferUsages) -> Self
pub fn new(usage: BufferUsages) -> Self
A pool whose buffers are created with usage.
Sourcepub fn set_max_pooled_bytes(&self, max: u64)
pub fn set_max_pooled_bytes(&self, max: u64)
Change how many bytes of freed buffers the pool keeps (0 disables reuse). Buffers above the new cap are released immediately.
Sourcepub fn pooled_bytes(&self) -> u64
pub fn pooled_bytes(&self) -> u64
Bytes currently held for reuse.
Sourcepub fn get(&self, device: &Device, size: u64) -> Arc<Buffer> ⓘ
pub fn get(&self, device: &Device, size: u64) -> Arc<Buffer> ⓘ
A free buffer of exactly size bytes, or a new one.
Sourcepub fn return_buffer(&self, size: u64, buffer: Arc<Buffer>)
pub fn return_buffer(&self, size: u64, buffer: Arc<Buffer>)
Returns buffer (of size bytes) to the pool for reuse.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for BufferPool
impl RefUnwindSafe for BufferPool
impl Send for BufferPool
impl Sync for BufferPool
impl Unpin for BufferPool
impl UnsafeUnpin for BufferPool
impl UnwindSafe for BufferPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more