Class DefaultCpuMemoryManager
- Namespace
- DotCompute.Core.Memory
- Assembly
- DotCompute.Core.dll
Default, backend-agnostic CPU memory manager that extends BaseMemoryManager.
public class DefaultCpuMemoryManager : BaseMemoryManager, IUnifiedMemoryManager, IAsyncDisposable, IDisposable
- Inheritance
-
DefaultCpuMemoryManager
- Implements
- Inherited Members
- Extension Methods
Remarks
This is the generic CPU implementation used as a test harness and by consumers that
don't need the NUMA-aware CPU backend (see
DotCompute.Backends.CPU.Accelerators.CpuMemoryManager for the production
NUMA-specialized manager). Both types exist so that the backend's specialized manager
can remain the single public CpuMemoryManager symbol for new code.
Constructors
DefaultCpuMemoryManager(IAccelerator, ILogger<DefaultCpuMemoryManager>)
Default, backend-agnostic CPU memory manager that extends BaseMemoryManager.
public DefaultCpuMemoryManager(IAccelerator accelerator, ILogger<DefaultCpuMemoryManager> logger)
Parameters
acceleratorIAcceleratorloggerILogger<DefaultCpuMemoryManager>
Remarks
This is the generic CPU implementation used as a test harness and by consumers that
don't need the NUMA-aware CPU backend (see
DotCompute.Backends.CPU.Accelerators.CpuMemoryManager for the production
NUMA-specialized manager). Both types exist so that the backend's specialized manager
can remain the single public CpuMemoryManager symbol for new code.
Properties
Accelerator
Gets the accelerator this memory manager is associated with.
public override IAccelerator Accelerator { get; }
Property Value
CurrentAllocatedMemory
Gets the current allocated memory in bytes.
public override long CurrentAllocatedMemory { get; }
Property Value
MaxAllocationSize
Gets the maximum memory allocation size in bytes.
public override long MaxAllocationSize { get; }
Property Value
Statistics
Gets memory usage statistics.
public override MemoryStatistics Statistics { get; }
Property Value
TotalAvailableMemory
Gets the total available memory in bytes.
public override long TotalAvailableMemory { get; }
Property Value
Methods
AllocateAndCopyAsync<T>(ReadOnlyMemory<T>, MemoryOptions, CancellationToken)
Allocates memory and copies data from host.
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 data to copy.
optionsMemoryOptionsMemory allocation options.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask<IUnifiedMemoryBuffer<T>>
A newly allocated and initialized memory buffer.
Type Parameters
TThe element type.
AllocateAsync<T>(int, MemoryOptions, CancellationToken)
Allocates a memory buffer for a specific number of elements.
public override ValueTask<IUnifiedMemoryBuffer<T>> AllocateAsync<T>(int count, MemoryOptions options = MemoryOptions.None, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
countintThe number of elements to allocate.
optionsMemoryOptionsMemory allocation options.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask<IUnifiedMemoryBuffer<T>>
A newly allocated memory buffer.
Type Parameters
TThe element type.
AllocateInternalAsync(long, MemoryOptions, CancellationToken)
Allocates memory using backend-specific implementation.
protected override ValueTask<IUnifiedMemoryBuffer> AllocateInternalAsync(long sizeInBytes, MemoryOptions options, CancellationToken cancellationToken)
Parameters
sizeInByteslongoptionsMemoryOptionscancellationTokenCancellationToken
Returns
AllocateRawAsync(long, MemoryOptions, CancellationToken)
Allocates memory by size in bytes (for advanced scenarios).
public override ValueTask<IUnifiedMemoryBuffer> AllocateRawAsync(long sizeInBytes, MemoryOptions options = MemoryOptions.None, CancellationToken cancellationToken = default)
Parameters
sizeInByteslongThe size in bytes to allocate.
optionsMemoryOptionsMemory allocation options.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask<IUnifiedMemoryBuffer>
A newly allocated memory buffer.
Clear()
Clears all allocated memory and resets the manager.
public override void Clear()
CopyAsync<T>(IUnifiedMemoryBuffer<T>, IUnifiedMemoryBuffer<T>, CancellationToken)
Copies data between buffers.
public override ValueTask CopyAsync<T>(IUnifiedMemoryBuffer<T> source, IUnifiedMemoryBuffer<T> destination, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
sourceIUnifiedMemoryBuffer<T>The source buffer.
destinationIUnifiedMemoryBuffer<T>The destination buffer.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask
A task representing the copy operation.
Type Parameters
TThe element type.
CopyAsync<T>(IUnifiedMemoryBuffer<T>, int, IUnifiedMemoryBuffer<T>, int, int, CancellationToken)
Copies data between buffers with specified ranges.
public override ValueTask CopyAsync<T>(IUnifiedMemoryBuffer<T> source, int sourceOffset, IUnifiedMemoryBuffer<T> destination, int destinationOffset, int count, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
sourceIUnifiedMemoryBuffer<T>The source buffer.
sourceOffsetintThe offset in the source buffer.
destinationIUnifiedMemoryBuffer<T>The destination buffer.
destinationOffsetintThe offset in the destination buffer.
countintThe number of elements to copy.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask
A task representing the copy operation.
Type Parameters
TThe element type.
CopyFromDeviceAsync<T>(IUnifiedMemoryBuffer<T>, Memory<T>, CancellationToken)
Copies data from a device buffer to host memory.
public override ValueTask CopyFromDeviceAsync<T>(IUnifiedMemoryBuffer<T> source, Memory<T> destination, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
sourceIUnifiedMemoryBuffer<T>The source buffer.
destinationMemory<T>The destination memory.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask
A task representing the copy operation.
Type Parameters
TThe element type.
CopyToDeviceAsync<T>(ReadOnlyMemory<T>, IUnifiedMemoryBuffer<T>, CancellationToken)
Copies data from host memory to a device buffer.
public override ValueTask CopyToDeviceAsync<T>(ReadOnlyMemory<T> source, IUnifiedMemoryBuffer<T> destination, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
sourceReadOnlyMemory<T>The source data.
destinationIUnifiedMemoryBuffer<T>The destination buffer.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask
A task representing the copy operation.
Type Parameters
TThe element type.
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 view over existing memory.
public override IUnifiedMemoryBuffer<T> CreateView<T>(IUnifiedMemoryBuffer<T> buffer, int offset, int length) where T : unmanaged
Parameters
bufferIUnifiedMemoryBuffer<T>The source buffer.
offsetintThe offset in elements.
lengthintThe length of the view in elements.
Returns
- IUnifiedMemoryBuffer<T>
A view over the existing buffer.
Type Parameters
TThe element type.
FreeAsync(IUnifiedMemoryBuffer, CancellationToken)
Asynchronously frees a memory buffer.
public override ValueTask FreeAsync(IUnifiedMemoryBuffer buffer, CancellationToken cancellationToken = default)
Parameters
bufferIUnifiedMemoryBufferThe buffer to free.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask
A task representing the free operation.
OptimizeAsync(CancellationToken)
Optimizes memory by defragmenting and releasing unused memory.
public override ValueTask OptimizeAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask
A task representing the optimization operation.