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:
- Scans loaded assemblies for [RingKernel] methods
- Filters for Metal-compatible kernels (checks Backends flag)
- Validates method signatures (static, void return, public accessibility)
- Extracts attribute configuration (queue sizes, messaging strategy, etc.)
- Analyzes parameter types for Metal/MSL compatibility
- Builds metadata registry for compilation pipeline
Constructors
MetalRingKernelDiscovery(ILogger<MetalRingKernelDiscovery>)
Initializes a new instance of the MetalRingKernelDiscovery class.
public MetalRingKernelDiscovery(ILogger<MetalRingKernelDiscovery> logger)
Parameters
loggerILogger<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
kernelIdstringThe unique kernel ID to find.
assembliesIEnumerable<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
assembliesIEnumerable<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
kernelIdstringThe kernel ID.
Returns
- DiscoveredMetalRingKernel
The discovered kernel, or null if not in registry.