Class OpenCLMemoryPoolManager
- Namespace
- DotCompute.Backends.OpenCL.Memory
- Assembly
- DotCompute.Backends.OpenCL.dll
Production-grade memory pool manager for OpenCL buffers. Implements three-tier pooling strategy (Small/Medium/Large) with comprehensive statistics tracking.
public sealed class OpenCLMemoryPoolManager : IAsyncDisposable
- Inheritance
-
OpenCLMemoryPoolManager
- Implements
- Inherited Members
Remarks
This pool manager implements a sophisticated buffer pooling system optimized for OpenCL workloads:
- Three-tier pooling: Small (4KB), Medium (64KB), Large (1MB) buffers
- Thread-safe operations using ConcurrentDictionary and Interlocked
- Automatic buffer validation and alignment
- Comprehensive statistics tracking (pool hits, misses, memory usage)
- Memory pressure handling with configurable pool size limits
- Integration with MemoryConfiguration for all settings
Target pool hit rate: >80% for optimal performance. Pool hit rate calculation: PoolHits / (PoolHits + PoolMisses) × 100%
Constructors
OpenCLMemoryPoolManager(OpenCLContext, MemoryConfiguration, ILogger<OpenCLMemoryPoolManager>)
Initializes a new instance of the OpenCLMemoryPoolManager class.
public OpenCLMemoryPoolManager(OpenCLContext context, MemoryConfiguration config, ILogger<OpenCLMemoryPoolManager> logger)
Parameters
contextOpenCLContextThe OpenCL context for buffer creation.
configMemoryConfigurationMemory configuration settings.
loggerILogger<OpenCLMemoryPoolManager>Logger for diagnostic information.
Exceptions
- ArgumentNullException
Thrown when any parameter is null.
Methods
AcquireBufferAsync(ulong, MemoryFlags, CancellationToken)
Acquires a buffer from the pool or allocates a new one.
public ValueTask<OpenCLMemoryPoolManager.PooledBufferHandle> AcquireBufferAsync(ulong size, MemoryFlags flags, CancellationToken cancellationToken = default)
Parameters
sizeulongThe size of the buffer in bytes.
flagsMemoryFlagsMemory flags for buffer creation.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask<OpenCLMemoryPoolManager.PooledBufferHandle>
A handle to the acquired buffer with RAII semantics.
Exceptions
- ObjectDisposedException
Thrown when the pool has been disposed.
- ArgumentOutOfRangeException
Thrown when size is 0.
ClearTierAsync(BufferTier)
Clears a specific tier pool, destroying all buffers.
public ValueTask ClearTierAsync(OpenCLMemoryPoolManager.BufferTier tier)
Parameters
tierOpenCLMemoryPoolManager.BufferTierThe tier to clear.
Returns
DisposeAsync()
Asynchronously disposes the memory pool manager and all pooled buffers.
public ValueTask DisposeAsync()
Returns
GetStatistics()
Gets comprehensive statistics about pool performance.
public OpenCLMemoryPoolManager.PoolStatistics GetStatistics()
Returns
- OpenCLMemoryPoolManager.PoolStatistics
A snapshot of current pool statistics.
ReleaseBufferAsync(OpenCLBuffer)
Releases a buffer back to the pool for reuse.
public ValueTask ReleaseBufferAsync(OpenCLMemoryPoolManager.OpenCLBuffer buffer)
Parameters
bufferOpenCLMemoryPoolManager.OpenCLBufferThe buffer to release.
Returns
Exceptions
- ArgumentNullException
Thrown when buffer is null.