Class RoutingTableBuilder
- Namespace
- DotCompute.Backends.CUDA.RingKernels
- Assembly
- DotCompute.Backends.CUDA.dll
Builds and manages GPU-resident routing tables for inter-kernel messaging.
public sealed class RoutingTableBuilder : IDisposable
- Inheritance
-
RoutingTableBuilder
- Implements
- Inherited Members
- Extension Methods
Remarks
The routing table builder performs the following operations: 1. Validates kernel registrations and assigns queue indices 2. Calculates optimal hash table capacity (power of 2, ~50% load factor) 3. Allocates GPU memory for routing table structures 4. Populates hash table with kernel ID → queue index mappings 5. Returns initialized KernelRoutingTable for GPU usage
Memory Management: - Hash table: capacity * 4 bytes (32-bit entries) - Output queues array: kernel_count * 8 bytes (device pointers) - Control blocks array: kernel_count * 64 bytes (RingKernelControlBlock)
Thread Safety: Not thread-safe. Builder should be used sequentially during initialization.
Constructors
RoutingTableBuilder(CudaContext)
Initializes a new routing table builder for the specified CUDA context.
public RoutingTableBuilder(CudaContext context)
Parameters
contextCudaContextCUDA context for GPU memory allocation.
Exceptions
- ArgumentNullException
Thrown if context is null.
Methods
Build()
Builds the routing table and allocates GPU memory.
public KernelRoutingTable Build()
Returns
- KernelRoutingTable
Initialized KernelRoutingTable with GPU-resident data.
Remarks
GPU Memory Allocation: - Hash table: capacity * 4 bytes - Output queues: kernel_count * 8 bytes - Control blocks: kernel_count * 64 bytes
Hash Table Construction: Uses linear probing to insert kernel ID → queue index mappings. Entry format: (kernel_id << 16) | queue_index
Exceptions
- InvalidOperationException
Thrown if no kernels registered or validation fails.
- ObjectDisposedException
Thrown if builder has been disposed.
Dispose()
Disposes the routing table builder (does not free GPU memory allocated during Build).
public void Dispose()
Remarks
GPU memory allocated by Build() must be freed separately using CudaInterop.cuMemFree.
RegisterKernel(string, long, long)
Registers a kernel in the routing table.
public int RegisterKernel(string kernelName, long outputQueuePtr, long controlBlockPtr)
Parameters
kernelNamestringUnique kernel name (will be hashed to 16-bit ID).
outputQueuePtrlongDevice pointer to kernel's output queue.
controlBlockPtrlongDevice pointer to kernel's control block.
Returns
- int
Assigned queue index for this kernel.
Exceptions
- ArgumentException
Thrown if kernel name is null/empty or already registered.
- ObjectDisposedException
Thrown if builder has been disposed.