-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Lazy loading nvcuda.dll #2215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lazy loading nvcuda.dll #2215
Conversation
|
In your latest patch, GetProcAddress/dlsym are used to identify "cuCtxGetCurrent" and it is fine. However, you can notice that "cuCtxPushCurrent" and "cuCtxPopCurrent" are defined as macros in cuda.h and are aliasing cuCtxPushCurrent_v2 and cuCtxPopCurrent_v2. That's why I suggest using a stringify macro to build the "cuCtxGetCurrent" symbol name, because it will protect from such changes and compatibility breaking. #define MACRO_STRINGIFY(name) #name ... const char* cuCtxGetCurrent_name = FUNCTION_NAME(cuCtxGetCurrent); GetProcAddress(hNVCuda, cuCtxGetCurrent_name); |
cuCtxGetCurrent() is used to only fetch the runtime context and there is only 1 runtime context. This function has no further evolution of v2 and above and hence we can keep it simple for this function. |
|
👍 |
|
Hi @alalek |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
singleton's constructor/destructor should not be "public".
| { | ||
| static LoadNvidiaModules* m_pInstance; | ||
| if (!m_pInstance) | ||
| m_pInstance = new LoadNvidiaModules; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pointer
which code should call object destruction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object destruction will happen by default right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added object destruction code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Destructor code has never been called. You can ensure by adding printf() there.
Please follow the example (link is above):
- no instance pointers
- just static (global) object in function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Done and i ensured it by adding printf in destructor. Thanks :-)
Please take a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thank you 👍
Added lazy loading of nvcuda.dll. Removed unwanted driver APIs as the final output remains same and replaced driver API with runtime API wherever possible
resolves #2210