I saw in a CUDA code example that
memset is used to initialize vectors to all 0's that will store the sum of two others vectors. For example:
hostRef = (float *)malloc(nBytes);
gpuRef = (float *)malloc(nBytes);
memset(hostRef, 0, nBytes);
memset(gpuRef, 0, nBytes);
What purpose does this serve if nothing else is done with these vectors?
You can see the code here: https://books.google.com/books?id=Jgx_BAAAQBAJ&pg=PA42#v=onepage&q&f=false
Not sure how long the link will work though.
Best How To :
This is the answer given by njuffa in the comments:
...The content of GPU memory doesn't change between invocations of the application. In case of a program failure, we would want to avoid picking up good data from a previous run, which may lead (erroneously) to a belief that the program executed fine. I have seen such cases in real-life, and it was very confusing to the affected programmers. Thus it is better to initialize result data to a known value, although I would have chosen 0xff instead of 0 as this corresponds to a NaN pattern for floating-point data.