question regarding cuda memory

I have 2 applications implemented on cuda. My 1st application works correctly but 2nd one has some errors which i am yet to debug.

I run 2nd application which leads to an error and after that if i try running my 1st application . When i do this, my 1st application does not work. But when i re run it again it works.

Why does this happen? Is there something i need to do at the end of every program or at the beginning of a program in order to avoid a situation like this.


You don’t have to do anything at the end of your programs. The CUDA runtime/driver will handle that (including freeing memory leaks on the GPU).

I would expect the kind of behavior you describe if you use uninitialized memory or your program writes past the end of the array. Check carefully for these bugs. If you are running on linux, you can compile in emulation mode and run your application through valgrind to check for these situations.