Prefer to read without ads? Become a member — from $10/month — and support the work. Already a member? Log in to read ad-free on this device.

9.3 UVA: Inferring Device from Address

Since UVA is always enabled on peer-to-peer-capable systems, the address ranges for different devices do not overlap and the driver can infer the owning device from a pointer value. The cuPointerGetAttribute() function may be used to query information about UVA pointers, including the owning context.

CUresult CUDAAPI cuPointerGetAttribute(void *data, CUpointer_attribute attribute, CUdeviceptr ptr);
Attribute Passback Type Description
CU_POINTER_ATTRIBUTE_CONTEXT CUcontext Context in which a pointer was allocated or registered.
CU_POINTER_ATTRIBUTE_MEMORY_TYPE CUmemorytype Physical location of a pointer.
CU_POINTER_ATTRIBUTE_DEVICE_POINTER CUdeviceptr Pointer at which the memory may be accessed by the GPU.
CU_POINTER_ATTRIBUTE_HOST_POINTER void * Pointer at which the memory may be accessed by the host.

Table 9-1. cuPointerGetAttribute() attributes.

cuPointerGetAttribute() or cudaPointerGetAttributes() may be used to query the attributes of a pointer. Table 9-1 gives the values that can be passed into cuPointerGetAttribute(); the structure passed back by cudaPointerGetAttributes() is as follows:

struct cudaPointerAttributes {
        enum cudaMemoryType memoryType;
        int device;
        void *devicePointer;
        void *hostPointer;
    }

memoryType may be cudaMemoryTypeHost or cudaMemoryTypeDevice.

device is the device for which the pointer was allocated. For device memory, device identifies the device where the memory corresponding to ptr was allocated. For host memory, device identifies the device that was current when the allocation was performed.

devicePointer gives the device pointer value that may be used to reference ptr from the current device. If ptr cannot be accessed by the current device, devicePointer is NULL.

hostPointer gives the host pointer value that may be used to reference ptr from the CPU. If ptr cannot be accessed by the current host, hostPointer is NULL.