Caffe2 - C++ API
A deep learning, cross platform ML framework
accumulate_op.h
1 #ifndef CAFFE2_OPERATORS_ACCUMULATE_OP_H_
2 #define CAFFE2_OPERATORS_ACCUMULATE_OP_H_
3 
4 #include "caffe2/core/context.h"
5 #include "caffe2/core/operator.h"
6 #include "caffe2/utils/math.h"
7 
8 namespace caffe2 {
9 
10 template <typename T, class Context>
11 class AccumulateOp final : public Operator<Context> {
12  public:
13  AccumulateOp(const OperatorDef& operator_def, Workspace* ws)
14  : Operator<Context>(operator_def, ws),
15  gamma_(static_cast<T>(
16  OperatorBase::template GetSingleArgument<float>("gamma", 1.0))) {}
17  USE_OPERATOR_CONTEXT_FUNCTIONS;
18 
19  bool RunOnDevice() override {
20  auto& input = Input(0);
21  auto* output = Output(0);
22  if (output->dims() != input.dims()) {
23  LOG(INFO) << "Reshaping and initializing output.";
24  output->ResizeLike(input);
25  math::Set<T, Context>(
26  output->size(), 0, output->template mutable_data<T>(), &context_);
27  }
28  math::Axpby<T, Context>(
29  input.size(),
30  static_cast<T>(1),
31  input.template data<T>(),
32  gamma_,
33  output->template mutable_data<T>(),
34  &context_);
35  return true;
36  }
37 
38  protected:
39  T gamma_;
40 };
41 
42 } // namespace caffe2
43 
44 #endif // CAFFE2_OPERATORS_ACCUMULATE_OP_H_
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 ...