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
Lifecycle problems with device_by_index
#20
Comments
Yeah, so due to the usage of lifetimes to track the relationships between the The best solution here is to initialize a global, static use nvml_wrapper::{error::NvmlError, Device, NVML};
use once_cell::sync::Lazy;
static NVML_INSTANCE: Lazy<NVML> = Lazy::new(|| NVML::init().unwrap());
#[derive(Debug)]
struct NvmlDevices<'a> {
devices: Vec<Device<'a>>,
}
impl<'a> NvmlDevices<'a> {
pub fn new() -> Result<Self, NvmlError> {
Ok(NvmlDevices {
devices: (0..NVML_INSTANCE.device_count()?)
.map(|i| NVML_INSTANCE.device_by_index(i))
.collect::<Result<_, _>>()?,
})
}
}
fn main() {
let devices = NvmlDevices::new();
dbg!(&devices);
} (I'm traveling and only have access to a mac right now, so I can't run that at the moment, but it compiles successfully for me.) In the past I've thought about moving away from lifetimes and instead using |
@Cldfire I checked, it works. I think the Thank you. |
Awesome! Glad to hear that worked out for you. |
This is what I am trying
But it does not work. It gives me lifecycle errors. Specifically:
I am not sure if this is related to #2 or not. Any suggestions on how to fix this?
The text was updated successfully, but these errors were encountered: