Class CudaStream
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
flagsCudaStreamCreationFlagsThe 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
flagsCudaStreamCreationFlagsThe stream-creation flags. stream 创建标志。
priorityintThe 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
DeviceOrdinal
Gets the device ordinal associated with this stream when supported by the CUDA runtime. 在 CUDA runtime 支持时,获取该 stream 关联的设备序号。
public int DeviceOrdinal { get; }
Property Value
Flags
Gets the CUDA flags associated with this stream. 获取当前 stream 关联的 CUDA 标志。
public CudaStreamCreationFlags Flags { get; }
Property Value
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
Priority
Gets the CUDA priority associated with this stream. 获取当前 stream 关联的 CUDA 优先级。
public int Priority { get; }
Property Value
Methods
BeginCapture(CudaStreamCaptureMode)
Begins CUDA graph capture on this stream. 在当前 stream 上开始 CUDA graph capture。
public void BeginCapture(CudaStreamCaptureMode mode = CudaStreamCaptureMode.Global)
Parameters
modeCudaStreamCaptureModeThe 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
sourceCudaStreamThe 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
modeCudaStreamCaptureModeThe 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
MeasureElapsedTime(Action<CudaStream>)
Measures elapsed GPU time for work submitted to this stream. 测量提交到当前 stream 的工作所消耗的 GPU 时间。
public float MeasureElapsedTime(Action<CudaStream> submitWork)
Parameters
submitWorkAction<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
captureInfoCudaStreamCaptureInfoThe capture metadata when the query succeeds. 查询成功时返回的 capture 元数据。
diagnosticstringAn empty string on success, or the CUDA bridge diagnostic on failure. 成功时为空字符串,失败时为 CUDA 桥接诊断。
Returns
- bool
truewhen 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
cudaEventCudaEventThe event to wait on. 要等待的 event。