Caffe2 - C++ API
A deep learning, cross platform ML framework
blobs_queue_db.cc
1 #include "caffe2/queue/blobs_queue_db.h"
2 
3 #include <algorithm>
4 #include <chrono>
5 #include <random>
6 #include <string>
7 
8 #include "caffe2/core/context.h"
9 #include "caffe2/core/logging.h"
10 #include "caffe2/core/operator.h"
11 #include "caffe2/queue/blobs_queue.h"
12 
13 namespace caffe2 {
14 namespace db {
15 
16 template <class Context>
17 class CreateBlobsQueueDBOp : public Operator<CPUContext> {
18  public:
19  CreateBlobsQueueDBOp(const OperatorDef& operator_def, Workspace* ws)
20  : Operator<CPUContext>(operator_def, ws) {}
21 
22  bool RunOnDevice() override {
23  std::unique_ptr<db::DB> db = caffe2::make_unique<BlobsQueueDB>(
24  "",
25  db::READ,
26  OperatorBase::Input<std::shared_ptr<BlobsQueue>>(0),
27  OperatorBase::template GetSingleArgument<int>("key_blob_index", -1),
28  OperatorBase::template GetSingleArgument<int>("value_blob_index", 0),
29  OperatorBase::template GetSingleArgument<float>("timeout_secs", 0.0));
30  OperatorBase::Output<db::DBReader>(0)->Open(std::move(db), 1, 0);
31  return true;
32  }
33 
34  private:
35  DISABLE_COPY_AND_ASSIGN(CreateBlobsQueueDBOp);
36 };
37 
38 REGISTER_CPU_OPERATOR(CreateBlobsQueueDB, CreateBlobsQueueDBOp<CPUContext>);
39 
40 OPERATOR_SCHEMA(CreateBlobsQueueDB)
41  .NumInputs(1)
42  .NumOutputs(1)
43  .Arg(
44  "key_blob_index",
45  "(default: -1 (no key)) index of blob for DB key in the BlobsQueue.")
46  .Arg(
47  "value_blob_index",
48  "(default: 0) index of blob for DB value in the BlobsQueue.")
49  .Arg(
50  "timeout_secs",
51  "(default: 0.0 (no timeout)) Timeout in seconds for reading from the "
52  "BlobsQueue.")
53  .SetDoc("Create a DBReader from a BlobsQueue")
54  .Input(0, "queue", "The shared pointer to a queue containing Blobs.")
55  .Output(0, "reader", "The DBReader for the given BlobsQueue");
56 
57 SHOULD_NOT_DO_GRADIENT(CreateBlobsQueueDB);
58 
59 } // namespace db
60 } // namespace caffe2
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
Definition: workspace.h:47
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...