Table of Contents

Class MetalCommandExecutor

Namespace
DotCompute.Backends.Metal.Execution
Assembly
DotCompute.Backends.Metal.dll

Production implementation of IMetalCommandExecutor that makes actual Metal native API calls.

public sealed class MetalCommandExecutor : IMetalCommandExecutor
Inheritance
MetalCommandExecutor
Implements
Inherited Members

Constructors

MetalCommandExecutor(ILogger<MetalCommandExecutor>)

public MetalCommandExecutor(ILogger<MetalCommandExecutor> logger)

Parameters

logger ILogger<MetalCommandExecutor>

Methods

CommitAndWaitAsync(nint, CancellationToken)

Commits a command buffer and waits for completion.

public Task CommitAndWaitAsync(nint commandBuffer, CancellationToken cancellationToken = default)

Parameters

commandBuffer nint

The command buffer to commit.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task

A task that completes when the command buffer finishes execution.

CopyBuffer(nint, nint, long, nint, long, long)

Copies data between Metal buffers.

public void CopyBuffer(nint encoder, nint sourceBuffer, long sourceOffset, nint destBuffer, long destOffset, long size)

Parameters

encoder nint

The blit encoder.

sourceBuffer nint

Source buffer handle.

sourceOffset long

Offset in source buffer.

destBuffer nint

Destination buffer handle.

destOffset long

Offset in destination buffer.

size long

Number of bytes to copy.

CreateBlitCommandEncoder(nint)

Creates a blit command encoder for memory operations.

public nint CreateBlitCommandEncoder(nint commandBuffer)

Parameters

commandBuffer nint

The command buffer.

Returns

nint

Handle to the created blit encoder.

CreateCommandBuffer(nint)

Creates a Metal command buffer from the command queue.

public nint CreateCommandBuffer(nint commandQueue)

Parameters

commandQueue nint

The Metal command queue.

Returns

nint

Handle to the created command buffer.

CreateComputeCommandEncoder(nint)

Creates a compute command encoder for kernel execution.

public nint CreateComputeCommandEncoder(nint commandBuffer)

Parameters

commandBuffer nint

The command buffer.

Returns

nint

Handle to the created compute encoder.

DispatchThreadgroups(nint, MTLSize, MTLSize)

Dispatches compute threadgroups for kernel execution.

public void DispatchThreadgroups(nint encoder, MTLSize threadgroupsPerGrid, MTLSize threadsPerThreadgroup)

Parameters

encoder nint

The compute encoder.

threadgroupsPerGrid MTLSize

Number of threadgroups per grid.

threadsPerThreadgroup MTLSize

Number of threads per threadgroup.

EndEncoding(nint)

Ends command encoding.

public void EndEncoding(nint encoder)

Parameters

encoder nint

The encoder to end.

FillBuffer(nint, nint, byte, long)

Fills a Metal buffer with a specific byte value.

public void FillBuffer(nint encoder, nint buffer, byte value, long size)

Parameters

encoder nint

The blit encoder.

buffer nint

Buffer handle.

value byte

Fill value.

size long

Number of bytes to fill.

ReleaseCommandBuffer(nint)

Releases a command buffer and its resources.

public void ReleaseCommandBuffer(nint commandBuffer)

Parameters

commandBuffer nint

The command buffer to release.

SetComputePipelineState(nint, object)

Sets the compute pipeline state for kernel execution.

public void SetComputePipelineState(nint encoder, object kernel)

Parameters

encoder nint

The compute encoder.

kernel object

The kernel to execute.

SetKernelArgument(nint, int, object)

Sets a kernel argument at the specified index.

public void SetKernelArgument(nint encoder, int index, object argument)

Parameters

encoder nint

The compute encoder.

index int

The argument index.

argument object

The argument value.