Table of Contents

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

logger ILogger<CudaRingKernelCompiler>

Logger instance.

kernelDiscovery RingKernelDiscovery

Ring kernel discovery service.

stubGenerator CudaRingKernelStubGenerator

CUDA stub generator.

serializerGenerator CudaMemoryPackSerializerGenerator

MemoryPack serialization code generator.

handlerTranslator RingKernelHandlerTranslator

Ring 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

kernelId string

The unique kernel identifier.

cudaContext nint

The CUDA context to load the module into.

options CompilationOptions

Compilation options (optional).

assemblies IEnumerable<Assembly>

Assemblies to search for the kernel (optional, scans all if null).

cancellationToken CancellationToken

Cancellation 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

kernelDefinition KernelDefinition

Kernel definition metadata.

sourceCode string

C# source code to translate.

config RingKernelConfig

Ring 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

disposing bool

true 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

kernelId string

The kernel ID.

Returns

CudaCompiledRingKernel

The compiled kernel, or null if not in cache.