Caffe2 - C++ API
A deep learning, cross platform ML framework
blobs_queue_db.cc
1 
17 #include "caffe2/queue/blobs_queue_db.h"
18 
19 #include <algorithm>
20 #include <chrono>
21 #include <random>
22 #include <string>
23 
24 #include "caffe2/core/context.h"
25 #include "caffe2/core/logging.h"
26 #include "caffe2/core/operator.h"
27 #include "caffe2/queue/blobs_queue.h"
28 
29 namespace caffe2 {
30 namespace db {
31 
32 template <class Context>
33 class CreateBlobsQueueDBOp : public Operator<CPUContext> {
34  public:
35  CreateBlobsQueueDBOp(const OperatorDef& operator_def, Workspace* ws)
36  : Operator<CPUContext>(operator_def, ws) {}
37 
38  bool RunOnDevice() override {
39  std::unique_ptr<db::DB> db = caffe2::make_unique<BlobsQueueDB>(
40  "",
41  db::READ,
42  OperatorBase::Input<std::shared_ptr<BlobsQueue>>(0),
43  OperatorBase::template GetSingleArgument<int>("key_blob_index", -1),
44  OperatorBase::template GetSingleArgument<int>("value_blob_index", 0),
45  OperatorBase::template GetSingleArgument<float>("timeout_secs", 0.0));
46  OperatorBase::Output<db::DBReader>(0)->Open(std::move(db), 1, 0);
47  return true;
48  }
49 
50  private:
51  DISABLE_COPY_AND_ASSIGN(CreateBlobsQueueDBOp);
52 };
53 
54 REGISTER_CPU_OPERATOR(CreateBlobsQueueDB, CreateBlobsQueueDBOp<CPUContext>);
55 
56 OPERATOR_SCHEMA(CreateBlobsQueueDB)
57  .NumInputs(1)
58  .NumOutputs(1)
59  .Arg(
60  "key_blob_index",
61  "(default: -1 (no key)) index of blob for DB key in the BlobsQueue.")
62  .Arg(
63  "value_blob_index",
64  "(default: 0) index of blob for DB value in the BlobsQueue.")
65  .Arg(
66  "timeout_secs",
67  "(default: 0.0 (no timeout)) Timeout in seconds for reading from the "
68  "BlobsQueue.")
69  .SetDoc("Create a DBReader from a BlobsQueue")
70  .Input(0, "queue", "The shared pointer to a queue containing Blobs.")
71  .Output(0, "reader", "The DBReader for the given BlobsQueue");
72 
73 SHOULD_NOT_DO_GRADIENT(CreateBlobsQueueDB);
74 
75 } // namespace db
76 } // namespace caffe2
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
Definition: workspace.h:63
Copyright (c) 2016-present, Facebook, Inc.