Class TopicRegistryBuilder
- Namespace
- DotCompute.Backends.CUDA.RingKernels
- Assembly
- DotCompute.Backends.CUDA.dll
Builds and manages GPU-resident topic registries for pub/sub messaging.
public sealed class TopicRegistryBuilder : IDisposable
- Inheritance
-
TopicRegistryBuilder
- Implements
- Inherited Members
- Extension Methods
Remarks
The topic registry builder performs the following operations: 1. Manages topic subscriptions (kernel + topic associations) 2. Calculates optimal hash table capacity for topic lookup 3. Allocates GPU memory for registry structures 4. Populates subscription array sorted by topic ID 5. Returns initialized TopicRegistry for GPU usage
Memory Management: - Subscriptions array: subscription_count * 12 bytes (TopicSubscription) - Hash table: capacity * 8 bytes (64-bit entries)
Thread Safety: Not thread-safe. Builder should be used sequentially during initialization.
Constructors
TopicRegistryBuilder(CudaContext)
Initializes a new topic registry builder for the specified CUDA context.
public TopicRegistryBuilder(CudaContext context)
Parameters
contextCudaContextCUDA context for GPU memory allocation.
Exceptions
- ArgumentNullException
Thrown if context is null.
Methods
Build()
Builds the topic registry and allocates GPU memory.
public TopicRegistry Build()
Returns
- TopicRegistry
Initialized TopicRegistry with GPU-resident data.
Remarks
GPU Memory Allocation: - Subscriptions array: subscription_count * 12 bytes - Hash table: capacity * 8 bytes
Subscription Array Construction: Subscriptions are sorted by topic ID for efficient scanning.
Exceptions
- InvalidOperationException
Thrown if no subscriptions registered or validation fails.
- ObjectDisposedException
Thrown if builder has been disposed.
Dispose()
Disposes the topic registry builder (does not free GPU memory allocated during Build).
public void Dispose()
Remarks
GPU memory allocated by Build() must be freed separately using CudaRuntime.cudaFree.
Subscribe(string, ushort, ushort, ushort)
Subscribes a kernel to a topic.
public int Subscribe(string topicName, ushort kernelId, ushort queueIndex, ushort flags = 0)
Parameters
topicNamestringTopic name (will be hashed to 32-bit ID).
kernelIdushortSubscriber kernel ID (16-bit hash).
queueIndexushortSubscriber's queue index.
flagsushortSubscription flags (default: none).
Returns
- int
Assigned subscription index.
Exceptions
- ArgumentException
Thrown if topic name is null/empty.
- ObjectDisposedException
Thrown if builder has been disposed.
SubscribeMultiple(string, ushort[], ushort[], ushort)
Subscribes multiple kernels to a topic (broadcast subscription).
public int SubscribeMultiple(string topicName, ushort[] kernelIds, ushort[] queueIndices, ushort flags = 0)
Parameters
topicNamestringTopic name.
kernelIdsushort[]Array of subscriber kernel IDs.
queueIndicesushort[]Array of subscriber queue indices (must match kernelIds length).
flagsushortSubscription flags (applied to all subscriptions).
Returns
- int
Number of subscriptions added.
Exceptions
- ArgumentException
Thrown if arrays have different lengths.