Class CudaDevice
Provides current-device helpers over the CUDA runtime. 提供 CUDA runtime 当前设备相关 helper。
public static class CudaDevice
- Inheritance
-
CudaDevice
- Inherited Members
Properties
CacheConfig
Gets the current process-wide CUDA device cache preference. 获取当前进程级 CUDA device cache 偏好。
public static CudaFunctionCachePreference CacheConfig { get; set; }
Property Value
Count
Gets the number of CUDA devices visible to the current process. 获取当前进程可见的 CUDA 设备数量。
public static int Count { get; }
Property Value
Current
Gets the current CUDA device ordinal for the process. 获取当前进程的 CUDA 当前设备序号。
public static int Current { get; }
Property Value
CurrentGraphMemoryInfo
Gets CUDA graph-memory allocator counters for the current device. 获取当前设备的 CUDA graph memory 分配器计数。
public static CudaDeviceGraphMemoryInfo CurrentGraphMemoryInfo { get; }
Property Value
CurrentProperties
Gets a deployment-oriented property snapshot for the current CUDA device. 获取当前 CUDA 设备面向模型部署的属性快照。
public static CudaDeviceProperties CurrentProperties { get; }
Property Value
DriverVersion
Gets the CUDA driver version reported by the bridge. 获取桥接层报告的 CUDA driver 版本。
public static int DriverVersion { get; }
Property Value
RuntimeFlags
Gets or sets CUDA runtime device flags used by the current process. 获取或设置当前进程使用的 CUDA runtime device flags。
public static CudaDeviceRuntimeFlags RuntimeFlags { get; set; }
Property Value
Remarks
Set this before creating a CUDA context when you need mapped host memory or a specific scheduling policy. 如果需要 mapped host memory 或特定调度策略,应在创建 CUDA context 前设置。
RuntimeVersion
Gets the CUDA runtime version reported by the bridge. 获取桥接层报告的 CUDA runtime 版本。
public static int RuntimeVersion { get; }
Property Value
SharedMemoryConfig
Gets or sets the CUDA shared-memory bank configuration for compatible devices. 获取或设置兼容设备上的 CUDA shared-memory bank 配置。
public static CudaSharedMemoryConfig SharedMemoryConfig { get; set; }
Property Value
Methods
CanAccessPeer(int, int)
Gets whether one CUDA device can access another through peer access. 获取一个 CUDA 设备是否可以通过 peer access 访问另一个设备。
public static bool CanAccessPeer(int ordinal, int peerOrdinal)
Parameters
ordinalintThe source CUDA device ordinal. 源 CUDA 设备序号。
peerOrdinalintThe peer CUDA device ordinal. 对端 CUDA 设备序号。
Returns
DisablePeerAccess(int)
Disables peer access from the current device to the specified peer device. 关闭当前设备到指定 peer 设备的 peer access。
public static void DisablePeerAccess(int peerOrdinal)
Parameters
peerOrdinalintThe peer CUDA device ordinal. 对端 CUDA 设备序号。
EnablePeerAccess(int)
Enables peer access from the current device to the specified peer device. 启用当前设备到指定 peer 设备的 peer access。
public static void EnablePeerAccess(int peerOrdinal)
Parameters
peerOrdinalintThe peer CUDA device ordinal. 对端 CUDA 设备序号。
FlushGpuDirectRdmaWrites(CudaGpuDirectRdmaWritesTarget, CudaGpuDirectRdmaWritesScope)
Flushes GPU Direct RDMA writes for the selected target and scope. 为指定目标与范围刷新 GPU Direct RDMA 写入。
public static void FlushGpuDirectRdmaWrites(CudaGpuDirectRdmaWritesTarget target, CudaGpuDirectRdmaWritesScope scope)
Parameters
targetCudaGpuDirectRdmaWritesTargetThe RDMA target to flush. 要刷新的 RDMA 目标。
scopeCudaGpuDirectRdmaWritesScopeThe RDMA visibility scope. RDMA 可见性范围。
GetAttribute(int, CudaDeviceAttribute)
Gets a raw CUDA device attribute value. 获取原始 CUDA 设备属性值。
public static int GetAttribute(int ordinal, CudaDeviceAttribute attribute)
Parameters
ordinalintThe CUDA device ordinal. CUDA 设备序号。
attributeCudaDeviceAttributeThe device attribute to query. 要查询的设备属性。
Returns
- int
The raw CUDA attribute value. 原始 CUDA 属性值。
GetBooleanAttribute(int, CudaDeviceAttribute)
Gets a CUDA device attribute as a boolean capability. 将 CUDA 设备属性读取为布尔能力值。
public static bool GetBooleanAttribute(int ordinal, CudaDeviceAttribute attribute)
Parameters
ordinalintThe CUDA device ordinal. CUDA 设备序号。
attributeCudaDeviceAttributeThe device attribute to query. 要查询的设备属性。
Returns
GetByPciBusId(string)
Resolves a CUDA device ordinal from a PCI bus id string. 根据 PCI bus id 字符串解析 CUDA 设备序号。
public static int GetByPciBusId(string pciBusId)
Parameters
pciBusIdstringThe PCI bus id reported by CUDA. CUDA 返回的 PCI bus id。
Returns
- int
The CUDA device ordinal. CUDA 设备序号。
GetCurrentMemoryPool(int)
Gets the current CUDA memory pool for a device. 获取指定设备当前使用的 CUDA memory pool。
public static CudaMemoryPool GetCurrentMemoryPool(int ordinal)
Parameters
ordinalintThe CUDA device ordinal. CUDA 设备序号。
Returns
- CudaMemoryPool
The current memory pool wrapper. 当前 memory pool 封装。
GetDefaultMemoryPool(int)
Gets the default CUDA memory pool for a device. 获取指定设备的默认 CUDA memory pool。
public static CudaMemoryPool GetDefaultMemoryPool(int ordinal)
Parameters
ordinalintThe CUDA device ordinal. CUDA 设备序号。
Returns
- CudaMemoryPool
The default memory pool wrapper. 默认 memory pool 封装。
GetErrorName(int)
Gets the symbolic CUDA error name for an error code. 获取某个错误码对应的 CUDA 符号名。
public static string GetErrorName(int errorCode)
Parameters
errorCodeintThe CUDA error code. CUDA 错误码。
Returns
- string
The CUDA symbolic error name. CUDA 符号错误名。
GetErrorString(int)
Gets the human-readable CUDA error string for an error code. 获取某个错误码对应的 CUDA 可读错误描述。
public static string GetErrorString(int errorCode)
Parameters
errorCodeintThe CUDA error code. CUDA 错误码。
Returns
- string
The CUDA error description. CUDA 错误描述。
GetGraphMemoryAttribute(int, CudaGraphMemoryAttribute)
Gets a CUDA graph-memory allocator attribute for a device. 获取指定设备的 CUDA graph memory 分配器属性。
public static ulong GetGraphMemoryAttribute(int ordinal, CudaGraphMemoryAttribute attribute)
Parameters
ordinalintThe CUDA device ordinal. CUDA 设备序号。
attributeCudaGraphMemoryAttributeThe graph-memory attribute to query. 要查询的 graph memory 属性。
Returns
- ulong
The attribute value in bytes. 以字节表示的属性值。
GetGraphMemoryInfo(int)
Gets all CUDA graph-memory allocator counters for a device. 获取指定设备的全部 CUDA graph memory 分配器计数。
public static CudaDeviceGraphMemoryInfo GetGraphMemoryInfo(int ordinal)
Parameters
ordinalintThe CUDA device ordinal. CUDA 设备序号。
Returns
- CudaDeviceGraphMemoryInfo
A graph-memory allocator snapshot. Graph memory 分配器快照。
GetInfo(int)
Gets a basic CUDA device information snapshot. 获取基础 CUDA 设备信息快照。
public static CudaDeviceInfo GetInfo(int ordinal)
Parameters
ordinalintThe CUDA device ordinal. CUDA 设备序号。
Returns
- CudaDeviceInfo
The mapped CUDA device information. 已映射的 CUDA 设备信息。
GetLastErrorCode()
Gets and clears the last CUDA error code. 获取并清除最近一次 CUDA 错误码。
public static int GetLastErrorCode()
Returns
- int
The last CUDA error code. 最近一次 CUDA 错误码。
GetLimit(CudaDeviceLimit)
Gets a CUDA runtime device limit for the current process. 获取当前进程的 CUDA runtime device limit。
public static ulong GetLimit(CudaDeviceLimit limit)
Parameters
limitCudaDeviceLimitThe CUDA device limit to query. 要查询的 CUDA device limit。
Returns
- ulong
The configured limit value in bytes or CUDA-defined units. 以字节或 CUDA 定义单位表示的 limit 值。
GetMemoryInfo()
Gets free and total memory information for the current CUDA device. 获取当前 CUDA 设备的空闲与总显存信息。
public static CudaMemoryInfo GetMemoryInfo()
Returns
- CudaMemoryInfo
The current CUDA memory information snapshot. 当前 CUDA 显存信息快照。
GetMemoryPressureSnapshot()
Gets a CUDA memory pressure snapshot for the current device. 获取当前 CUDA 设备的显存压力快照。
public static CudaMemoryPressureSnapshot GetMemoryPressureSnapshot()
Returns
- CudaMemoryPressureSnapshot
A memory pressure snapshot for deployment diagnostics. 用于部署诊断的显存压力快照。
GetP2PAttribute(CudaDeviceP2PAttribute, int, int)
Gets a CUDA peer-to-peer attribute for a pair of devices. 获取两个 CUDA 设备之间的 peer-to-peer 属性。
public static int GetP2PAttribute(CudaDeviceP2PAttribute attribute, int sourceOrdinal, int destinationOrdinal)
Parameters
attributeCudaDeviceP2PAttributeThe CUDA P2P attribute to query. 要查询的 CUDA P2P 属性。
sourceOrdinalintThe source CUDA device ordinal. 源 CUDA 设备序号。
destinationOrdinalintThe destination CUDA device ordinal. 目标 CUDA 设备序号。
Returns
- int
The raw CUDA attribute value. CUDA 返回的原始属性值。
GetPciBusId(int)
Gets the PCI bus id string for a CUDA device. 获取 CUDA 设备的 PCI bus id 字符串。
public static string GetPciBusId(int ordinal)
Parameters
ordinalintThe CUDA device ordinal. CUDA 设备序号。
Returns
- string
The PCI bus id reported by CUDA, such as
0000:65:00.0. CUDA 返回的 PCI bus id。
GetProperties(int)
Gets a deployment-oriented property snapshot for a CUDA device. 获取面向模型部署的 CUDA 设备属性快照。
public static CudaDeviceProperties GetProperties(int ordinal)
Parameters
ordinalintThe CUDA device ordinal. CUDA 设备序号。
Returns
- CudaDeviceProperties
A high-level CUDA device property snapshot. 高层 CUDA 设备属性快照。
GetTexture1DLinearMaxWidth(CudaChannelFormatDescriptor, int)
Gets the maximum linear texture width supported for the specified descriptor. 获取指定通道描述符支持的最大 linear texture 宽度。
public static ulong GetTexture1DLinearMaxWidth(CudaChannelFormatDescriptor descriptor, int ordinal)
Parameters
descriptorCudaChannelFormatDescriptorThe CUDA channel descriptor. CUDA 通道描述符。
ordinalintThe CUDA device ordinal. CUDA 设备序号。
Returns
- ulong
The maximum width in bytes or CUDA-defined units. 以字节或 CUDA 定义单位表示的最大宽度。
PeekAtLastErrorCode()
Gets the last CUDA error code without clearing it. 获取最近一次 CUDA 错误码,但不清除。
public static int PeekAtLastErrorCode()
Returns
- int
The last CUDA error code. 最近一次 CUDA 错误码。
Reset()
Resets the current CUDA device. 重置当前 CUDA 设备。
public static void Reset()
ResetGraphMemoryHighWatermark(int, CudaGraphMemoryAttribute)
Resets one CUDA graph-memory high-watermark counter to zero. 将一个 CUDA graph memory 峰值计数器重置为零。
public static void ResetGraphMemoryHighWatermark(int ordinal, CudaGraphMemoryAttribute attribute)
Parameters
ordinalintThe CUDA device ordinal. CUDA 设备序号。
attributeCudaGraphMemoryAttributeThe high-watermark attribute to reset. 要重置的峰值属性。
ResetGraphMemoryHighWatermarks(int)
Resets both CUDA graph-memory high-watermark counters to zero. 将两个 CUDA graph memory 峰值计数器都重置为零。
public static void ResetGraphMemoryHighWatermarks(int ordinal)
Parameters
ordinalintThe CUDA device ordinal. CUDA 设备序号。
ResetPersistingL2Cache()
Resets the persisting L2 cache state for the current device. 重置当前设备的 persisting L2 cache 状态。
public static void ResetPersistingL2Cache()
SetCurrent(int)
Sets the current CUDA device for the process. 为当前进程设置 CUDA 当前设备。
public static void SetCurrent(int ordinal)
Parameters
ordinalintThe CUDA device ordinal. CUDA 设备序号。
SetCurrentMemoryPool(CudaMemoryPool)
Sets the current CUDA memory pool for the memory pool's device. 为该 memory pool 所属设备设置当前 CUDA memory pool。
public static void SetCurrentMemoryPool(CudaMemoryPool memoryPool)
Parameters
memoryPoolCudaMemoryPoolThe memory pool to make current. 要设置为当前池的 memory pool。
SetLimit(CudaDeviceLimit, ulong)
Sets a CUDA runtime device limit for the current process. 设置当前进程的 CUDA runtime device limit。
public static void SetLimit(CudaDeviceLimit limit, ulong value)
Parameters
limitCudaDeviceLimitThe CUDA device limit to update. 要更新的 CUDA device limit。
valueulongThe new limit value in bytes or CUDA-defined units. 以字节或 CUDA 定义单位表示的新 limit 值。
Synchronize()
Synchronizes the current CUDA device. 同步当前 CUDA 设备。
public static void Synchronize()
TrimGraphMemory(int)
Trims graph-memory allocations cached by CUDA for a device. 裁剪 CUDA 为指定设备缓存的 graph memory 分配。
public static void TrimGraphMemory(int ordinal)
Parameters
ordinalintThe CUDA device ordinal. CUDA 设备序号。
TryGetAttribute(int, CudaDeviceAttribute)
Tries to read a CUDA device attribute without failing the whole capability snapshot. 尝试读取 CUDA device attribute,不会因为单个 attribute 不可用而中断整个能力快照。
public static int? TryGetAttribute(int ordinal, CudaDeviceAttribute attribute)
Parameters
ordinalintattributeCudaDeviceAttribute
Returns
- int?
TryGetBooleanAttribute(int, CudaDeviceAttribute)
Tries to read a CUDA device attribute as a boolean capability. 尝试把 CUDA device attribute 读取为布尔能力。
public static bool? TryGetBooleanAttribute(int ordinal, CudaDeviceAttribute attribute)
Parameters
ordinalintattributeCudaDeviceAttribute
Returns
- bool?
TryGetMemoryInfo(out CudaMemoryInfo?, out string)
Tries to read CUDA memory information without throwing when the runtime is unavailable. 在 CUDA runtime 不可用时以诊断字符串返回失败,而不是抛出异常。
public static bool TryGetMemoryInfo(out CudaMemoryInfo? memoryInfo, out string diagnostic)
Parameters
memoryInfoCudaMemoryInfoThe memory information when the query succeeds. 查询成功时返回的显存信息。
diagnosticstringAn empty string on success, or the CUDA bridge diagnostic on failure. 成功时为空字符串,失败时为 CUDA 桥接诊断。
Returns
- bool
truewhen memory information was read successfully. 成功读取显存信息时返回true。
Use(int)
Temporarily switches the current CUDA device and restores the previous device on dispose. 临时切换当前 CUDA 设备,并在释放时恢复之前的设备。
public static CudaDeviceScope Use(int ordinal)
Parameters
ordinalintThe CUDA device ordinal to activate. 要激活的 CUDA 设备序号。
Returns
- CudaDeviceScope
A disposable scope that restores the previous device. 可恢复之前设备的可释放作用域。