pub struct CapturePool { /* private fields */ }Expand description
A dedicated memory pool for CUDA graph capture.
Two responsibilities:
-
Sealed flag — gates
begin_capture_with_poolso the caller can express “no more allocations after this point” semantically. Sealed pools cannot satisfy new allocations during capture. -
Buffer lifetime tracking (CL-278) — registered buffers are kept alive by the pool itself, so they outlive any
CapturedGraphthat holds anArc<CapturePool>. Dropping the graph drops the Arc, and dropping the last Arc drops every registered buffer in registration order.
§Usage
use std::sync::Arc;
let pool = Arc::new(CapturePool::new());
// Allocate every buffer the captured kernels will read or
// write, and register each one with the pool so it stays alive
// for the graph's lifetime.
let mut buf_a = alloc_zeros_f32(1024, &device)?;
let mut buf_b = alloc_zeros_f32(1024, &device)?;
pool.record_buffer(buf_a.try_clone()?);
pool.record_buffer(buf_b.try_clone()?);
pool.seal();
begin_capture_with_pool(&pool, stream)?;
// ... launch kernels using buf_a and buf_b ...
let graph = end_capture_with_pool(stream, Arc::clone(&pool))?;
// Dropping `pool` here is safe — the graph holds its own Arc.Implementations§
Source§impl CapturePool
impl CapturePool
Sourcepub fn is_capture_pool_sealed(&self) -> bool
pub fn is_capture_pool_sealed(&self) -> bool
Check whether the pool is sealed.
Sourcepub fn record_buffer<B>(&self, buffer: B) -> usize
pub fn record_buffer<B>(&self, buffer: B) -> usize
Register a buffer with the pool so it stays alive for the
lifetime of any CapturedGraph that holds this pool.
CL-278.
buffer can be any type that owns GPU memory (typically
CudaBuffer<f32>, CudaBuffer<f64>, or Arc<CudaBuffer<T>>).
The pool stores it in a type-erased Box<dyn Any + Send + Sync> and drops it (in registration order) when the pool
itself is dropped.
Returns the index of the registered buffer for diagnostic purposes.
Sourcepub fn buffer_count(&self) -> usize
pub fn buffer_count(&self) -> usize
Number of buffers currently registered with the pool. CL-278.
Sourcepub fn clear_buffers(&self)
pub fn clear_buffers(&self)
Drop every registered buffer immediately, in registration order. The pool itself remains usable; new buffers can still be registered after this call. CL-278.
Use this when reusing a pool across multiple capture cycles.
Calling clear while a CapturedGraph still holds an Arc
to this pool is safe — the graph’s strong reference keeps
the pool struct alive, but the buffer slots are reset.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for CapturePool
impl RefUnwindSafe for CapturePool
impl Send for CapturePool
impl Sync for CapturePool
impl Unpin for CapturePool
impl UnsafeUnpin for CapturePool
impl UnwindSafe for CapturePool
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
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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