pub struct Workspace { /* private fields */ }
Expand description

| Workspace is a class that holds all the | related objects created during runtime: | (1) all blobs, and (2) all instantiated | networks. | | It is the owner of all these objects and | deals with the scaffolding logistics. |

Implementations§

source§

impl Workspace

source

pub fn new_from_root_folder(root_folder: &String) -> Self

| Initializes an empty workspace with | the given root folder. | | For any operators that are going to interface | with the file system, such as load operators, | they will write things under this root | folder given by the workspace. |

source

pub fn new_from_shared_workspace(shared: *const Workspace) -> Self

| Initializes a workspace with a shared | workspace. | | When we access a Blob, we will first try | to access the blob that exists in the | local workspace, and if not, access | the blob that exists in the shared workspace. | | The caller keeps the ownership of the | shared workspace and is responsible | for making sure that its lifetime is | longer than the created workspace. |

source

pub fn new_from_parent_workspace_and_blob_remapping( shared: *const Workspace, forwarded_blobs: &HashMap<String, String> ) -> Self

| Initializes workspace with parent | workspace, blob name remapping (new | name -> parent blob name), no other blobs | are inherited from parent workspace |

source

pub fn new_from_root_folder_and_shared_workspace( root_folder: &String, shared: *const Workspace ) -> Self

| Initializes a workspace with a root | folder and a shared workspace. |

source

pub fn copy_forwarded_tensors<Context>(&mut self, blobs: &HashSet<String>)

| Converts previously mapped tensor | blobs to local blobs, copies values | from parent workspace blobs into new | local blobs. Ignores undefined blobs. |

source

pub fn root_folder(&mut self) -> &String

| Return the root folder of the workspace. |

source

pub fn has_blob(&self, name: &String) -> bool

| Checks if a blob with the given name is | present in the current workspace. |

source

pub fn nets(&self) -> Vec<String>

| Returns a list of names of the currently | instantiated networks. |

source

pub fn print_blob_sizes(&mut self)

source

pub fn local_blobs(&self) -> Vec<String>

| Return list of blobs owned by this | Workspace, not including blobs shared | from parent workspace. |

source

pub fn blobs(&self) -> Vec<String>

| Return a list of blob names. | | This may be a bit slow since it will involve | creation of multiple temp variables. | | For best performance, simply use HasBlob() | and GetBlob(). |

source

pub fn create_blob(&mut self, name: &String) -> *mut Blob

| Creates a blob of the given name. | | The pointer to the blob is returned, | but the workspace keeps ownership of | the pointer. | | If a blob of the given name already exists, | the creation is skipped and the existing | blob is returned. |

source

pub fn create_local_blob(&mut self, name: &String) -> *mut Blob

| Similar to CreateBlob(), but it creates | a blob in the local workspace even if | another blob with the same name already | exists in the parent workspace – in | such case the new blob hides the blob | in parent workspace. | | If a blob of the given name already exists | in the local workspace, the creation | is skipped and the existing blob is returned. |

source

pub fn rename_blob(&mut self, old_name: &String, new_name: &String) -> *mut Blob

| Renames a local workspace blob. | | If blob is not found in the local blob | list or if the target name is already | present in local or any parent blob list | the function will throw. |

source

pub fn remove_blob(&mut self, name: &String) -> bool

| Remove the blob of the given name. Return | true if removed and false if not exist. | | Will NOT remove from the shared workspace. |

source

pub fn get_blob(&self, name: &String) -> *const Blob

| Gets the blob with the given name as a | const pointer. | | If the blob does not exist, a nullptr | is returned. |

source

pub fn add_blob_mapping( &mut self, parent: *const Workspace, forwarded_blobs: &HashMap<String, String>, skip_defined_blobs: Option<bool> )

| Adds blob mappings from workspace to | the blobs from parent workspace. | | Creates blobs under possibly new names | that redirect read/write operations | to the blobs in the parent workspace. | | Arguments: | | - parent - pointer to parent workspace | | - forwarded_blobs - map from new blob | name to blob name in parent’s | | - workspace skip_defined_blob - if | set skips blobs with names that already | exist in the workspace, otherwise throws | exception |

source

pub fn create_net_from_net_def_ref( &mut self, net_def: &NetDef, overwrite: Option<bool> ) -> *mut NetBase

source

pub fn create_net( &mut self, net_def: &Arc<NetDef>, overwrite: Option<bool> ) -> *mut NetBase

| Creates a network with the given NetDef, | and returns the pointer to the network. | | If there is anything wrong during the | creation of the network, a nullptr is | returned. | | The Workspace keeps ownership of the | pointer. | | If there is already a net created in the | workspace with the given name, CreateNet | will overwrite it if overwrite=true | is specified. | | Otherwise, an exception is thrown. |

source

pub fn get_net(&mut self, name: &String) -> *mut NetBase

| Gets the pointer to a created net. The | workspace keeps ownership of the network. |

source

pub fn delete_net(&mut self, name: &String)

| Deletes the instantiated network with | the given name. |

source

pub fn run_net(&mut self, name: &String) -> bool

| Finds and runs the instantiated network | with the given name. | | If the network does not exist or there | are errors running the network, the | function returns false. |

source

pub fn run_operator_once(&mut self, op_def: &OperatorDef) -> bool

| RunOperatorOnce and RunNetOnce runs | an operator or net once. | | The difference between RunNet and RunNetOnce | lies in the fact that RunNet allows you | to have a persistent net object, while | RunNetOnce creates a net and discards | it on the fly | | - this may make things like database | read and random number generators repeat | the same thing over multiple calls. |

source

pub fn run_net_once(&mut self, net_def: &NetDef) -> bool

source

pub fn run_plan( &mut self, plan: &PlanDef, should_continue: Option<ShouldContinue> ) -> bool

| Runs a plan that has multiple nets and | execution steps. |

source

pub fn get_thread_pool(&mut self) -> *mut ThreadPool

| Returns a CPU threadpool instance for | parallel execution of work. | | The threadpool is created lazily; if | no operators use it, then no threadpool | will be created. |

source

pub fn bookkeeper(&mut self) -> Arc<Bookkeeper>

source

pub fn for_each<F>(&mut self, f: F)

| Applies a function f on each workspace | that currently exists. | | This function is thread safe and there | is no race condition between workspaces | being passed to f in this thread and destroyed | in another. |

Trait Implementations§

source§

impl Default for Workspace

source§

fn default() -> Self

| Initializes an empty workspace. |

source§

impl Drop for Workspace

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Send for Workspace

source§

impl Sync for Workspace

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> Ungil for Twhere T: Send,