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 =
ArmNNToDType(inputs[0]->GetDataType());
53 if(inputName.find(
"input_") != std::string::npos)
56 tensors.push_back(
new TosaSerializationTensor(inputName, inputShape0, inputDType0, {}));
60 DType outputDType0 =
ArmNNToDType(outputs[0]->GetDataType());
61 tensors.push_back(
new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}));
63 if (inputDType0 == DType::DType_FP32 ||
64 inputDType0 == DType::DType_FP16)
67 TosaSerializationOperator* alphaOp =
nullptr;
68 TosaSerializationTensor* alphaTensor =
nullptr;
69 CreateConstTosaOperator<float>(outputNameAlpha,
70 activationDescriptor->
m_A,
75 tensors.push_back(alphaTensor);
79 TosaMulAttribute mulAttribute(shift);
80 TosaSerializationOperator* mulOp =
new TosaSerializationOperator(Op_MUL,
81 Attribute_MulAttribute,
83 {inputName, outputNameAlpha},
85 tensors.push_back(
new TosaSerializationTensor(outputNameMul, inputShape0, inputDType0, {}));
87 TosaSerializationOperator* op =
nullptr;
88 if (activationDescriptor->
m_A <= 1.0)
90 op =
new TosaSerializationOperator(Op_MAXIMUM,
93 {inputName, outputNameMul},
98 op =
new TosaSerializationOperator(Op_MINIMUM,
101 {inputName, outputNameMul},
108 return new TosaSerializationBasicBlock(blockName,
110 {alphaOp, mulOp, op},
121 DType rescale_type = DType::DType_INT32;
122 float alpha = activationDescriptor->
m_A;
123 double scale_alpha = inputs[0]->GetQuantizationScale() * alpha / outputs[0]->GetQuantizationScale();
124 double scale_identity = inputs[0]->GetQuantizationScale() / outputs[0]->GetQuantizationScale();
125 int32_t input_zp = inputs[0]->GetQuantizationOffset();
126 int32_t output_zp = outputs[0]->GetQuantizationOffset();
131 TosaSerializationOperator* rescaleAlphaOp =
nullptr;
133 outputNameRescaleAlpha,
142 tensors.push_back(
new TosaSerializationTensor(outputNameRescaleAlpha,
148 TosaSerializationOperator* rescaleIdentityOp =
nullptr;
150 outputNameRescaleIdentity,
159 tensors.push_back(
new TosaSerializationTensor(outputNameRescaleIdentity,
174 TosaSerializationOperator* op =
nullptr;
177 op =
new TosaSerializationOperator(Op_MAXIMUM,
180 {outputNameRescaleAlpha, outputNameRescaleIdentity},
181 {outputNameRescaleMaxMin});
185 op =
new TosaSerializationOperator(Op_MINIMUM,
188 {outputNameRescaleAlpha, outputNameRescaleIdentity},
189 {outputNameRescaleMaxMin});
192 tensors.push_back(
new TosaSerializationTensor(outputNameRescaleMaxMin,
198 TosaSerializationOperator* rescaleOutputOp =
nullptr;
212 return new TosaSerializationBasicBlock(blockName,
214 {rescaleAlphaOp, rescaleIdentityOp, op, rescaleOutputOp},
std::string GenerateUniqueOutputName(const Layer &layer, uint32_t layerSlot=0)
const std::string mainName
DType ArmNNToDType(const DataType &type)
std::vector< int32_t > GetTosaTensorShape(const TensorShape &shape)
std::string GenerateUniqueInputName(const armnn::InputSlot &slot)
std::string GetUniqueTosaMappingID()
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 m_A
Alpha upper bound value used by the activation functions. (BoundedReLu, Linear, TanH,...