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
devicenintcommandQueuenintloggerILoggercommandBufferPoolMetalCommandBufferPoolkernelCacheMetalKernelCache
Properties
Capabilities
Gets compiler capabilities as a dictionary of feature flags.
public IReadOnlyDictionary<string, object> Capabilities { get; }
Property Value
Name
Gets the name of the compiler.
public string Name { get; }
Property Value
SupportedSourceTypes
Gets the supported source types this compiler can handle.
public IReadOnlyList<KernelLanguage> SupportedSourceTypes { get; }
Property Value
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
kernelDefinitionsIEnumerable<KernelDefinition>The kernel definitions to compile
acceleratorIAcceleratorThe target accelerator
cancellationTokenCancellationTokenOptional 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
kernelDefinitionKernelDefinitionThe kernel definition to validate
acceleratorIAcceleratorThe target accelerator
Returns
CompileAsync(KernelDefinition, CompilationOptions?, CancellationToken)
Compiles a kernel source to executable form.
public ValueTask<ICompiledKernel> CompileAsync(KernelDefinition definition, CompilationOptions? options = null, CancellationToken cancellationToken = default)
Parameters
definitionKernelDefinitionoptionsCompilationOptionsOptional compilation options.
cancellationTokenCancellationTokenToken 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
kernelDefinitionKernelDefinitionThe kernel definition to compile
acceleratorIAcceleratorThe target accelerator
cancellationTokenCancellationTokenOptional 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
acceleratorIAcceleratorThe 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
kernelICompiledKernelThe compiled kernel to optimize.
levelOptimizationLevelThe optimization level to apply.
cancellationTokenCancellationTokenToken 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
definitionKernelDefinition
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
kernelKernelDefinitioncancellationTokenCancellationTokenToken to cancel the validation operation.
Returns
- ValueTask<UnifiedValidationResult>
A task that represents the asynchronous validation operation.