Interface IUnifiedMemoryManager
- Namespace
- DotCompute.Abstractions
- Assembly
- DotCompute.Abstractions.dll
Unified memory manager interface that replaces all duplicate memory management interfaces. This is the ONLY memory manager interface in the entire solution.
public interface IUnifiedMemoryManager : IAsyncDisposable, IDisposable
- Inherited Members
- Extension Methods
Properties
Accelerator
Gets the accelerator this memory manager is associated with.
IAccelerator Accelerator { get; }
Property Value
CurrentAllocatedMemory
Gets the current allocated memory in bytes.
long CurrentAllocatedMemory { get; }
Property Value
MaxAllocationSize
Gets the maximum memory allocation size in bytes.
long MaxAllocationSize { get; }
Property Value
Statistics
Gets memory usage statistics.
MemoryStatistics Statistics { get; }
Property Value
TotalAvailableMemory
Gets the total available memory in bytes.
long TotalAvailableMemory { get; }
Property Value
Methods
AllocateAndCopyAsync<T>(ReadOnlyMemory<T>, MemoryOptions, CancellationToken)
Allocates memory and copies data from host.
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.
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.
AllocateDevice(long)
Allocates device-specific memory.
DeviceMemory AllocateDevice(long sizeInBytes)
Parameters
sizeInByteslongSize in bytes to allocate.
Returns
- DeviceMemory
Device memory handle.
AllocateRawAsync(long, MemoryOptions, CancellationToken)
Allocates memory by size in bytes (for advanced scenarios).
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.
void Clear()
CopyAsync<T>(IUnifiedMemoryBuffer<T>, IUnifiedMemoryBuffer<T>, CancellationToken)
Copies data between buffers.
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.
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.
CopyDeviceToDevice(DeviceMemory, DeviceMemory, long)
Copies data between device memories.
void CopyDeviceToDevice(DeviceMemory sourceDevice, DeviceMemory destinationDevice, long sizeInBytes)
Parameters
sourceDeviceDeviceMemorySource device memory.
destinationDeviceDeviceMemoryDestination device memory.
sizeInByteslongSize in bytes.
CopyDeviceToHost(DeviceMemory, nint, long)
Copies data from device to host memory.
void CopyDeviceToHost(DeviceMemory deviceMemory, nint hostPointer, long sizeInBytes)
Parameters
deviceMemoryDeviceMemoryDevice memory.
hostPointernintHost memory pointer.
sizeInByteslongSize in bytes.
CopyDeviceToHostAsync(DeviceMemory, nint, long, CancellationToken)
Asynchronously copies data from device to host memory.
ValueTask CopyDeviceToHostAsync(DeviceMemory deviceMemory, nint hostPointer, long sizeInBytes, CancellationToken cancellationToken = default)
Parameters
deviceMemoryDeviceMemoryDevice memory.
hostPointernintHost memory pointer.
sizeInByteslongSize in bytes.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask
A task representing the operation.
CopyFromDeviceAsync<T>(IUnifiedMemoryBuffer<T>, Memory<T>, CancellationToken)
Copies data from a device buffer to host memory.
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.
CopyHostToDevice(nint, DeviceMemory, long)
Copies data from host to device memory.
void CopyHostToDevice(nint hostPointer, DeviceMemory deviceMemory, long sizeInBytes)
Parameters
hostPointernintHost memory pointer.
deviceMemoryDeviceMemoryDevice memory.
sizeInByteslongSize in bytes.
CopyHostToDeviceAsync(nint, DeviceMemory, long, CancellationToken)
Asynchronously copies data from host to device memory.
ValueTask CopyHostToDeviceAsync(nint hostPointer, DeviceMemory deviceMemory, long sizeInBytes, CancellationToken cancellationToken = default)
Parameters
hostPointernintHost memory pointer.
deviceMemoryDeviceMemoryDevice memory.
sizeInByteslongSize in bytes.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask
A task representing the operation.
CopyToDeviceAsync<T>(ReadOnlyMemory<T>, IUnifiedMemoryBuffer<T>, CancellationToken)
Copies data from host memory to a device buffer.
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.
CreateView<T>(IUnifiedMemoryBuffer<T>, int, int)
Creates a view over existing memory.
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.
Free(IUnifiedMemoryBuffer)
Frees a memory buffer.
void Free(IUnifiedMemoryBuffer buffer)
Parameters
bufferIUnifiedMemoryBufferThe buffer to free.
FreeAsync(IUnifiedMemoryBuffer, CancellationToken)
Asynchronously frees a memory buffer.
ValueTask FreeAsync(IUnifiedMemoryBuffer buffer, CancellationToken cancellationToken = default)
Parameters
bufferIUnifiedMemoryBufferThe buffer to free.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask
A task representing the free operation.
FreeDevice(DeviceMemory)
Frees device-specific memory.
void FreeDevice(DeviceMemory deviceMemory)
Parameters
deviceMemoryDeviceMemoryDevice memory to free.
MemsetDevice(DeviceMemory, byte, long)
Sets device memory to a specific value.
void MemsetDevice(DeviceMemory deviceMemory, byte value, long sizeInBytes)
Parameters
deviceMemoryDeviceMemoryDevice memory to set.
valuebyteValue to set.
sizeInByteslongSize in bytes.
MemsetDeviceAsync(DeviceMemory, byte, long, CancellationToken)
Asynchronously sets device memory to a specific value.
ValueTask MemsetDeviceAsync(DeviceMemory deviceMemory, byte value, long sizeInBytes, CancellationToken cancellationToken = default)
Parameters
deviceMemoryDeviceMemoryDevice memory to set.
valuebyteValue to set.
sizeInByteslongSize in bytes.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask
A task representing the operation.
OptimizeAsync(CancellationToken)
Optimizes memory by defragmenting and releasing unused memory.
ValueTask OptimizeAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask
A task representing the optimization operation.