Table of Contents

Class RingKernelMessageAttribute

Namespace
DotCompute.Abstractions.Attributes
Assembly
DotCompute.Abstractions.dll

Marks a type as a ring kernel message, enabling automatic serialization and routing code generation.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
public sealed class RingKernelMessageAttribute : Attribute
Inheritance
RingKernelMessageAttribute
Inherited Members

Remarks

Types marked with this attribute will have their serialization code automatically generated for GPU communication. The attribute also specifies the message direction which helps the code generator optimize routing and memory allocation.

Usage Examples:

[RingKernelMessage(Direction = MessageDirection.Input)]
public partial record AddRequest(int A, int B);

[RingKernelMessage(Direction = MessageDirection.Output)]
public partial record AddResponse(int Result);

[RingKernelMessage(Direction = MessageDirection.KernelToKernel)]
public partial record ForwardMessage(int Value, string TargetKernelId);

Generated Code:

  • MemoryPack serialization/deserialization
  • CUDA struct definition matching binary layout
  • CUDA serialize/deserialize functions
  • Message routing metadata for K2K communication

Properties

Direction

Gets or sets the direction of message flow for this message type.

public MessageDirection Direction { get; set; }

Property Value

MessageDirection

The message direction. Defaults to Bidirectional.

Remarks

Direction affects code generation and memory allocation:

  • Input: Allocates in input queue, generates host→kernel serialization
  • Output: Allocates in output queue, generates kernel→host serialization
  • KernelToKernel: Uses K2K routing infrastructure
  • Bidirectional: Full serialization in both directions

KernelId

Gets or sets the kernel ID this message is associated with.

public string KernelId { get; set; }

Property Value

string

The kernel identifier, or empty string for auto-detection based on naming convention.

Remarks

When empty, the generator will attempt to match the message type to a kernel based on naming conventions (e.g., AddRequest matches Add kernel).

MessageTypeId

Gets or sets the message type identifier for routing.

public int MessageTypeId { get; set; }

Property Value

int

A unique integer identifier for this message type, or 0 for auto-assignment.

Remarks

Used for type discrimination in polymorphic message handling. When 0, a unique ID is generated based on the type's full name hash.

Priority

Gets or sets the priority level for this message type.

public byte Priority { get; set; }

Property Value

byte

Priority value from 0 (lowest) to 255 (highest). Defaults to 128 (normal).

Remarks

Higher priority messages are processed before lower priority ones when multiple messages are waiting in the queue.

RequiresCausalOrdering

Gets or sets whether this message type requires causal ordering guarantees.

public bool RequiresCausalOrdering { get; set; }

Property Value

bool

true to include HLC timestamp in serialization; false for best-effort ordering. Defaults to false.

Remarks

When enabled, messages include Hybrid Logical Clock timestamps for causal ordering. This adds ~12 bytes overhead per message but enables happened-before relationships.