22 "ConvertQuantizeToTosaOperator: Quantize must have only one input" );
24 "ConvertQuantizeToTosaOperator: Quantize must have only one output" );
26 std::string inputName = std::string(
"input_");
27 std::string outputName = std::string(
"output0_");
50 scale = (scale != 0) ? (1 / scale) : scale;
52 std::vector<TosaSerializationTensor*> tensors;
56 bool isFloatInput = inputDType0 == DType::DType_FP16 || inputDType0 == DType::DType_FP32;
61 if(inputName.find(
"input_") != std::string::npos)
63 DType tmp = inputDType0;
71 tensors.push_back(
new TosaSerializationTensor(inputName, inputShape0, tmp, {}));
78 throw armnn::Exception(fmt::format(
"ConvertQuantizeToTosaOperator: {} intermediate input"
79 " layer not supported.",EnumNamesDType()[inputDType0]));
101 TosaSerializationOperator* zeroPointOp =
nullptr;
102 TosaSerializationTensor* zeroPointTensor =
nullptr;
103 CreateConstTosaOperator<float>(outputNameZeroPoint,
109 tensors.push_back(zeroPointTensor);
112 TosaSerializationOperator* scaleOp =
nullptr;
113 TosaSerializationTensor* scaleTensor =
nullptr;
114 CreateConstTosaOperator<float>(outputNameScale,
120 tensors.push_back(scaleTensor);
124 TosaMulAttribute mulAttribute(shift);
125 TosaSerializationOperator* mulOp =
new TosaSerializationOperator(Op_MUL,
126 Attribute_MulAttribute,
128 {inputName, outputNameScale},
130 tensors.push_back(
new TosaSerializationTensor(outputNameMul, inputShape0, inputDType0, {}));
133 TosaSerializationOperator* addOp =
new TosaSerializationOperator(Op_ADD,
136 {outputNameMul, outputNameZeroPoint},
138 tensors.push_back(
new TosaSerializationTensor(outputNameAdd, inputShape0, inputDType0, {}));
141 TosaSerializationOperator* castOp =
new TosaSerializationOperator(Op_CAST,
147 tensors.push_back(
new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}));
151 return new TosaSerializationBasicBlock(blockName,
153 {zeroPointOp, scaleOp, mulOp, addOp, castOp},
160 double scale_alpha = inputs[0]->GetQuantizationScale() / outputs[0]->GetQuantizationScale();
161 int32_t input_zp = inputs[0]->GetQuantizationOffset();
162 int32_t output_zp = outputs[0]->GetQuantizationOffset();
164 TosaSerializationOperator* rescaleOp =
nullptr;
183 tensors.push_back(
new TosaSerializationTensor(outputName,
189 return new TosaSerializationBasicBlock(blockName,
#define ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(_cond, _str)
std::string GenerateUniqueOutputName(const Layer &layer, uint32_t layerSlot=0)
const std::string mainName
bool IsUnsignedDataType(DType type)
DType ArmNNToDType(const DataType &type)
std::vector< int32_t > GetTosaTensorShape(const TensorShape &shape)
std::string GenerateUniqueInputName(const armnn::InputSlot &slot)
std::string GetUniqueTosaMappingID()
void FlipSignage(DType &type)
void CreateRescaleTosaOperator(const std::string &inputName, const std::string &outputName, double scale, int32_t input_zp, int32_t output_zp, bool input_unsigned, bool output_unsigned, bool double_round, bool scale32, TosaSerializationOperator **op)
Base class for all ArmNN exceptions so that users can filter to just those.
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
float GetQuantizationScale() const
int32_t GetQuantizationOffset() const
const TensorShape & GetShape() const
DataType GetDataType() const