Table of Contents

Class MetalCompiledRingKernel

Namespace
DotCompute.Backends.Metal.Compilation
Assembly
DotCompute.Backends.Metal.dll

Represents a compiled Ring Kernel with Metal library and pipeline state.

public sealed class MetalCompiledRingKernel : CompiledKernel, IDisposable
Inheritance
MetalCompiledRingKernel
Implements
Inherited Members
Extension Methods

Remarks

This class extends CompiledKernel with Ring Kernel-specific metadata including the discovered kernel information, Metal library handle, and compute pipeline state.

Lifecycle:

  1. Created by MetalRingKernelCompiler after successful compilation
  2. Metal library compiled from MSL source
  3. Compute pipeline state created for kernel execution
  4. Library and pipeline released on disposal

Constructors

MetalCompiledRingKernel(DiscoveredMetalRingKernel, nint, nint, nint, string, nint, int, int)

Initializes a new instance of the MetalCompiledRingKernel class.

[SetsRequiredMembers]
public MetalCompiledRingKernel(DiscoveredMetalRingKernel discoveredKernel, nint libraryHandle, nint pipelineStateHandle, nint kernelFunctionHandle, string mslSource, nint metalDevice, int threadExecutionWidth = 32, int maxTotalThreadsPerThreadgroup = 1024)

Parameters

discoveredKernel DiscoveredMetalRingKernel

The discovered kernel metadata.

libraryHandle nint

The Metal library handle.

pipelineStateHandle nint

The compute pipeline state handle.

kernelFunctionHandle nint

The kernel function handle.

mslSource string

The MSL source code.

metalDevice nint

The Metal device.

threadExecutionWidth int

The thread execution width.

maxTotalThreadsPerThreadgroup int

The maximum threads per threadgroup.

Properties

CompilationTimestamp

Gets the compilation timestamp.

public DateTime CompilationTimestamp { get; }

Property Value

DateTime

DiscoveredKernel

Gets the discovered kernel metadata from reflection.

public DiscoveredMetalRingKernel DiscoveredKernel { get; }

Property Value

DiscoveredMetalRingKernel

IsValid

Gets a value indicating whether this kernel is valid for execution.

public bool IsValid { get; }

Property Value

bool

KernelEntryPoint

Gets the kernel entry point name (function name in MSL).

public string KernelEntryPoint { get; }

Property Value

string

KernelFunctionHandle

Gets the kernel function handle from the library.

public nint KernelFunctionHandle { get; }

Property Value

nint

LibraryHandle

Gets the Metal library handle.

public nint LibraryHandle { get; }

Property Value

nint

MaxTotalThreadsPerThreadgroup

Gets the maximum total threads per threadgroup for this kernel.

public int MaxTotalThreadsPerThreadgroup { get; }

Property Value

int

MetalDevice

Gets the Metal device this kernel was compiled for.

public nint MetalDevice { get; }

Property Value

nint

MslSource

Gets the MSL source code.

public string MslSource { get; }

Property Value

string

PipelineStateHandle

Gets the compute pipeline state handle for kernel execution.

public nint PipelineStateHandle { get; }

Property Value

nint

ThreadExecutionWidth

Gets the thread execution width (SIMD size) for this kernel.

public int ThreadExecutionWidth { get; }

Property Value

int

Remarks

On Apple Silicon, this is typically 32 threads.

Methods

Dispose(bool)

Releases the unmanaged resources used by the CompiledKernel and optionally releases the managed resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

True to release both managed and unmanaged resources; false to release only unmanaged resources.

Remarks

This method is called by the Dispose() method and the finalizer. Override this method in derived classes to provide specific resource cleanup logic.