Class MetalUnifiedMemoryBuffer
- Namespace
- DotCompute.Backends.Metal.Memory
- Assembly
- DotCompute.Backends.Metal.dll
Metal unified memory buffer optimized for Apple Silicon, providing zero-copy access between CPU and GPU on systems with unified memory architecture.
public sealed class MetalUnifiedMemoryBuffer : IUnifiedMemoryBuffer, IAsyncDisposable, IDisposable
- Inheritance
-
MetalUnifiedMemoryBuffer
- Implements
- Inherited Members
- Extension Methods
Constructors
MetalUnifiedMemoryBuffer(long, MemoryOptions, bool)
Initializes a new instance of the MetalUnifiedMemoryBuffer class.
public MetalUnifiedMemoryBuffer(long sizeInBytes, MemoryOptions options, bool isAppleSilicon)
Parameters
sizeInByteslongThe size in bytes.
optionsMemoryOptionsMemory options.
isAppleSiliconboolWhether running on Apple Silicon.
Properties
IsAppleSiliconOptimized
Gets whether this buffer uses Apple Silicon unified memory optimizations.
public bool IsAppleSiliconOptimized { get; }
Property Value
IsDisposed
Gets whether the buffer has been disposed.
public bool IsDisposed { get; }
Property Value
NativeHandle
Gets the native Metal buffer handle.
public nint NativeHandle { get; }
Property Value
Options
Gets the memory allocation options.
public MemoryOptions Options { get; }
Property Value
SizeInBytes
Gets the size of the buffer in bytes.
public long SizeInBytes { get; }
Property Value
State
Gets the current state of the buffer.
public BufferState State { get; }
Property Value
Methods
CopyFromAsync<T>(ReadOnlyMemory<T>, long, CancellationToken)
Copies data from a source memory into this buffer.
public ValueTask CopyFromAsync<T>(ReadOnlyMemory<T> source, long offset = 0, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
sourceReadOnlyMemory<T>The source memory to copy from.
offsetlongThe offset in bytes where to start copying.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask
A task representing the copy operation.
Type Parameters
TThe element type.
CopyFromHostAsync<T>(ReadOnlyMemory<T>, long, CancellationToken)
Legacy support method (calls CopyFromAsync).
public ValueTask CopyFromHostAsync<T>(ReadOnlyMemory<T> source, long offset = 0, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
sourceReadOnlyMemory<T>offsetlongcancellationTokenCancellationToken
Returns
Type Parameters
T
CopyToAsync<T>(Memory<T>, long, CancellationToken)
Copies data from this buffer to a destination memory.
public ValueTask CopyToAsync<T>(Memory<T> destination, long offset = 0, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
destinationMemory<T>The destination memory to copy to.
offsetlongThe offset in bytes where to start copying from.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask
A task representing the copy operation.
Type Parameters
TThe element type.
CopyToHostAsync<T>(Memory<T>, long, CancellationToken)
Legacy support method (calls CopyToAsync).
public ValueTask CopyToHostAsync<T>(Memory<T> destination, long offset = 0, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
destinationMemory<T>offsetlongcancellationTokenCancellationToken
Returns
Type Parameters
T
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
InitializeAsync(CancellationToken)
Initializes the unified memory buffer.
public ValueTask InitializeAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationToken
Returns
PrefetchAsync(long, long, CancellationToken)
Prefetches memory to optimize upcoming operations.
public ValueTask PrefetchAsync(long offset, long length, CancellationToken cancellationToken = default)
Parameters
offsetlonglengthlongcancellationTokenCancellationToken
Returns
SynchronizeAsync(CancellationToken)
Synchronizes memory between CPU and GPU caches (if needed).
public ValueTask SynchronizeAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken