22 if (inputs.size() != 1)
24 throw armnn::Exception(
"ConvertGeluToTosaOperator: 1 input tensors required.");
27 if (outputs.size() != 1)
29 throw armnn::Exception(
"ConvertGeluToTosaOperator: 1 output tensor required.");
32 if (desc->
m_Function != ActivationFunction::Gelu)
34 throw armnn::Exception(
"ConvertGeluToTosaOperator ActivationDescriptor only supports function Gelu.");
37 std::string inputName = std::string(
"input_");
38 std::string outputName = std::string(
"output0_");
49 std::vector<TosaSerializationTensor*> tensors;
50 std::vector<TosaSerializationOperator*> operators;
52 float input_scale = inputs[0]->GetQuantizationScale();
53 float output_scale = outputs[0]->GetQuantizationScale();
54 int32_t input_zp = inputs[0]->GetQuantizationOffset();
55 int32_t output_zp = outputs[0]->GetQuantizationOffset();
56 DataType inputDType = inputs[0]->GetDataType();
58 bool isInt8 = inputDType == DataType::QAsymmS8 || inputDType == DataType::QSymmS8;
61 auto gelu_transform = [](
float in) ->
float {
62 return 0.5f * in * std::erfc(in *
static_cast<float>(-0.70710678118654752440));
65 TosaTableAttribute attribute(
67 operators.push_back(
new TosaSerializationOperator(tosa::Op_TABLE,
68 Attribute_TableAttribute,
73 else if (inputDType == DataType::QSymmS16 ||
74 inputDType == DataType::Signed32 ||
75 inputDType == DataType::Signed64)
77 throw Exception(
"ConvertGeluOperator() only supports int8 quantized types.");
81 throw Exception(
"ConvertGeluOperator() floating point types currently unimplemented.");
87 std::vector<int32_t> inputShape0;
88 DType inputDType0 = DType::DType_UNKNOWN;
89 if(inputName.find(
"input_") != std::string::npos)
93 tensors.push_back(
new TosaSerializationTensor(inputName, inputShape0, inputDType0, {}));
97 DType outputDType0 =
ArmNNToDType(outputs[0]->GetDataType());
98 tensors.push_back(
new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}));
102 return new TosaSerializationBasicBlock(blockName,