diff options
Diffstat (limited to 'src/backends/tosaCommon/operatorMappings/ActivationOperator.cpp')
-rw-r--r-- | src/backends/tosaCommon/operatorMappings/ActivationOperator.cpp | 58 |
1 files changed, 24 insertions, 34 deletions
diff --git a/src/backends/tosaCommon/operatorMappings/ActivationOperator.cpp b/src/backends/tosaCommon/operatorMappings/ActivationOperator.cpp index c3e424ea83..c13555da6a 100644 --- a/src/backends/tosaCommon/operatorMappings/ActivationOperator.cpp +++ b/src/backends/tosaCommon/operatorMappings/ActivationOperator.cpp @@ -29,7 +29,7 @@ TosaSerializationBasicBlock* ConvertActivationToTosaOperator(const Layer* layer, throw armnn::Exception("ConvertActivationToTosaOperator: 1 output tensor required."); } - std::string inputName = std::string("input0_"); + std::string inputName = std::string("input_"); std::string outputNameAlpha = std::string("intermediate1_") + GetUniqueTosaMappingID(); std::string outputNameMul = std::string("intermediate2_") + GetUniqueTosaMappingID(); std::string outputName = std::string("output0_"); @@ -39,12 +39,8 @@ TosaSerializationBasicBlock* ConvertActivationToTosaOperator(const Layer* layer, // using the previous and following layers so the graph is connected correctly. For validation this doesn't matter. if (layer != nullptr) { - // Get the layers connected to the input slots and determine unique tensors names. - Layer& connectedInputLayer = layer->GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer(); - inputName = GenerateUniqueName(connectedInputLayer, 0); - - // Determine unique output tensor name. - outputName = GenerateUniqueOutputName(*layer, 0); + inputName = GenerateUniqueInputName(layer->GetInputSlot(0)); + outputName = GenerateUniqueOutputName(*layer); } std::vector<TosaSerializationTensor*> tensors; @@ -54,7 +50,7 @@ TosaSerializationBasicBlock* ConvertActivationToTosaOperator(const Layer* layer, // There also can't be duplicate tensor. std::vector<int32_t> inputShape0; DType inputDType0 = DType::DType_UNKNOWN; - if(inputName.find("input0_") != std::string::npos) + if(inputName.find("input_") != std::string::npos) { inputShape0 = GetTosaTensorShape(inputs[0]->GetShape()); inputDType0 = ArmNNToDType(inputs[0]->GetDataType()); @@ -68,7 +64,8 @@ TosaSerializationBasicBlock* ConvertActivationToTosaOperator(const Layer* layer, #if TOSA_COMPAT_VERSION(0, 60, 0) std::string outputNameMAXMIN= std::string("intermediate3_") + GetUniqueTosaMappingID(); - if (inputDType0 == DType::DType_FP32) + if (inputDType0 == DType::DType_FP32 || + inputDType0 == DType::DType_FP16) { // const_alpha TosaSerializationOperator* alphaOp = nullptr; @@ -125,49 +122,43 @@ TosaSerializationBasicBlock* ConvertActivationToTosaOperator(const Layer* layer, std::string outputNameRescaleIdentity = std::string("intermediate4_") + GetUniqueTosaMappingID(); std::string outputNameRescaleMaxMin = std::string("intermediate5_") + GetUniqueTosaMappingID(); - DType rescale_type = DType::DType_INT32; - float alpha = activationDescriptor->m_A; - double scale_alpha = inputs[0]->GetQuantizationScale() * alpha / outputs[0]->GetQuantizationScale(); - double scale_identity = inputs[0]->GetQuantizationScale() / outputs[0]->GetQuantizationScale(); - int32_t input_zp = inputs[0]->GetQuantizationOffset(); - int32_t output_zp = outputs[0]->GetQuantizationOffset(); + DType rescale_type = DType::DType_INT32; + float alpha = activationDescriptor->m_A; + double scale_alpha = inputs[0]->GetQuantizationScale() * alpha / outputs[0]->GetQuantizationScale(); + double scale_identity = inputs[0]->GetQuantizationScale() / outputs[0]->GetQuantizationScale(); + int32_t input_zp = inputs[0]->GetQuantizationOffset(); + int32_t output_zp = outputs[0]->GetQuantizationOffset(); // Value op_rescale_alpha_in = // buildRescale(rewriter, op, rescale_type, input, scale_alpha, // input_qtype.getZeroPoint(), 0, true, true); TosaSerializationOperator* rescaleAlphaOp = nullptr; - TosaSerializationTensor* rescaleAlphaTensor = nullptr; CreateRescaleTosaOperator(inputName, outputNameRescaleAlpha, - rescale_type, - inputShape0, scale_alpha, input_zp, 0, true, true, - &rescaleAlphaOp, - &rescaleAlphaTensor); - tensors.push_back(rescaleAlphaTensor); - + &rescaleAlphaOp); + tensors.push_back(new TosaSerializationTensor(outputNameRescaleAlpha, + GetTosaTensorShape(inputs[0]->GetShape()), + rescale_type, {})); // Value op_rescale_identity_in = // buildRescale(rewriter, op, rescale_type, input, scale_identity, // input_qtype.getZeroPoint(), 0, true, true); TosaSerializationOperator* rescaleIdentityOp = nullptr; - TosaSerializationTensor* rescaleIdentityTensor = nullptr; CreateRescaleTosaOperator(inputName, outputNameRescaleIdentity, - rescale_type, - inputShape0, scale_identity, input_zp, 0, true, true, - &rescaleIdentityOp, - &rescaleIdentityTensor); - tensors.push_back(rescaleIdentityTensor); - + &rescaleIdentityOp); + tensors.push_back(new TosaSerializationTensor(outputNameRescaleIdentity, + GetTosaTensorShape(inputs[0]->GetShape()), + rescale_type, {})); // Value result_int32; // if (alpha <= 1.0) { // auto max_op = CreateOpAndInfer<tosa::MaximumOp>( @@ -198,19 +189,18 @@ TosaSerializationBasicBlock* ConvertActivationToTosaOperator(const Layer* layer, {outputNameRescaleMaxMin}); } - tensors.push_back(new TosaSerializationTensor(outputNameRescaleMaxMin, inputShape0, rescale_type, {})); + tensors.push_back(new TosaSerializationTensor(outputNameRescaleMaxMin, + GetTosaTensorShape(inputs[0]->GetShape()), + rescale_type, {})); // Value output = buildRescaleFromInt32(rewriter, op, output_type, result_int32, // 1.0, output_qtype.getZeroPoint()); TosaSerializationOperator* rescaleOutputOp = nullptr; CreateFromInt32RescaleTosaOperator(outputNameRescaleMaxMin, outputName, - outputDType0, - outputShape0, 1.0, output_zp, - &rescaleOutputOp, - nullptr); + &rescaleOutputOp); // operatorInputNames/operatorOutputNames ends up being the same as // blockInputNames/blockOutputNames for one-to-one ArmNN to Tosa mappings |