Class MetalKernelCache
- Namespace
- DotCompute.Backends.Metal.Kernels
- Assembly
- DotCompute.Backends.Metal.dll
Production-grade cache for compiled Metal kernels with LRU eviction and memory pressure handling.
public sealed class MetalKernelCache : IDisposable
- Inheritance
-
MetalKernelCache
- Implements
- Inherited Members
- Extension Methods
Constructors
MetalKernelCache(ILogger<MetalKernelCache>, int, TimeSpan?, string?, nint)
Initializes a new instance of the MetalKernelCache class.
public MetalKernelCache(ILogger<MetalKernelCache> logger, int maxCacheSize = 1000, TimeSpan? defaultTtl = null, string? persistentCachePath = null, nint device = 0)
Parameters
loggerILogger<MetalKernelCache>maxCacheSizeintdefaultTtlTimeSpan?persistentCachePathstringdevicenint
Methods
AddKernel(KernelDefinition, CompilationOptions, nint, nint, nint, byte[]?, long)
Adds a compiled kernel to the cache.
public void AddKernel(KernelDefinition definition, CompilationOptions options, nint library, nint function, nint pipelineState, byte[]? binaryData = null, long compilationTimeMs = 0)
Parameters
definitionKernelDefinitionoptionsCompilationOptionslibrarynintfunctionnintpipelineStatenintbinaryDatabyte[]compilationTimeMslong
Clear()
Clears all cached kernels.
public void Clear()
ComputeCacheKey(KernelDefinition, CompilationOptions)
Computes a cache key for the given kernel definition and options.
public static string ComputeCacheKey(KernelDefinition definition, CompilationOptions options)
Parameters
definitionKernelDefinitionoptionsCompilationOptions
Returns
Dispose()
Disposes the cache and all cached kernels.
public void Dispose()
InvalidateKernel(KernelDefinition, CompilationOptions)
Invalidates a specific kernel in the cache.
public bool InvalidateKernel(KernelDefinition definition, CompilationOptions options)
Parameters
definitionKernelDefinitionoptionsCompilationOptions
Returns
TryGetKernel(KernelDefinition, CompilationOptions, out nint, out nint, out nint)
Attempts to retrieve a cached kernel.
public bool TryGetKernel(KernelDefinition definition, CompilationOptions options, out nint library, out nint function, out nint pipelineState)
Parameters
definitionKernelDefinitionoptionsCompilationOptionslibrarynintfunctionnintpipelineStatenint