Got "Invalid Device Function" error after reload DLL

I’m developing an application that allows to load/unload CUDA codes from DLL manually. It works perfectly for the first DLL load, and has no problem if it continues calling CUDA codes. The problem happens when I unload and reload the DLL. All kernel codes are failed with error: invalid device function. On unload, all DLL’s allocated memory & texture are freed and unbinded, and cudaDeviceReset()'s also called to make sure there is nothing remains. It seems to me that the kernel codes are not loaded and/or mapped correctly when reloading. So, is there any option or CUDA function that I have to set/call to overcome this situation?

My system information:

  • Card: GTX690
  • LIB: CUDA 5.0
  • IDE: VS2010
  • SYS: Win7 64bit

Thanks,

LD

Problem solved.

How did you solve it? Post for others to get an idea :)

That was my fault :). I forgot that child threads don’t inherit device context from main thread. In my app, main thread controls load/unload DLLs, why child threads are dealing with computation. The error happens when child threads are created and they use GPU0 by default, why main thread uses a designated GPU (GPU1).

HTH,

LD