Class CudaStreamExtensions
- Namespace
- DotCompute.Backends.CUDA.Types
- Assembly
- DotCompute.Backends.CUDA.dll
Extension methods for CudaStream.
public static class CudaStreamExtensions
- Inheritance
-
CudaStreamExtensions
- Inherited Members
Methods
SynchronizeAsync(CudaStream, CancellationToken)
Asynchronously synchronizes the CUDA stream, waiting for all operations to complete.
public static Task SynchronizeAsync(this CudaStream stream, CancellationToken cancellationToken = default)
Parameters
streamCudaStreamThe CUDA stream to synchronize.
cancellationTokenCancellationTokenOptional cancellation token.
Returns
- Task
A task that completes when the stream is synchronized.
Remarks
This method captures the current CUDA device before Task.Run and ensures the device context is current on the thread pool thread. This is necessary because CUDA contexts are thread-local and Task.Run switches to a thread pool thread.
Exceptions
- InvalidOperationException
Thrown when stream synchronization fails or device context cannot be set.