Class CudaRingKernelCompiler
- Namespace
- DotCompute.Backends.CUDA.RingKernels
- Assembly
- DotCompute.Backends.CUDA.dll
Compiles C# ring kernel definitions to CUDA C persistent kernels.
public class CudaRingKernelCompiler : IDisposable
- Inheritance
-
CudaRingKernelCompiler
- Implements
- Inherited Members
- Extension Methods
Remarks
Generates CUDA C code for persistent kernels with:
- Cooperative groups for synchronization
- Lock-free message queues using atomics
- Persistent kernel loop with activation control
- Grid-stride loops for work distribution
Constructors
CudaRingKernelCompiler(ILogger<CudaRingKernelCompiler>, RingKernelDiscovery, CudaRingKernelStubGenerator, CudaMemoryPackSerializerGenerator, RingKernelHandlerTranslator?)
Initializes a new instance of the CudaRingKernelCompiler class.
public CudaRingKernelCompiler(ILogger<CudaRingKernelCompiler> logger, RingKernelDiscovery kernelDiscovery, CudaRingKernelStubGenerator stubGenerator, CudaMemoryPackSerializerGenerator serializerGenerator, RingKernelHandlerTranslator? handlerTranslator = null)
Parameters
loggerILogger<CudaRingKernelCompiler>Logger instance.
kernelDiscoveryRingKernelDiscoveryRing kernel discovery service.
stubGeneratorCudaRingKernelStubGeneratorCUDA stub generator.
serializerGeneratorCudaMemoryPackSerializerGeneratorMemoryPack serialization code generator.
handlerTranslatorRingKernelHandlerTranslatorRing kernel handler translator for unified kernel API.
Methods
ClearCache()
Clears the compiled kernel cache.
public void ClearCache()
CompileRingKernelAsync(string, nint, CompilationOptions?, IEnumerable<Assembly>?, CancellationToken)
Compiles a Ring Kernel to executable PTX using the 6-stage pipeline.
[RequiresUnreferencedCode("Ring Kernel compilation uses runtime reflection which is not compatible with trimming.")]
public Task<CudaCompiledRingKernel> CompileRingKernelAsync(string kernelId, nint cudaContext, CompilationOptions? options = null, IEnumerable<Assembly>? assemblies = null, CancellationToken cancellationToken = default)
Parameters
kernelIdstringThe unique kernel identifier.
cudaContextnintThe CUDA context to load the module into.
optionsCompilationOptionsCompilation options (optional).
assembliesIEnumerable<Assembly>Assemblies to search for the kernel (optional, scans all if null).
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<CudaCompiledRingKernel>
The compiled kernel with PTX module and function pointer.
Exceptions
- ArgumentException
Thrown when kernelId is null or empty.
- InvalidOperationException
Thrown when compilation fails at any stage.
CompileToCudaC(KernelDefinition, string, RingKernelConfig)
Compiles a ring kernel definition to CUDA C source code.
public string CompileToCudaC(KernelDefinition kernelDefinition, string sourceCode, RingKernelConfig config)
Parameters
kernelDefinitionKernelDefinitionKernel definition metadata.
sourceCodestringC# source code to translate.
configRingKernelConfigRing kernel configuration.
Returns
- string
Generated CUDA C source code.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Dispose(bool)
Releases the unmanaged resources used by the CudaRingKernelCompiler and optionally releases the managed resources.
protected virtual void Dispose(bool disposing)
Parameters
disposingbooltrue to release both managed and unmanaged resources; false to release only unmanaged resources.
GetAllCompiledKernels()
Gets all compiled kernels.
public IReadOnlyCollection<CudaCompiledRingKernel> GetAllCompiledKernels()
Returns
- IReadOnlyCollection<CudaCompiledRingKernel>
A read-only collection of all compiled kernels.
GetCompiledKernel(string)
Gets a compiled kernel from the cache.
public CudaCompiledRingKernel? GetCompiledKernel(string kernelId)
Parameters
kernelIdstringThe kernel ID.
Returns
- CudaCompiledRingKernel
The compiled kernel, or null if not in cache.