-
Notifications
You must be signed in to change notification settings - Fork 430
add PluggableDeviceLibrary #402
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use crate::{Result, Status}; | ||
use std::ffi::CString; | ||
use tensorflow_sys as tf; | ||
|
||
/// PluggableDeviceLibrary handler. | ||
#[derive(Debug)] | ||
pub struct PluggableDeviceLibrary { | ||
inner: *mut tf::TF_Library, | ||
} | ||
|
||
impl PluggableDeviceLibrary { | ||
/// Load the library specified by library_filename and register the pluggable | ||
/// device and related kernels present in that library. This function is not | ||
/// supported on embedded on mobile and embedded platforms and will fail if | ||
/// called. | ||
/// | ||
/// Pass "library_filename" to a platform-specific mechanism for dynamically | ||
/// loading a library. The rules for determining the exact location of the | ||
/// library are platform-specific and are not documented here. | ||
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 { | ||
/// Frees the memory associated with the library handle. | ||
/// Does NOT unload the library. | ||
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())); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* automatically generated by rust-bindgen 0.59.1 */ | ||
|
||
extern "C" { | ||
pub fn TF_LoadPluggableDeviceLibrary( | ||
library_filename: *const ::std::os::raw::c_char, | ||
status: *mut TF_Status, | ||
) -> *mut TF_Library; | ||
} | ||
extern "C" { | ||
pub fn TF_DeletePluggableDeviceLibraryHandle(lib_handle: *mut TF_Library); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We might as well leave the test out, since there's no reasonable way to run it (as far as I know). We have similar issues with TF_LoadLibrary.
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.
Yes, right. I tried some, but none of them succeeded. There is too little information on this API.
Is there anything else I can do with this pull request?
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.
In #387 they solved it (at least for macOS) by installing tensorflow-metal and loading that. If you want to leave this test out, I can merge this first and ask them to rebase their changes on top of this, so we'd at least have a test that runs in the CI, even if not on everyone's local machine.
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 adjusting the PRs. If that order is acceptable, please do so.
A while ago, I was trying to see if the C-API would work with a plugin for Windows, and latest plugin version (currently build from source only) seemed to work with TF 2.12. I'm thinking of trying to see if I can support that as well (apart from this PR) when the version of tensorflow here is updated.
https://github.com/microsoft/tensorflow-directml-plugin