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 #ifdef CAFFE2_USE_MKLDNN
14 #include <caffe2/ideep/operators/operator_fallback_ideep.h>
15 #include <caffe2/ideep/utils/ideep_operator.h>
16 #endif
17 
18 namespace caffe2 {
19 namespace db {
20 
21 template <class Context>
22 class CreateBlobsQueueDBOp : public Operator<CPUContext> {
23  public:
24  CreateBlobsQueueDBOp(const OperatorDef& operator_def, Workspace* ws)
25  : Operator<CPUContext>(operator_def, ws) {}
26 
27  bool RunOnDevice() override {
28  std::unique_ptr<db::DB> db = caffe2::make_unique<BlobsQueueDB>(
29  "",
30  db::READ,
31  OperatorBase::Input<std::shared_ptr<BlobsQueue>>(0),
32  OperatorBase::template GetSingleArgument<int>("key_blob_index", -1),
33  OperatorBase::template GetSingleArgument<int>("value_blob_index", 0),
34  OperatorBase::template GetSingleArgument<float>("timeout_secs", 0.0));
35  OperatorBase::Output<db::DBReader>(0)->Open(std::move(db), 1, 0);
36  return true;
37  }
38 
39  private:
40  C10_DISABLE_COPY_AND_ASSIGN(CreateBlobsQueueDBOp);
41 };
42 
43 REGISTER_CPU_OPERATOR(CreateBlobsQueueDB, CreateBlobsQueueDBOp<CPUContext>);
44 
45 #ifdef CAFFE2_USE_MKLDNN
46 REGISTER_IDEEP_OPERATOR(
47  CreateBlobsQueueDB,
49 #endif
50 
51 OPERATOR_SCHEMA(CreateBlobsQueueDB)
52  .NumInputs(1)
53  .NumOutputs(1)
54  .Arg(
55  "key_blob_index",
56  "(default: -1 (no key)) index of blob for DB key in the BlobsQueue.")
57  .Arg(
58  "value_blob_index",
59  "(default: 0) index of blob for DB value in the BlobsQueue.")
60  .Arg(
61  "timeout_secs",
62  "(default: 0.0 (no timeout)) Timeout in seconds for reading from the "
63  "BlobsQueue.")
64  .SetDoc("Create a DBReader from a BlobsQueue")
65  .Input(0, "queue", "The shared pointer to a queue containing Blobs.")
66  .Output(0, "reader", "The DBReader for the given BlobsQueue");
67 
68 SHOULD_NOT_DO_GRADIENT(CreateBlobsQueueDB);
69 
70 } // namespace db
71 } // 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 ...
Definition: blob.h:13
A templated class to allow one to wrap a CPU operator as an IDEEP operator.