Skip to main content

Module memory_pool

Module memory_pool 

Source
Expand description

Tensor Memory Pool

This module provides two complementary memory pool implementations:

  1. TensorMemoryPool — Slab-based pool with size-class bucketing for efficient allocation of variable-sized tensor buffers.

  2. TensorBlockPool — Pre-allocated fixed-size block pool that reduces allocation overhead by maintaining a reservoir of identically-sized memory blocks with owner tracking, reservation support, and defragmentation.

§Slab Pool (TensorMemoryPool)

Uses four size classes (Small/Medium/Large/Huge) with power-of-two bucket sizes. Best suited when tensor sizes vary widely.

use ipfrs_tensorlogic::memory_pool::{TensorMemoryPool, SizeClass};

let mut pool = TensorMemoryPool::new(64);
let slot_id = pool.allocate(2048, 1).expect("example: should succeed in docs");
assert!(pool.deallocate(slot_id, 2));
let slot_id2 = pool.allocate(1024, 3).expect("example: should succeed in docs");
assert_eq!(slot_id, slot_id2);

§Block Pool (TensorBlockPool)

All blocks share a single configured size. Supports reservation, owner tracking, generation counting, defragmentation, and shrink-to-fit.

use ipfrs_tensorlogic::memory_pool::{TensorBlockPool, PoolConfig};

let config = PoolConfig::default();
let mut pool = TensorBlockPool::new(config);
let id = pool.allocate("matmul").expect("example: should succeed in docs");
assert!(pool.deallocate(id).is_ok());

Structs§

BlockPoolStats
Aggregate statistics for a TensorBlockPool.
MemoryBlock
A single block managed by the TensorBlockPool.
MemoryPoolStats
Aggregate statistics for a TensorMemoryPool.
PoolConfig
Configuration for a TensorBlockPool.
PoolSlot
A single slot managed by the TensorMemoryPool.
TensorBlockPool
Pre-allocated memory pool for tensor operations to reduce allocation overhead.
TensorMemoryPool
A slab-based memory pool that pre-allocates tensor buffers organised into size-class buckets to minimise allocation overhead on hot inference paths.

Enums§

BlockStatus
Status of a single block within a TensorBlockPool.
SizeClass
Categorises a byte count into one of four allocation buckets.