Query memory type

Hello,

I am working on a piece of code that takes a pointer P to a block allocated with CUDA, its size N and an enum specifying whether the block should be read or written. I don’t know if cudaMalloc() or cudaMallocManaged() was used for the allocation. The case of unified memory allows for the simple handling of content, whereas I also want to be able to work with unmanaged device blocks if they are provided.

How can I detect if P comes from the unified pool?

Seems like cudaPointerGetAttributes() may be what you want. It is documented here. You can also find various forum questions about its usage.

It indeed looks like what I need. Thank you very much, Robert!