12 const std::vector<const TensorInfo*>& inputs,
13 const std::vector<const TensorInfo*>& outputs,
16 std::vector<std::string> inputNames;
17 std::string outputName = std::string(
"output0_");
20 DType inputDType0 =
ArmNNToDType(inputs[0]->GetDataType());
21 DType outputDType0 =
ArmNNToDType(outputs[0]->GetDataType());
26 inputNames.emplace_back(
"input_0");
27 inputNames.emplace_back(
"input_1");
30 inputNames.emplace_back(
"input_2");
39 for (uint32_t i = 0; i < inputs.size(); ++i)
42 inputNames.push_back(inputName);
49 std::vector<TosaSerializationTensor*> tensors;
50 std::vector<TosaSerializationOperator*> operators;
56 if(inputNames[0].find(
"input_") != std::string::npos)
59 tensors.push_back(
new TosaSerializationTensor(inputNames[0], inputShape0, inputDType0, {}));
64 if(!inputs[1]->IsConstant() || layer ==
nullptr)
69 int32_t multiplier = inputShape1[3]/inputShape0[3];
72 std::vector<int32_t> inputShapeHWCM = {
73 inputShape1[1], inputShape1[2], inputShape0[3], multiplier
76 DType inputDType1 =
ArmNNToDType(inputs[1]->GetDataType());
78 tensors.push_back(
new TosaSerializationTensor(inputNames[1], inputShapeHWCM, inputDType1, {}));
83 if(!inputs[2]->IsConstant() || layer ==
nullptr)
86 DType inputDType2 =
ArmNNToDType(inputs[2]->GetDataType());
88 tensors.push_back(
new TosaSerializationTensor(inputNames[2], inputShape2, inputDType2, {}));
96 operators.push_back(
new TosaSerializationOperator(Op_CONST, Attribute_NONE,
nullptr, {}, {constantName}));
99 unsigned int index = (conv2dDescriptor->
m_DataLayout == DataLayout::NHWC) ? 3 : 1;
101 const DType dType = (inputDType0 == DType_INT8) ? DType_INT32 : outputDType0;
102 std::vector<float> data(outputs[0]->GetShape()[index], 0);
104 std::vector<uint8_t> uint8Data;
105 TosaSerializationHandler::ConvertF32toU8(data, uint8Data);
107 tensors.push_back(
new TosaSerializationTensor(constantName,
108 {
static_cast<int32_t
>(outputs[0]->GetShape()[index])},
111 inputNames.emplace_back(constantName);
116 std::string outputConv2dName;
117 bool isInputInt8 = (inputDType0 == DType_INT8);
121 tensors.push_back(
new TosaSerializationTensor(outputConv2dName, outputShape0, DType_INT32, {}));
125 tensors.push_back(
new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}));
129 std::vector<int> pad = {
static_cast<int>(conv2dDescriptor->
m_PadTop),
131 static_cast<int>(conv2dDescriptor->
m_PadLeft),
132 static_cast<int>(conv2dDescriptor->
m_PadRight)};
133 std::vector<int> stride = {
static_cast<int>(conv2dDescriptor->
m_StrideY),
134 static_cast<int>(conv2dDescriptor->
m_StrideX)};
135 std::vector<int> dilation = {
static_cast<int>(conv2dDescriptor->
m_DilationY),
137 TosaConvAttribute attribute(pad, stride, dilation,
138 inputs[0]->GetQuantizationOffset(),
139 inputs[1]->GetQuantizationOffset(),
142 std::string& convOutStr = isInputInt8 ? outputConv2dName : outputName;
143 auto* conv2d_op =
new TosaSerializationOperator(Op_DEPTHWISE_CONV2D,
144 Attribute_ConvAttribute,
148 operators.push_back(conv2d_op);
152 int32_t output_zp = outputs[0]->GetQuantizationOffset();
153 double output_scale = outputs[0]->GetQuantizationScales()[0];
154 double input_scale = inputs[0]->GetQuantizationScales()[0];
155 const std::vector<float>& weight_scales = inputs[1]->GetQuantizationScales();
157 TosaSerializationOperator* rescaleOp =
nullptr;
168 operators.push_back(rescaleOp);
169 tensors.push_back(
new TosaSerializationTensor(outputName,
176 return new TosaSerializationBasicBlock(blockName,