Caffe2 - C++ API
A deep learning, cross platform ML framework
activation_ops.cc
1 #include "caffe2/mobile/contrib/arm-compute/core/context.h"
2 #include "caffe2/mobile/contrib/arm-compute/core/operator.h"
3 
4 #include "caffe2/mobile/contrib/arm-compute/operators/activation_ops.h"
5 #include "caffe2/operators/relu_op.h"
6 
7 namespace caffe2 {
8 
9 template <typename T>
10 bool GLReluOp<T>::RunOnDevice() {
11 
12  auto *Xblob = OperatorBase::Inputs()[0];
13  if (first_run_) {
14  X_ = GLContext::getGLTensor<T>(Xblob);
15  }
16 
17  GLTensor<T> *Y =
18  OperatorBase::Outputs()[0]->template GetMutable<GLTensor<T>>();
19 
20  if (first_run_) {
21  first_run_ = false;
22  if (Y->get_underlying() != X_->get_underlying())
23  {
24  Y->ResizeLike(*X_);
25  }
26  relu_layer_.configure(
27  X_->get_underlying(), Y->get_underlying(),
28  arm_compute::ActivationLayerInfo(
29  arm_compute::ActivationLayerInfo::ActivationFunction::RELU));
30 
31  } else {
32  X_->lazy_allocate(Xblob, second_run_, true);
33  if (second_run_) {
34  second_run_ = false;
35  // in place activation, do not need to allocate new memory
36  if (Y->get_underlying() != X_->get_underlying())
37  {
38  Y->allocate();
39  }
40  }
41  relu_layer_.run();
42  }
43 
44  return true;
45 }
46 
47 REGISTER_GL_OPERATOR(Relu, GLReluOp<half>);
48 
49 template <typename T>
50 bool GLSigmoidOp<T>::RunOnDevice() {
51 
52  auto *Xblob = OperatorBase::Inputs()[0];
53  if (first_run_) {
54  X_ = GLContext::getGLTensor<T>(Xblob);
55  }
56 
57  GLTensor<T> *Y =
58  OperatorBase::Outputs()[0]->template GetMutable<GLTensor<T>>();
59  if (first_run_) {
60  first_run_ = false;
61 
62  if (Y->get_underlying() != X_->get_underlying())
63  {
64  Y->ResizeLike(*X_);
65  }
66 
67  sigmoid_layer_.configure(
68  X_->get_underlying(), Y->get_underlying(),
69  arm_compute::ActivationLayerInfo(
70  arm_compute::ActivationLayerInfo::ActivationFunction::LOGISTIC));
71  } else {
72  X_->lazy_allocate(Xblob, second_run_, true);
73  if (second_run_) {
74  second_run_ = false;
75  // in place activation, do not need to allocate new memory
76  if (Y->get_underlying() != X_->get_underlying())
77  {
78  Y->allocate();
79  }
80  }
81  sigmoid_layer_.run();
82  }
83 
84  return true;
85 }
86 
87 REGISTER_GL_OPERATOR(Sigmoid, GLSigmoidOp<DataType>);
88 
89 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...