Memory Management
Detailed explanation of the memory pool design.
Overview
Mini-ImagePipe uses a two-tier memory pool system:
- Pinned host memory: For fast async transfers
- Device memory: For GPU operations
Best-Fit Allocation
The memory manager uses best-fit allocation to minimize fragmentation:
cpp
void* MemoryManager::allocateDevice(size_t size) {
// Find smallest block that fits
auto best = findBestFit(size);
if (best) {
// Split if much larger than needed
if (best->size > size + SPLIT_THRESHOLD) {
splitBlock(best, size);
}
return best->ptr;
}
// Allocate new block
return allocateNewBlock(size);
}Pool Reuse
Buffers are retained between pipeline executions:
Execution 1: Allocate buffers
Execution 2: Reuse buffers (no allocation)
Execution 3: Reuse buffers (no allocation)
...Configuration
cpp
PipelineConfig config;
config.pinnedPoolSize = 64 * 1024 * 1024; // 64MB
// Device pool behavior is managed internally by MemoryManager.Thread Safety
MemoryManager uses mutex locks for thread-safe pool operations.