Caffe2 - C++ API
A deep learning, cross platform ML framework
dequantize_dnnlowp_op.cc
1 #include "dequantize_dnnlowp_op.h"
2 
3 #include "caffe2/core/tensor_int8.h"
4 #include "caffe2_dnnlowp_utils.h"
5 
6 namespace caffe2 {
7 
8 template <typename T>
9 DequantizeDNNLowPOp<T>::DequantizeDNNLowPOp(
10  const OperatorDef& operator_def,
11  Workspace* ws)
12  : Operator<CPUContext>(operator_def, ws),
13  qfactory_(dnnlowp::GetQuantizationFactoryOf(this)) {
14  if (this->debug_def().engine() == "DNNLOWP_16" ||
15  this->debug_def().engine() == "DNNLOWP_ROWWISE_16") {
16  LOG(WARNING)
17  << this->debug_def().engine()
18  << " is an experimental feature mostly for testing accuracy with "
19  "fixed-point precision higher than 8 and performance is very slow";
20  }
21 }
22 
23 template <typename T>
24 bool DequantizeDNNLowPOp<T>::RunOnDevice() {
25  using namespace dnnlowp;
26  TensorQuantizationParams in_qparams =
27  GetInputTensorQuantizationParamsOf(this, 0, qfactory_.get());
28 
29  const TensorCPU& input = InputIsType<int8::Int8TensorCPU>(0)
30  ? this->template Input<int8::Int8TensorCPU>(0).t
31  : Input(0);
32 
33  CAFFE_ENFORCE(input.template IsType<T>());
34  Output(0)->ResizeLike(input);
35  fbgemm::Dequantize<T>(
36  input.template data<T>(),
37  Output(0)->template mutable_data<float>(),
38  input.numel(),
39  in_qparams);
40 
41  return true;
42 }
43 
44 OPERATOR_SCHEMA(Dequantize)
45  .NumInputs(1)
46  .NumOutputs(1)
47  .IdenticalTypeAndShapeOfInput(0);
48 
49 REGISTER_CPU_OPERATOR_WITH_ENGINE(
50  Dequantize,
51  DNNLOWP,
52  DequantizeDNNLowPOp<std::uint8_t>);
53 REGISTER_CPU_OPERATOR_WITH_ENGINE(
54  Dequantize,
55  DNNLOWP_ROWWISE,
56  DequantizeDNNLowPOp<std::uint8_t>);
57 
58 REGISTER_CPU_OPERATOR_WITH_ENGINE(
59  Dequantize,
60  DNNLOWP_16,
61  DequantizeDNNLowPOp<std::uint16_t>);
62 REGISTER_CPU_OPERATOR_WITH_ENGINE(
63  Dequantize,
64  DNNLOWP_ROWWISE_16,
65  DequantizeDNNLowPOp<std::uint16_t>);
66 
67 REGISTER_CPU_OPERATOR_WITH_ENGINE(
68  Int8Dequantize,
69  DNNLOWP,
70  DequantizeDNNLowPOp<std::uint8_t>);
71 REGISTER_CPU_OPERATOR_WITH_ENGINE(
72  Int8Dequantize,
73  DNNLOWP_ROWWISE,
74  DequantizeDNNLowPOp<std::uint8_t>);
75 REGISTER_CPU_OPERATOR_WITH_ENGINE(
76  Int8DequantizeRowWise,
77  DNNLOWP,
78  DequantizeDNNLowPOp<std::uint8_t>);
79 
80 } // namespace caffe2
const Tensor & Input(int idx, DeviceType type=Context::GetDeviceType())
Retrieve a non-owning reference to the input at position &#39;idx&#39; for this operator. ...
Definition: operator.h:702
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13