Expand description
Memory-pooled tensor operations
This module demonstrates best practices for using the memory pool in custom tensor operations. It provides utility functions and examples showing how to leverage buffer pooling for better performance.
§Memory Pool Integration Patterns
§Pattern 1: RAII-style Buffer Management
Use the with_pooled_buffer_* helpers to automatically acquire and release buffers:
ⓘ
executor.with_pooled_buffer_f32(&shape, |buffer| {
// Use buffer for computation
// Buffer is automatically released when closure returns
Ok(result)
})§Pattern 2: Manual Buffer Management
For more control, manually acquire and release buffers:
ⓘ
let mut buffer = executor.acquire_f32(&shape);
// ... perform computations with buffer ...
executor.release_f32(&shape, buffer);§Pattern 3: Temporary Intermediate Buffers
Pool temporary buffers for multi-step operations:
ⓘ
// Step 1: Acquire intermediate buffer
let intermediate = executor.acquire_f32(&intermediate_shape);
// Step 2: Compute intermediate result
// ... fill intermediate buffer ...
// Step 3: Use intermediate for final computation
// ... compute final result ...
// Step 4: Release intermediate buffer
executor.release_f32(&intermediate_shape, intermediate);§Performance Considerations
- Pool reuse is most beneficial for operations with matching shapes
- Consider pooling buffers >10KB to amortize lookup overhead
- Use type-specific pools (f32 vs f64) for better locality
- Limit pool size per shape to prevent unbounded memory growth
§Examples
See the individual function documentation for detailed examples.