LoaderLock was detectedIt took me a while to figure out what was going on, and it was related to how I build CUDA libraries.
Message: DLL 'Cephalon.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.
When I make a CUDA enabled library, I wrap up the compiled kernel cubin files as a resource compiled into the DLL itself. An alternative simpler method is to supply a cubin text file along with each dll and load it directly using the CUDA function:
cuModuleLoad(&cuModule, pszModulePath)
So I wrap up the compiled code string neatly inside the DLL as a resource, then get that resource string and compile it on-the-fly (or just-in-time) using the alternative CUDA function:
cuModuleLoadDataEx( &cuModule,pCubinStr,3,&jitOptions[0],&jitOptVals[0]);
This is great but in order to get the string resource from inside the DLL I need to call a varient of LoadResource. And I need to call FindResource to find that resource first. And I need to call GetModuleHandle("LibraryName.dll") before any of those. The problem is that GetModuleHandle is a prohibited function to call even indirectly from LoadLibrary when the DLL is first loaded and mapped into the process address space.
The C# application was loading the DLL when it first encountered one of the functions, this then tried to initialise the CUDA module and load the resource automatically from the dll entry point. Ultimately, the call to GetModuleHandle raised an alarm back in the managed code. Not easy to spot.
More on the LoaderLock MDA can be found here
Vision Experts
No comments:
Post a Comment