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
loggerILogger<UnifiedMemoryService>The logger.
poolServiceMemoryPoolServiceThe pool service.
Properties
Statistics
Gets statistics about unified memory usage.
public UnifiedMemoryStatistics Statistics { get; }
Property Value
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
sizeInByteslongThe size in bytes
acceleratorIdsstring[]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
bufferIUnifiedMemoryBufferThe buffer to synchronize.
cancellationTokenCancellationTokenCancellation token.
Returns
GetCoherenceStatus(IUnifiedMemoryBuffer)
Gets memory coherence status for a buffer
public MemoryCoherenceStatus GetCoherenceStatus(IUnifiedMemoryBuffer buffer)
Parameters
bufferIUnifiedMemoryBufferThe 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
bufferIUnifiedMemoryBufferThe memory buffer to migrate
sourceAcceleratorIdstringThe source accelerator ID
targetAcceleratorIdstringThe 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
bufferIUnifiedMemoryBufferThe buffer to release.
cancellationTokenCancellationTokenCancellation token.
Returns
SynchronizeCoherenceAsync(IUnifiedMemoryBuffer, params string[])
Synchronizes memory coherence across accelerators
public Task SynchronizeCoherenceAsync(IUnifiedMemoryBuffer buffer, params string[] acceleratorIds)
Parameters
bufferIUnifiedMemoryBufferThe memory buffer to synchronize
acceleratorIdsstring[]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
sourceBufferIUnifiedMemoryBufferSource buffer.
targetBufferIUnifiedMemoryBufferTarget buffer.
cancellationTokenCancellationTokenCancellation token.