Skip to main content

StreamMemoryPool

Struct StreamMemoryPool 

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

A memory pool for stream-ordered allocations.

On platforms with a real CUDA driver (Linux, Windows), creating a pool calls cuMemPoolCreate under the hood. On macOS (where there is no NVIDIA driver), pool metadata is tracked locally but any operation that would require the driver returns Err(CudaError::NotSupported).

§Allocation tracking

The pool tracks allocation counts and byte totals locally for diagnostics. These statistics are maintained even on macOS so that the API surface can be exercised in tests.

Implementations§

Source§

impl StreamMemoryPool

Source

pub fn new(config: StreamOrderedAllocConfig) -> CudaResult<Self>

Create a new memory pool for the given device.

The configuration is validated before the pool is created. On platforms with a real CUDA driver, cuMemPoolCreate is invoked. On macOS, a local-only pool is created for testing purposes.

§Errors
Source

pub fn alloc_async( &mut self, size: usize, stream: u64, ) -> CudaResult<StreamAllocation>

Allocate memory on a stream (stream-ordered).

The allocation becomes available when all prior work on the stream has completed. The returned StreamAllocation tracks the pointer, size, and ownership.

§Errors
Source

pub fn free_async(&mut self, alloc: &mut StreamAllocation) -> CudaResult<()>

Free memory on a stream (stream-ordered).

The memory is returned to the pool when all prior work on the stream has completed. The allocation is marked as freed and cannot be freed again.

§Errors
Source

pub fn trim(&mut self, min_bytes_to_keep: usize) -> CudaResult<()>

Trim the pool, releasing unused memory back to the OS.

At least min_bytes_to_keep bytes of reserved memory will remain in the pool for future allocations.

§Errors
Source

pub fn stats(&self) -> PoolUsageStats

Get pool usage statistics.

The returned PoolUsageStats combines locally tracked allocation counts with byte-level information. On macOS, the reserved/used byte fields mirror the local bookkeeping since no driver is available.

Source

pub fn set_attribute(&mut self, attr: PoolAttribute) -> CudaResult<()>

Set a pool attribute.

Only attributes that carry a value (e.g. PoolAttribute::ReleaseThreshold) modify pool state. Read-only attributes (e.g. ReservedMemCurrent) return CudaError::InvalidValue.

§Errors
Source

pub fn enable_peer_access(&self, peer_device: i32) -> CudaResult<()>

Enable peer access from another device to allocations in this pool.

After this call, kernels running on peer_device can access memory allocated from this pool.

§Errors
Source

pub fn disable_peer_access(&self, peer_device: i32) -> CudaResult<()>

Disable peer access from another device to allocations in this pool.

§Errors
Source

pub fn reset_peak_stats(&mut self)

Reset peak statistics (peak allocated bytes and peak allocation count).

Source

pub fn default_pool(device: i32) -> CudaResult<Self>

Get the default memory pool for a device.

CUDA provides a default pool per device. On macOS, this returns a local-only pool with default configuration.

§Errors
Source

pub fn handle(&self) -> u64

Returns the raw pool handle.

Source

pub fn device(&self) -> i32

Returns the device ordinal.

Source

pub fn config(&self) -> &StreamOrderedAllocConfig

Returns the pool configuration.

Trait Implementations§

Source§

impl Debug for StreamMemoryPool

Source§

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

Formats the value using the given formatter. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = 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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more