Struct caffe2_operator::Workspace
source · 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
impl Workspace
sourcepub fn new_from_root_folder(root_folder: &String) -> Self
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. |
| 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. |
sourcepub fn new_from_parent_workspace_and_blob_remapping(
shared: *const Workspace,
forwarded_blobs: &HashMap<String, String>
) -> Self
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 |
| Initializes a workspace with a root | folder and a shared workspace. |
sourcepub fn copy_forwarded_tensors<Context>(&mut self, blobs: &HashSet<String>)
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. |
sourcepub fn root_folder(&mut self) -> &String
pub fn root_folder(&mut self) -> &String
| Return the root folder of the workspace. |
sourcepub fn has_blob(&self, name: &String) -> bool
pub fn has_blob(&self, name: &String) -> bool
| Checks if a blob with the given name is | present in the current workspace. |
sourcepub fn nets(&self) -> Vec<String>
pub fn nets(&self) -> Vec<String>
| Returns a list of names of the currently | instantiated networks. |
pub fn print_blob_sizes(&mut self)
sourcepub fn local_blobs(&self) -> Vec<String>
pub fn local_blobs(&self) -> Vec<String>
| Return list of blobs owned by this | Workspace, not including blobs shared | from parent workspace. |
sourcepub fn blobs(&self) -> Vec<String>
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(). |
sourcepub fn create_blob(&mut self, name: &String) -> *mut Blob
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. |
sourcepub fn create_local_blob(&mut self, name: &String) -> *mut Blob
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. |
sourcepub fn rename_blob(&mut self, old_name: &String, new_name: &String) -> *mut Blob
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. |
sourcepub fn remove_blob(&mut self, name: &String) -> bool
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. |
sourcepub fn get_blob(&self, name: &String) -> *const Blob
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. |
sourcepub fn add_blob_mapping(
&mut self,
parent: *const Workspace,
forwarded_blobs: &HashMap<String, String>,
skip_defined_blobs: Option<bool>
)
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 |
pub fn create_net_from_net_def_ref( &mut self, net_def: &NetDef, overwrite: Option<bool> ) -> *mut NetBase
sourcepub fn create_net(
&mut self,
net_def: &Arc<NetDef>,
overwrite: Option<bool>
) -> *mut NetBase
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. |
sourcepub fn get_net(&mut self, name: &String) -> *mut NetBase
pub fn get_net(&mut self, name: &String) -> *mut NetBase
| Gets the pointer to a created net. The | workspace keeps ownership of the network. |
sourcepub fn delete_net(&mut self, name: &String)
pub fn delete_net(&mut self, name: &String)
| Deletes the instantiated network with | the given name. |
sourcepub fn run_net(&mut self, name: &String) -> bool
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. |
sourcepub fn run_operator_once(&mut self, op_def: &OperatorDef) -> bool
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. |
pub fn run_net_once(&mut self, net_def: &NetDef) -> bool
sourcepub fn run_plan(
&mut self,
plan: &PlanDef,
should_continue: Option<ShouldContinue>
) -> bool
pub fn run_plan( &mut self, plan: &PlanDef, should_continue: Option<ShouldContinue> ) -> bool
| Runs a plan that has multiple nets and | execution steps. |
sourcepub fn get_thread_pool(&mut self) -> *mut ThreadPool
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. |
pub fn bookkeeper(&mut self) -> Arc<Bookkeeper>
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.