Class CudaKernelCache
- Namespace
- DotCompute.Backends.CUDA.Compilation
- Assembly
- DotCompute.Backends.CUDA.dll
Cache for compiled CUDA kernels to avoid recompilation.
public sealed class CudaKernelCache : IDisposable
- Inheritance
-
CudaKernelCache
- Implements
- Inherited Members
- Extension Methods
Constructors
CudaKernelCache()
Initializes a new instance of the CudaKernelCache class.
public CudaKernelCache()
CudaKernelCache(ILogger)
Initializes a new instance of the CudaKernelCache class with logging.
public CudaKernelCache(ILogger logger)
Parameters
loggerILoggerLogger instance.
Properties
Count
Gets the number of cached kernels.
public int Count { get; }
Property Value
Instance
Gets the singleton instance of the cache.
public static CudaKernelCache Instance { get; }
Property Value
Methods
AddOrUpdateKernel(string, ICompiledKernel)
Adds or updates a kernel in the cache.
public void AddOrUpdateKernel(string key, ICompiledKernel kernel)
Parameters
keystringThe cache key.
kernelICompiledKernelThe compiled kernel.
CacheKernel(string, ICompiledKernel)
Caches a compiled kernel with the specified key.
public void CacheKernel(string key, ICompiledKernel kernel)
Parameters
keystringCache key.
kernelICompiledKernelCompiled kernel to cache.
Cleanup()
Performs cleanup of unused kernels from the cache.
public void Cleanup()
Clear()
Clears all cached kernels.
public void Clear()
Dispose()
Disposes the cache and releases resources.
public void Dispose()
GenerateCacheKey(KernelDefinition, CompilationOptions?)
Generates a cache key for a kernel definition.
public static string GenerateCacheKey(KernelDefinition definition, CompilationOptions? options = null)
Parameters
definitionKernelDefinitionThe kernel definition.
optionsCompilationOptionsCompilation options.
Returns
- string
A unique cache key.
OptimizeForWorkload(object)
Optimizes the cache for a specific workload profile.
public void OptimizeForWorkload(object profile)
Parameters
profileobjectWorkload profile for optimization.
RemoveKernel(string)
Removes a kernel from the cache.
public bool RemoveKernel(string key)
Parameters
keystringThe cache key.
Returns
- bool
True if removed; otherwise, false.
TryGetKernel(string, out ICompiledKernel?)
Tries to get a cached kernel.
public bool TryGetKernel(string key, out ICompiledKernel? kernel)
Parameters
keystringThe cache key.
kernelICompiledKernelThe cached kernel if found.
Returns
- bool
True if found; otherwise, false.