Caffe2 - C++ API
A deep learning, cross platform ML framework
elementwise_sum_op.cc
1 #include "caffe2/mobile/contrib/arm-compute/core/context.h"
2 #include "caffe2/mobile/contrib/arm-compute/core/operator.h"
3 #include "caffe2/operators/utility_ops.h"
4 
5 namespace caffe2 {
6 
7 template <typename T> class GLSumOp final : public Operator<GLContext> {
8 public:
9  GLSumOp(const OperatorDef &operator_def, Workspace *ws)
10  : Operator<GLContext>(operator_def, ws) {}
11  virtual ~GLSumOp() noexcept {}
12  USE_OPERATOR_FUNCTIONS(GLContext);
13  bool RunOnDevice() override;
14 private:
15  arm_compute::GCArithmeticAddition add_layer_;
16  bool first_run_ = true, second_run_ = true;
17  GLContext::deleted_unique_ptr<const GLTensor<T>> A_, B_;
18 };
19 
20 
21 template <typename T>
23 
24  auto *Ablob = OperatorBase::Inputs()[0];
25  auto *Bblob = OperatorBase::Inputs()[1];
26 
27  if (first_run_) {
28  A_ = GLContext::getGLTensor<T>(Ablob);
29  B_ = GLContext::getGLTensor<T>(Bblob);
30  }
31 
32  GLTensor<T> *Y =
33  OperatorBase::Outputs()[0]->template GetMutable<GLTensor<T>>();
34  if (first_run_) {
35  first_run_ = false;
36  Y->ResizeLike(*A_);
37  add_layer_.configure(A_->get_underlying(), B_->get_underlying(), Y->get_underlying(), arm_compute::ConvertPolicy::SATURATE);
38  } else {
39  A_->lazy_allocate(Ablob, second_run_, true);
40  B_->lazy_allocate(Bblob, second_run_, true);
41  if (second_run_) {
42  Y->allocate();
43  second_run_ = false;
44  }
45  add_layer_.run();
46  }
47 
48  return true;
49 }
50 
51 REGISTER_GL_OPERATOR(Sum, GLSumOp<DataType>);
52 REGISTER_GL_OPERATOR(Add, GLSumOp<DataType>);
53 
54 } // namespace caffe2
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 ...