-
Notifications
You must be signed in to change notification settings - Fork 32
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
Dynamic lib loading #14
Conversation
Hi, thanks so much for getting this started! I really appreciate it 😄 Everything worked great on my machine 🎉 so it looks like dynamically loading NVML at runtime isn't far off. I've done some work on top of your branch over here; do you mind if I push to your branch so we can work together on this? Here's an overview of what I've done:
I also cleaned up the issue you mentioned:
So, you were off to the right start: We don't need to load the wrapper type again for the other structs, though, or create a singleton; we just need to make sure that all of the other structs have a reference to an As an example, previously the pub struct Device<'nvml> {
device: nvmlDevice_t,
_phantom: PhantomData<&'nvml NVML>,
} I had no need for a reference to an Now that we need access to stuff the pub struct Device<'nvml> {
device: nvmlDevice_t,
pub nvml: &'nvml NVML,
} This removes the usage of As far as the next steps that need to be taken care of here:
I'll chip away at it all over the course of the next few days! |
Also, I have no idea why CI failed to run here; maybe restarting it will help? EDIT: and now it worked, very odd |
Libloading support
Hello Jarek, Thanks a lot for all the modification! I have push them to my |
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.
Thanks for going through and updating the rest of it!
I don't have access to a Windows system with a NVIDIA GPU unfortunately, neither macOS.
No worries; I have access to both, so I'll take care of that part.
Works great on Windows as well (other than that ^ small issue). EDIT: and compiles on macOS, erroring at runtime. Sweet! |
This import library is no longer required since we are now loading the dll at runtime
This would introduce the ability to unsafely store function pointers contained within the lib after the `NVML` instance gets destroyed
Otherwise `self.lib` could get accessed again by the `Drop` impl if `lib.__library.close()` returned an error
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, I think this is ready to merge! There's some work left to be done before I can release this, but I can finish that outside of this PR.
Thanks again for all your work here!
Hello,
I started working on using libloading with bindgen dynamic lib support.
So far it seems to work but the dynamic lib loading is not handle as it should be. I am not familiar with Rust so I am not sure how it should be done.
I added a
new()
method to the NVML struct (inlib.rs
). Thisnew()
method will take care of loading the.so
file through libloading and use it for every call to NVML method.the tricky part is for other struct. For example with the Device struct (in
device.rs
) I reload the library every time a call is made to one of the Device's methods.I can either implement the same
new()
method for every struct or maybe you have a better idea (Singleton ?).