cudaFree() giving "invalid device pointer"


I am using CUDA4 and a Tesla C2070

I have run into a problem when trying to run two host threads, each with their own context.

It seems like there is some kind of conflict. They are both running the same code (with different data), but one of them will eventually get a “invalid device pointer” error, that I have trapped after a call to “cudaFree()”

Now, if I am running a single thread, I never get this issue.

Any ideas what could be causing this? The point I am passing is definitely a device pointer. Can there be a conflict across two threads somehow? Like I said, both of the host threads each have their own instance of the class that contains the device pointer, and each thread independently declares :

cudaError err = cudaSetDevice(0);
CUcontext ctx;
cuCtxCreate(&ctx, 0, 0);

Which I would have thought would have precented any conflicts.

Thanks for any ideas where to start looking to devug this

If it matters, the pointer that I am freeing is an array of cuComplex

Out of curiosity, what necessitates you having multiple contexts for the same GPU? You generally don’t want to do this (if you don’t believe me, take it from tmurray)