6.5. 设备管理

本节介绍底层CUDA驱动应用程序编程接口的设备管理功能。

Functions

CUresult cuDeviceGet ( CUdevice* device, int  ordinal )
Returns a handle to a compute device.
CUresult cuDeviceGetAttribute ( int* pi, CUdevice_attribute attrib, CUdevice dev )
Returns information about the device.
CUresult cuDeviceGetCount ( int* count )
Returns the number of compute-capable devices.
CUresult cuDeviceGetDefaultMemPool ( CUmemoryPool* pool_out, CUdevice dev )
Returns the default mempool of a device.
CUresult cuDeviceGetExecAffinitySupport ( int* pi, CUexecAffinityType type, CUdevice dev )
Returns information about the execution affinity support of the device.
CUresult cuDeviceGetLuid ( char* luid, unsigned int* deviceNodeMask, CUdevice dev )
Return an LUID and device node mask for the device.
CUresult cuDeviceGetMemPool ( CUmemoryPool* pool, CUdevice dev )
Gets the current mempool for a device.
CUresult cuDeviceGetName ( char* name, int  len, CUdevice dev )
Returns an identifier string for the device.
CUresult cuDeviceGetNvSciSyncAttributes ( void* nvSciSyncAttrList, CUdevice dev, int  flags )
Return NvSciSync attributes that this device can support.
CUresult cuDeviceGetTexture1DLinearMaxWidth ( size_t* maxWidthInElements, CUarray_format format, unsigned numChannels, CUdevice dev )
Returns the maximum number of elements allocatable in a 1D linear texture for a given texture element size.
CUresult cuDeviceGetUuid ( CUuuid* uuid, CUdevice dev )
Return an UUID for the device.
CUresult cuDeviceGetUuid_v2 ( CUuuid* uuid, CUdevice dev )
Return an UUID for the device (11.4+).
CUresult cuDeviceSetMemPool ( CUdevice dev, CUmemoryPool pool )
Sets the current memory pool of a device.
CUresult cuDeviceTotalMem ( size_t* bytes, CUdevice dev )
Returns the total amount of memory on the device.
CUresult cuFlushGPUDirectRDMAWrites ( CUflushGPUDirectRDMAWritesTarget target, CUflushGPUDirectRDMAWritesScope scope )
Blocks until remote writes are visible to the specified scope.

Functions

CUresult cuDeviceGet ( CUdevice* device, int  ordinal )
返回计算设备的句柄。
参数
device
- Returned device handle
ordinal
- Device number to get handle for
描述

在给定范围[0, cuDeviceGetCount()-1]内的序号时,返回*device中的设备句柄。

Note:

请注意,此函数也可能返回之前异步启动的错误代码。

另请参阅:

cuDeviceGetAttribute, cuDeviceGetCount, cuDeviceGetName, cuDeviceGetUuid, cuDeviceGetLuid, cuDeviceTotalMem, cuDeviceGetExecAffinitySupport

CUresult cuDeviceGetAttribute ( int* pi, CUdevice_attribute attrib, CUdevice dev )
返回有关设备的信息。
参数
pi
- Returned device attribute value
attrib
- Device attribute to query
dev
- Device handle
描述

返回设备dev上属性attrib的整数值到*pi中。支持的属性包括:

Note:

请注意,此函数也可能返回之前异步启动的错误代码。

另请参阅:

cuDeviceGetCount, cuDeviceGetName, cuDeviceGetUuid, cuDeviceGet, cuDeviceTotalMem, cuDeviceGetExecAffinitySupport, cudaDeviceGetAttribute, cudaGetDeviceProperties

CUresult cuDeviceGetCount ( int* count )
返回支持计算功能的设备数量。
参数
count
- Returned number of compute-capable devices
描述

返回*count中可用于执行且计算能力大于等于2.0的设备数量。如果没有此类设备,cuDeviceGetCount()将返回0。

Note:

