Reputation: 16796
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.
Upvotes: 2
Views: 437
Reputation: 27809
Reading the DLLMain documentation, I would advise against it. From the docs:
Warning There are serious limits on what you can do in a DLL entry point. To provide more complex initialization, create an initialization routine for the DLL. You can require applications to call the initialization routine before calling any other routines in the DLL.
More specifically:
Calling functions that require DLLs other than Kernel32.dll may result in problems that are difficult to diagnose.
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.
Upvotes: 3