Table of Contents

Class MetalKernelCompiler

Namespace
DotCompute.Backends.Metal.Kernels
Assembly
DotCompute.Backends.Metal.dll

Compiles kernels to Metal Shading Language and creates compute pipeline states.

public sealed class MetalKernelCompiler : IUnifiedKernelCompiler, IUnifiedKernelCompiler<KernelDefinition, ICompiledKernel>, IDisposable
Inheritance
MetalKernelCompiler
Implements
Inherited Members
Extension Methods

Constructors

MetalKernelCompiler(nint, nint, ILogger, MetalCommandBufferPool?, MetalKernelCache?)

public MetalKernelCompiler(nint device, nint commandQueue, ILogger logger, MetalCommandBufferPool? commandBufferPool = null, MetalKernelCache? kernelCache = null)

Parameters

device nint
commandQueue nint
logger ILogger
commandBufferPool MetalCommandBufferPool
kernelCache MetalKernelCache

Properties

Capabilities

Gets compiler capabilities as a dictionary of feature flags.

public IReadOnlyDictionary<string, object> Capabilities { get; }

Property Value

IReadOnlyDictionary<string, object>

Name

Gets the name of the compiler.

public string Name { get; }

Property Value

string

SupportedSourceTypes

Gets the supported source types this compiler can handle.

public IReadOnlyList<KernelLanguage> SupportedSourceTypes { get; }

Property Value

IReadOnlyList<KernelLanguage>

Methods

BatchCompileAsync(IEnumerable<KernelDefinition>, IAccelerator, CancellationToken)

Performs batch compilation of multiple kernels for optimization. This method provides backward compatibility with legacy IKernelCompiler interface.

public Task<IDictionary<string, ICompiledKernel>> BatchCompileAsync(IEnumerable<KernelDefinition> kernelDefinitions, IAccelerator accelerator, CancellationToken cancellationToken = default)

Parameters

kernelDefinitions IEnumerable<KernelDefinition>

The kernel definitions to compile

accelerator IAccelerator

The target accelerator

cancellationToken CancellationToken

Optional cancellation token

Returns

Task<IDictionary<string, ICompiledKernel>>

Dictionary mapping kernel names to compiled kernels

CanCompileAsync(KernelDefinition, IAccelerator)

Validates whether a kernel can be compiled for the specified accelerator. This method provides backward compatibility with legacy IKernelCompiler interface.

public Task<bool> CanCompileAsync(KernelDefinition kernelDefinition, IAccelerator accelerator)

Parameters

kernelDefinition KernelDefinition

The kernel definition to validate

accelerator IAccelerator

The target accelerator

Returns

Task<bool>

True if the kernel can be compiled, false otherwise

CompileAsync(KernelDefinition, CompilationOptions?, CancellationToken)

Compiles a kernel source to executable form.

public ValueTask<ICompiledKernel> CompileAsync(KernelDefinition definition, CompilationOptions? options = null, CancellationToken cancellationToken = default)

Parameters

definition KernelDefinition
options CompilationOptions

Optional compilation options.

cancellationToken CancellationToken

Token to cancel the compilation.

Returns

ValueTask<ICompiledKernel>

A task that represents the asynchronous compilation operation.

CompileAsync(KernelDefinition, IAccelerator, CancellationToken)

Compiles a kernel definition for the specified accelerator. This method provides backward compatibility with legacy IKernelCompiler interface.

public Task<ICompiledKernel> CompileAsync(KernelDefinition kernelDefinition, IAccelerator accelerator, CancellationToken cancellationToken = default)

Parameters

kernelDefinition KernelDefinition

The kernel definition to compile

accelerator IAccelerator

The target accelerator

cancellationToken CancellationToken

Optional cancellation token

Returns

Task<ICompiledKernel>

The compiled kernel ready for execution

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GetSupportedOptions(IAccelerator)

Gets the supported compilation options for the accelerator. This method provides backward compatibility with legacy IKernelCompiler interface.

public CompilationOptions GetSupportedOptions(IAccelerator accelerator)

Parameters

accelerator IAccelerator

The target accelerator

Returns

CompilationOptions

The supported compilation options

OptimizeAsync(ICompiledKernel, OptimizationLevel, CancellationToken)

Optimizes an already compiled kernel for better performance.

public ValueTask<ICompiledKernel> OptimizeAsync(ICompiledKernel kernel, OptimizationLevel level, CancellationToken cancellationToken = default)

Parameters

kernel ICompiledKernel

The compiled kernel to optimize.

level OptimizationLevel

The optimization level to apply.

cancellationToken CancellationToken

Token to cancel the optimization.

Returns

ValueTask<ICompiledKernel>

A task that represents the asynchronous optimization operation.

Validate(KernelDefinition)

Validates a kernel source without compiling.

public UnifiedValidationResult Validate(KernelDefinition definition)

Parameters

definition KernelDefinition

Returns

UnifiedValidationResult

A validation result indicating whether compilation is possible.

ValidateAsync(KernelDefinition, CancellationToken)

Asynchronously validates a kernel source with detailed analysis.

public ValueTask<UnifiedValidationResult> ValidateAsync(KernelDefinition kernel, CancellationToken cancellationToken = default)

Parameters

kernel KernelDefinition
cancellationToken CancellationToken

Token to cancel the validation operation.

Returns

ValueTask<UnifiedValidationResult>

A task that represents the asynchronous validation operation.