Skip to main content

CapturePool

Struct CapturePool 

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

A dedicated memory pool for CUDA graph capture.

Two responsibilities:

  1. Sealed flag — gates begin_capture_with_pool so the caller can express “no more allocations after this point” semantically. Sealed pools cannot satisfy new allocations during capture.

  2. Buffer lifetime tracking (CL-278) — registered buffers are kept alive by the pool itself, so they outlive any CapturedGraph that holds an Arc<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

Source

pub fn new() -> Self

Create a new, unsealed capture pool.

Source

pub fn seal(&self)

Seal the pool, preventing any further allocations.

Source

pub fn unseal(&self)

Unseal the pool, allowing allocations again.

Source

pub fn is_capture_pool_sealed(&self) -> bool

Check whether the pool is sealed.

Source

pub fn record_buffer<B>(&self, buffer: B) -> usize
where B: Send + Sync + 'static,

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.

Source

pub fn buffer_count(&self) -> usize

Number of buffers currently registered with the pool. CL-278.

Source

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§

Source§

impl Default for CapturePool

Available on crate feature cuda only.
Source§

fn default() -> Self

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

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

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

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<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> 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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