use crate::{Result, Status};
use std::ffi::CString;
use tensorflow_sys as tf;
#[derive(Debug)]
pub struct PluggableDeviceLibrary {
inner: *mut tf::TF_Library,
}
impl PluggableDeviceLibrary {
pub fn load(library_filename: &str) -> Result<PluggableDeviceLibrary> {
let status = Status::new();
let library_filename = CString::new(library_filename)?;
let lib_handle =
unsafe { tf::TF_LoadPluggableDeviceLibrary(library_filename.as_ptr(), status.inner) };
status.into_result()?;
Ok(PluggableDeviceLibrary { inner: lib_handle })
}
}
impl Drop for PluggableDeviceLibrary {
fn drop(&mut self) {
unsafe {
tf::TF_DeletePluggableDeviceLibraryHandle(self.inner);
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[ignore]
#[test]
fn load_pluggable_device_library() {
let library_filename = "path-to-library";
let pluggable_divice_library = PluggableDeviceLibrary::load(library_filename);
dbg!(&pluggable_divice_library);
assert!((pluggable_divice_library.is_ok()));
}
}