1 #include "quant_decode_op.h" 3 #include "caffe2/core/tensor.h" 4 #include <c10/util/typeid.h> 8 REGISTER_CPU_OPERATOR(QuantDecode, QuantDecodeOp<QuantDecodeRunTy::RUN_ALWAYS>);
9 REGISTER_CPU_GRADIENT_OPERATOR(QuantDecodeGradient, QuantDecodeGradientOp);
10 #ifdef CAFFE2_USE_MPSCNN 11 REGISTER_CPU_OPERATOR(
13 QuantDecodeOp<QuantDecodeRunTy::RUN_ONCE>);
16 OPERATOR_SCHEMA(QuantDecode)
17 .NumInputsOutputs([](
int in,
int out) {
return in > 1 && out + 1 == in; })
19 Decode inputs using codebook. This is a general LUT operator that returns 20 tensors with values from codebook (input 0) based on given indices in 28 codebook = [1.5, 2.5, 3.5] 29 codes_0 = [0, 1, 1, 2] 34 decoded_0 = [1.5, 2.5, 2.5, 3.5] 35 decoded_1 = [3.5, 1.5, 1.5] 37 .Input(0, "codebook",
"Codebook in 1d tensor (float)")
38 .Input(1,
"codes_0",
"Encoded codes 0 (uint8/uint16/int32)")
39 .Input(2,
"codes_1",
"Encoded codes 1 if existed (uint8/uint16/int32)")
40 .Input(3,
"codes_n",
"Encoded codes n if existed (uint8/uint16/int32)")
41 .Output(0,
"decoded_0",
"Decoded tensor for codes_0 (float)")
42 .Output(1,
"decoded_1",
"Decoded tensor for codes_1 (float)")
43 .Output(2,
"decoded_n",
"Decoded tensor for codes_n (float)");
45 GRADIENT_OPERATOR_SCHEMA(QuantDecodeGradient)
46 .NumInputs([](
int in) {
return in >= 3 && in % 2 == 1; })
49 class GetQuantDecodeGradient :
public GradientMakerBase {
50 using GradientMakerBase::GradientMakerBase;
51 vector<OperatorDef> GetGradientDefs()
override {
52 CAFFE_ENFORCE_EQ(Def().input_size(), Def().output_size() + 1);
53 vector<string> gradient_op_inputs;
54 for (
int i = 0; i < Def().input_size(); i++) {
55 gradient_op_inputs.push_back(I(i));
57 for (
int i = 0; i < Def().output_size(); i++) {
58 gradient_op_inputs.push_back(GO(i));
60 return SingleGradientDef(
61 "QuantDecodeGradient",
"", gradient_op_inputs, vector<string>{GI(0)});
65 REGISTER_GRADIENT(QuantDecode, GetQuantDecodeGradient);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...