In C/CUDA, if I am passed a pointer, how can I programmatically determine whether the pointer points to memory on the CPU or the GPU? Is there a CUDA function for this purpose?
In C/CUDA, if I am passed a pointer, how can I programmatically determine whether
Share
I don’t know how it is with CUDA 4.0, but in 3.2 you simply cannot deduct if it is CPU or GPU pointer based solely on the address stored in it.
A way around it would be to create a class
CudaPtr<T>, hide a pointer there and provide basic functionality (e.g.memset,memload,memstore,memallocetc. which would in turn use CUDA stuff).Then, if you have a function which may operate on host or on device, you can easily overload it for
T*andCudaPtr<T>.Update: Since the Unified Memory Addressing and new CUDA toolkit things have changed a bit. It seems you can now make such distinction at run time via cuPointerGetAttribute