Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does NVIDIA GPU do with device memory 0x0?

Tags:

cuda

It seems the examples in one of the CUDA books (CUDA by Example: An Introduction to General-Purpose GPU Programming) never nullify pointers when initializing them.

Two questions:

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

  2. Do we need to check whether the pointer is NULL before cudaFree it ? if (devPtr) HANDLE_ERROR(cudaFree(devPtr));

Someone said that for Fermi architecture, 0x0 is used for on-chip shared memory, it seems that it's still okay for use to assume that 0x0 should not be pointed by a used pointer.
http://forums.thedailywtf.com/forums/p/25369/273567.aspx

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

Thank you!

like image 629
DataHungry Avatar asked Aug 25 '12 22:08

DataHungry


1 Answers

Generally, you can treat NULL pointers just like you do with host pointers. To answer your questions.

  1. Yes. Feel free to use the same practice you use on the host (nullify at will).

  2. It's safe to check for NULL before you free it, but not necessary, since cudaFree(0) will not actually attempt to free any memory. (In fact cudaFree(0) is commonly used to initialize the CUDA context!) I believe that most modern malloc implementations do not attempt to free zero-valued pointers.

like image 57
harrism Avatar answered Sep 30 '22 13:09

harrism