c++memory-managementcudamapped-memory

Is there an opposite to cudaHostGetDevicePointer()?


Suppose my device is Kepler and up, CUDA is 6.5 or up, and my driver is from 2015 at the earliest.

Is it possible to do the opposite of cudaHostGetDevicePointer()? i.e., provided the address of the device-side manifestation of some mapped memory, obtain the host address?


Solution

  • If you are running on a platform with unified addressing support, you can call cudaPointerGetAttributes on any pointer which is registered or allocated in the unified address space. The function returns a structure

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

    which will tell you the both device and host addresses of the memory, as well as which device it physically resides on, or in which device context it was originally registered (for host memory).

    If you do not have access to unified addressing, I do not believe there is a way to achieve this.