Class CudaRingKernelStubGenerator
- Namespace
- DotCompute.Backends.CUDA.Compilation
- Assembly
- DotCompute.Backends.CUDA.dll
Generates CUDA C++ kernel stubs from runtime-discovered Ring Kernel metadata.
public sealed class CudaRingKernelStubGenerator
- Inheritance
-
CudaRingKernelStubGenerator
- Inherited Members
Remarks
This generator creates CUDA C++ source code (.cu files) from Ring Kernel definitions discovered at runtime via reflection. The generated code includes: - CUDA kernel function declarations with proper type mapping - Message queue parameter setup - Ring buffer management code - Cooperative kernel launch configuration
The generated stubs integrate with the Ring Kernel message processing pipeline, supporting MemoryPack serialization and multi-GPU execution.
Generated code targets the compute capability detected by CudaCapabilityManager.
Constructors
CudaRingKernelStubGenerator(ILogger<CudaRingKernelStubGenerator>)
Initializes a new instance of the CudaRingKernelStubGenerator class.
public CudaRingKernelStubGenerator(ILogger<CudaRingKernelStubGenerator> logger)
Parameters
loggerILogger<CudaRingKernelStubGenerator>Logger for diagnostic output.
Methods
EstimateSharedMemorySize(DiscoveredRingKernel)
Estimates the shared memory requirements for a Ring Kernel.
public static int EstimateSharedMemorySize(DiscoveredRingKernel kernel)
Parameters
kernelDiscoveredRingKernelThe kernel to analyze.
Returns
- int
The estimated shared memory size in bytes.
GenerateBatchKernelStubs(IEnumerable<DiscoveredRingKernel>, string, bool)
Generates CUDA stubs for multiple Ring Kernels in a single compilation unit.
public string GenerateBatchKernelStubs(IEnumerable<DiscoveredRingKernel> kernels, string compilationUnitName = "RingKernels", bool includeHostLauncher = false)
Parameters
kernelsIEnumerable<DiscoveredRingKernel>The collection of discovered Ring Kernels.
compilationUnitNamestringThe name of the compilation unit (e.g., "RingKernels").
includeHostLauncherboolIf true, generates host-side launch wrapper functions. Set to false for NVRTC device-only compilation (JIT mode).
Returns
- string
The generated CUDA C++ source code containing all kernels.
GenerateKernelStub(DiscoveredRingKernel, bool)
Generates a complete CUDA C++ source file (.cu) for a Ring Kernel.
public string GenerateKernelStub(DiscoveredRingKernel kernel, bool includeHostLauncher = false)
Parameters
kernelDiscoveredRingKernelThe discovered Ring Kernel metadata.
includeHostLauncherboolIf true, generates host-side launch wrapper functions. Set to false for NVRTC device-only compilation (JIT mode).
Returns
- string
The generated CUDA C++ source code.
Exceptions
- ArgumentNullException
Thrown when
kernelis null.- InvalidOperationException
Thrown when code generation fails.
ValidateKernelForCuda(DiscoveredRingKernel)
Validates that a kernel can be compiled to CUDA.
public static bool ValidateKernelForCuda(DiscoveredRingKernel kernel)
Parameters
kernelDiscoveredRingKernelThe kernel to validate.
Returns
- bool
True if the kernel is valid for CUDA compilation; otherwise, false.