1 #ifndef CAFFE2_CORE_WORKSPACE_H_ 2 #define CAFFE2_CORE_WORKSPACE_H_ 4 #include "caffe2/core/common.h" 7 #error "mobile build state not defined" 16 #include "caffe2/core/blob.h" 17 #include "caffe2/core/registry.h" 18 #include "caffe2/core/net.h" 19 #include "caffe2/proto/caffe2.pb.h" 20 #include "caffe2/utils/signal_handler.h" 22 #include "caffe2/utils/threadpool/ThreadPool.h" 23 #endif // CAFFE2_MOBILE 25 CAFFE2_DECLARE_bool(caffe2_print_blob_sizes_at_exit);
30 struct CompiledExecutionStep;
34 : handler_(std::make_shared<SignalHandler>(
35 SignalHandler::Action::STOP,
36 SignalHandler::Action::STOP)) {}
40 bool operator()(
int iter) {
41 return handler_->CheckForSignals() != SignalHandler::Action::STOP;
44 std::shared_ptr<SignalHandler> handler_;
55 typedef std::function<bool(int)> ShouldContinue;
56 typedef CaffeMap<string, unique_ptr<Blob> > BlobMap;
57 typedef CaffeMap<string, unique_ptr<NetBase> > NetMap;
71 : root_folder_(root_folder) {}
87 : root_folder_(root_folder), shared_(shared) {}
89 if (FLAGS_caffe2_print_blob_sizes_at_exit) {
106 vector<string> LocalBlobs()
const;
113 vector<string> Blobs()
const;
122 inline bool HasBlob(
const string& name)
const {
123 return (blob_map_.count(name) || (shared_ && shared_->HasBlob(name)));
126 void PrintBlobSizes();
133 Blob* CreateBlob(
const string& name);
139 bool RemoveBlob(
const string& name);
144 const Blob* GetBlob(
const string& name)
const;
149 Blob* GetBlob(
const string& name);
166 NetBase* GetNet(
const string& net_name);
170 void DeleteNet(
const string& net_name);
176 bool RunNet(
const string& net_name);
182 vector<string> names;
183 for (
auto& entry : net_map_) {
184 names.push_back(entry.first);
192 bool RunPlan(
const PlanDef& plan_def,
201 ThreadPool* GetThreadPool();
209 bool RunOperatorOnce(
const OperatorDef& op_def);
210 bool RunNetOnce(
const NetDef& net_def);
218 string root_folder_ =
".";
221 std::unique_ptr<ThreadPool> thread_pool_;
222 std::mutex thread_pool_creation_mutex_;
223 #endif // CAFFE2_MOBILE 230 #endif // CAFFE2_CORE_WORKSPACE_H_
Workspace(Workspace *const shared)
Initializes a workspace with a shared workspace.
const string & RootFolder()
Return the root folder of the workspace.
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
Workspace(const string &root_folder)
Initializes an empty workspace with the given root folder.
Workspace(const string &root_folder, Workspace *shared)
Initializes a workspace with a root folder and a shared workspace.
Simple registry implementation in Caffe2 that uses static variables to register object creators durin...
Blob is a general container that hosts a typed pointer.
vector< string > Nets() const
Returns a list of names of the currently instantiated networks.
Workspace()
Initializes an empty workspace.
unique_ptr< NetBase > CreateNet(const NetDef &net_def, Workspace *ws)
Creates a network, accessing / creating blobs in the given workspace.
void SetParentWorkspace(Workspace *shared)
Allows to add a parent workspace post factum after the object was already constructed.
bool HasBlob(const string &name) const
Checks if a blob with the given name is present in the current workspace.