pytorch

Форк
0
/
queue_ops.cc 
99 строк · 3.7 Кб
1
#include "queue_ops.h"
2
#include <memory>
3
#include "caffe2/utils/math.h"
4

5
namespace caffe2 {
6

7
CAFFE_KNOWN_TYPE(std::shared_ptr<BlobsQueue>);
8

9
REGISTER_CPU_OPERATOR(CreateBlobsQueue, CreateBlobsQueueOp<CPUContext>);
10
REGISTER_CPU_OPERATOR(EnqueueBlobs, EnqueueBlobsOp<CPUContext>);
11
REGISTER_CPU_OPERATOR(DequeueBlobs, DequeueBlobsOp<CPUContext>);
12
REGISTER_CPU_OPERATOR(CloseBlobsQueue, CloseBlobsQueueOp<CPUContext>);
13

14
REGISTER_CPU_OPERATOR(SafeEnqueueBlobs, SafeEnqueueBlobsOp<CPUContext>);
15
REGISTER_CPU_OPERATOR(SafeDequeueBlobs, SafeDequeueBlobsOp<CPUContext>);
16
REGISTER_CPU_OPERATOR(
17
    WeightedSampleDequeueBlobs,
18
    WeightedSampleDequeueBlobsOp<CPUContext>);
19

20
OPERATOR_SCHEMA(CreateBlobsQueue).NumInputs(0).NumOutputs(1);
21
OPERATOR_SCHEMA(EnqueueBlobs)
22
    .NumInputsOutputs([](int inputs, int outputs) {
23
      return inputs >= 2 && outputs >= 1 && inputs == outputs + 1;
24
    })
25
    .EnforceInplace([](int input, int output) { return input == output + 1; });
26
OPERATOR_SCHEMA(DequeueBlobs)
27
    .NumInputsOutputs([](int inputs, int outputs) {
28
      return inputs == 1 && outputs >= 1;
29
    })
30
    .SetDoc(R"DOC(
31
  Dequeue the blobs from queue.
32
  )DOC")
33
    .Arg("timeout_secs", "Timeout in secs, default: no timeout")
34
    .Input(0, "queue", "The shared pointer for the BlobsQueue")
35
    .Output(0, "blob", "The blob to store the dequeued data");
36

37
OPERATOR_SCHEMA(CloseBlobsQueue).NumInputs(1).NumOutputs(0);
38

39
OPERATOR_SCHEMA(SafeEnqueueBlobs)
40
    .NumInputsOutputs([](int inputs, int outputs) {
41
      return inputs >= 2 && outputs >= 2 && inputs == outputs;
42
    })
43
    .EnforceInplace([](int input, int output) { return input == output + 1; })
44
    .SetDoc(R"DOC(
45
Enqueue the blobs into queue. When the queue is closed and full, the output
46
status will be set to true which can be used as exit criteria for execution
47
step.
48
The 1st input is the queue and the last output is the status. The rest are
49
data blobs.
50
)DOC")
51
    .Input(0, "queue", "The shared pointer for the BlobsQueue");
52

53
OPERATOR_SCHEMA(SafeDequeueBlobs)
54
    .NumInputsOutputs([](int inputs, int outputs) {
55
      return inputs == 1 && outputs >= 2;
56
    })
57
    .SetDoc(R"DOC(
58
Dequeue the blobs from queue. When the queue is closed and empty, the output
59
status will be set to true which can be used as exit criteria for execution
60
step.
61
The 1st input is the queue and the last output is the status. The rest are
62
data blobs.
63
)DOC")
64
    .Arg(
65
        "num_records",
66
        "(default 1) If > 1, multiple records will be dequeued and tensors "
67
        "for each column will be concatenated. This requires all tensors in "
68
        "the records to be at least 1D, and to have the same inner dimensions.")
69
    .Input(0, "queue", "The shared pointer for the BlobsQueue")
70
    .Output(0, "blob", "The blob to store the dequeued data")
71
    .Output(1, "status", "Is set to 0/1 depending on the success of dequeue");
72

73
OPERATOR_SCHEMA(WeightedSampleDequeueBlobs)
74
    .NumInputs(1, INT_MAX)
75
    .NumOutputs(2, INT_MAX)
76
    .SetDoc(R"DOC(
77
Dequeue the blobs from multiple queues. When one of queues is closed and empty,
78
the output status will be set to true which can be used as exit criteria for
79
execution step.
80
The 1st input is the queue and the last output is the status. The rest are
81
data blobs.
82
)DOC")
83
    .Arg("weights", "Weights for sampling from multiple queues")
84
    .Arg(
85
        "table_idx_blob",
86
        "The index of the blob (among the output blob list) "
87
        "that will be used to store the index of the table chosen to read the "
88
        "current batch.");
89

90
NO_GRADIENT(CreateBlobsQueue);
91
NO_GRADIENT(EnqueueBlobs);
92
NO_GRADIENT(DequeueBlobs);
93
NO_GRADIENT(CloseBlobsQueue);
94

95
NO_GRADIENT(SafeEnqueueBlobs);
96
NO_GRADIENT(SafeDequeueBlobs);
97
NO_GRADIENT(WeightedSampleDequeueBlobs);
98

99
} // namespace caffe2
100

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.