What does an NVIDIA GPU do with 0x0 device memory?

It looks like the examples in one of the CUDA books (CUDA for example: an introduction to general-purpose programming GPUs) never reset pointers when they are initialized.

Two questions:

  • Does the GPU use 0x0 (or the integer 0) as a NULL pointer? Should we follow the C / C ++ pointer practice with device pointers (e.g. reset them when initializing)

  • Do I need to check if the pointer is NULL before cudaFree? if (devPtr) HANDLE_ERROR (cudaFree (devPtr));

Someone said that for the Fermi architecture 0x0 is used for shared memory on the chip, it seems that everything is still in order to suggest that 0x0 should not be indicated by the pointer used.
http://forums.thedailywtf.com/forums/p/25369/273567.aspx

What about Kepler architecture? What does the GPU do with address 0x0?

Thank!

+5
source share
1 answer

As a rule, you can handle NULL pointers the same way you do with node pointers. To answer your questions.

  • Yes. Feel free to use the same practice that you use on the host (void if desired).

  • It is safe to check for NULL before freeing it, but it is not necessary, since it cudaFree(0)is not actually trying to free memory. (In fact, cudaFree(0)it is usually used to initialize the CUDA context!) I believe that most modern implementations mallocdo not try to free null pointers.

+1
source

All Articles