Table of Contents

Struct TopicSubscription

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

GPU-resident topic subscription entry for pub/sub messaging.

public struct TopicSubscription : IEquatable<TopicSubscription>
Implements
Inherited Members

Remarks

Topic subscriptions enable decoupled communication between kernels. Kernels subscribe to topics at initialization, and messages published to those topics are automatically broadcast to all subscribers.

Memory Layout (12 bytes, 4-byte aligned): - TopicId: 4 bytes (hash of topic name) - KernelId: 4 bytes (subscriber kernel identifier) - QueueIndex: 2 bytes (subscriber's queue index) - Flags: 2 bytes (wildcard, priority, etc.)

Subscription Flags: - Bit 0: Wildcard subscription (matches "physics.*") - Bit 1: High priority (delivered first) - Bits 2-15: Reserved for future use

Fields

FlagHighPriority

Flag: High-priority subscription (delivered before normal subscriptions).

public const ushort FlagHighPriority = 2

Field Value

ushort

FlagWildcard

Flag: Subscription matches wildcard patterns (e.g., "physics.*").

public const ushort FlagWildcard = 1

Field Value

ushort

Flags

Subscription flags (wildcard, priority, etc.).

public ushort Flags

Field Value

ushort

Remarks

  • Bit 0: Wildcard subscription
  • Bit 1: High priority delivery
  • Bits 2-15: Reserved

KernelId

Subscriber kernel ID (16-bit hash of kernel name).

public uint KernelId

Field Value

uint

Remarks

Identifies the kernel that subscribed to this topic. Stored as uint32 for alignment (upper 16 bits unused).

QueueIndex

Queue index for this subscriber (0-65535).

public ushort QueueIndex

Field Value

ushort

Remarks

Index into the routing table's output queues array. Used to route messages to the subscriber's input queue.

TopicId

Topic ID (hash of topic name using FNV-1a algorithm).

public uint TopicId

Field Value

uint

Remarks

Topic names are hashed to 32-bit IDs for efficient comparison. Example: "physics.particles" → 0x7A3B9C12

Methods

Create(uint, uint, ushort, ushort)

Creates a topic subscription entry.

public static TopicSubscription Create(uint topicId, uint kernelId, ushort queueIndex, ushort flags = 0)

Parameters

topicId uint

Topic ID (hash of topic name).

kernelId uint

Subscriber kernel ID.

queueIndex ushort

Subscriber's queue index.

flags ushort

Subscription flags (default: none).

Returns

TopicSubscription

Initialized topic subscription.

Equals(TopicSubscription)

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

public readonly bool Equals(TopicSubscription other)

Parameters

other TopicSubscription

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.

Operators

operator ==(TopicSubscription, TopicSubscription)

Equality operator.

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

Parameters

left TopicSubscription
right TopicSubscription

Returns

bool

operator !=(TopicSubscription, TopicSubscription)

Inequality operator.

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

Parameters

left TopicSubscription
right TopicSubscription

Returns

bool