Table of Contents

Class MetalRingKernelDiscovery

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

Discovers Ring Kernel methods via runtime reflection and builds a registry for Metal compilation.

public sealed class MetalRingKernelDiscovery
Inheritance
MetalRingKernelDiscovery
Inherited Members

Remarks

This component provides runtime discovery of methods marked with [RingKernel] attribute that are compatible with the Metal backend. Unlike the source generator's compile-time analysis, this performs runtime reflection to enable dynamic kernel loading and compilation.

Discovery process:

  1. Scans loaded assemblies for [RingKernel] methods
  2. Filters for Metal-compatible kernels (checks Backends flag)
  3. Validates method signatures (static, void return, public accessibility)
  4. Extracts attribute configuration (queue sizes, messaging strategy, etc.)
  5. Analyzes parameter types for Metal/MSL compatibility
  6. Builds metadata registry for compilation pipeline

Constructors

MetalRingKernelDiscovery(ILogger<MetalRingKernelDiscovery>)

Initializes a new instance of the MetalRingKernelDiscovery class.

public MetalRingKernelDiscovery(ILogger<MetalRingKernelDiscovery> logger)

Parameters

logger ILogger<MetalRingKernelDiscovery>

The logger for diagnostic messages.

Methods

ClearRegistry()

Clears the kernel registry cache.

public void ClearRegistry()

DiscoverKernelById(string, IEnumerable<Assembly>?)

Discovers a specific Ring Kernel by its kernel ID.

[RequiresUnreferencedCode("Ring Kernel discovery uses runtime reflection which is not compatible with trimming.")]
public DiscoveredMetalRingKernel? DiscoverKernelById(string kernelId, IEnumerable<Assembly>? assemblies = null)

Parameters

kernelId string

The unique kernel ID to find.

assemblies IEnumerable<Assembly>

Optional assemblies to scan. If null, scans all loaded assemblies.

Returns

DiscoveredMetalRingKernel

The discovered kernel, or null if not found.

DiscoverKernels(IEnumerable<Assembly>?)

Discovers all Ring Kernel methods compatible with Metal in the specified assemblies.

[RequiresUnreferencedCode("Ring Kernel discovery uses runtime reflection which is not compatible with trimming.")]
public IReadOnlyCollection<DiscoveredMetalRingKernel> DiscoverKernels(IEnumerable<Assembly>? assemblies = null)

Parameters

assemblies IEnumerable<Assembly>

The assemblies to scan. If null or empty, scans all loaded assemblies.

Returns

IReadOnlyCollection<DiscoveredMetalRingKernel>

A collection of discovered Ring Kernels compatible with Metal.

GetAllRegisteredKernels()

Gets all kernels currently in the registry.

public IReadOnlyCollection<DiscoveredMetalRingKernel> GetAllRegisteredKernels()

Returns

IReadOnlyCollection<DiscoveredMetalRingKernel>

A read-only collection of all registered kernels.

GetKernelFromRegistry(string)

Gets a discovered kernel from the registry.

public DiscoveredMetalRingKernel? GetKernelFromRegistry(string kernelId)

Parameters

kernelId string

The kernel ID.

Returns

DiscoveredMetalRingKernel

The discovered kernel, or null if not in registry.