Expand description
Stream-ordered memory allocation (CUDA 11.2+ / 12.x+).
Stream-ordered memory allocation allows memory operations (alloc / free)
to participate in the stream execution order, eliminating the need for
explicit synchronisation between allocation and kernel launch.
This module provides:
StreamMemoryPool— a memory pool bound to a specific device.StreamAllocation— a handle to a stream-ordered allocation.StreamOrderedAllocConfig— pool configuration (sizes, thresholds).PoolAttribute/PoolUsageStats— attribute queries and statistics.PoolExportDescriptor/ShareableHandleType— IPC sharing metadata.stream_alloc/stream_free— convenience free functions.
§The stream-ordered model
Independently of the GPU driver, every pool carries a faithful CPU
simulation of the stream-ordered allocator (see
stream_ordered_model). Allocations
(alloc_async / alloc_on) and frees
(free_async / free_on) are sequenced per
stream; freed blocks return to the pool once their stream reaches the free
point and are then reused by a later same-or-larger request. This makes
the allocator’s semantics — visibility ordering, block reuse, and
reserved-vs-used accounting — observable on a plain CPU, with no GPU
required.
§Platform behaviour
On platforms with a real CUDA driver (Linux, Windows),
StreamMemoryPool::new additionally creates a driver-side pool via
cuMemPoolCreate. The lower-level cuMem*Async bindings remain available
for real-GPU use. StreamMemoryPool::cpu_pool builds a pool backed only
by the CPU model, so the full stream-ordered API can be exercised without a
driver on any platform.
§Example
use oxicuda_driver::stream_ordered_alloc::*;
use oxicuda_driver::StreamOrderId;
// A pool backed by the faithful CPU model — no GPU driver required.
let config = StreamOrderedAllocConfig::default_for_device(0);
let mut pool = StreamMemoryPool::cpu_pool(config)?;
// A genuine stream-ordering identity. In a GPU program this is derived
// from a real `Stream` via `StreamMemoryPool::stream_id`; the model
// sequences this token exactly like a real stream would.
let stream = StreamOrderId::from(1);
let mut alloc = pool.alloc_on(1024, stream)?;
assert_eq!(alloc.size(), 1024);
assert!(!alloc.is_freed());
pool.free_on(&mut alloc, stream)?;
assert!(alloc.is_freed());Structs§
- Pool
Export Descriptor - Descriptor for exporting a pool for IPC sharing.
- Pool
Usage Stats - Snapshot of pool memory usage.
- Stream
Allocation - Handle to a stream-ordered memory allocation.
- Stream
Memory Pool - A memory pool for stream-ordered allocations.
- Stream
Ordered Alloc Config - Configuration for a stream-ordered memory pool.
Enums§
- Pool
Attribute - Attributes that can be queried or set on a
StreamMemoryPool. - Shareable
Handle Type - Handle type used for IPC sharing of memory pools.
Constants§
- CU_
MEMPOOL_ ATTR_ RELEASE_ THRESHOLD - Release threshold in bytes (memory returned to OS when usage drops below).
- CU_
MEMPOOL_ ATTR_ RESERVED_ MEM_ CURRENT - Current reserved memory (bytes) — read-only.
- CU_
MEMPOOL_ ATTR_ RESERVED_ MEM_ HIGH - High-water mark of reserved memory (bytes) — resettable.
- CU_
MEMPOOL_ ATTR_ REUSE_ ALLOW_ INTERNAL_ DEPENDENCIES - Pool reuse policy: allow internal dependency insertion.
- CU_
MEMPOOL_ ATTR_ REUSE_ ALLOW_ OPPORTUNISTIC - Pool reuse policy: allow opportunistic reuse.
- CU_
MEMPOOL_ ATTR_ REUSE_ FOLLOW_ EVENT_ DEPENDENCIES - Pool reuse policy: follow event dependencies.
- CU_
MEMPOOL_ ATTR_ USED_ MEM_ CURRENT - Current used memory (bytes) — read-only.
- CU_
MEMPOOL_ ATTR_ USED_ MEM_ HIGH - High-water mark of used memory (bytes) — resettable.
Functions§
- stream_
alloc - Allocate memory on a stream using the default pool for device 0.
- stream_
free - Free a stream-ordered allocation.