Caffe2 - C++ API
A deep learning, cross platform ML framework
workspace_ops.cc
1 #include "caffe2/core/context.h"
2 #include "caffe2/core/operator.h"
3 
4 namespace caffe2 {
5 namespace {
6 
7 class GetAllBlobNamesOp final : public Operator<CPUContext> {
8  public:
9  explicit GetAllBlobNamesOp(const OperatorDef& operator_def, Workspace* ws)
10  : Operator<CPUContext>(operator_def, ws),
11  include_shared_(GetSingleArgument<int>("include_shared", true)),
12  ws_(ws) {}
13 
14  bool RunOnDevice() override {
15  const auto& blobs = include_shared_ ? ws_->Blobs() : ws_->LocalBlobs();
16  auto* out = Output(0, {static_cast<int64_t>(blobs.size())}, at::dtype<std::string>());
17  std::copy(
18  blobs.begin(), blobs.end(), out->template mutable_data<std::string>());
19  return true;
20  }
21 
22  private:
23  bool include_shared_;
24  Workspace* ws_;
25 };
26 
27 REGISTER_CPU_OPERATOR(GetAllBlobNames, GetAllBlobNamesOp);
28 OPERATOR_SCHEMA(GetAllBlobNames)
29  .NumInputs(0)
30  .NumOutputs(1)
31  .SetDoc(R"DOC(
32 Return a 1D tensor of strings containing the names
33 of each blob in the active workspace.
34 )DOC")
35  .Arg(
36  "include_shared",
37  "(bool, default true) Whether to include blobs "
38  "inherited from parent workspaces.")
39  .Output(0, "blob_names", "1D tensor of strings containing blob names.");
40 SHOULD_NOT_DO_GRADIENT(GetAllBlobNamesOp);
41 }
42 }
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13