Table of Contents

Struct RingKernelControlBlock

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

GPU-resident control block for managing persistent ring kernel state.

public struct RingKernelControlBlock : IEquatable<RingKernelControlBlock>
Implements
Inherited Members

Remarks

This structure is allocated in device memory and shared between host and kernel. All fields use 32-bit atomics for lock-free coordination.

Memory layout (128 bytes, dual cache-line aligned):

  • Flags: active (offset 0), terminate (offset 4), terminated (offset 8), errors (offset 12)
  • Counters: messagesProcessed (offset 16)
  • Timestamp: lastActivityTicks (offset 24)
  • Input Queue: head ptr (offset 32), tail ptr (offset 40), buffer ptr (offset 48), capacity (offset 56), messageSize (offset 60)
  • Output Queue: head ptr (offset 64), tail ptr (offset 72), buffer ptr (offset 80), capacity (offset 88), messageSize (offset 92)
  • Reserved: padding to 128 bytes (offsets 96-127)

Fields

ErrorsEncountered

Atomic counter: total errors encountered during processing.

public int ErrorsEncountered

Field Value

int

HasTerminated

Atomic flag: 1 = kernel has finished termination, 0 = still running. Value meanings: 0 = running, 1 = terminated permanently, 2 = terminated but relaunchable (EventDriven mode)

public int HasTerminated

Field Value

int

InputQueueBufferPtr

Device pointer to input message queue data buffer.

public long InputQueueBufferPtr

Field Value

long

InputQueueCapacity

Capacity of input message queue (number of slots, power of 2).

public int InputQueueCapacity

Field Value

int

InputQueueHeadPtr

Device pointer to input message queue head atomic counter.

public long InputQueueHeadPtr

Field Value

long

InputQueueMessageSize

Size of each message in the input queue (bytes).

public int InputQueueMessageSize

Field Value

int

InputQueueTailPtr

Device pointer to input message queue tail atomic counter.

public long InputQueueTailPtr

Field Value

long

IsActive

Atomic flag: 1 = kernel is active and processing, 0 = inactive/paused.

public int IsActive

Field Value

int

LastActivityTicks

Atomic timestamp: last time kernel processed a message (ticks).

public long LastActivityTicks

Field Value

long

MessagesProcessed

Atomic counter: total messages processed by this kernel.

public long MessagesProcessed

Field Value

long

OutputQueueBufferPtr

Device pointer to output message queue data buffer.

public long OutputQueueBufferPtr

Field Value

long

OutputQueueCapacity

Capacity of output message queue (number of slots, power of 2).

public int OutputQueueCapacity

Field Value

int

OutputQueueHeadPtr

Device pointer to output message queue head atomic counter.

public long OutputQueueHeadPtr

Field Value

long

OutputQueueMessageSize

Size of each message in the output queue (bytes).

public int OutputQueueMessageSize

Field Value

int

OutputQueueTailPtr

Device pointer to output message queue tail atomic counter.

public long OutputQueueTailPtr

Field Value

long

ShouldTerminate

Atomic flag: 1 = kernel should terminate gracefully, 0 = continue running.

public int ShouldTerminate

Field Value

int

Methods

CreateActive()

Creates a new control block with active state.

public static RingKernelControlBlock CreateActive()

Returns

RingKernelControlBlock

Remarks

This is used for WSL2 where cross-CPU/GPU memory visibility is unreliable. By starting the kernel with is_active=1 already set, we avoid the need for mid-execution activation signaling which doesn't work with system-scope atomics in virtualized GPU environments.

CreateInactive()

Creates a new control block with default (inactive) state.

public static RingKernelControlBlock CreateInactive()

Returns

RingKernelControlBlock

Equals(RingKernelControlBlock)

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

public readonly bool Equals(RingKernelControlBlock other)

Parameters

other RingKernelControlBlock

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 ==(RingKernelControlBlock, RingKernelControlBlock)

Equality operator.

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

Parameters

left RingKernelControlBlock
right RingKernelControlBlock

Returns

bool

operator !=(RingKernelControlBlock, RingKernelControlBlock)

Inequality operator.

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

Parameters

left RingKernelControlBlock
right RingKernelControlBlock

Returns

bool