Caffe2 - C++ API
A deep learning, cross platform ML framework
sigmoid_dnnlowp_op.cc
1 #include "caffe2/quantization/server/elementwise_dnnlowp_op.h"
2 #include "caffe2/quantization/server/sigmoid.h"
3 
4 namespace caffe2 {
5 
6 using namespace dnnlowp;
7 
8 template <typename T>
9 class SigmoidFunctor {
10  public:
11  explicit SigmoidFunctor() : sigmoid_() {}
12 
13  inline void operator()(const int n, const T* x, T* y) {
14  for (int i = 0; i < n; ++i) {
15  y[i] = sigmoid_.Compute(x[i]);
16  }
17  }
18 
19  TensorQuantizationParams GetOutputQuantizationParams() const {
20  return sigmoid_.GetOutputQuantizationParams();
21  }
22 
23  private:
24  Sigmoid<T> sigmoid_;
25 };
26 
27 REGISTER_CPU_OPERATOR_WITH_ENGINE(
28  Sigmoid,
29  DNNLOWP,
30  UnaryElementwiseWithArgsDNNLowPOp<
31  std::uint8_t,
32  SigmoidFunctor<std::uint8_t>>);
33 
34 REGISTER_CPU_OPERATOR_WITH_ENGINE(
35  Int8Sigmoid,
36  DNNLOWP,
37  UnaryElementwiseWithArgsDNNLowPOp<
38  std::uint8_t,
39  SigmoidFunctor<std::uint8_t>>);
40 
41 } // namespace caffe2
sigmoid(x) = (tanh(x/2) + 1)/2 Quantized sigmoid is computed as tanh under the hood, we just use different input/output quantization parameters.
Definition: sigmoid.h:13
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13