请注意,此函数也可能返回之前异步启动的错误代码。

另请参阅:

cuDeviceGetAttribute, cuDeviceGetName, cuDeviceGetUuid, cuDeviceGetLuid, cuDeviceGet, cuDeviceTotalMem, cuDeviceGetExecAffinitySupport, cudaGetDeviceCount

CUresult cuDeviceGetDefaultMemPool ( CUmemoryPool* pool_out, CUdevice dev )
返回设备的默认内存池。
描述

设备的默认内存池包含来自该设备的设备内存。

Note:

请注意,此函数也可能返回之前异步启动的错误代码。

另请参阅:

cuMemAllocAsync, cuMemPoolTrimTo, cuMemPoolGetAttribute, cuMemPoolSetAttribute, cuMemPoolSetAccess, cuDeviceGetMemPool, cuMemPoolCreate

CUresult cuDeviceGetExecAffinitySupport ( int* pi, CUexecAffinityType type, CUdevice dev )
返回有关设备执行亲和性支持的信息。
参数
pi
- 1 if the execution affinity type type is supported by the device, or 0 if not
type
- Execution affinity type to query
dev
- Device handle
描述

返回在*pi中表示设备dev是否支持执行亲和类型type。支持的类型包括:

Note:

请注意,此函数也可能返回之前异步启动的错误代码。

另请参阅:

cuDeviceGetAttribute, cuDeviceGetCount, cuDeviceGetName, cuDeviceGetUuid, cuDeviceGet, cuDeviceTotalMem

CUresult cuDeviceGetLuid ( char* luid, unsigned int* deviceNodeMask, CUdevice dev )
返回设备的LUID和设备节点掩码。
参数
luid
- Returned LUID
deviceNodeMask
- Returned device node mask
dev
- Device to get identifier string for
描述

返回标识信息(luiddeviceNodeMask)以便将设备与图形API进行匹配。

Note:

请注意,此函数也可能返回之前异步启动的错误代码。

另请参阅:

cuDeviceGetAttribute, cuDeviceGetCount, cuDeviceGetName, cuDeviceGet, cuDeviceTotalMem, cuDeviceGetExecAffinitySupport, cudaGetDeviceProperties

CUresult cuDeviceGetMemPool ( CUmemoryPool* pool, CUdevice dev )
获取设备的当前内存池。
描述

返回为此设备提供的最后一个内存池(如果从未调用过cuDeviceSetMemPool则返回设备的默认内存池)。默认情况下当前内存池是设备的默认内存池。否则返回的池必须是通过cuDeviceSetMemPool设置的。

另请参阅:

cuDeviceGetDefaultMemPool, cuMemPoolCreate, cuDeviceSetMemPool

CUresult cuDeviceGetName ( char* name, int  len, CUdevice dev )
返回设备的标识符字符串。
参数
name
- Returned identifier string for the device
len
- Maximum length of string to store in name
dev
- Device to get identifier string for
描述

返回一个ASCII字符串,用于标识设备dev,该字符串以NULL结尾并由name指向。len指定可返回字符串的最大长度。

Note:

请注意,此函数也可能返回之前异步启动的错误代码。

另请参阅:

cuDeviceGetAttribute, cuDeviceGetUuid, cuDeviceGetLuid, cuDeviceGetCount, cuDeviceGet, cuDeviceTotalMem, cuDeviceGetExecAffinitySupport, cudaGetDeviceProperties

CUresult cuDeviceGetNvSciSyncAttributes ( void* nvSciSyncAttrList, CUdevice dev, int  flags )
返回该设备支持的NvSciSync属性。
参数
nvSciSyncAttrList
- Return NvSciSync attributes supported.
dev
- Valid Cuda Device to get NvSciSync attributes for.
flags
- flags describing NvSciSync usage.
描述

返回nvSciSyncAttrList中该CUDA设备dev支持的NvSciSync属性。返回的nvSciSyncAttrList可用于创建与该设备功能匹配的NvSciSync对象。

