16 const std::vector<const TensorInfo*>& inputs,
17 const std::vector<const TensorInfo*>& outputs)
20 "ConvertQuantizeToTosaOperator: Quantize must have only one input" );
22 "ConvertQuantizeToTosaOperator: Quantize must have only one output" );
24 std::string inputName = std::string(
"input_");
25 std::string outputName = std::string(
"output0_");
48 scale = (scale != 0) ? (1 / scale) : scale;
50 std::vector<TosaSerializationTensor*> tensors;
54 bool isFloatInput = inputDType0 == DType::DType_FP16 || inputDType0 == DType::DType_FP32;
59 if(inputName.find(
"input_") != std::string::npos)
61 tensors.push_back(
new TosaSerializationTensor(inputName, inputShape0, inputDType0, {}));
82 TosaSerializationOperator* zeroPointOp =
nullptr;
83 TosaSerializationTensor* zeroPointTensor =
nullptr;
84 CreateConstTosaOperator<float>(outputNameZeroPoint,
90 tensors.push_back(zeroPointTensor);
93 TosaSerializationOperator* scaleOp =
nullptr;
94 TosaSerializationTensor* scaleTensor =
nullptr;
95 CreateConstTosaOperator<float>(outputNameScale,
101 tensors.push_back(scaleTensor);
105 TosaMulAttribute mulAttribute(shift);
106 TosaSerializationOperator* mulOp =
new TosaSerializationOperator(Op_MUL,
107 Attribute_MulAttribute,
109 {inputName, outputNameScale},
111 tensors.push_back(
new TosaSerializationTensor(outputNameMul, inputShape0, inputDType0, {}));
114 TosaSerializationOperator* addOp =
new TosaSerializationOperator(Op_ADD,
117 {outputNameMul, outputNameZeroPoint},
119 tensors.push_back(
new TosaSerializationTensor(outputNameAdd, inputShape0, inputDType0, {}));
122 TosaSerializationOperator* castOp =
new TosaSerializationOperator(Op_CAST,
128 tensors.push_back(
new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}));
132 return new TosaSerializationBasicBlock(blockName,
134 {zeroPointOp, scaleOp, mulOp, addOp, castOp},
141 double scale_alpha = inputs[0]->GetQuantizationScale() / outputs[0]->GetQuantizationScale();
142 int32_t input_zp = inputs[0]->GetQuantizationOffset();
143 int32_t output_zp = outputs[0]->GetQuantizationOffset();
145 TosaSerializationOperator* rescaleOp =
nullptr;
154 tensors.push_back(
new TosaSerializationTensor(outputName,
160 return new TosaSerializationBasicBlock(blockName,