Table of Contents

Struct TopicRegistry

Namespace
DotCompute.Backends.CUDA.RingKernels
Assembly
DotCompute.Backends.CUDA.dll

GPU-resident topic registry for pub/sub messaging.

public struct TopicRegistry : IEquatable<TopicRegistry>
Implements
Inherited Members

Remarks

The topic registry manages subscriptions and enables efficient message broadcasting. When a message is published to a topic, it is automatically delivered to all subscribers of that topic.

Memory Layout (24 bytes, 8-byte aligned): - SubscriptionCount: 4 bytes - Padding: 4 bytes (alignment) - SubscriptionsPtr: 8 bytes - TopicHashTablePtr: 8 bytes - HashTableCapacity: 4 bytes - Padding: 4 bytes (alignment)

Performance Characteristics: - Topic lookup: O(1) with hash table - Subscription scan: O(n) where n = subscription count - Broadcast latency: <10μs for 100 subscribers

Fields

HashTableCapacity

Hash table capacity (must be power of 2).

public int HashTableCapacity

Field Value

int

Remarks

Recommended: 2x unique topic count for <50% load factor. Valid range: 16-65536 (must be power of 2).

SubscriptionCount

Number of active subscriptions.

public int SubscriptionCount

Field Value

int

Remarks

Valid range: 0-65535 Total subscriptions across all topics.

SubscriptionsPtr

Device pointer to array of TopicSubscription entries.

public long SubscriptionsPtr

Field Value

long

Remarks

Array size: SubscriptionCount elements (12 bytes each). Subscriptions are sorted by topic ID for efficient scanning.

TopicHashTablePtr

Device pointer to topic hash table (topic ID → first subscription index).

public long TopicHashTablePtr

Field Value

long

Remarks

Array size: HashTableCapacity entries (8 bytes each). Entry format: (topic_id << 32) | first_subscription_index Empty entries: 0x0000000000000000 Collision resolution: Linear probing

Methods

CalculateCapacity(int)

Calculates the recommended hash table capacity for a given number of unique topics.

public static int CalculateCapacity(int uniqueTopicCount)

Parameters

uniqueTopicCount int

Number of unique topics with subscriptions.

Returns

int

Next power of 2 that is at least 2x the unique topic count.

Remarks

Targets ~50% load factor for optimal performance. Minimum capacity: 16 (even for 1-8 topics). Maximum capacity: 65536.

CreateEmpty()

Creates an uninitialized topic registry (all pointers null, counts zero).

public static TopicRegistry CreateEmpty()

Returns

TopicRegistry

Empty topic registry suitable for GPU allocation.

Equals(TopicRegistry)

Indicates whether the current object is equal to another object of the same type.

public readonly bool Equals(TopicRegistry other)

Parameters

other TopicRegistry

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override readonly bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override readonly int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Validate()

Validates the topic registry structure for correctness.

public readonly bool Validate()

Returns

bool

True if valid, false if any invariant is violated.

Remarks

Checks:

  • SubscriptionCount in valid range [0, 65535]
  • HashTableCapacity is power of 2
  • All device pointers are non-zero (if SubscriptionCount > 0)

Operators

operator ==(TopicRegistry, TopicRegistry)

Equality operator.

public static bool operator ==(TopicRegistry left, TopicRegistry right)

Parameters

left TopicRegistry
right TopicRegistry

Returns

bool

operator !=(TopicRegistry, TopicRegistry)

Inequality operator.

public static bool operator !=(TopicRegistry left, TopicRegistry right)

Parameters

left TopicRegistry
right TopicRegistry

Returns

bool