11 const std::vector<const TensorInfo*>& inputs,
12 const std::vector<const TensorInfo*>& outputs,
15 std::vector<std::string> inputNames;
16 std::string outputName = std::string(
"output0_");
19 DType inputDType0 =
ArmNNToDType(inputs[0]->GetDataType());
20 DType outputDType0 =
ArmNNToDType(outputs[0]->GetDataType());
25 inputNames.emplace_back(
"input_0");
26 inputNames.emplace_back(
"input_1");
29 inputNames.emplace_back(
"input_2");
38 for (uint32_t i = 0; i < inputs.size(); ++i)
41 inputNames.push_back(inputName);
48 std::vector<TosaSerializationTensor*> tensors;
49 std::vector<TosaSerializationOperator*> operators;
55 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)
67 DType inputDType1 =
ArmNNToDType(inputs[1]->GetDataType());
69 tensors.push_back(
new TosaSerializationTensor(inputNames[1], inputShape1, inputDType1, {}));
74 if(!inputs[2]->IsConstant() || layer ==
nullptr)
77 DType inputDType2 =
ArmNNToDType(inputs[2]->GetDataType());
79 tensors.push_back(
new TosaSerializationTensor(inputNames[2], inputShape2, inputDType2, {}));
87 operators.push_back(
new TosaSerializationOperator(Op_CONST, Attribute_NONE,
nullptr, {}, {constantName}));
90 unsigned int index = (conv2dDescriptor->
m_DataLayout == DataLayout::NHWC) ? 3 : 1;
92 const DType dType = (inputDType0 == DType_INT8) ? DType_INT32 : outputDType0;
93 std::vector<float> data(outputs[0]->GetShape()[index], 0);
95 std::vector<uint8_t> uint8Data;
96 TosaSerializationHandler::ConvertF32toU8(data, uint8Data);
98 tensors.push_back(
new TosaSerializationTensor(constantName,
99 {
static_cast<int32_t
>(outputs[0]->GetShape()[index])},
102 inputNames.emplace_back(constantName);
107 std::string outputConv2dName;
108 bool isInputInt8 = (inputDType0 == DType_INT8);
112 tensors.push_back(
new TosaSerializationTensor(outputConv2dName, outputShape0, DType_INT32, {}));
116 tensors.push_back(
new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}));
120 std::vector<int> pad = {
static_cast<int>(conv2dDescriptor->
m_PadTop),
122 static_cast<int>(conv2dDescriptor->
m_PadLeft),
123 static_cast<int>(conv2dDescriptor->
m_PadRight)};
124 std::vector<int> stride = {
static_cast<int>(conv2dDescriptor->
m_StrideY),
125 static_cast<int>(conv2dDescriptor->
m_StrideX)};
126 std::vector<int> dilation = {
static_cast<int>(conv2dDescriptor->
m_DilationY),
128 TosaConvAttribute attribute(pad, stride, dilation,
129 inputs[0]->GetQuantizationOffset(),
130 inputs[1]->GetQuantizationOffset(),
133 std::string& convOutStr = isInputInt8 ? outputConv2dName : outputName;
134 auto* conv2d_op =
new TosaSerializationOperator(Op_CONV2D,
135 Attribute_ConvAttribute,
139 operators.push_back(conv2d_op);
143 int32_t output_zp = outputs[0]->GetQuantizationOffset();
144 double output_scale = outputs[0]->GetQuantizationScales()[0];
145 double input_scale = inputs[0]->GetQuantizationScales()[0];
146 const std::vector<float>& weight_scales = inputs[1]->GetQuantizationScales();
148 TosaSerializationOperator* rescaleOp =
nullptr;
159 operators.push_back(rescaleOp);
160 tensors.push_back(
new TosaSerializationTensor(outputName,
167 return new TosaSerializationBasicBlock(blockName,