Table of Contents

Class UnifiedMemoryService

Namespace
DotCompute.Runtime.Services
Assembly
DotCompute.Runtime.dll

Production unified memory service that provides cross-device memory management and coherency.

public sealed class UnifiedMemoryService : IUnifiedMemoryService, IDisposable
Inheritance
UnifiedMemoryService
Implements
Inherited Members
Extension Methods

Constructors

UnifiedMemoryService(ILogger<UnifiedMemoryService>, MemoryPoolService?)

Initializes a new instance of the UnifiedMemoryService class.

public UnifiedMemoryService(ILogger<UnifiedMemoryService> logger, MemoryPoolService? poolService = null)

Parameters

logger ILogger<UnifiedMemoryService>

The logger.

poolService MemoryPoolService

The pool service.

Properties

Statistics

Gets statistics about unified memory usage.

public UnifiedMemoryStatistics Statistics { get; }

Property Value

UnifiedMemoryStatistics

Methods

AllocateUnifiedAsync(long, params string[])

Allocates unified memory that can be accessed by multiple accelerators

public Task<IUnifiedMemoryBuffer> AllocateUnifiedAsync(long sizeInBytes, params string[] acceleratorIds)

Parameters

sizeInBytes long

The size in bytes

acceleratorIds string[]

The accelerator IDs that will access this memory

Returns

Task<IUnifiedMemoryBuffer>

The allocated unified memory buffer

Dispose()

Performs dispose.

public void Dispose()

EnsureCoherencyAsync(IUnifiedMemoryBuffer, CancellationToken)

Ensures data coherency across all registered devices for a buffer.

public ValueTask EnsureCoherencyAsync(IUnifiedMemoryBuffer buffer, CancellationToken cancellationToken = default)

Parameters

buffer IUnifiedMemoryBuffer

The buffer to synchronize.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

GetCoherenceStatus(IUnifiedMemoryBuffer)

Gets memory coherence status for a buffer

public MemoryCoherenceStatus GetCoherenceStatus(IUnifiedMemoryBuffer buffer)

Parameters

buffer IUnifiedMemoryBuffer

The memory buffer

Returns

MemoryCoherenceStatus

The coherence status

MigrateAsync(IUnifiedMemoryBuffer, string, string)

Migrates data between accelerators

public Task MigrateAsync(IUnifiedMemoryBuffer buffer, string sourceAcceleratorId, string targetAcceleratorId)

Parameters

buffer IUnifiedMemoryBuffer

The memory buffer to migrate

sourceAcceleratorId string

The source accelerator ID

targetAcceleratorId string

The target accelerator ID

Returns

Task

A task representing the migration operation

ReleaseAsync(IUnifiedMemoryBuffer, CancellationToken)

Releases a unified memory buffer.

public ValueTask ReleaseAsync(IUnifiedMemoryBuffer buffer, CancellationToken cancellationToken = default)

Parameters

buffer IUnifiedMemoryBuffer

The buffer to release.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

SynchronizeCoherenceAsync(IUnifiedMemoryBuffer, params string[])

Synchronizes memory coherence across accelerators

public Task SynchronizeCoherenceAsync(IUnifiedMemoryBuffer buffer, params string[] acceleratorIds)

Parameters

buffer IUnifiedMemoryBuffer

The memory buffer to synchronize

acceleratorIds string[]

The accelerator IDs to synchronize

Returns

Task

A task representing the synchronization operation

TransferAsync(IUnifiedMemoryBuffer, IUnifiedMemoryBuffer, CancellationToken)

Transfers data between devices asynchronously.

public ValueTask TransferAsync(IUnifiedMemoryBuffer sourceBuffer, IUnifiedMemoryBuffer targetBuffer, CancellationToken cancellationToken = default)

Parameters

sourceBuffer IUnifiedMemoryBuffer

Source buffer.

targetBuffer IUnifiedMemoryBuffer

Target buffer.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask