Class CudaKernelCompiler
- Namespace
- DotCompute.Backends.CUDA.Compilation
- Assembly
- DotCompute.Backends.CUDA.dll
CUDA kernel compiler implementation using NVRTC. Now delegates to specialized compilation pipeline for improved maintainability.
public sealed class CudaKernelCompiler : IDisposable, IAsyncDisposable
- Inheritance
-
CudaKernelCompiler
- Implements
- Inherited Members
- Extension Methods
Constructors
CudaKernelCompiler(CudaContext, ILogger)
Initializes a new instance of the CudaKernelCompiler class.
[RequiresUnreferencedCode("This type uses runtime code generation and reflection")]
[RequiresDynamicCode("This type uses runtime code generation for CUDA kernel compilation")]
public CudaKernelCompiler(CudaContext context, ILogger logger)
Parameters
contextCudaContextThe context.
loggerILoggerThe logger.
Methods
ClearCache()
Performs clear cache.
public void ClearCache()
CompileAsync(KernelDefinition, CompilationOptions?, CancellationToken)
Gets compile asynchronously.
public Task<ICompiledKernel> CompileAsync(KernelDefinition definition, CompilationOptions? options = null, CancellationToken cancellationToken = default)
Parameters
definitionKernelDefinitionThe definition.
optionsCompilationOptionsThe options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<ICompiledKernel>
The result of the operation.
CompileBatchAsync(KernelDefinition[], CompilationOptions?, CancellationToken)
Gets compile batch asynchronously.
public Task<ICompiledKernel[]> CompileBatchAsync(KernelDefinition[] definitions, CompilationOptions? options = null, CancellationToken cancellationToken = default)
Parameters
definitionsKernelDefinition[]The definitions.
optionsCompilationOptionsThe options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<ICompiledKernel[]>
The result of the operation.
CompileKernelAsync(KernelDefinition, CompilationOptions?, CancellationToken)
Gets compile kernel asynchronously.
public Task<ICompiledKernel> CompileKernelAsync(KernelDefinition definition, CompilationOptions? options = null, CancellationToken cancellationToken = default)
Parameters
definitionKernelDefinitionThe definition.
optionsCompilationOptionsThe options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<ICompiledKernel>
The result of the operation.
Dispose()
Performs dispose.
public void Dispose()
DisposeAsync()
Gets dispose asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
The result of the operation.
GetAllMangledNames(string)
Gets all mangled function names for a kernel.
public static Dictionary<string, string>? GetAllMangledNames(string kernelName)
Parameters
kernelNamestring
Returns
GetCacheStatistics()
Gets cache statistics for monitoring and debugging
public CacheStatistics GetCacheStatistics()
Returns
GetMangledFunctionName(string, string)
Gets the mangled function name for a kernel and function name.
public static string? GetMangledFunctionName(string kernelName, string functionName)
Parameters
Returns
GetNvrtcVersion()
Gets NVRTC version information
public static (int major, int minor) GetNvrtcVersion()
Returns
IsNvrtcAvailable()
Checks NVRTC availability and version
public static bool IsNvrtcAvailable()
Returns
SetTimingProvider(CudaTimingProvider?)
Sets the timing provider for automatic timestamp injection support.
public void SetTimingProvider(CudaTimingProvider? timingProvider)
Parameters
timingProviderCudaTimingProviderThe timing provider instance, or null to disable injection.
Remarks
When a timing provider is set and timestamp injection is enabled via EnableTimestampInjection(bool), all subsequently compiled kernels will have timestamp recording code automatically injected at their entry point.
This allows for automatic kernel profiling without manually modifying kernel code. The injected code records a GPU timestamp (via %%globaltimer on CC 6.0+) in parameter slot 0, shifting all user parameters by one position.
TryGetCached(string, out ICompiledKernel?)
Returns true if able to get cached, otherwise false.
public bool TryGetCached(string kernelName, out ICompiledKernel? compiledKernel)
Parameters
kernelNamestringThe kernel name.
compiledKernelICompiledKernelThe compiled kernel.
Returns
- bool
true if the operation succeeded; otherwise, false.