6.31. 对等上下文内存访问

本节介绍CUDA底层驱动应用程序编程接口的直接对等上下文内存访问函数。

Functions

CUresult cuCtxDisablePeerAccess ( CUcontext peerContext )
Disables direct access to memory allocations in a peer context and unregisters any registered allocations.
CUresult cuCtxEnablePeerAccess ( CUcontext peerContext, unsigned int  Flags )
Enables direct access to memory allocations in a peer context.
CUresult cuDeviceCanAccessPeer ( int* canAccessPeer, CUdevice dev, CUdevice peerDev )
Queries if a device may directly access a peer device's memory.
CUresult cuDeviceGetP2PAttribute ( int* value, CUdevice_P2PAttribute attrib, CUdevice srcDevice, CUdevice dstDevice )
Queries attributes of the link between two devices.

Functions

CUresult cuCtxDisablePeerAccess ( CUcontext peerContext )
禁用对等上下文中内存分配的直接访问,并取消注册任何已注册的分配。
参数
peerContext
- Peer context to disable direct access to
描述

如果尚未从peerContext到当前上下文启用直接对等访问,则返回CUDA_ERROR_PEER_ACCESS_NOT_ENABLED

如果没有当前上下文,或者peerContext不是有效上下文,则返回CUDA_ERROR_INVALID_CONTEXT

Note:

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

另请参阅:

cuDeviceCanAccessPeer, cuCtxEnablePeerAccess, cudaDeviceDisablePeerAccess

CUresult cuCtxEnablePeerAccess ( CUcontext peerContext, unsigned int  Flags )
支持直接访问对等上下文中的内存分配。
参数
peerContext
- Peer context to enable direct access to from the current context
Flags
- Reserved for future use and must be set to 0
描述

如果当前上下文和peerContext所在的设备都支持统一寻址(可通过CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING查询)且具有相同的主计算能力,那么成功后,当前上下文将立即能够访问peerContext中的所有分配。更多详情请参阅Unified Addressing

请注意,此调用授予的访问权限是单向的,为了在peerContext中访问当前上下文的内存,还需要对cuCtxEnablePeerAccess()进行单独的对称调用。

请注意,根据系统配置,存在设备级和系统级的限制,如CUDA编程指南中"点对点内存访问"部分所述。

如果cuDeviceCanAccessPeer()表明当前上下文的CUdevice无法直接访问peerContextCUdevice内存,则返回CUDA_ERROR_PEER_ACCESS_UNSUPPORTED

如果当前上下文已启用对peerContext的直接访问,则返回CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED

如果由于对等访问所需的硬件资源已耗尽而无法直接进行对等访问,则返回CUDA_ERROR_TOO_MANY_PEERS

如果没有当前上下文、peerContext不是有效上下文,或者当前上下文就是peerContext,则返回CUDA_ERROR_INVALID_CONTEXT

如果Flags不为0,则返回CUDA_ERROR_INVALID_VALUE

Note:

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

另请参阅:

cuDeviceCanAccessPeer, cuCtxDisablePeerAccess, cudaDeviceEnablePeerAccess

CUresult cuDeviceCanAccessPeer ( int* canAccessPeer, CUdevice dev, CUdevice peerDev )
查询设备是否可以直接访问对等设备的内存。
参数
canAccessPeer
- Returned access capability
dev
- Device from which allocations on peerDev are to be directly accessed.
peerDev
- Device on which the allocations to be directly accessed by dev reside.
描述

如果在dev上的上下文能够直接访问peerDev上的上下文内存,则在*canAccessPeer中返回1,否则返回0。如果从dev直接访问peerDev是可能的,则可以通过调用cuCtxEnablePeerAccess()在两个特定上下文上启用访问。

Note:

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

另请参阅:

cuCtxEnablePeerAccess, cuCtxDisablePeerAccess, cudaDeviceCanAccessPeer

CUresult cuDeviceGetP2PAttribute ( int* value, CUdevice_P2PAttribute attrib, CUdevice srcDevice, CUdevice dstDevice )
查询两个设备之间链接的属性。
参数
value
- Returned value of the requested attribute
attrib
- The requested attribute of the link between srcDevice and dstDevice.
srcDevice
- The source device of the target link.
dstDevice
- The destination device of the target link.
描述

*value中返回srcDevicedstDevice之间链接的请求属性attrib的值。支持的属性包括:

如果srcDevicedstDevice无效,或者它们代表同一个设备,则返回CUDA_ERROR_INVALID_DEVICE

如果attrib无效或value是空指针,则返回CUDA_ERROR_INVALID_VALUE

Note:

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

另请参阅:

cuCtxEnablePeerAccess, cuCtxDisablePeerAccess, cuDeviceCanAccessPeer, cudaDeviceGetP2PAttribute