22 if (inputs.size() != 1)
24 throw armnn::Exception(
"ConvertLeakyReluToTosaOperator: 1 input tensors required.");
27 if (outputs.size() != 1)
29 throw armnn::Exception(
"ConvertLeakyReluToTosaOperator: 1 output tensor required.");
32 std::string inputName = std::string(
"input_");
35 std::string outputName = std::string(
"output0_");
46 std::vector<TosaSerializationTensor*> tensors;
51 std::vector<int32_t> inputShape0;
52 DType inputDType0 = DType::DType_UNKNOWN;
53 if(inputName.find(
"input_") != std::string::npos)
57 tensors.push_back(
new TosaSerializationTensor(inputName, inputShape0, inputDType0, {}));
61 DType outputDType0 =
ArmNNToDType(outputs[0]->GetDataType());
62 tensors.push_back(
new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}));
66 if (inputDType0 == DType::DType_FP32 ||
67 inputDType0 == DType::DType_FP16)
70 TosaSerializationOperator* alphaOp =
nullptr;
71 TosaSerializationTensor* alphaTensor =
nullptr;
72 CreateConstTosaOperator<float>(outputNameAlpha,
73 activationDescriptor->
m_A,
78 tensors.push_back(alphaTensor);
82 TosaMulAttribute mulAttribute(shift);
83 TosaSerializationOperator* mulOp =
new TosaSerializationOperator(Op_MUL,
84 Attribute_MulAttribute,
86 {inputName, outputNameAlpha},
88 tensors.push_back(
new TosaSerializationTensor(outputNameMul, inputShape0, inputDType0, {}));
90 TosaSerializationOperator* op =
nullptr;
91 if (activationDescriptor->
m_A <= 1.0)
93 op =
new TosaSerializationOperator(Op_MAXIMUM,
96 {inputName, outputNameMul},
101 op =
new TosaSerializationOperator(Op_MINIMUM,
104 {inputName, outputNameMul},
111 return new TosaSerializationBasicBlock(blockName,
113 {alphaOp, mulOp, op},
124 DType rescale_type = DType::DType_INT32;
125 float alpha = activationDescriptor->
m_A;
126 double scale_alpha = inputs[0]->GetQuantizationScale() * alpha / outputs[0]->GetQuantizationScale();
127 double scale_identity = inputs[0]->GetQuantizationScale() / outputs[0]->GetQuantizationScale();
128 int32_t input_zp = inputs[0]->GetQuantizationOffset();
129 int32_t output_zp = outputs[0]->GetQuantizationOffset();
134 TosaSerializationOperator* rescaleAlphaOp =
nullptr;
136 outputNameRescaleAlpha,
143 tensors.push_back(
new TosaSerializationTensor(outputNameRescaleAlpha,
149 TosaSerializationOperator* rescaleIdentityOp =
nullptr;
151 outputNameRescaleIdentity,
158 tensors.push_back(
new TosaSerializationTensor(outputNameRescaleIdentity,
173 TosaSerializationOperator* op =
nullptr;
176 op =
new TosaSerializationOperator(Op_MAXIMUM,
179 {outputNameRescaleAlpha, outputNameRescaleIdentity},
180 {outputNameRescaleMaxMin});
184 op =
new TosaSerializationOperator(Op_MINIMUM,
187 {outputNameRescaleAlpha, outputNameRescaleIdentity},
188 {outputNameRescaleMaxMin});
191 tensors.push_back(
new TosaSerializationTensor(outputNameRescaleMaxMin,
197 TosaSerializationOperator* rescaleOutputOp =
nullptr;
206 return new TosaSerializationBasicBlock(blockName,
208 {rescaleAlphaOp, rescaleIdentityOp, op, rescaleOutputOp},