21{
22 if (inputs.size() != 1)
23 {
24 throw armnn::Exception(
"ConvertGeluToTosaOperator: 1 input tensors required.");
25 }
26
27 if (outputs.size() != 1)
28 {
29 throw armnn::Exception(
"ConvertGeluToTosaOperator: 1 output tensor required.");
30 }
31
32 if (desc->
m_Function != ActivationFunction::Gelu)
33 {
34 throw armnn::Exception(
"ConvertGeluToTosaOperator ActivationDescriptor only supports function Gelu.");
35 }
36
37 std::string inputName = std::string("input_");
38 std::string outputName = std::string("output0_");
40
41
42
43 if (layer != nullptr)
44 {
47 }
48
49 std::vector<TosaSerializationTensor*> tensors;
50 std::vector<TosaSerializationOperator*> operators;
51
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();
57
58 bool isInt8 = inputDType == DataType::QAsymmS8 || inputDType == DataType::QSymmS8;
59 if (isInt8)
60 {
61 auto gelu_transform = [](float in) -> float {
62 return 0.5f * in * std::erfc(in * static_cast<float>(-0.70710678118654752440));
63 };
64
65 TosaTableAttribute attribute(
67 operators.push_back(new TosaSerializationOperator(tosa::Op_TABLE,
68 Attribute_TableAttribute,
69 &attribute,
70 {inputName},
71 {outputName}));
72 }
73 else if (inputDType == DataType::QSymmS16 ||
74 inputDType == DataType::Signed32 ||
75 inputDType == DataType::Signed64)
76 {
77 throw Exception(
"ConvertGeluOperator() only supports int8 quantized types.");
78 }
79 else
80 {
81 throw Exception(
"ConvertGeluOperator() floating point types currently unimplemented.");
82 }
83
84
85
86
87 std::vector<int32_t> inputShape0;
88 DType inputDType0 =
ArmNNToDType(inputs[0]->GetDataType());
89 if(inputName.find("input_") != std::string::npos)
90 {
92 tensors.push_back(new TosaSerializationTensor(inputName, inputShape0, inputDType0, {}));
93 }
94
96 DType outputDType0 =
ArmNNToDType(outputs[0]->GetDataType());
97 tensors.push_back(new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}));
98
99
100
101 return new TosaSerializationBasicBlock(blockName,
103 operators,
104 tensors,
105 {inputName},
106 {outputName});
107}
std::string GenerateUniqueOutputName(const Layer &layer, uint32_t layerSlot=0)
const std::string mainName
DType ArmNNToDType(const DataType &type)
std::string GenerateUniqueInputName(const armnn::InputSlot &slot)
std::string GetUniqueTosaMappingID()
std::vector< int32_t > GetTosaTensorShape(const TensorShape &shape)
std::vector< int16_t > getTosaConst8bitTable(float input_scale, int32_t input_zp, float output_scale, int32_t output_zp, std::function< float(float)> func)
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.
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu,...