Table of Contents

Interface IKernelCache

Namespace
DotCompute.Runtime.Services.Interfaces
Assembly
DotCompute.Runtime.dll

Caches compiled kernels to avoid recompilation overhead.

public interface IKernelCache

Methods

ClearAsync()

Clears all cached kernels.

Task<int> ClearAsync()

Returns

Task<int>

The number of entries cleared

GenerateCacheKey(KernelDefinition, IAccelerator, CompilationOptions?)

Generates a cache key for a kernel configuration.

string GenerateCacheKey(KernelDefinition kernelDefinition, IAccelerator accelerator, CompilationOptions? compilationOptions)

Parameters

kernelDefinition KernelDefinition

The kernel definition

accelerator IAccelerator

The target accelerator

compilationOptions CompilationOptions

Optional compilation options

Returns

string

A unique cache key

GetAsync(string)

Retrieves a compiled kernel from the cache.

Task<ICompiledKernel?> GetAsync(string cacheKey)

Parameters

cacheKey string

The cache key

Returns

Task<ICompiledKernel>

The cached compiled kernel, or null if not found

GetStatisticsAsync()

Gets cache statistics.

Task<CacheStatistics> GetStatisticsAsync()

Returns

Task<CacheStatistics>

Cache statistics including hit rate, size, etc.

InvalidateAsync(string)

Invalidates a specific cache entry.

Task<bool> InvalidateAsync(string cacheKey)

Parameters

cacheKey string

The cache key to invalidate

Returns

Task<bool>

True if the entry was removed, false if not found

PrewarmAsync(IEnumerable<KernelDefinition>, IEnumerable<IAccelerator>)

Pre-warms the cache with commonly used kernels.

Task<int> PrewarmAsync(IEnumerable<KernelDefinition> kernelDefinitions, IEnumerable<IAccelerator> accelerators)

Parameters

kernelDefinitions IEnumerable<KernelDefinition>

Kernel definitions to pre-compile and cache

accelerators IEnumerable<IAccelerator>

Available accelerators

Returns

Task<int>

Number of kernels successfully cached

StoreAsync(string, ICompiledKernel)

Stores a compiled kernel in the cache.

Task StoreAsync(string cacheKey, ICompiledKernel compiledKernel)

Parameters

cacheKey string

The cache key

compiledKernel ICompiledKernel

The compiled kernel to cache

Returns

Task

A task representing the store operation