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
TMessage type implementing IRingKernelMessage.
- Inheritance
-
GpuRingBufferBridge<T>
- Implements
- Inherited Members
- Extension Methods
Remarks
This bridge manages the data flow between:
- Host-side: IMessageQueue<T> (managed memory)
- GPU-side: GpuRingBuffer<T> (device memory)
Two Transfer Modes:
- Unified Memory Mode (non-WSL2): GPU kernel directly accesses host queue via unified memory. Bridge is passive and only provides pointer translation.
- 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
hostQueueIMessageQueue<T>Host-side message queue.
gpuBufferGpuRingBuffer<T>GPU-side ring buffer.
enableDmaTransferboolTrue to enable background DMA transfer tasks (WSL2 mode), false for unified memory mode.
directionGpuBridgeDirectionDirection of data flow. Use HostToDevice for input bridges and DeviceToHost for output bridges.
loggerILoggerOptional logger for diagnostics.
Properties
GpuBuffer
Gets the GPU-side ring buffer (typed).
public GpuRingBuffer<T> GpuBuffer { get; }
Property Value
GpuRingBuffer
Gets the GPU-side ring buffer (interface access for non-generic scenarios).
public IGpuRingBuffer GpuRingBuffer { get; }
Property Value
GpuToHostTransferCount
Gets the count of messages transferred from GPU to host.
public long GpuToHostTransferCount { get; }
Property Value
HostQueue
Gets the host-side message queue.
public IMessageQueue<T> HostQueue { get; }
Property Value
HostToGpuTransferCount
Gets the count of messages transferred from host to GPU.
public long HostToGpuTransferCount { get; }
Property Value
IsDmaTransferEnabled
Gets whether explicit DMA transfer is enabled.
public bool IsDmaTransferEnabled { get; }
Property Value
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
StopTransfers()
Stops the bridge's background DMA transfer tasks (synchronous wrapper).
public void StopTransfers()