Class MetalBackend
- Namespace
- DotCompute.Backends.Metal
- Assembly
- DotCompute.Backends.Metal.dll
Main entry point for Metal compute backend
public sealed class MetalBackend : IDisposable, IAsyncDisposable
- Inheritance
-
MetalBackend
- Implements
- Inherited Members
- Extension Methods
Constructors
MetalBackend(ILogger<MetalBackend>, ILoggerFactory)
public MetalBackend(ILogger<MetalBackend> logger, ILoggerFactory loggerFactory)
Parameters
loggerILogger<MetalBackend>loggerFactoryILoggerFactory
Methods
AllocateBufferAsync<T>(int)
Allocate a buffer on the Metal device
public Task<IUnifiedMemoryBuffer> AllocateBufferAsync<T>(int size) where T : unmanaged
Parameters
sizeint
Returns
Type Parameters
T
CompileFunction(string, string)
Compile a Metal function from source code
public nint CompileFunction(string source, string functionName)
Parameters
Returns
CopyFromBufferAsync<T>(IUnifiedMemoryBuffer<T>, T[])
Copy data from a Metal buffer asynchronously
public Task CopyFromBufferAsync<T>(IUnifiedMemoryBuffer<T> buffer, T[] data) where T : unmanaged
Parameters
bufferIUnifiedMemoryBuffer<T>dataT[]
Returns
Type Parameters
T
CopyToBufferAsync<T>(IUnifiedMemoryBuffer<T>, T[])
Copy data to a Metal buffer asynchronously
public Task CopyToBufferAsync<T>(IUnifiedMemoryBuffer<T> buffer, T[] data) where T : unmanaged
Parameters
bufferIUnifiedMemoryBuffer<T>dataT[]
Returns
Type Parameters
T
CreateCommandQueue()
Create a Metal command queue
public nint CreateCommandQueue()
Returns
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
DisposeAsync()
Asynchronously disposes the backend by awaiting each Metal accelerator's DisposeAsync() in sequence.
public ValueTask DisposeAsync()
Returns
Remarks
Prefer this over Dispose() in async hosts: Metal accelerators
hold command queues, buffer pools, and MPS handles whose clean shutdown
involves asynchronous work. Awaiting here avoids the
AsTask().GetAwaiter().GetResult() sync-over-async pattern and
prevents thread-pool starvation during multi-GPU teardown.
ExecuteComputeShaderAsync(nint, params IUnifiedMemoryBuffer[])
Execute a compute shader asynchronously
public Task ExecuteComputeShaderAsync(nint function, params IUnifiedMemoryBuffer[] buffers)
Parameters
functionnintbuffersIUnifiedMemoryBuffer[]
Returns
GetAccelerators()
Get all available Metal accelerators
public IReadOnlyList<MetalAccelerator> GetAccelerators()
Returns
GetDefaultAccelerator()
Get default Metal accelerator
public MetalAccelerator? GetDefaultAccelerator()
Returns
IsAvailable()
Check if Metal is available on this platform
public static bool IsAvailable()