I have developed a C++ DLL in windows which has many CUDA accelerated functions.
Currently i haven’t created the DllMain function as it is not mandatory.
I know that there are many limitations on the functions that can be called in the DllMain.
I just want to know that is it safe to call a CUDA Runtime function in DllMain just to initialize the default context, so that the subsequent CUDA calls are faster?
I’m using Visual Studio 2008, CUDA 5.0 and Windows 8 for development.
Reading the DLLMain documentation, I would advise against it. From the docs:
More specifically:
Since the CUDA Runtime API requires cudart.dll, this applies to your question.
So I would create an initialization function for your library that does CUDA initialization, and require it to be called explicitly at application startup.