Caffe2 - C++ API
A deep learning, cross platform ML framework
elementwise_sum_op.cc
1 #include "caffe2/operators/utility_ops.h"
2 
3 namespace caffe2 {
4 
5 namespace {
6 OpSchema::Cost CostInferenceForSum(
7  const OperatorDef& def,
8  const vector<TensorShape>& in) {
9  struct OpSchema::Cost cost = PointwiseCostInference<1>(def, in);
10  cost.flops *= (in.size() - 1);
11  cost.params_bytes = 0;
12  return cost;
13 }
14 } // namespace
15 
16 REGISTER_CPU_OPERATOR(Sum, SumOp<CPUContext>);
17 
18 OPERATOR_SCHEMA(Sum)
19  .NumInputs(1, INT_MAX)
20  .NumOutputs(1)
21  .AllowInplace({{0, 0}})
22  .CostInferenceFunction(CostInferenceForSum)
23  .InputsCanCrossDevices()
24  .IdenticalTypeAndShapeOfInput(0)
25  .SetDoc(R"DOC(
26 Element-wise sum of each of the input tensors. The first input tensor can be
27 used in-place as the output tensor, in which case the sum will be done in
28 place and results will be accumulated in input0. All inputs and outputs must
29 have the same shape and data type.
30 )DOC")
31  .Input(0, "data_0", "First of the input tensors. Can be inplace.")
32  .Output(0, "sum", "Output tensor. Same dimension as inputs.")
33  .InheritOnnxSchema("Sum");
34 }
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...