Caffe2 - C++ API
A deep learning, cross platform ML framework
resize_nearest_dnnlowp_op.cc
1 #include "caffe2/quantization/server/resize_nearest_dnnlowp_op.h"
2 
3 namespace caffe2 {
4 
5 template <typename T>
6 bool ResizeNearestDNNLowPOp<T>::RunOnDevice() {
7  using namespace dnnlowp;
8 
9  this->ParseDNNLowPOperatorArguments_();
10 
11  // Choose quantization params
12  in_qparams_[0] = GetInputTensorQuantizationParamsOf(this, 0, qfactory_.get());
13 
14  const auto& X = InputTensorCPU_(0);
15  auto* Y = OutputTensorCPU_(0);
16 
17  CAFFE_ENFORCE_EQ(X.ndim(), 4);
18  const int N = X.dim32(0);
19  const int IH = X.dim32(1);
20  const int IW = X.dim32(2);
21  const int C = X.dim32(3);
22  const int OW = IW * width_scale_;
23  const int OH = IH * height_scale_;
24 
25  Y->Resize(N, OH, OW, C);
26  const T* X_data = X.template data<T>();
27  T* Y_data = Y->template mutable_data<T>();
28 
29 #ifdef _OPENMP
30 #pragma omp parallel for
31 #endif
32  for (int n = 0; n < N; ++n) {
33  for (int y = 0; y < OH; ++y) {
34  const int in_y = std::min((int)(y / height_scale_), (IH - 1));
35  for (int x = 0; x < OW; ++x) {
36  const int in_x = std::min((int)(x / width_scale_), (IW - 1));
37  std::memcpy(
38  &Y_data[((n * OH + y) * OW + x) * C],
39  &X_data[((n * IH + in_y) * IW + in_x) * C],
40  C * sizeof(T));
41  }
42  }
43  }
44 
45  // Even if there is a pre-chosen quantization parameters for the output,
46  // it is ignored because resize nearest output quantization should be same
47  // as the input.
48  PropagateOutputTensorQuantizationParams(this, 0, in_qparams_[0]);
49 
50  return true;
51 }
52 
53 REGISTER_CPU_OPERATOR_WITH_ENGINE(
54  Int8ResizeNearest,
55  DNNLOWP,
56  ResizeNearestDNNLowPOp<uint8_t>);
57 
58 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13
Definition: static.cpp:64