Table of Contents

Class GpuRingBufferBridge<T>

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

Bidirectional bridge between host IMessageQueue<T> and GPU ring buffer.

public sealed class GpuRingBufferBridge<T> : IGpuRingBufferBridge, IDisposable where T : IRingKernelMessage

Type Parameters

T

Message type implementing IRingKernelMessage.

Inheritance
GpuRingBufferBridge<T>
Implements
Inherited Members
Extension Methods

Remarks

This bridge manages the data flow between:

Two Transfer Modes:

  1. Unified Memory Mode (non-WSL2): GPU kernel directly accesses host queue via unified memory. Bridge is passive and only provides pointer translation.
  2. Explicit DMA Mode (WSL2): Background tasks periodically copy messages between host queue and GPU buffer using cudaMemcpy. Required for WSL2 due to unified memory limitations.

Message Flow:

Host → HostQueue.Enqueue() → [Bridge: Host→GPU DMA] → GPU Buffer → GPU Kernel
GPU Kernel → GPU Buffer → [Bridge: GPU→Host DMA] → HostQueue.Dequeue() → Host

Constructors

GpuRingBufferBridge(IMessageQueue<T>, GpuRingBuffer<T>, bool, GpuBridgeDirection, ILogger?)

Initializes a new instance of the GpuRingBufferBridge<T> class.

public GpuRingBufferBridge(IMessageQueue<T> hostQueue, GpuRingBuffer<T> gpuBuffer, bool enableDmaTransfer, GpuBridgeDirection direction = GpuBridgeDirection.Bidirectional, ILogger? logger = null)

Parameters

hostQueue IMessageQueue<T>

Host-side message queue.

gpuBuffer GpuRingBuffer<T>

GPU-side ring buffer.

enableDmaTransfer bool

True to enable background DMA transfer tasks (WSL2 mode), false for unified memory mode.

direction GpuBridgeDirection

Direction of data flow. Use HostToDevice for input bridges and DeviceToHost for output bridges.

logger ILogger

Optional logger for diagnostics.

Properties

GpuBuffer

Gets the GPU-side ring buffer (typed).

public GpuRingBuffer<T> GpuBuffer { get; }

Property Value

GpuRingBuffer<T>

GpuRingBuffer

Gets the GPU-side ring buffer (interface access for non-generic scenarios).

public IGpuRingBuffer GpuRingBuffer { get; }

Property Value

IGpuRingBuffer

GpuToHostTransferCount

Gets the count of messages transferred from GPU to host.

public long GpuToHostTransferCount { get; }

Property Value

long

HostQueue

Gets the host-side message queue.

public IMessageQueue<T> HostQueue { get; }

Property Value

IMessageQueue<T>

HostToGpuTransferCount

Gets the count of messages transferred from host to GPU.

public long HostToGpuTransferCount { get; }

Property Value

long

IsDmaTransferEnabled

Gets whether explicit DMA transfer is enabled.

public bool IsDmaTransferEnabled { get; }

Property Value

bool

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Start()

Starts the bridge's background DMA transfer tasks (if enabled).

public void Start()

Remarks

Only starts the transfer loop(s) appropriate for the configured DotCompute.Backends.CUDA.RingKernels.GpuRingBufferBridge<T>._direction:

  • HostToDevice: Only Host→GPU loop (input bridges)
  • DeviceToHost: Only GPU→Host loop (output bridges)
  • Bidirectional: Both loops (debugging only)

StopAsync()

Stops the bridge's background DMA transfer tasks.

public Task StopAsync()

Returns

Task

StopTransfers()

Stops the bridge's background DMA transfer tasks (synchronous wrapper).

public void StopTransfers()