14 const std::vector<const TensorInfo*>& inputs,
15 const std::vector<const TensorInfo*>& outputs)
18 "ConvertQuantizeToTosaOperator: Quantize must have only one input" );
20 "ConvertQuantizeToTosaOperator: Quantize must have only one output" );
22 std::string inputName = std::string(
"input0_");
27 std::string outputName = std::string(
"output0_");
54 scale = (scale != 0) ? (1 / scale) : scale;
56 std::vector<TosaSerializationTensor*> tensors;
61 std::vector<int32_t> inputShape0;
62 DType inputDType0 = DType::DType_UNKNOWN;
63 if(inputName.find(
"input0_") != std::string::npos)
68 "ConvertQuantizeToTosaOperator: Quantize input must be of type Float" );
69 tensors.push_back(
new TosaSerializationTensor(inputName, inputShape0, inputDType0, {}));
83 TosaSerializationOperator* zeroPointOp =
nullptr;
84 TosaSerializationTensor* zeroPointTensor =
nullptr;
85 CreateConstTosaOperator<float>(outputNameZeroPoint,
91 tensors.push_back(zeroPointTensor);
94 TosaSerializationOperator *scaleOp =
nullptr;
95 TosaSerializationTensor* scaleTensor =
nullptr;
96 CreateConstTosaOperator<float>(outputNameScale,
102 tensors.push_back(scaleTensor);
106 TosaMulAttribute mulAttribute(shift);
107 TosaSerializationOperator* mulOp =
new TosaSerializationOperator(Op_MUL,
108 Attribute_MulAttribute,
110 {inputName, outputNameScale},
112 tensors.push_back(
new TosaSerializationTensor(outputNameMul, inputShape0, inputDType0, {}));
115 TosaSerializationOperator* addOp =
new TosaSerializationOperator(Op_ADD,
118 {outputNameMul, outputNameZeroPoint},
120 tensors.push_back(
new TosaSerializationTensor(outputNameAdd, inputShape0, inputDType0, {}));
123 TosaSerializationOperator* castOp =
new TosaSerializationOperator(Op_CAST,
129 tensors.push_back(
new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}));
133 return new TosaSerializationBasicBlock(blockName,
135 {zeroPointOp, scaleOp, mulOp, addOp, castOp},