20{
21
23 {
25 }
26
27 std::vector<std::string> inputNames;
28 std::string outputName = std::string("output0_");
30
31 DType inputDType0 =
ArmNNToDType(inputs[0]->GetDataType());
32 DType outputDType0 =
ArmNNToDType(outputs[0]->GetDataType());
33
34
35 if(layer == nullptr)
36 {
37 inputNames.emplace_back("input_0");
38 inputNames.emplace_back("input_1");
40 {
41 inputNames.emplace_back("input_2");
42 }
43 }
44
45
46
47 else
48 {
49
50 for (uint32_t i = 0; i < inputs.size(); ++i)
51 {
53 inputNames.push_back(inputName);
54 }
55
56
58 }
59
60 std::vector<TosaSerializationTensor*> tensors;
61 std::vector<TosaSerializationOperator*> operators;
62
63
64
65
66
68 if(inputNames[0].find("input_") != std::string::npos)
69 {
70 tensors.push_back(new TosaSerializationTensor(inputNames[0], inputShape0, inputDType0, {}));
71 }
72
73
74
76 if(!inputs[1]->IsConstant() || layer == nullptr)
77 {
78 DType inputDType1 =
ArmNNToDType(inputs[1]->GetDataType());
79
80 tensors.push_back(new TosaSerializationTensor(inputNames[1], inputShape1, inputDType1, {}));
81 }
82
84 {
85 if(!inputs[2]->IsConstant() || layer == nullptr)
86 {
88 DType inputDType2 =
ArmNNToDType(inputs[2]->GetDataType());
89
90 tensors.push_back(new TosaSerializationTensor(inputNames[2], inputShape2, inputDType2, {}));
91 }
92 }
93 else
94 {
95
97
98 operators.push_back(new TosaSerializationOperator(Op_CONST, Attribute_NONE, nullptr, {}, {constantName}));
99
100
101 unsigned int index = 4;
102
103 const DType dType = (inputDType0 == DType_INT8) ? DType_INT32 : outputDType0;
104 std::vector<float> data(outputs[0]->GetShape()[index], 0);
105
106 std::vector<uint8_t> uint8Data;
107 TosaSerializationHandler::ConvertF32toU8(data, uint8Data);
108
109 tensors.push_back(new TosaSerializationTensor(constantName,
110 {static_cast<int32_t>(outputs[0]->GetShape()[index])},
111 dType,
112 uint8Data));
113 inputNames.emplace_back(constantName);
114 }
115
116
118 std::string outputConv3dName;
119 bool isInputInt8 = (inputDType0 == DType_INT8);
120 if (isInputInt8)
121 {
123 tensors.push_back(new TosaSerializationTensor(outputConv3dName, outputShape0, DType_INT32, {}));
124 }
125 else
126 {
127 tensors.push_back(new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}));
128 }
129
130
132 std::vector<int32_t> transposeOutputShape = {transposeInputShape[4],
133 transposeInputShape[0],
134 transposeInputShape[1],
135 transposeInputShape[2],
136 transposeInputShape[3]};
137
139 tensors.push_back(new TosaSerializationTensor(transposeOutputName, transposeOutputShape, inputDType0, {}));
140
141
142 std::string transposeInputName = inputNames[1];
143 std::string conv3dInput = inputNames[0];
144 std::string conv3dWeight = transposeOutputName;
145 std::string conv3dBias = inputNames[2];
146
147
148
149 std::vector<int> perm = {4, 0, 1, 2, 3};
150 TosaTransposeAttribute transposeAttribute(perm);
151 auto transpose_op = new TosaSerializationOperator(Op_TRANSPOSE,
152 Attribute_TransposeAttribute,
153 &transposeAttribute,
154 {transposeInputName},
155 {transposeOutputName});
156 operators.push_back(transpose_op);
157
158
159 std::vector<int> pad = {
static_cast<int>(conv3dDescriptor->
m_PadFront),
160 static_cast<int>(conv3dDescriptor->
m_PadBack),
161 static_cast<int>(conv3dDescriptor->
m_PadTop),
163 static_cast<int>(conv3dDescriptor->
m_PadLeft),
164 static_cast<int>(conv3dDescriptor->
m_PadRight)};
165 std::vector<int> stride = {
static_cast<int>(conv3dDescriptor->
m_StrideZ),
166 static_cast<int>(conv3dDescriptor->
m_StrideY),
167 static_cast<int>(conv3dDescriptor->
m_StrideX)};
168 std::vector<int> dilation = {
static_cast<int>(conv3dDescriptor->
m_DilationZ),
171
173 conv3dInput,
175 inputDType0,
176 transposeOutputShape,
177 pad,
178 stride,
179 dilation,
180 tensors,
181 operators);
182
183 TosaConvAttribute attribute(pad, stride, dilation,
184 inputs[0]->GetQuantizationOffset(),
185 inputs[1]->GetQuantizationOffset(),
186 false);
187
188 std::string& convOutStr = isInputInt8 ? outputConv3dName : outputName;
189 auto* conv3d_op = new TosaSerializationOperator(Op_CONV3D,
190 Attribute_ConvAttribute,
191 &attribute,
192 {sliceOutputName, conv3dWeight, conv3dBias},
193 {convOutStr});
194 operators.push_back(conv3d_op);
195
196 if (isInputInt8)
197 {
198 int32_t output_zp = outputs[0]->GetQuantizationOffset();
199 double output_scale = outputs[0]->GetQuantizationScales()[0];
200 double input_scale = inputs[0]->GetQuantizationScales()[0];
201 const std::vector<float>& weight_scales = inputs[1]->GetQuantizationScales();
202
203 TosaSerializationOperator* rescaleOp = nullptr;
205 outputName,
206 0,
207 output_zp,
208 false,
209 false,
210 true,
211 true,
212 input_scale,
213 output_scale,
214 weight_scales,
215 &rescaleOp);
216 operators.push_back(rescaleOp);
217 tensors.push_back(new TosaSerializationTensor(outputName,
218 outputShape0,
219 DType_INT8, {}));
220 }
221
222 return new TosaSerializationBasicBlock(blockName,
224 operators,
225 tensors,
226 inputNames,
227 {outputName});
228}
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 GetInputSlicedToItsUsedSize(const std::vector< int32_t > &inputShape, const std::string &inputName, const DataLayout layout, const DType datatype, const std::vector< int32_t > &kernel, const std::vector< int32_t > &pad, const std::vector< int32_t > &stride, const std::vector< int32_t > &dilations, std::vector< TosaSerializationTensor * > &tensors, std::vector< TosaSerializationOperator * > &operators, const bool isPoolingOp=false)
std::string GetUniqueTosaMappingID()
std::vector< int32_t > GetTosaTensorShape(const TensorShape &shape)
void CreateRescaleTosaOperatorForWeights(const std::string &inputName, const std::string &outputName, int32_t input_zp, int32_t output_zp, bool input_unsigned, bool output_unsigned, bool double_round, bool scale32, double input_scale, double output_scale, const std::vector< float > &weight_scales, TosaSerializationOperator **op)
Creates a TOSA rescale operator for weight tensors.
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
uint32_t m_PadRight
Padding right value in the width dimension.
uint32_t m_PadBack
Padding back value in the depth dimension.
uint32_t m_DilationZ
Dilation along z axis.
uint32_t m_DilationY
Dilation along y axis.
uint32_t m_StrideZ
Stride value when proceeding through input for the depth dimension.
uint32_t m_PadTop
Padding top value in the height dimension.
DataLayout m_DataLayout
The data layout to be used (NDHWC, NCDHW).
uint32_t m_PadFront
Padding front value in the depth dimension.
uint32_t m_DilationX
Dilation along x axis.
uint32_t m_PadBottom
Padding bottom value in the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
bool m_BiasEnabled
Enable/disable bias.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.