Table of Contents

Class CudaStream

Namespace
NVMathNet
Assembly
NVMath.Net.dll

Wraps a CUDA stream handle and provides async-friendly synchronization. Owns the stream handle; call NVMathNet.CudaStream.DisposeAsync (or use await using) to destroy it.

public sealed class CudaStream : IAsyncDisposable, IDisposable

Inheritance

Implements

Inherited Members

Constructors

CudaStream(bool)

Creates a new CUDA stream.

public CudaStream(bool nonBlocking = true)

Parameters

nonBlocking bool

When true (default) the stream does not synchronize with the default stream.

Properties

Handle

The raw CUDA stream handle (cudaStream_t).

public nint Handle { get; }

Property Value

nint

Methods

Dispose()

Releases the resources used by this instance.

public void Dispose()

Remarks

This method can be called multiple times safely. If the stream is owned, it will be destroyed using the CUDA runtime.

DisposeAsync()

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

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

FromHandle(nint)

Creates a NVMathNet.CudaStream that wraps an externally-owned handle. Disposal of this instance does not destroy the handle.

public static CudaStream FromHandle(nint handle)

Parameters

handle nint

Returns

CudaStream

Synchronize()

Synchronizes this stream on the calling thread. Prefer NVMathNet.CudaStream.SynchronizeAsync(System.Threading.CancellationToken) in async code.

public void Synchronize()

SynchronizeAsync(CancellationToken)

Enqueues an event record on this stream and returns a System.Threading.Tasks.Task that completes once the event is reached (using a background thread to avoid blocking the thread-pool).

public Task SynchronizeAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task

WaitEvent(CudaEvent)

Makes this stream wait until event has been recorded. This is a GPU-side dependency — the CPU is not blocked.

public void WaitEvent(CudaEvent @event)

Parameters

event CudaEvent