Table of Contents

Interface IMemoryManagementPort

Namespace
DotCompute.Abstractions.Ports
Assembly
DotCompute.Abstractions.dll

Port interface for memory management operations. Part of hexagonal architecture - defines the contract that backend adapters must implement.

public interface IMemoryManagementPort

Remarks

This port abstracts memory allocation, transfer, and synchronization from backend-specific implementations. Each backend (CUDA, Metal, OpenCL, CPU) provides an adapter that implements this interface.

Properties

Capabilities

Gets the memory management capabilities of this backend.

MemoryCapabilities Capabilities { get; }

Property Value

MemoryCapabilities

Methods

AllocateAsync<T>(int, BufferAllocationFlags, CancellationToken)

Allocates a buffer of the specified size.

ValueTask<IPortBuffer<T>> AllocateAsync<T>(int length, BufferAllocationFlags flags = BufferAllocationFlags.None, CancellationToken cancellationToken = default) where T : unmanaged

Parameters

length int

Number of elements to allocate.

flags BufferAllocationFlags

Buffer allocation flags.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask<IPortBuffer<T>>

The allocated buffer.

Type Parameters

T

The element type (must be unmanaged).

CopyAsync<T>(IPortBuffer<T>, IPortBuffer<T>, CancellationToken)

Copies data between buffers.

ValueTask CopyAsync<T>(IPortBuffer<T> source, IPortBuffer<T> destination, CancellationToken cancellationToken = default) where T : unmanaged

Parameters

source IPortBuffer<T>

Source buffer.

destination IPortBuffer<T>

Destination buffer.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

Type Parameters

T

The element type.

CopyRangeAsync<T>(IPortBuffer<T>, int, IPortBuffer<T>, int, int, CancellationToken)

Copies a range of data between buffers.

ValueTask CopyRangeAsync<T>(IPortBuffer<T> source, int sourceOffset, IPortBuffer<T> destination, int destinationOffset, int count, CancellationToken cancellationToken = default) where T : unmanaged

Parameters

source IPortBuffer<T>
sourceOffset int
destination IPortBuffer<T>
destinationOffset int
count int
cancellationToken CancellationToken

Returns

ValueTask

Type Parameters

T

GetStatistics()

Gets current memory statistics.

MemoryStatistics GetStatistics()

Returns

MemoryStatistics