如果nvSciSyncAttrList中的NvSciSyncAttrKey_RequiredPerm字段已设置,此API将返回CUDA_ERROR_INVALID_VALUE

应用程序应将nvSciSyncAttrList设置为有效的NvSciSyncAttrList,否则此API将返回CUDA_ERROR_INVALID_HANDLE

flags 控制应用程序如何使用从 nvSciSyncAttrList 创建的 NvSciSync。有效的标志包括:

必须设置这些标志中的至少一个,否则API将返回CUDA_ERROR_INVALID_VALUE。这两个标志彼此独立:开发者可以同时设置这两个标志,从而允许在同一个nvSciSyncAttrList中设置等待和信号特定属性。

请注意,此API会使用以下公共属性键值等效的值更新输入nvSciSyncAttrList:NvSciSyncAttrKey_RequiredPerm被设置为

  • 如果flags中设置了CUDA_NVSCISYNC_ATTR_SIGNAL,则为NvSciSyncAccessPerm_SignalOnly权限。

  • NvSciSyncAccessPerm_WaitOnly 如果在flags中设置了CUDA_NVSCISYNC_ATTR_WAIT

  • 如果CUDA_NVSCISYNC_ATTR_WAITCUDA_NVSCISYNC_ATTR_SIGNAL都在flags中被设置,则使用NvSciSyncAccessPerm_WaitSignal。NvSciSyncAttrKey_PrimitiveInfo被设置为

  • 在任何有效的设备上使用NvSciSyncAttrValPrimitiveType_SysmemSemaphore。

  • 如果device是Tegra设备,则使用NvSciSyncAttrValPrimitiveType_Syncpoint。

  • 如果device是GA10X+,则使用NvSciSyncAttrValPrimitiveType_SysmemSemaphorePayload64b。NvSciSyncAttrKey_GpuId被设置为与通过cuDeviceGetUuid为此device返回的相同UUID。

CUDA_SUCCESS, CUDA_ERROR_DEINITIALIZED, CUDA_ERROR_NOT_INITIALIZED, CUDA_ERROR_INVALID_VALUE, CUDA_ERROR_INVALID_HANDLE, CUDA_ERROR_INVALID_DEVICE, CUDA_ERROR_NOT_SUPPORTED, CUDA_ERROR_OUT_OF_MEMORY

另请参阅:

cuImportExternalSemaphore, cuDestroyExternalSemaphore, cuSignalExternalSemaphoresAsync, cuWaitExternalSemaphoresAsync

CUresult cuDeviceGetTexture1DLinearMaxWidth ( size_t* maxWidthInElements, CUarray_format format, unsigned numChannels, CUdevice dev )
返回给定纹理元素大小下可在一维线性纹理中分配的最大元素数量。
参数
maxWidthInElements
- Returned maximum number of texture elements allocatable for given format and numChannels.
format
- Texture format.
numChannels
- Number of channels per texture element.
dev
- Device handle.
描述

返回在maxWidthInElements中,针对给定的formatnumChannels,可在一维线性纹理中分配的最大纹理元素数量。

Note:

请注意,此函数也可能返回之前异步启动的错误代码。

另请参阅:

cuDeviceGetAttribute, cuDeviceGetCount, cuDeviceGetName, cuDeviceGetUuid, cuDeviceGet, cudaMemGetInfo, cuDeviceTotalMem

CUresult cuDeviceGetUuid ( CUuuid* uuid, CUdevice dev )
返回设备的UUID。
参数
uuid
- Returned UUID
dev
- Device to get identifier string for
描述

请注意此API有一个更新的版本cuDeviceGetUuid_v2。它将在12.0版本中取代当前版本,当前版本保留是为了保持小版本兼容性。

返回16字节标识符,用于在uuid指针指向的结构中标识设备dev

Note:

请注意,此函数也可能返回之前异步启动的错误代码。

