Problems on memory allocation

Hi all,

currently I faced some problems when I try to run my cuda code. I have on program which needs to compute an array of 969696, but sometimes the result will diverge.

However, when I find out my result is diverging, if I run another simple program with a array of 8112*8112 and then back to execute the former code, the result won’t diverge.

It just like every time when I need to run my code, I need to use another code to free memory space on my device, otherwise I cannot get my result correct.

I have no idea why this problem will happen, since I just use cudaMalloc() and cudaFree() for my memory allocation and release, please help me on this, thanks a lot.

There is a problem in the code. Memory access is out of bonds. add the flags -g -G to the compiling line and then run the program with cuda memcheck.

hi, pasoleatis

thanks for your reply, I tried it today with compiling my code first with

nvcc -arch=sm_21 -O3 -g -G -o executefile

and then used cuda-memcheck to check like

cuda-memcheck -c ./executefile

However, the report is

=== ERROR SUMMARY: 0 errors

I think it means there is no error in my source code, did I miss something to do or there is really no mistake in my code?

Yes. It appears there are no memory problem (outbonds). Did you run the program with 969696? You mentioned the problem does not appear always, so you should run your program until you get a divergence. Post also the output when you get a divergence. Usually when an address is not initialise I get a very large number, negative most of the time.

thank you a lot, pasoleatis, I think the reason causing my problem is just about initialization.

currently I can run my code with a 192192192 array size, and what I did was to initialize all variables I declared, which I did do previously.

thanks again.

After you allocate memory on gpu for an array you can set it all to zero with a cudaset function. You should check why does program read an address which was not written first.