cudaMalloc strange behaviour

Can someone tell me if “cudaMalloc” initialize all the memory locations to zero ? In my computer the location take random values!

thanks

No - it behaves just like malloc or new on the CPU. The contents of freshly allocated memory are undefined.

Well, on a CPU, the first time a virtual page is mapped it probably will be zero-filled in the interests of security (if it is free’d and subsequently malloc’d again, it’ll probably contain whatever value your program wrote there last - but you shouldn’t count on it). NVIDIA might do this on the GPU too, but it’s not behaviour you should depend on. If you want a block of RAM to have a particular value, set it yourself.

No - it behaves just like malloc or new on the CPU. The contents of freshly allocated memory are undefined.

Well, on a CPU, the first time a virtual page is mapped it probably will be zero-filled in the interests of security (if it is free’d and subsequently malloc’d again, it’ll probably contain whatever value your program wrote there last - but you shouldn’t count on it). NVIDIA might do this on the GPU too, but it’s not behaviour you should depend on. If you want a block of RAM to have a particular value, set it yourself.