1 #include "quantize_dnnlowp_op.h" 2 #include "dnnlowp_op.h" 8 #include "caffe2/core/tensor_int8.h" 9 #include "caffe2_dnnlowp_utils.h" 10 #include "dnnlowp_partition.h" 17 QuantizeDNNLowPOp<T>::QuantizeDNNLowPOp(
18 const OperatorDef& operator_def,
20 : Operator<CPUContext>(operator_def, ws),
21 qfactory_(
dnnlowp::GetQuantizationFactoryOf(this)) {}
24 bool QuantizeDNNLowPOp<T>::RunOnDevice() {
27 if (!arguments_parsed_) {
28 dnnlowp::ParseDNNLowPOperatorArguments(
this);
29 arguments_parsed_ =
true;
32 CAFFE_ENFORCE(Input(0).
template IsType<float>());
34 TensorQuantizationParams in_qparams;
35 if (HasStaticQuantization(
this)) {
36 in_qparams = GetStaticQuantizationParamsOf(
this, 0);
38 in_qparams = GetInputTensorQuantizationParamsOf(
this, 0, qfactory_.get());
40 int8::Int8TensorCPU* output =
41 Outputs()[0]->template GetMutable<int8::Int8TensorCPU>();
42 output->t.ResizeLike(Input(0));
44 const float* in_data = Input(0).template data<float>();
45 T* out_data = output->t.template mutable_data<T>();
52 tie(i_begin, i_end) = Get1DPartition(
53 Input(0).numel(), dnnlowp_get_num_threads(), dnnlowp_get_thread_num());
55 in_data + i_begin, out_data + i_begin, i_end - i_begin, in_qparams);
58 PropagateOutputTensorQuantizationParams(
this, 0, in_qparams);
63 OPERATOR_SCHEMA(Quantize)
66 .IdenticalTypeAndShapeOfInput(0);
68 REGISTER_CPU_OPERATOR_WITH_ENGINE(
71 QuantizeDNNLowPOp<uint8_t>);
72 REGISTER_CPU_OPERATOR_WITH_ENGINE(
75 QuantizeDNNLowPOp<uint8_t>);
77 REGISTER_CPU_OPERATOR_WITH_ENGINE(
80 QuantizeDNNLowPOp<uint16_t>);
81 REGISTER_CPU_OPERATOR_WITH_ENGINE(
84 QuantizeDNNLowPOp<uint16_t>);
86 REGISTER_CPU_OPERATOR_WITH_ENGINE(
89 QuantizeDNNLowPOp<uint8_t>);
90 REGISTER_CPU_OPERATOR_WITH_ENGINE(
93 QuantizeDNNLowPOp<uint8_t>);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...