另请参阅:

cuDeviceGetUuid_v2cuDeviceGetAttribute, cuDeviceGetCount, cuDeviceGetName, cuDeviceGetLuid, cuDeviceGet, cuDeviceTotalMem, cuDeviceGetExecAffinitySupport, cudaGetDeviceProperties

CUresult cuDeviceGetUuid_v2 ( CUuuid* uuid, CUdevice dev )
返回设备的UUID(11.4+版本)。
参数
uuid
- Returned UUID
dev
- Device to get identifier string for
描述

返回16字节的标识符,用于在uuid指针指向的结构中识别设备dev。如果设备处于MIG模式,则返回其MIG UUID,该UUID唯一标识订阅的MIG计算实例。

Note:

请注意,此函数也可能返回之前异步启动的错误代码。

另请参阅:

cuDeviceGetAttribute, cuDeviceGetCount, cuDeviceGetName, cuDeviceGetLuid, cuDeviceGet, cuDeviceTotalMem, cudaGetDeviceProperties

CUresult cuDeviceSetMemPool ( CUdevice dev, CUmemoryPool pool )
设置设备的当前内存池。
描述

内存池必须位于指定设备本地。cuMemAllocAsync会从提供流所在设备的当前内存池中分配内存。默认情况下,设备的当前内存池就是其默认内存池。

Note:

使用cuMemAllocFromPoolAsync可以从与流运行设备不同的设备上指定异步分配。

另请参阅:

cuDeviceGetDefaultMemPool, cuDeviceGetMemPool, cuMemPoolCreate, cuMemPoolDestroy, cuMemAllocFromPoolAsync

CUresult cuDeviceTotalMem ( size_t* bytes, CUdevice dev )
返回设备上的内存总量。
参数
bytes
- Returned memory available on device in bytes
dev
- Device handle
描述

返回设备dev上可用的总内存量(以字节为单位),结果存储在*bytes中。

Note:

请注意,此函数也可能返回之前异步启动的错误代码。

另请参阅:

cuDeviceGetAttribute, cuDeviceGetCount, cuDeviceGetName, cuDeviceGetUuid, cuDeviceGet, cuDeviceGetExecAffinitySupport, cudaMemGetInfo

CUresult cuFlushGPUDirectRDMAWrites ( CUflushGPUDirectRDMAWritesTarget target, CUflushGPUDirectRDMAWritesScope scope )
阻塞直到远程写入对指定范围可见。
参数
target
- The target of the operation, see CUflushGPUDirectRDMAWritesTarget
scope
- The scope of the operation, see CUflushGPUDirectRDMAWritesScope
描述

阻塞直到通过类似nvidia_p2p_get_pages等API创建的映射(详见https://docs.nvidia.com/cuda/gpudirect-rdma)对目标上下文执行的GPUDirect RDMA写入操作,在指定范围内可见。

如果作用域等于或位于CU_DEVICE_ATTRIBUTE_GPU_DIRECT_RDMA_WRITES_ORDERING指定的范围内,则该调用将是无操作,可以安全地省略以提高性能。这可以通过比较两个枚举的数值来确定,其中较小作用域对应的数值也更小。

在支持通过硬件中多个路径进行GPUDirect RDMA写入的平台上(参见CU_MEM_RANGE_FLAG_DMA_BUF_MAPPING_TYPE_PCIE),用户应将这些路径视为属于不同的排序域。请注意,在这种情况下,CUDA驱动程序会将RDMA写入排序和RDMA写入范围都报告为ALL_DEVICES,并且调用cuFlushGPUDirectRDMA将无效,但当同时使用这些多个路径时,用户有责任通过CUDA范围之外的机制来确保排序。

用户可以通过CU_DEVICE_ATTRIBUTE_FLUSH_FLUSH_GPU_DIRECT_RDMA_OPTIONS查询该API的支持情况。

Note:

请注意,此函数也可能返回之前异步启动的错误代码。