Table of Contents

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

logger ILogger<CudaRingKernelStubGenerator>

Logger for diagnostic output.

Methods

EstimateSharedMemorySize(DiscoveredRingKernel)

Estimates the shared memory requirements for a Ring Kernel.

public static int EstimateSharedMemorySize(DiscoveredRingKernel kernel)

Parameters

kernel DiscoveredRingKernel

The 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

kernels IEnumerable<DiscoveredRingKernel>

The collection of discovered Ring Kernels.

compilationUnitName string

The name of the compilation unit (e.g., "RingKernels").

includeHostLauncher bool

If 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

kernel DiscoveredRingKernel

The discovered Ring Kernel metadata.

includeHostLauncher bool

If 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 kernel is 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

kernel DiscoveredRingKernel

The kernel to validate.

Returns

bool

True if the kernel is valid for CUDA compilation; otherwise, false.