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
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
InputQueueBufferPtr
Device pointer to input message queue data buffer.
public long InputQueueBufferPtr
Field Value
InputQueueCapacity
Capacity of input message queue (number of slots, power of 2).
public int InputQueueCapacity
Field Value
InputQueueHeadPtr
Device pointer to input message queue head atomic counter.
public long InputQueueHeadPtr
Field Value
InputQueueMessageSize
Size of each message in the input queue (bytes).
public int InputQueueMessageSize
Field Value
InputQueueTailPtr
Device pointer to input message queue tail atomic counter.
public long InputQueueTailPtr
Field Value
IsActive
Atomic flag: 1 = kernel is active and processing, 0 = inactive/paused.
public int IsActive
Field Value
LastActivityTicks
Atomic timestamp: last time kernel processed a message (ticks).
public long LastActivityTicks
Field Value
MessagesProcessed
Atomic counter: total messages processed by this kernel.
public long MessagesProcessed
Field Value
OutputQueueBufferPtr
Device pointer to output message queue data buffer.
public long OutputQueueBufferPtr
Field Value
OutputQueueCapacity
Capacity of output message queue (number of slots, power of 2).
public int OutputQueueCapacity
Field Value
OutputQueueHeadPtr
Device pointer to output message queue head atomic counter.
public long OutputQueueHeadPtr
Field Value
OutputQueueMessageSize
Size of each message in the output queue (bytes).
public int OutputQueueMessageSize
Field Value
OutputQueueTailPtr
Device pointer to output message queue tail atomic counter.
public long OutputQueueTailPtr
Field Value
ShouldTerminate
Atomic flag: 1 = kernel should terminate gracefully, 0 = continue running.
public int ShouldTerminate
Field Value
Methods
CreateActive()
Creates a new control block with active state.
public static RingKernelControlBlock CreateActive()
Returns
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
Equals(RingKernelControlBlock)
Indicates whether the current object is equal to another object of the same type.
public readonly bool Equals(RingKernelControlBlock other)
Parameters
otherRingKernelControlBlockAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override readonly bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand 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
leftRingKernelControlBlockrightRingKernelControlBlock
Returns
operator !=(RingKernelControlBlock, RingKernelControlBlock)
Inequality operator.
public static bool operator !=(RingKernelControlBlock left, RingKernelControlBlock right)
Parameters
leftRingKernelControlBlockrightRingKernelControlBlock