Is there an equivalent to intptr_t and uintptr_t in CUDA

Since intptr_t and uintptr_t refer to integer types capable of holding a host pointer, is there some equivalent that can be used in device code?

This would be particularly useful for device-side atomics, since the atomic functions don’t accept pointers to pointer types, and thus a conversion is required (to whatever the equivalent of uintptr_t * is). Is it safe to assume that device pointers are 64 bits wide, and use unsigned long long *?

While googling, I’ve seen some mentions of a CUdeviceptr type, which sounds like it might be the equivalent of intptr_t, but can’t find much discussion or documentation for what it is or how it is supposed to be used.

  • 1

    CUDA adheres to C++. AFAIK these types are not defined in C++, but if you #include <cstdint> you will have access to them, including in CUDA device code. Regarding this: “Since intptr_t and uintptr_t refer to integer types capable of holding a host pointer,” with respect to the usage of the word host, I think that is your invention. I doubt any description of those types includes the word host. I also don’t understand their utility with respect to atomics, or under what circumstances using pointer-to-pointer types would be interesting with atomics, but that seems tangential.

    – 

  • 1

    regarding the width of pointers on the device, they always match the width of pointers on the host.

    – 

  • @RobertCrovella: The descriptions of std::intptr_t and std::uintptr_t know nothing about CUDA or GPUs, so of course they are concerned with the host pointer size (it’s the only kind of pointer they know about).

    – 

  • @RobertCrovella do you have a reference that states that device and host pointers always have the same width? This seems to indicate otherwise: cudahandbook.com/2013/08/…, and this question about OpenCL also says the same thing about pointer sizes in OpenCL: stackoverflow.com/questions/29302831/…

    – 




  • 1

    @BenVoigt you’re imagining a distinction where it doesn’t exist. CUDA device code also claims compatibility to C++. The point of that claim is that there is no need to restate, assume, or declare that every C++ specification is now unique to host only, and has a host word implicitly added in it somewhere, with a corresponding additional specification necessary to state the same thing for device.

    – 

Leave a Comment