Table of Contents

Interface IMetalCommandExecutor

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

Abstraction for Metal command execution operations. This interface decouples graph execution logic from low-level Metal API calls, enabling testability and potential support for other GPU backends.

public interface IMetalCommandExecutor

Methods

CommitAndWaitAsync(nint, CancellationToken)

Commits a command buffer and waits for completion.

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.

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.

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.

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.

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.

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.

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.

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.

void ReleaseCommandBuffer(nint commandBuffer)

Parameters

commandBuffer nint

The command buffer to release.

SetComputePipelineState(nint, object)

Sets the compute pipeline state for kernel execution.

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.

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

Parameters

encoder nint

The compute encoder.

index int

The argument index.

argument object

The argument value.