Table of Contents

Class CudaStream

Namespace
JYPPX.CudaSharp
Assembly
JYPPX.CudaSharp.dll

Managed wrapper around a CUDA stream handle. CUDA stream 句柄的托管封装。

public sealed class CudaStream : IDisposable
Inheritance
CudaStream
Implements
Inherited Members

Constructors

CudaStream()

Creates a CUDA stream with default flags. 使用默认标志创建一个 CUDA stream。

public CudaStream()

CudaStream(CudaStreamCreationFlags)

Creates a CUDA stream with explicit creation flags. 使用显式创建标志创建一个 CUDA stream。

public CudaStream(CudaStreamCreationFlags flags)

Parameters

flags CudaStreamCreationFlags

The stream-creation flags. stream 创建标志。

CudaStream(CudaStreamCreationFlags, int)

Creates a CUDA stream with explicit flags and priority. 使用显式标志和优先级创建一个 CUDA stream。

public CudaStream(CudaStreamCreationFlags flags, int priority)

Parameters

flags CudaStreamCreationFlags

The stream-creation flags. stream 创建标志。

priority int

The CUDA stream priority. CUDA stream 优先级。

Properties

CaptureStatus

Gets the current CUDA graph-capture status for this stream. 获取当前 stream 的 CUDA graph 捕获状态。

public CudaStreamCaptureStatus CaptureStatus { get; }

Property Value

CudaStreamCaptureStatus

DeviceOrdinal

Gets the device ordinal associated with this stream when supported by the CUDA runtime. 在 CUDA runtime 支持时,获取该 stream 关联的设备序号。

public int DeviceOrdinal { get; }

Property Value

int

Flags

Gets the CUDA flags associated with this stream. 获取当前 stream 关联的 CUDA 标志。

public CudaStreamCreationFlags Flags { get; }

Property Value

CudaStreamCreationFlags

Id

Gets the CUDA runtime stream id when the bridge was built with CUDA 12.0 or later. 当桥接库使用 CUDA 12.0 或更高版本构建时,获取 CUDA runtime stream id。

public ulong Id { get; }

Property Value

ulong

Priority

Gets the CUDA priority associated with this stream. 获取当前 stream 关联的 CUDA 优先级。

public int Priority { get; }

Property Value

int

Methods

BeginCapture(CudaStreamCaptureMode)

Begins CUDA graph capture on this stream. 在当前 stream 上开始 CUDA graph capture。

public void BeginCapture(CudaStreamCaptureMode mode = CudaStreamCaptureMode.Global)

Parameters

mode CudaStreamCaptureMode

The capture-validation mode. capture 校验模式。

CopyAttributesFrom(CudaStream)

Copies stream attributes from another CUDA stream into this stream. 将另一个 CUDA stream 的属性复制到当前 stream。

public void CopyAttributesFrom(CudaStream source)

Parameters

source CudaStream

The source stream whose attributes should be copied. 要复制属性的源 stream。

Dispose()

Releases the CUDA stream handle. 释放 CUDA stream 句柄。

public void Dispose()

EndCapture()

Ends CUDA graph capture and returns the captured graph. 结束 CUDA graph capture 并返回捕获得到的 graph。

public CudaGraph EndCapture()

Returns

CudaGraph

The captured CUDA graph. 捕获得到的 CUDA graph。

ExchangeThreadCaptureMode(CudaStreamCaptureMode)

Exchanges the per-thread CUDA stream-capture mode and returns the previous mode. 交换当前线程的 CUDA stream capture mode,并返回交换前的模式。

public static CudaStreamCaptureMode ExchangeThreadCaptureMode(CudaStreamCaptureMode mode)

Parameters

mode CudaStreamCaptureMode

The mode to install for the current thread. 要设置到当前线程的模式。

Returns

CudaStreamCaptureMode

The previous CUDA stream-capture mode. 之前的 CUDA stream capture mode。

GetCaptureInfo()

Gets CUDA graph-capture metadata for this stream. 获取当前 stream 的 CUDA graph 捕获元数据。

public CudaStreamCaptureInfo GetCaptureInfo()

Returns

CudaStreamCaptureInfo

The current capture status and capture id. 当前捕获状态和捕获 ID。

GetPriorityRange()

Gets the supported CUDA stream-priority range for the current device. 获取当前设备支持的 CUDA stream 优先级范围。

public static CudaStreamPriorityRange GetPriorityRange()

Returns

CudaStreamPriorityRange

The stream-priority range. stream 优先级范围。

IsReady()

Returns whether all queued work on this stream has completed. 返回当前 stream 上排队的工作是否已全部完成。

public bool IsReady()

Returns

bool

true when the stream is ready. 当 stream 已就绪时返回 true

MeasureElapsedTime(Action<CudaStream>)

Measures elapsed GPU time for work submitted to this stream. 测量提交到当前 stream 的工作所消耗的 GPU 时间。

public float MeasureElapsedTime(Action<CudaStream> submitWork)

Parameters

submitWork Action<CudaStream>

The delegate that submits CUDA work to this stream. 向当前 stream 提交 CUDA 工作的委托。

Returns

float

The elapsed GPU time in milliseconds. GPU 经过时间,单位为毫秒。

Synchronize()

Blocks the calling thread until this stream completes. 阻塞调用线程,直到当前 stream 完成。

public void Synchronize()

TryGetCaptureInfo(out CudaStreamCaptureInfo, out string)

Tries to read CUDA graph-capture metadata without throwing when the runtime or symbol is unavailable. 在 CUDA runtime 或相关符号不可用时以诊断字符串返回失败,而不是抛出异常。

public bool TryGetCaptureInfo(out CudaStreamCaptureInfo captureInfo, out string diagnostic)

Parameters

captureInfo CudaStreamCaptureInfo

The capture metadata when the query succeeds. 查询成功时返回的 capture 元数据。

diagnostic string

An empty string on success, or the CUDA bridge diagnostic on failure. 成功时为空字符串,失败时为 CUDA 桥接诊断。

Returns

bool

true when capture metadata was read successfully. 成功读取 capture 元数据时返回 true

WaitFor(CudaEvent)

Inserts a wait on a CUDA event into this stream. 在当前 stream 中插入对 CUDA event 的等待。

public void WaitFor(CudaEvent cudaEvent)

Parameters

cudaEvent CudaEvent

The event to wait on. 要等待的 event。