Class ProductionMemoryManager
- Namespace
- DotCompute.Runtime.Services.Memory
- Assembly
- DotCompute.Runtime.dll
Production memory manager implementation with advanced memory pool management, P2P transfers, and comprehensive error handling for accelerated computing workloads.
public sealed class ProductionMemoryManager : BaseMemoryManager, IUnifiedMemoryManager, IAsyncDisposable, IDisposable
- Inheritance
-
ProductionMemoryManager
- Implements
- Inherited Members
- Extension Methods
Constructors
ProductionMemoryManager(ILogger<ProductionMemoryManager>, IAccelerator?)
Initializes a new instance of the ProductionMemoryManager class.
public ProductionMemoryManager(ILogger<ProductionMemoryManager> logger, IAccelerator? accelerator = null)
Parameters
loggerILogger<ProductionMemoryManager>The logger.
acceleratorIAcceleratorThe accelerator.
Properties
Accelerator
Gets or sets the accelerator.
public override IAccelerator Accelerator { get; }
Property Value
- IAccelerator
The accelerator.
CurrentAllocatedMemory
Gets or sets the current allocated memory.
public override long CurrentAllocatedMemory { get; }
Property Value
- long
The current allocated memory.
MaxAllocationSize
Gets or sets the max allocation size.
public override long MaxAllocationSize { get; }
Property Value
- long
The max allocation size.
Statistics
Gets or sets the statistics.
public override MemoryStatistics Statistics { get; }
Property Value
- MemoryStatistics
The statistics.
TotalAvailableMemory
Gets or sets the total available memory.
public override long TotalAvailableMemory { get; }
Property Value
- long
The total available memory.
Methods
AllocateAndCopyAsync<T>(ReadOnlyMemory<T>, MemoryOptions, CancellationToken)
Gets allocate and copy asynchronously.
public override ValueTask<IUnifiedMemoryBuffer<T>> AllocateAndCopyAsync<T>(ReadOnlyMemory<T> source, MemoryOptions options = MemoryOptions.None, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
sourceReadOnlyMemory<T>The source.
optionsMemoryOptionsThe options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask<IUnifiedMemoryBuffer<T>>
The result of the operation.
Type Parameters
TThe T type parameter.
AllocateAsync<T>(int)
Allocates memory for a specific number of elements.
public override ValueTask<IUnifiedMemoryBuffer<T>> AllocateAsync<T>(int count) where T : unmanaged
Parameters
countintThe number of elements to allocate.
Returns
- ValueTask<IUnifiedMemoryBuffer<T>>
A memory buffer for the allocated elements.
Type Parameters
TThe element type.
AllocateAsync<T>(int, MemoryOptions, CancellationToken)
Gets allocate asynchronously.
public override ValueTask<IUnifiedMemoryBuffer<T>> AllocateAsync<T>(int count, MemoryOptions options = MemoryOptions.None, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
countintThe count.
optionsMemoryOptionsThe options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask<IUnifiedMemoryBuffer<T>>
The result of the operation.
Type Parameters
TThe T type parameter.
AllocateInternalAsync(long, MemoryOptions, CancellationToken)
Backend-specific buffer allocation implementation.
protected override ValueTask<IUnifiedMemoryBuffer> AllocateInternalAsync(long sizeInBytes, MemoryOptions options, CancellationToken cancellationToken)
Parameters
sizeInByteslongoptionsMemoryOptionscancellationTokenCancellationToken
Returns
AllocateRawAsync(long, MemoryOptions, CancellationToken)
Gets allocate raw asynchronously.
public override ValueTask<IUnifiedMemoryBuffer> AllocateRawAsync(long sizeInBytes, MemoryOptions options = MemoryOptions.None, CancellationToken cancellationToken = default)
Parameters
sizeInByteslongThe size in bytes.
optionsMemoryOptionsThe options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask<IUnifiedMemoryBuffer>
The result of the operation.
Clear()
Performs clear.
public override void Clear()
CopyAsync<T>(IUnifiedMemoryBuffer<T>, IUnifiedMemoryBuffer<T>, CancellationToken)
Gets copy asynchronously.
public override ValueTask CopyAsync<T>(IUnifiedMemoryBuffer<T> source, IUnifiedMemoryBuffer<T> destination, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
sourceIUnifiedMemoryBuffer<T>The source.
destinationIUnifiedMemoryBuffer<T>The destination.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask
The result of the operation.
Type Parameters
TThe T type parameter.
CopyAsync<T>(IUnifiedMemoryBuffer<T>, int, IUnifiedMemoryBuffer<T>, int, int, CancellationToken)
Gets copy asynchronously.
public override ValueTask CopyAsync<T>(IUnifiedMemoryBuffer<T> source, int sourceOffset, IUnifiedMemoryBuffer<T> destination, int destinationOffset, int length, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
sourceIUnifiedMemoryBuffer<T>The source.
sourceOffsetintThe source offset.
destinationIUnifiedMemoryBuffer<T>The destination.
destinationOffsetintThe destination offset.
lengthintThe count.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask
The result of the operation.
Type Parameters
TThe T type parameter.
CopyFromDeviceAsync<T>(IUnifiedMemoryBuffer<T>, Memory<T>, CancellationToken)
Gets copy from device asynchronously.
public override ValueTask CopyFromDeviceAsync<T>(IUnifiedMemoryBuffer<T> source, Memory<T> destination, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
sourceIUnifiedMemoryBuffer<T>The source.
destinationMemory<T>The destination.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask
The result of the operation.
Type Parameters
TThe T type parameter.
CopyFromDeviceAsync<T>(Memory<T>, IUnifiedMemoryBuffer, CancellationToken)
Copies data from a device buffer to host memory.
public Task CopyFromDeviceAsync<T>(Memory<T> data, IUnifiedMemoryBuffer buffer, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
dataMemory<T>The destination data span.
bufferIUnifiedMemoryBufferThe source buffer.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
A task representing the async operation.
Type Parameters
TThe element type.
CopyToDeviceAsync<T>(IUnifiedMemoryBuffer, ReadOnlyMemory<T>, CancellationToken)
Copies data from host memory to a device buffer.
public Task CopyToDeviceAsync<T>(IUnifiedMemoryBuffer buffer, ReadOnlyMemory<T> data, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
bufferIUnifiedMemoryBufferThe destination buffer.
dataReadOnlyMemory<T>The source data span.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
A task representing the async operation.
Type Parameters
TThe element type.
CopyToDeviceAsync<T>(ReadOnlyMemory<T>, IUnifiedMemoryBuffer<T>, CancellationToken)
Gets copy to device asynchronously.
public override ValueTask CopyToDeviceAsync<T>(ReadOnlyMemory<T> source, IUnifiedMemoryBuffer<T> destination, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
sourceReadOnlyMemory<T>The source.
destinationIUnifiedMemoryBuffer<T>The destination.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask
The result of the operation.
Type Parameters
TThe T type parameter.
CreateView(IUnifiedMemoryBuffer, long, long)
Creates a new view.
public override IUnifiedMemoryBuffer CreateView(IUnifiedMemoryBuffer buffer, long offset, long length)
Parameters
bufferIUnifiedMemoryBufferThe buffer.
offsetlongThe offset.
lengthlongThe length.
Returns
- IUnifiedMemoryBuffer
The created view.
CreateViewCore(IUnifiedMemoryBuffer, long, long)
Backend-specific view creation implementation.
protected override IUnifiedMemoryBuffer CreateViewCore(IUnifiedMemoryBuffer buffer, long offset, long length)
Parameters
bufferIUnifiedMemoryBufferoffsetlonglengthlong
Returns
CreateView<T>(IUnifiedMemoryBuffer<T>, int, int)
Creates a new view.
public override IUnifiedMemoryBuffer<T> CreateView<T>(IUnifiedMemoryBuffer<T> buffer, int offset, int length) where T : unmanaged
Parameters
bufferIUnifiedMemoryBuffer<T>The buffer.
offsetintThe offset.
lengthintThe length.
Returns
- IUnifiedMemoryBuffer<T>
The created view.
Type Parameters
TThe T type parameter.
Dispose()
Performs dispose.
public void Dispose()
Dispose(bool)
protected override void Dispose(bool disposing)
Parameters
disposingbool
DisposeAsync()
Gets dispose asynchronously.
public override ValueTask DisposeAsync()
Returns
- ValueTask
The result of the operation.
Free(IUnifiedMemoryBuffer)
Frees a memory buffer.
public override void Free(IUnifiedMemoryBuffer buffer)
Parameters
bufferIUnifiedMemoryBufferThe buffer to free.
FreeAsync(IUnifiedMemoryBuffer, CancellationToken)
Gets free asynchronously.
public override ValueTask FreeAsync(IUnifiedMemoryBuffer buffer, CancellationToken cancellationToken = default)
Parameters
bufferIUnifiedMemoryBufferThe buffer.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask
The result of the operation.
GetStatistics()
Gets the statistics.
public MemoryStatistics GetStatistics()
Returns
- MemoryStatistics
The statistics.
OptimizeAsync(CancellationToken)
Gets optimize asynchronously.
public override ValueTask OptimizeAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask
The result of the operation.