17{
18 if (unaryDescriptor->
m_Operation != UnaryOperation::Log)
19 {
20 throw armnn::Exception(
"ConvertLogOperator: Unsupported elementwise unary operation in descriptor.");
21 }
22
23 std::string inputName = std::string("input_");
24 std::string outputName = std::string("output0_");
26
27
28
29 if(layer != nullptr)
30 {
33 }
34
35 std::vector<TosaSerializationTensor*> tensors;
36 std::vector<TosaSerializationOperator*> operators;
37
38 float input_scale = inputs[0]->GetQuantizationScale();
39 float output_scale = outputs[0]->GetQuantizationScale();
40 int32_t input_zp = inputs[0]->GetQuantizationOffset();
41 int32_t output_zp = outputs[0]->GetQuantizationOffset();
42 DataType inputDType = inputs[0]->GetDataType();
43
44 if (inputDType == DataType::QAsymmS8 ||
45 inputDType == DataType::QSymmS8)
46 {
47 const float output_min = static_cast<float>(-128 - output_zp) * output_scale;
48
49 auto log_func = [&](float x) -> float
50 {
51 if (x <= 0.0f)
52 {
53 return output_min;
54 }
55 return std::log(x);
56 };
57
58 TosaTableAttribute attribute(
60 operators.push_back(new TosaSerializationOperator(tosa::Op_TABLE,
61 Attribute_TableAttribute,
62 &attribute,
63 {inputName},
64 {outputName}));
65 }
66 else if (inputDType == DataType::QSymmS16)
67 {
68 throw Exception(
"ConvertLogOperator() unsupported int 16 not implemented yet.");
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93 }
94 else if (inputDType == DataType::Signed32 ||
95 inputDType == DataType::Signed64)
96 {
98 "ConvertLogOperator() unsupported int 32. Only int 8 and int 16 quantized types are supported.");
99 }
100
101 else
102 {
103 operators.push_back(new TosaSerializationOperator(tosa::Op_LOG,
104 Attribute_NONE,
105 nullptr,
106 {inputName},
107 {outputName}));
108 }
109
110
111
112
113 if(inputName.find("input_") != std::string::npos)
114 {
117 tensors.push_back(new TosaSerializationTensor(inputName, inputShape0, inputDType0, {}));
118 }
119
121
122
123
124
125 DType outputDType0 =
ArmNNToDType(outputs[0]->GetDataType());
126
127 tensors.push_back(new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}));
128
129
130
131 return new TosaSerializationBasicBlock(blockName,
133 operators,
134 tensors,
135 {inputName},
136 {outputName});
137}
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.
UnaryOperation m_Operation
Specifies the elementwiseUnary operation to execute.