Caffe2 - C++ API
A deep learning, cross platform ML framework
lengths_reducer_ops.cc
1 #include "caffe2/operators/lengths_reducer_ops.h"
2 #include "caffe2/core/context.h"
3 #include "caffe2/core/operator.h"
4 #include "caffe2/utils/math.h"
5 
6 namespace caffe2 {
7 
8 // Use _STR option because the schema is declared using _STR version too in
9 // generic fashion. Otherwise it'd break schema declaration check.
10 // TODO(dzhulgakov): remove _STR when all lengths ops are off generic version.
11 
12 REGISTER_CPU_OPERATOR_STR(
13  "SparseLengthsSum",
14  CPUSparseLengthsReductionOp<float, TensorTypes<float, float16>, 0, 0>);
15 REGISTER_CPU_OPERATOR_STR(
16  "SparseLengthsWeightedSum",
17  CPUSparseLengthsReductionOp<float, TensorTypes<float, float16>, 1, 0>);
18 REGISTER_CPU_OPERATOR_STR(
19  "SparseLengthsMean",
20  CPUSparseLengthsReductionOp<float, TensorTypes<float, float16>, 0, 1>);
21 
22 OPERATOR_SCHEMA(SparseLengthsPositionalWeightedSum)
23  .NumInputs(4)
24  .NumOutputs(1)
25  .SetDoc(R"DOC(
26 Variation of SparseLengthsWeightedSum operator, where, for each row,
27 weights are accessed by indices [0..L-1], where L is the length of given row.
28 This is basically a fused operator of LengthsRangeFill + Gather +
29 SparseWeightedSum
30 )DOC")
31  .Input(
32  0,
33  "DATA",
34  "uint8 tensor obtained with "
35  "operator FloatToRowwiseQuantized8Bits")
36  .Input(
37  1,
38  "WEIGHT",
39  "Scalar multipliers for the input slices. Must "
40  "be a vector with the length matching the length of DATA")
41  .Input(
42  2,
43  "INDICES",
44  "Integer vector containing indices of the first "
45  "dimension of DATA for the slices that are being aggregated")
46  .Input(
47  3,
48  "LENGTHS",
49  "Vector with the same sum of elements as the first dimension of DATA")
50  .Output(0, "output", "output");
51 
52 REGISTER_CPU_OPERATOR_STR(
53  "SparseLengthsPositionalWeightedSum",
54  CPUSparseLengthsReductionOp<float, TensorTypes<float, float16>, 1, 0, 1>);
55 
56 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...