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 校验模式。

BeginCaptureToGraph(CudaGraph, IReadOnlyList<CudaGraphNodeDependency>, CudaStreamCaptureMode)

Begins capture into an existing graph and returns an owner-scoped session. 将 capture 写入已有 graph,并返回 owner-scoped session。

public CudaStreamCaptureToGraphSession BeginCaptureToGraph(CudaGraph graph, IReadOnlyList<CudaGraphNodeDependency> dependencies, CudaStreamCaptureMode mode = CudaStreamCaptureMode.Global)

Parameters

graph CudaGraph

The graph that remains the owner after End. End 后继续拥有该 graph 的对象。

dependencies IReadOnlyList<CudaGraphNodeDependency>

Graph-owned dependency nodes and copied edge data. graph-owned dependency 节点及复制型 edge data。

mode CudaStreamCaptureMode

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

Returns

CudaStreamCaptureToGraphSession

A session that must be ended before the stream or graph is disposed. 必须在 stream 或 graph dispose 前结束的 session。

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。

EnqueueDelay(int)

Enqueues a bridge-owned delay in this CUDA stream. 在当前 CUDA stream 中排入由桥接层持有的延迟。

public void EnqueueDelay(int milliseconds)

Parameters

milliseconds int

The non-negative delay in milliseconds. 非负延迟毫秒数。

Remarks

The delay is ordered with other stream work and does not expose a managed callback or borrowed callback state. 延迟与其他 stream 工作保持顺序,且不会暴露托管回调或借用的回调状态。

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。

GetCaptureInfoPtzs()

Gets the scalar capture metadata from CUDA's per-thread stream variant. 获取 CUDA per-thread stream 变体返回的标量 capture 元数据。

public CudaStreamCaptureScalarInfo GetCaptureInfoPtzs()

Returns

CudaStreamCaptureScalarInfo

Remarks

The vendor ptsz entry point reports only status and id; graph and dependency outputs are not part of this API. vendor ptsz 入口只报告 status 和 id;graph 与 dependency 输出不属于该 API。

GetDevResourceSnapshot(CudaDevResourceType)

Gets a pointer-free CUDA 13 resource snapshot associated with this stream. 获取与此 stream 关联的 CUDA 13 资源无指针快照。

public CudaDevResourceSnapshot GetDevResourceSnapshot(CudaDevResourceType resourceType)

Parameters

resourceType CudaDevResourceType

Returns

CudaDevResourceSnapshot

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。

TryGetCaptureInfoPtzs(out CudaStreamCaptureScalarInfo, out string)

Tries to read scalar capture metadata from CUDA's per-thread stream variant. 尝试读取 CUDA per-thread stream 变体返回的标量 capture 元数据。

public bool TryGetCaptureInfoPtzs(out CudaStreamCaptureScalarInfo captureInfo, out string diagnostic)

Parameters

captureInfo CudaStreamCaptureScalarInfo
diagnostic string

Returns

bool

UpdateCaptureDependencies(IReadOnlyList<CudaGraphNode>, CudaStreamCaptureDependencyMode)

Adds or replaces the dependency set used by the next operation in an active stream capture. 在 active stream capture 中追加或替换下一项操作使用的 dependency set。

public void UpdateCaptureDependencies(IReadOnlyList<CudaGraphNode> dependencies, CudaStreamCaptureDependencyMode mode = CudaStreamCaptureDependencyMode.Add)

Parameters

dependencies IReadOnlyList<CudaGraphNode>
mode CudaStreamCaptureDependencyMode

UpdateCaptureDependenciesPtzs(IReadOnlyList<CudaGraphNode>, CudaStreamCaptureDependencyMode)

Adds or replaces dependencies through CUDA's per-thread stream variant. 通过 CUDA per-thread stream 变体追加或替换依赖。

public void UpdateCaptureDependenciesPtzs(IReadOnlyList<CudaGraphNode> dependencies, CudaStreamCaptureDependencyMode mode = CudaStreamCaptureDependencyMode.Add)

Parameters

dependencies IReadOnlyList<CudaGraphNode>
mode CudaStreamCaptureDependencyMode

UpdateCaptureDependenciesV2(IReadOnlyList<CudaGraphNodeDependency>, CudaStreamCaptureDependencyMode)

Adds or replaces dependencies with copied CUDA graph edge data. 使用复制型 CUDA graph edge data 追加或替换依赖。

public void UpdateCaptureDependenciesV2(IReadOnlyList<CudaGraphNodeDependency> dependencies, CudaStreamCaptureDependencyMode mode = CudaStreamCaptureDependencyMode.Add)

Parameters

dependencies IReadOnlyList<CudaGraphNodeDependency>
mode CudaStreamCaptureDependencyMode

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。