Table of Contents

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

logger ILogger<ProductionMemoryManager>

The logger.

accelerator IAccelerator

The 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

source ReadOnlyMemory<T>

The source.

options MemoryOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask<IUnifiedMemoryBuffer<T>>

The result of the operation.

Type Parameters

T

The 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

count int

The number of elements to allocate.

Returns

ValueTask<IUnifiedMemoryBuffer<T>>

A memory buffer for the allocated elements.

Type Parameters

T

The 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

count int

The count.

options MemoryOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask<IUnifiedMemoryBuffer<T>>

The result of the operation.

Type Parameters

T

The T type parameter.

AllocateInternalAsync(long, MemoryOptions, CancellationToken)

Backend-specific buffer allocation implementation.

protected override ValueTask<IUnifiedMemoryBuffer> AllocateInternalAsync(long sizeInBytes, MemoryOptions options, CancellationToken cancellationToken)

Parameters

sizeInBytes long
options MemoryOptions
cancellationToken CancellationToken

Returns

ValueTask<IUnifiedMemoryBuffer>

AllocateRawAsync(long, MemoryOptions, CancellationToken)

Gets allocate raw asynchronously.

public override ValueTask<IUnifiedMemoryBuffer> AllocateRawAsync(long sizeInBytes, MemoryOptions options = MemoryOptions.None, CancellationToken cancellationToken = default)

Parameters

sizeInBytes long

The size in bytes.

options MemoryOptions

The options.

cancellationToken CancellationToken

The 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

source IUnifiedMemoryBuffer<T>

The source.

destination IUnifiedMemoryBuffer<T>

The destination.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

Type Parameters

T

The 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

source IUnifiedMemoryBuffer<T>

The source.

sourceOffset int

The source offset.

destination IUnifiedMemoryBuffer<T>

The destination.

destinationOffset int

The destination offset.

length int

The count.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

Type Parameters

T

The 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

source IUnifiedMemoryBuffer<T>

The source.

destination Memory<T>

The destination.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

Type Parameters

T

The 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

data Memory<T>

The destination data span.

buffer IUnifiedMemoryBuffer

The source buffer.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

A task representing the async operation.

Type Parameters

T

The 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

buffer IUnifiedMemoryBuffer

The destination buffer.

data ReadOnlyMemory<T>

The source data span.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

A task representing the async operation.

Type Parameters

T

The 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

source ReadOnlyMemory<T>

The source.

destination IUnifiedMemoryBuffer<T>

The destination.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

Type Parameters

T

The T type parameter.

CreateView(IUnifiedMemoryBuffer, long, long)

Creates a new view.

public override IUnifiedMemoryBuffer CreateView(IUnifiedMemoryBuffer buffer, long offset, long length)

Parameters

buffer IUnifiedMemoryBuffer

The buffer.

offset long

The offset.

length long

The 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

buffer IUnifiedMemoryBuffer
offset long
length long

Returns

IUnifiedMemoryBuffer

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

buffer IUnifiedMemoryBuffer<T>

The buffer.

offset int

The offset.

length int

The length.

Returns

IUnifiedMemoryBuffer<T>

The created view.

Type Parameters

T

The T type parameter.

Dispose()

Performs dispose.

public void Dispose()

Dispose(bool)

protected override void Dispose(bool disposing)

Parameters

disposing bool

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

buffer IUnifiedMemoryBuffer

The buffer to free.

FreeAsync(IUnifiedMemoryBuffer, CancellationToken)

Gets free asynchronously.

public override ValueTask FreeAsync(IUnifiedMemoryBuffer buffer, CancellationToken cancellationToken = default)

Parameters

buffer IUnifiedMemoryBuffer

The buffer.

cancellationToken CancellationToken

The 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

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.