21 #include <doctest/doctest.h> 25 using namespace armnn;
33 template<
typename Workload>
34 std::unique_ptr<Workload> MakeAndCheckWorkload(
Layer& layer,
38 std::unique_ptr<IWorkload> workload = layer.
CreateWorkload(factory);
39 CHECK_MESSAGE(workload.get() == PolymorphicDowncast<Workload*>(workload.get()),
40 "Cannot convert to derived class");
41 std::string reasonIfUnsupported;
44 return std::unique_ptr<Workload>(
static_cast<Workload*
>(workload.release()));
65 template <
typename ActivationWorkload, armnn::DataType DataType>
73 layerDesc.
m_B = -10.0f;
84 Connect(input, layer, tensorInfo);
85 Connect(layer, output, tensorInfo);
87 CreateTensorHandles(graph, factory);
90 auto workload = MakeAndCheckWorkload<ActivationWorkload>(*layer, factory);
93 CHECK(queueDescriptor.m_Inputs.size() == 1);
94 CHECK(queueDescriptor.m_Outputs.size() == 1);
95 CHECK(queueDescriptor.m_Parameters.m_A == 3.5f);
96 CHECK(queueDescriptor.m_Parameters.m_B == -10.0f);
103 template <
typename WorkloadType,
104 typename DescriptorType,
120 Connect(input1, layer, tensorInfo, 0, 0);
121 Connect(input2, layer, tensorInfo, 0, 1);
122 Connect(layer, output, tensorInfo);
123 CreateTensorHandles(graph, factory);
126 auto workload = MakeAndCheckWorkload<WorkloadType>(*layer, factory);
128 DescriptorType queueDescriptor = workload->GetData();
129 CHECK(queueDescriptor.m_Inputs.size() == 2);
130 CHECK(queueDescriptor.m_Outputs.size() == 1);
136 template<
typename WorkloadType,
137 typename DescriptorType,
145 auto activationDesc = std::make_shared<ActivationDescriptor>();
146 activationDesc->m_A = 10.0f;
147 activationDesc->m_B = 5.0f;
159 Connect(input1, layer, tensorInfo, 0, 0);
160 Connect(input2, layer, tensorInfo, 0, 1);
161 Connect(layer, output, tensorInfo);
162 CreateTensorHandles(graph, factory);
165 std::shared_ptr<ActivationDescriptor>
168 ARMNN_ASSERT(static_cast<float>(activationDescPtr->m_A) == 10.0f);
169 ARMNN_ASSERT(static_cast<float>(activationDescPtr->m_B) == 5.0f);
175 auto workload = MakeAndCheckWorkload<WorkloadType>(*layer, factory);
177 DescriptorType queueDescriptor = workload->GetData();
180 queueDescriptor.template GetAdditionalInformation<ActivationDescriptor>();
188 CHECK(queueDescriptor.m_Inputs.size() == 2);
189 CHECK(queueDescriptor.m_Outputs.size() == 1);
194 template<
typename WorkloadType,
195 typename DescriptorType,
203 auto activationDesc = std::make_shared<ActivationDescriptor>();
204 activationDesc->m_A = 10.0f;
205 activationDesc->m_B = 5.0f;
217 Connect(input1, layer, tensorInfo, 0, 0);
218 Connect(input2, layer, tensorInfo, 0, 1);
219 Connect(layer, output, tensorInfo);
220 CreateTensorHandles(graph, factory);
223 std::shared_ptr<ActivationDescriptor>
226 ARMNN_ASSERT(static_cast<float>(activationDescPtr->m_A) == 10.0f);
227 ARMNN_ASSERT(static_cast<float>(activationDescPtr->m_B) == 5.0f);
233 auto workload = MakeAndCheckWorkload<WorkloadType>(*layer, factory);
235 DescriptorType queueDescriptor = workload->GetData();
236 CHECK(queueDescriptor.m_Inputs.size() == 2);
237 CHECK(queueDescriptor.m_Outputs.size() == 1);
239 queueDescriptor.template GetAdditionalInformation<ActivationDescriptor>();
241 ARMNN_ASSERT(static_cast<float>(queueDescBlobPtr->m_A) == 10.0f);
242 ARMNN_ASSERT(static_cast<float>(queueDescBlobPtr->m_B) == 5.0f);
250 template<
typename WorkloadType,
251 typename DescriptorType,
259 auto activationDesc = std::make_shared<ActivationDescriptor>();
260 activationDesc->m_A = 10.0f;
261 activationDesc->m_B = 5.0f;
273 Connect(input1, layer, tensorInfo, 0, 0);
274 Connect(input2, layer, tensorInfo, 0, 1);
275 Connect(layer, output, tensorInfo);
276 CreateTensorHandles(graph, factory);
279 std::shared_ptr<ActivationDescriptor>
280 activationDescPtr = layer->template GetAdditionalInformation<ActivationDescriptor>();
282 ARMNN_ASSERT(static_cast<float>(activationDescPtr->m_A) == 10.0f);
283 ARMNN_ASSERT(static_cast<float>(activationDescPtr->m_B) == 5.0f);
289 auto workload = MakeAndCheckWorkload<WorkloadType>(*layer, factory);
291 DescriptorType queueDescriptor = workload->GetData();
293 queueDescriptor.template GetAdditionalInformation<ActivationDescriptor>();
295 CHECK(queueDescriptor.m_Inputs.size() == 2);
296 CHECK(queueDescriptor.m_Outputs.size() == 1);
306 template <
typename WorkloadType,
307 typename DescriptorType,
320 Connect(input, layer, tensorInfo, 0, 0);
321 Connect(layer, output, tensorInfo, 0, 0);
322 CreateTensorHandles(graph, factory);
324 auto workload = MakeAndCheckWorkload<WorkloadType>(*layer, factory);
325 DescriptorType queueDescriptor = workload->GetData();
327 CHECK(queueDescriptor.m_Inputs.size() == 1);
328 CHECK(queueDescriptor.m_Outputs.size() == 1);
333 template <
typename BatchNormalizationWorkloadType, armnn::DataType DataType>
334 std::unique_ptr<BatchNormalizationWorkloadType> CreateBatchNormalizationWorkloadTest(
341 tensorShape = { 2, 4, 4, 3 };
345 tensorShape = { 2, 3, 4, 4 };
350 layerDesc.
m_Eps = 0.05f;
356 layer->
m_Mean = std::make_unique<ScopedTensorHandle>(weightInfo);
357 layer->
m_Variance = std::make_unique<ScopedTensorHandle>(weightInfo);
358 layer->
m_Beta = std::make_unique<ScopedTensorHandle>(weightInfo);
359 layer->
m_Gamma = std::make_unique<ScopedTensorHandle>(weightInfo);
360 layer->
m_Mean->Allocate();
362 layer->
m_Beta->Allocate();
371 Connect(input, layer, tensorInfo);
372 Connect(layer, output, tensorInfo);
373 CreateTensorHandles(graph, factory);
376 auto workload = MakeAndCheckWorkload<BatchNormalizationWorkloadType>(*layer, factory);
378 CHECK(queueDescriptor.m_Parameters.m_Eps == 0.05f);
379 CHECK(queueDescriptor.m_Inputs.size() == 1);
380 CHECK(queueDescriptor.m_Outputs.size() == 1);
385 CHECK((queueDescriptor.m_Parameters.m_DataLayout == dataLayout));
391 template <
typename BatchNormalizationWorkloadType, armnn::DataType DataType>
392 std::unique_ptr<BatchNormalizationWorkloadType> CreateBatchNormalizationWithBlobWorkloadTest(
399 tensorShape = { 2, 4, 4, 3 };
403 tensorShape = { 2, 3, 4, 4 };
408 layerDesc.
m_Eps = 0.05f;
414 layer->
m_Mean = std::make_unique<ScopedTensorHandle>(weightInfo);
415 layer->
m_Variance = std::make_unique<ScopedTensorHandle>(weightInfo);
416 layer->
m_Beta = std::make_unique<ScopedTensorHandle>(weightInfo);
417 layer->
m_Gamma = std::make_unique<ScopedTensorHandle>(weightInfo);
418 layer->
m_Mean->Allocate();
420 layer->
m_Beta->Allocate();
423 auto activationDesc = std::make_shared<ActivationDescriptor>();
424 activationDesc->m_A = 10.0f;
425 activationDesc->m_B = 5.0f;
432 ARMNN_ASSERT(static_cast<float>(activationDescPtr->m_A) == 10.0f);
433 ARMNN_ASSERT(static_cast<float>(activationDescPtr->m_B) == 5.0f);
444 Connect(input, layer, tensorInfo);
445 Connect(layer, output, tensorInfo);
446 CreateTensorHandles(graph, factory);
449 auto workload = MakeAndCheckWorkload<BatchNormalizationWorkloadType>(*layer, factory);
459 CHECK(queueDescriptor.m_Parameters.m_Eps == 0.05f);
460 CHECK(queueDescriptor.m_Inputs.size() == 1);
461 CHECK(queueDescriptor.m_Outputs.size() == 1);
466 CHECK((queueDescriptor.m_Parameters.m_DataLayout == dataLayout));
472 template <
typename Convolution2dWorkload, armnn::DataType DataType>
503 weightsTensorInfo.SetConstant();
510 weights->m_LayerOutput = std::make_unique<ScopedTensorHandle>(weightsTensorInfo);
511 weights->m_LayerOutput->Allocate();
515 Connect(weights, layer, weightsTensorInfo, 0, 1);
517 CreateTensorHandles(graph, factory);
520 auto workload = MakeAndCheckWorkload<Convolution2dWorkload>(*layer, factory, modelOptions);
523 CHECK(queueDescriptor.m_Parameters.m_StrideX == 2);
524 CHECK(queueDescriptor.m_Parameters.m_StrideY == 4);
525 CHECK(queueDescriptor.m_Parameters.m_PadLeft == 3);
526 CHECK(queueDescriptor.m_Parameters.m_PadRight == 3);
527 CHECK(queueDescriptor.m_Parameters.m_PadTop == 1);
528 CHECK(queueDescriptor.m_Parameters.m_PadBottom == 1);
529 CHECK(!queueDescriptor.m_Parameters.m_BiasEnabled);
530 CHECK((queueDescriptor.m_Parameters.m_DataLayout == dataLayout));
532 CHECK(queueDescriptor.m_Inputs.size() == 2);
533 CHECK(queueDescriptor.m_Outputs.size() == 1);
539 template<
typename Convolution2dWorkload, armnn::DataType DataType>
540 std::unique_ptr<Convolution2dWorkload> CreateConvolution2dFusedActivationWithBlobWorkloadTest(
570 layer->
m_Bias->Allocate();
573 weightsTensorInfo.SetConstant();
577 auto activationDesc = std::make_shared<ActivationDescriptor>();
578 activationDesc->m_A = 10.0f;
579 activationDesc->m_B = 5.0f;
587 ARMNN_ASSERT(static_cast<float>(activationDescPtr->m_A) == 10.0f);
588 ARMNN_ASSERT(static_cast<float>(activationDescPtr->m_B) == 5.0f);
599 weights->m_LayerOutput = std::make_unique<ScopedTensorHandle>(weightsTensorInfo);
600 weights->m_LayerOutput->Allocate();
601 bias->
m_LayerOutput = std::make_unique<ScopedTensorHandle>(biasTensorInfo);
606 Connect(weights, layer, weightsTensorInfo, 0, 1);
607 Connect(bias, layer, biasTensorInfo, 0, 2);
609 CreateTensorHandles(graph, factory);
612 auto workload = MakeAndCheckWorkload<Convolution2dWorkload>(*layer, factory, modelOptions);
623 CHECK(queueDescriptor.m_Parameters.m_StrideX == 2);
624 CHECK(queueDescriptor.m_Parameters.m_StrideY == 4);
625 CHECK(queueDescriptor.m_Parameters.m_PadLeft == 3);
626 CHECK(queueDescriptor.m_Parameters.m_PadRight == 3);
627 CHECK(queueDescriptor.m_Parameters.m_PadTop == 1);
628 CHECK(queueDescriptor.m_Parameters.m_PadBottom == 1);
629 CHECK(queueDescriptor.m_Parameters.m_BiasEnabled);
630 CHECK((queueDescriptor.m_Parameters.m_DataLayout == dataLayout));
632 CHECK(queueDescriptor.m_Outputs.size() == 1);
633 CHECK(queueDescriptor.m_Inputs.size() == 3);
639 template <
typename Convolution2dWorkload, armnn::DataType DataType>
640 std::unique_ptr<Convolution2dWorkload> CreateConvolution2dWorkloadFastMathTest(
armnn::IWorkloadFactory& factory,
670 layer->
m_Bias->Allocate();
673 weightsTensorInfo.SetConstant();
675 biasTensorInfo.SetConstant();
685 Connect(weights, layer, weightsTensorInfo, 0, 1);
686 Connect(bias, layer, biasTensorInfo, 0, 2);
688 CreateTensorHandles(graph, factory);
691 auto workload = MakeAndCheckWorkload<Convolution2dWorkload>(*layer, factory, modelOptions);
694 CHECK(queueDescriptor.m_Parameters.m_StrideX == 1);
695 CHECK(queueDescriptor.m_Parameters.m_StrideY == 1);
696 CHECK(queueDescriptor.m_Parameters.m_PadLeft == 0);
697 CHECK(queueDescriptor.m_Parameters.m_PadRight == 0);
698 CHECK(queueDescriptor.m_Parameters.m_PadTop == 0);
699 CHECK(queueDescriptor.m_Parameters.m_PadBottom == 0);
700 CHECK((queueDescriptor.m_Parameters.m_DataLayout == dataLayout));
702 CHECK(queueDescriptor.m_Inputs.size() == 3);
703 CHECK(queueDescriptor.m_Outputs.size() == 1);
709 template <
typename LstmWorkload>
722 unsigned int batchSize = 2;
723 unsigned int inputSize = 2;
724 unsigned int numUnits = 4;
725 unsigned int outputSize = 4;
757 if (layerDesc.m_PeepholeEnabled)
780 armnn::TensorInfo lstmTensorInfoScratchBuff({ batchSize, numUnits * (layerDesc.m_CifgEnabled ? 3 : 4) },
782 Connect(input, layer, lstmTensorInfo1, 0, 0);
783 Connect(cellStateIn, layer, lstmTensorInfo2, 0, 1);
784 Connect(outputStateIn, layer, lstmTensorInfo3, 0, 2);
785 Connect(layer, scratchBuffer, lstmTensorInfoScratchBuff, 0, 0);
786 Connect(layer, outputStateOut, lstmTensorInfo3, 1, 0);
787 Connect(layer, cellStateOut, lstmTensorInfo2, 2, 0);
788 Connect(layer, output, lstmTensorInfo3, 3, 0);
790 CreateTensorHandles(graph, factory);
793 auto workload = MakeAndCheckWorkload<LstmWorkload>(*layer, factory);
795 CHECK(queueDescriptor.m_Parameters.m_ActivationFunc == 4);
796 CHECK(queueDescriptor.m_Parameters.m_ClippingThresCell == 0.0f);
797 CHECK(queueDescriptor.m_Parameters.m_ClippingThresProj == 0.0f);
798 CHECK(queueDescriptor.m_Inputs.size() == 3);
799 CHECK(queueDescriptor.m_Outputs.size() == 4);
801 CHECK((queueDescriptor.m_InputToForgetWeights->GetTensorInfo() ==
TensorInfo({ numUnits, inputSize },
803 CHECK((queueDescriptor.m_OutputGateBias->GetTensorInfo() ==
TensorInfo({ numUnits },
809 template <
typename QuantizedLstmWorkload>
814 unsigned int numBatches = 2;
815 unsigned int inputSize = 2;
816 unsigned int outputSize = 4;
819 float inputOutputScale = 0.0078125f;
820 int32_t inputOutputOffset = 128;
822 float cellStateScale = 0.00048828125f;
823 int32_t cellStateOffset = 0;
825 float weightsScale = 0.00408021f;
826 int32_t weightsOffset = 100;
828 float biasScale = 3.1876640625e-05f;
829 int32_t biasOffset = 0;
848 layer->m_QuantizedLstmParameters.m_InputToInputWeights =
849 std::make_unique<ScopedTensorHandle>(inputWeightsInfo);
850 layer->m_QuantizedLstmParameters.m_InputToForgetWeights =
851 std::make_unique<ScopedTensorHandle>(inputWeightsInfo);
852 layer->m_QuantizedLstmParameters.m_InputToCellWeights =
853 std::make_unique<ScopedTensorHandle>(inputWeightsInfo);
854 layer->m_QuantizedLstmParameters.m_InputToOutputWeights =
855 std::make_unique<ScopedTensorHandle>(inputWeightsInfo);
857 layer->m_QuantizedLstmParameters.m_RecurrentToInputWeights =
858 std::make_unique<ScopedTensorHandle>(recurrentWeightsInfo);
859 layer->m_QuantizedLstmParameters.m_RecurrentToForgetWeights =
860 std::make_unique<ScopedTensorHandle>(recurrentWeightsInfo);
861 layer->m_QuantizedLstmParameters.m_RecurrentToCellWeights =
862 std::make_unique<ScopedTensorHandle>(recurrentWeightsInfo);
863 layer->m_QuantizedLstmParameters.m_RecurrentToOutputWeights =
864 std::make_unique<ScopedTensorHandle>(recurrentWeightsInfo);
866 layer->m_QuantizedLstmParameters.m_InputGateBias = std::make_unique<ScopedTensorHandle>(biasInfo);
867 layer->m_QuantizedLstmParameters.m_ForgetGateBias = std::make_unique<ScopedTensorHandle>(biasInfo);
868 layer->m_QuantizedLstmParameters.m_CellBias = std::make_unique<ScopedTensorHandle>(biasInfo);
869 layer->m_QuantizedLstmParameters.m_OutputGateBias = std::make_unique<ScopedTensorHandle>(biasInfo);
872 layer->m_QuantizedLstmParameters.m_InputToInputWeights->Allocate();
873 layer->m_QuantizedLstmParameters.m_InputToForgetWeights->Allocate();
874 layer->m_QuantizedLstmParameters.m_InputToCellWeights->Allocate();
875 layer->m_QuantizedLstmParameters.m_InputToOutputWeights->Allocate();
877 layer->m_QuantizedLstmParameters.m_RecurrentToInputWeights->Allocate();
878 layer->m_QuantizedLstmParameters.m_RecurrentToForgetWeights->Allocate();
879 layer->m_QuantizedLstmParameters.m_RecurrentToCellWeights->Allocate();
880 layer->m_QuantizedLstmParameters.m_RecurrentToOutputWeights->Allocate();
882 layer->m_QuantizedLstmParameters.m_InputGateBias->Allocate();
883 layer->m_QuantizedLstmParameters.m_ForgetGateBias->Allocate();
884 layer->m_QuantizedLstmParameters.m_CellBias->Allocate();
885 layer->m_QuantizedLstmParameters.m_OutputGateBias->Allocate();
912 Connect(input, layer, inputInfo, 0, 0);
913 Connect(cellStateIn, layer, cellStateInfo, 0, 1);
914 Connect(outputStateIn, layer, outputStateInfo, 0, 2);
916 Connect(layer, cellStateOut, cellStateInfo, 0, 0);
917 Connect(layer, outputStateOut, outputStateInfo, 1, 0);
919 CreateTensorHandles(graph, factory);
922 auto workload = MakeAndCheckWorkload<QuantizedLstmWorkload>(*layer, factory);
926 CHECK(queueDescriptor.m_Inputs.size() == 3);
927 CHECK(queueDescriptor.m_Outputs.size() == 2);
930 CHECK((queueDescriptor.m_InputToInputWeights->GetTensorInfo() == inputWeightsInfo));
931 CHECK((queueDescriptor.m_InputToForgetWeights->GetTensorInfo() == inputWeightsInfo));
932 CHECK((queueDescriptor.m_InputToCellWeights->GetTensorInfo() == inputWeightsInfo));
933 CHECK((queueDescriptor.m_InputToOutputWeights->GetTensorInfo() == inputWeightsInfo));
935 CHECK((queueDescriptor.m_RecurrentToInputWeights->GetTensorInfo() == recurrentWeightsInfo));
936 CHECK((queueDescriptor.m_RecurrentToForgetWeights->GetTensorInfo() == recurrentWeightsInfo));
937 CHECK((queueDescriptor.m_RecurrentToCellWeights->GetTensorInfo() == recurrentWeightsInfo));
938 CHECK((queueDescriptor.m_RecurrentToOutputWeights->GetTensorInfo() == recurrentWeightsInfo));
940 CHECK((queueDescriptor.m_InputGateBias->GetTensorInfo() == biasInfo));
941 CHECK((queueDescriptor.m_ForgetGateBias->GetTensorInfo() == biasInfo));
942 CHECK((queueDescriptor.m_CellBias->GetTensorInfo() == biasInfo));
943 CHECK((queueDescriptor.m_OutputGateBias->GetTensorInfo() == biasInfo));
948 template <
typename QLstmWorkload>
971 unsigned int numBatches = 2;
972 unsigned int inputSize = 4;
973 unsigned int numUnits = 4;
974 unsigned int outputSize = 4;
977 float inputScale = 0.0078125f;
978 int32_t inputOffset = 0;
981 float outputScale = layerDesc.m_HiddenStateScale;
982 int32_t outputOffset = layerDesc.m_HiddenStateZeroPoint;
984 float cellStateScale = 3.05176e-05f;
985 int32_t cellStateOffset = 0;
987 float weightsScale = 0.00784314f;
988 int32_t weightsOffset = 0;
990 float layerNormScale = 3.05182e-05f;
991 int32_t layerNormOffset = 0;
993 float biasScale = layerNormScale / 1024;
994 int32_t biasOffset = 0;
1017 std::make_unique<ScopedTensorHandle>(recurrentWeightsInfo);
1019 std::make_unique<ScopedTensorHandle>(recurrentWeightsInfo);
1021 std::make_unique<ScopedTensorHandle>(recurrentWeightsInfo);
1028 std::make_unique<ScopedTensorHandle>(layerNormWeightsInfo);
1030 std::make_unique<ScopedTensorHandle>(layerNormWeightsInfo);
1032 std::make_unique<ScopedTensorHandle>(layerNormWeightsInfo);
1076 Connect(input, layer, inputInfo, 0, 0);
1077 Connect(outputStateIn, layer, outputStateInfo, 0, 1);
1078 Connect(cellStateIn, layer, cellStateInfo, 0, 2);
1080 Connect(layer, outputStateOut, outputStateInfo, 0, 0);
1081 Connect(layer, cellStateOut, cellStateInfo, 1, 0);
1082 Connect(layer, output, outputStateInfo, 2, 0);
1084 CreateTensorHandles(graph, factory);
1087 auto workload = MakeAndCheckWorkload<QLstmWorkload>(*layer, factory);
1089 CHECK(queueDescriptor.m_Parameters.m_CellClip == 0.0f);
1090 CHECK(queueDescriptor.m_Parameters.m_ProjectionClip == 0.0f);
1091 CHECK(queueDescriptor.m_Inputs.size() == 3);
1092 CHECK(queueDescriptor.m_Outputs.size() == 3);
1094 CHECK((queueDescriptor.m_InputToForgetWeights->GetTensorInfo() == inputWeightsInfo));
1095 CHECK((queueDescriptor.m_InputToCellWeights->GetTensorInfo() == inputWeightsInfo));
1096 CHECK((queueDescriptor.m_InputToOutputWeights->GetTensorInfo() == inputWeightsInfo));
1098 CHECK((queueDescriptor.m_RecurrentToForgetWeights->GetTensorInfo() == recurrentWeightsInfo));
1099 CHECK((queueDescriptor.m_RecurrentToCellWeights->GetTensorInfo() == recurrentWeightsInfo));
1100 CHECK((queueDescriptor.m_RecurrentToOutputWeights->GetTensorInfo() == recurrentWeightsInfo));
1102 CHECK((queueDescriptor.m_ForgetGateBias->GetTensorInfo() == biasInfo));
1103 CHECK((queueDescriptor.m_CellBias->GetTensorInfo() == biasInfo));
1104 CHECK((queueDescriptor.m_OutputGateBias->GetTensorInfo() == biasInfo));
1109 template<
typename Convolution2dWorkload, armnn::DataType DataType>
1110 std::unique_ptr<Convolution2dWorkload> CreateDirectConvolution2dWorkloadTest(
armnn::IWorkloadFactory& factory,
1125 float inputsQScale =
DataType == armnn::DataType::QAsymmU8 ? 1.0f : 0.0;
1126 float outputQScale =
DataType == armnn::DataType::QAsymmU8 ? 2.0f : 0.0;
1131 weightsTensorInfo.SetConstant();
1133 biasTensorInfo.SetConstant();
1135 layer->
m_Weight = std::make_unique<ScopedTensorHandle>(weightsTensorInfo);
1136 layer->
m_Bias = std::make_unique<ScopedTensorHandle>(biasTensorInfo);
1139 layer->
m_Bias->Allocate();
1147 weights->m_LayerOutput = std::make_unique<ScopedTensorHandle>(weightsTensorInfo);
1148 weights->m_LayerOutput->Allocate();
1149 bias->
m_LayerOutput = std::make_unique<ScopedTensorHandle>(biasTensorInfo);
1154 Connect(weights, layer, weightsTensorInfo, 0, 1);
1155 Connect(bias, layer, biasTensorInfo, 0, 2);
1157 CreateTensorHandles(graph, factory);
1160 auto workload = MakeAndCheckWorkload<Convolution2dWorkload>(*layer, factory);
1163 CHECK(queueDescriptor.m_Parameters.m_StrideX == 1);
1164 CHECK(queueDescriptor.m_Parameters.m_StrideY == 1);
1165 CHECK(queueDescriptor.m_Parameters.m_PadLeft == 1);
1166 CHECK(queueDescriptor.m_Parameters.m_PadRight == 1);
1167 CHECK(queueDescriptor.m_Parameters.m_PadTop == 1);
1168 CHECK(queueDescriptor.m_Parameters.m_PadBottom == 1);
1169 CHECK(queueDescriptor.m_Parameters.m_BiasEnabled ==
true);
1171 CHECK(queueDescriptor.m_Inputs.size() == 3);
1172 CHECK(queueDescriptor.m_Outputs.size() == 1);
1173 CHECK((queueDescriptor.m_Weight->GetTensorInfo() == weightsTensorInfo));
1174 CHECK((queueDescriptor.m_Bias->GetTensorInfo() == biasTensorInfo));
1180 template <
typename DepthwiseConvolution2dFloat32Workload, armnn::DataType DataType>
1181 std::unique_ptr<DepthwiseConvolution2dFloat32Workload> CreateDepthwiseConvolution2dWorkloadTest(
1195 float inputsQScale =
DataType == armnn::DataType::QAsymmU8 ? 1.0f : 0.0;
1196 float outputQScale =
DataType == armnn::DataType::QAsymmU8 ? 2.0f : 0.0;
1219 CreateTensorHandles(graph, factory);
1222 auto workload = MakeAndCheckWorkload<DepthwiseConvolution2dFloat32Workload>(*layer, factory);
1225 CHECK(queueDescriptor.m_Parameters.m_StrideX == 1);
1226 CHECK(queueDescriptor.m_Parameters.m_StrideY == 1);
1227 CHECK(queueDescriptor.m_Parameters.m_PadLeft == 1);
1228 CHECK(queueDescriptor.m_Parameters.m_PadRight == 2);
1229 CHECK(queueDescriptor.m_Parameters.m_PadTop == 1);
1230 CHECK(queueDescriptor.m_Parameters.m_PadBottom == 2);
1231 CHECK(queueDescriptor.m_Parameters.m_BiasEnabled ==
false);
1232 CHECK((queueDescriptor.m_Parameters.m_DataLayout == dataLayout));
1234 CHECK(queueDescriptor.m_Inputs.size() == 2);
1235 CHECK(queueDescriptor.m_Outputs.size() == 1);
1241 template <
typename FullyConnectedWorkload, armnn::DataType DataType>
1252 float inputsQScale =
DataType == armnn::DataType::QAsymmU8 ? 1.0f : 0.0;
1253 float outputQScale =
DataType == armnn::DataType::QAsymmU8 ? 2.0f : 0.0;
1267 weights->m_LayerOutput = std::make_unique<ScopedTensorHandle>(weightsTensorInfo);
1268 weights->m_LayerOutput->Allocate();
1272 Connect(weights, layer, weightsTensorInfo, 0, 1);
1274 CreateTensorHandles(graph, factory);
1277 auto workload = MakeAndCheckWorkload<FullyConnectedWorkload>(*layer, factory);
1280 CHECK(queueDescriptor.m_Parameters.m_TransposeWeightMatrix ==
true);
1282 CHECK(queueDescriptor.m_Inputs.size() == 2);
1283 CHECK(queueDescriptor.m_Outputs.size() == 1);
1289 template <
typename FullyConnectedWorkload, armnn::DataType DataType>
1290 std::unique_ptr<FullyConnectedWorkload> CreateFullyConnectedWithBlobWorkloadTest
1301 float inputsQScale =
DataType == armnn::DataType::QAsymmU8 ? 1.0f : 0.0;
1302 float outputQScale =
DataType == armnn::DataType::QAsymmU8 ? 2.0f : 0.0;
1308 layer->
m_Bias->Allocate();
1313 biasesTensorInfo.SetConstant();
1315 auto activationDesc = std::make_shared<ActivationDescriptor>();
1316 activationDesc->m_A = 10.0f;
1317 activationDesc->m_B = 5.0f;
1324 ARMNN_ASSERT(static_cast<float>(activationDescPtr->m_A) == 10.0f);
1325 ARMNN_ASSERT(static_cast<float>(activationDescPtr->m_B) == 5.0f);
1326 ARMNN_ASSERT(static_cast<ActivationFunction>(activationDescPtr->m_Function) ==
1335 weights->m_LayerOutput = std::make_unique<ScopedTensorHandle>(weightsTensorInfo);
1336 weights->m_LayerOutput->Allocate();
1337 biases->
m_LayerOutput = std::make_unique<ScopedTensorHandle>(biasesTensorInfo);
1342 Connect(weights, layer, weightsTensorInfo, 0, 1);
1343 Connect(biases, layer, biasesTensorInfo, 0, 2);
1345 CreateTensorHandles(graph, factory);
1348 auto workload = MakeAndCheckWorkload<FullyConnectedWorkload>(*layer, factory);
1361 CHECK(queueDescriptor.m_Parameters.m_BiasEnabled ==
true);
1362 CHECK(queueDescriptor.m_Parameters.m_TransposeWeightMatrix ==
true);
1363 CHECK(queueDescriptor.m_Inputs.size() == 3);
1364 CHECK(queueDescriptor.m_Outputs.size() == 1);
1370 template <
typename FullyConnectedWorkload, armnn::DataType DataType>
1371 std::unique_ptr<FullyConnectedWorkload> CreateFullyConnectedWorkloadWeightsBiasesAsInputsTest
1383 float inputsQScale =
DataType == armnn::DataType::QAsymmU8 ? 1.0f : 0.0;
1384 float outputQScale =
DataType == armnn::DataType::QAsymmU8 ? 2.0f : 0.0;
1397 CreateTensorHandles(graph, factory);
1400 auto workload = MakeAndCheckWorkload<FullyConnectedWorkload>(*layer, factory);
1404 CHECK(queueDescriptor.m_Parameters.m_BiasEnabled ==
true);
1405 CHECK(queueDescriptor.m_Parameters.m_TransposeWeightMatrix ==
true);
1406 CHECK(queueDescriptor.m_Parameters.m_ConstantWeights ==
false);
1407 CHECK(queueDescriptor.m_Inputs.size() == 3);
1408 CHECK(queueDescriptor.m_Outputs.size() == 1);
1415 template <
typename NormalizationWorkload, armnn::DataType DataType>
1426 layerDesc.
m_Beta = -1.0f;
1427 layerDesc.
m_K = 0.2f;
1444 Connect(input, layer, inputTensorInfo);
1445 Connect(layer, output, outputTensorInfo);
1446 CreateTensorHandles(graph, factory);
1449 auto workload = MakeAndCheckWorkload<NormalizationWorkload>(*layer, factory);
1454 CHECK(queueDescriptor.m_Parameters.m_NormSize == 3);
1455 CHECK(queueDescriptor.m_Parameters.m_Alpha == 0.5f);
1456 CHECK(queueDescriptor.m_Parameters.m_Beta == -1.0f);
1457 CHECK(queueDescriptor.m_Parameters.m_K == 0.2f);
1458 CHECK((queueDescriptor.m_Parameters.m_DataLayout == dataLayout));
1460 CHECK(queueDescriptor.m_Inputs.size() == 1);
1461 CHECK(queueDescriptor.m_Outputs.size() == 1);
1467 template <
typename Pooling2dWorkload, armnn::DataType DataType>
1498 CreateTensorHandles(graph, factory);
1501 auto workload = MakeAndCheckWorkload<Pooling2dWorkload>(*layer, factory);
1506 CHECK(queueDescriptor.m_Parameters.m_PoolWidth == 3);
1507 CHECK(queueDescriptor.m_Parameters.m_PoolHeight == 3);
1508 CHECK(queueDescriptor.m_Parameters.m_StrideX == 2);
1509 CHECK(queueDescriptor.m_Parameters.m_StrideY == 3);
1510 CHECK(queueDescriptor.m_Parameters.m_PadLeft == 2);
1511 CHECK(queueDescriptor.m_Parameters.m_PadRight == 2);
1512 CHECK(queueDescriptor.m_Parameters.m_PadTop == 1);
1513 CHECK(queueDescriptor.m_Parameters.m_PadBottom == 1);
1514 CHECK((queueDescriptor.m_Parameters.m_DataLayout == dataLayout));
1516 CHECK(queueDescriptor.m_Inputs.size() == 1);
1517 CHECK(queueDescriptor.m_Outputs.size() == 1);
1523 template <
typename SoftmaxWorkload, armnn::DataType DataType>
1532 softmaxDescriptor.
m_Axis = -1;
1542 if (
DataType == armnn::DataType::QAsymmU8)
1545 tensorInfo.SetQuantizationScale(1.f / 256);
1547 else if (
DataType == armnn::DataType::QAsymmS8)
1549 tensorInfo.SetQuantizationOffset(-128);
1550 tensorInfo.SetQuantizationScale(1.f / 256);
1553 Connect(input, layer, tensorInfo);
1554 Connect(layer, output, tensorInfo);
1555 CreateTensorHandles(graph, factory);
1558 auto workload = MakeAndCheckWorkload<SoftmaxWorkload>(*layer, factory);
1561 CHECK(queueDescriptor.m_Inputs.size() == 1);
1562 CHECK(queueDescriptor.m_Outputs.size() == 1);
1568 template<
typename SplitterWorkload, armnn::DataType DataType>
1569 std::unique_ptr<SplitterWorkload>
1580 layerDesc.SetViewOriginCoord(0, 0, 0);
1581 layerDesc.SetViewOriginCoord(1, 0, 1);
1582 layerDesc.SetViewOriginCoord(2, 0, 3);
1594 Connect(input, layer, tensorInfo);
1600 Connect(layer, output0, output0Info, 0, 0);
1601 Connect(layer, output1, output1Info, 1, 0);
1602 Connect(layer, output2, output2Info, 2, 0);
1604 CreateTensorHandles(graph, factory);
1607 auto workload = MakeAndCheckWorkload<SplitterWorkload>(*layer, factory);
1610 CHECK(queueDescriptor.m_Inputs.size() == 1);
1611 CHECK(queueDescriptor.m_Outputs.size() == 3);
1612 CHECK(queueDescriptor.m_ViewOrigins.size() == 3);
1614 CHECK(queueDescriptor.m_ViewOrigins[0].m_Origin[0] == 0);
1615 CHECK(queueDescriptor.m_ViewOrigins[1].m_Origin[0] == 1);
1616 CHECK(queueDescriptor.m_ViewOrigins[2].m_Origin[0] == 3);
1617 CHECK(queueDescriptor.m_ViewOrigins[0].m_Origin[1] == 0);
1618 CHECK(queueDescriptor.m_ViewOrigins[1].m_Origin[1] == 0);
1619 CHECK(queueDescriptor.m_ViewOrigins[2].m_Origin[1] == 0);
1620 CHECK(queueDescriptor.m_ViewOrigins[0].m_Origin[2] == 0);
1621 CHECK(queueDescriptor.m_ViewOrigins[1].m_Origin[2] == 0);
1622 CHECK(queueDescriptor.m_ViewOrigins[2].m_Origin[2] == 0);
1629 template<
typename SplitterWorkload,
typename ConcatWorkload, armnn::DataType DataType>
1630 std::pair<std::unique_ptr<SplitterWorkload>, std::unique_ptr<ConcatWorkload>>
1642 splitterViews.SetViewOriginCoord(0, 0, 0);
1643 splitterViews.SetViewOriginCoord(0, 1, 0);
1644 splitterViews.SetViewOriginCoord(0, 2, 0);
1645 splitterViews.SetViewOriginCoord(0, 3, 0);
1647 splitterViews.SetViewOriginCoord(1, 0, 0);
1648 splitterViews.SetViewOriginCoord(1, 1, 1);
1649 splitterViews.SetViewOriginCoord(1, 2, 0);
1650 splitterViews.SetViewOriginCoord(1, 3, 0);
1657 concatViews.SetViewOriginCoord(0, 0, 0);
1658 concatViews.SetViewOriginCoord(0, 1, 1);
1659 concatViews.SetViewOriginCoord(0, 2, 0);
1660 concatViews.SetViewOriginCoord(0, 3, 0);
1662 concatViews.SetViewOriginCoord(1, 0, 0);
1663 concatViews.SetViewOriginCoord(1, 1, 0);
1664 concatViews.SetViewOriginCoord(1, 2, 0);
1665 concatViews.SetViewOriginCoord(1, 3, 0);
1675 Connect(input, splitter, inputTensorInfo, 0, 0);
1677 Connect(splitter, concat, splitTensorInfo1, 0, 1);
1679 Connect(splitter, concat, splitTensorInfo2, 1, 0);
1681 Connect(concat, output, inputTensorInfo, 0, 0);
1684 CreateTensorHandles(graph, factory);
1687 auto workloadSplitter = MakeAndCheckWorkload<SplitterWorkload>(*splitter, factory);
1688 CHECK(workloadSplitter);
1690 auto workloadConcat = MakeAndCheckWorkload<ConcatWorkload>(*concat, factory);
1691 CHECK(workloadConcat);
1693 return {std::move(workloadSplitter), std::move(workloadConcat)};
1699 template<
typename SplitterWorkload,
typename ActivationWorkload, armnn::DataType DataType>
1701 std::unique_ptr<SplitterWorkload>& wlSplitter,
1702 std::unique_ptr<ActivationWorkload>& wlActiv0_0,
1703 std::unique_ptr<ActivationWorkload>& wlActiv0_1,
1704 std::unique_ptr<ActivationWorkload>& wlActiv1_0,
1705 std::unique_ptr<ActivationWorkload>& wlActiv1_1)
1716 splitterViews.SetViewOriginCoord(0, 0, 0);
1717 splitterViews.SetViewOriginCoord(0, 1, 0);
1718 splitterViews.SetViewOriginCoord(0, 2, 0);
1719 splitterViews.SetViewOriginCoord(0, 3, 0);
1721 splitterViews.SetViewOriginCoord(1, 0, 0);
1722 splitterViews.SetViewOriginCoord(1, 1, 1);
1723 splitterViews.SetViewOriginCoord(1, 2, 0);
1724 splitterViews.SetViewOriginCoord(1, 3, 0);
1741 Connect(input, splitter, inputTensorInfo, 0, 0);
1742 Connect(splitter, activ0_0, splitTensorInfo1, 0, 0);
1743 Connect(splitter, activ0_1, splitTensorInfo1, 0, 0);
1745 Connect(splitter, activ1_0, splitTensorInfo2, 1, 0);
1746 Connect(splitter, activ1_1, splitTensorInfo2, 1, 0);
1748 Connect(activ0_0, output1, splitTensorInfo1, 0, 0);
1749 Connect(activ0_1, output2, splitTensorInfo1, 0, 0);
1750 Connect(activ1_0, output3, splitTensorInfo2, 0, 0);
1751 Connect(activ1_1, output4, splitTensorInfo2, 0, 0);
1753 CreateTensorHandles(graph, factory);
1755 auto workloadSplitter = MakeAndCheckWorkload<SplitterWorkload>(*splitter, factory);
1756 auto workloadActiv0_0 = MakeAndCheckWorkload<ActivationWorkload>(*activ0_0, factory);
1757 auto workloadActiv0_1 = MakeAndCheckWorkload<ActivationWorkload>(*activ0_1, factory);
1758 auto workloadActiv1_0 = MakeAndCheckWorkload<ActivationWorkload>(*activ1_0, factory);
1759 auto workloadActiv1_1 = MakeAndCheckWorkload<ActivationWorkload>(*activ1_1, factory);
1761 wlSplitter = std::move(workloadSplitter);
1762 wlActiv0_0 = std::move(workloadActiv0_0);
1763 wlActiv0_1 = std::move(workloadActiv0_1);
1764 wlActiv1_0 = std::move(workloadActiv1_0);
1765 wlActiv1_1 = std::move(workloadActiv1_1);
1768 template <
typename ResizeWorkload, armnn::DataType DataType>
1776 switch (dataLayout) {
1778 inputShape = { 2, 4, 4, 3 };
1779 outputShape = { 2, 2, 2, 3 };
1783 inputShape = { 2, 3, 4, 4 };
1784 outputShape = { 2, 3, 2, 2 };
1803 Connect(input, layer, inputTensorInfo);
1804 Connect(layer, output, outputTensorInfo);
1805 CreateTensorHandles(graph, factory);
1808 auto workload = MakeAndCheckWorkload<ResizeWorkload>(*layer, factory);
1810 auto queueDescriptor = workload->GetData();
1811 CHECK(queueDescriptor.m_Inputs.size() == 1);
1812 CHECK(queueDescriptor.m_Outputs.size() == 1);
1813 CHECK(queueDescriptor.m_Parameters.m_DataLayout == dataLayout);
1819 template <
typename BatchToSpaceNdWorkload, armnn::DataType DataType>
1833 Connect(input, layer, tensorInfo);
1834 Connect(layer, output, tensorInfo);
1836 CreateTensorHandles(graph, factory);
1839 auto workload = MakeAndCheckWorkload<BatchToSpaceNdWorkload>(*layer, factory);
1842 CHECK(queueDescriptor.m_Inputs.size() == 1);
1843 CHECK(queueDescriptor.m_Outputs.size() == 1);
1848 template <
typename LogSoftmaxWorkload, armnn::DataType DataType>
1857 logSoftmaxDescriptor.
m_Axis = -1;
1868 Connect(input, layer, tensorInfo);
1869 Connect(layer, output, tensorInfo);
1870 CreateTensorHandles(graph, factory);
1873 auto workload = MakeAndCheckWorkload<LogSoftmaxWorkload>(*layer, factory);
1876 CHECK(queueDescriptor.m_Inputs.size() == 1);
1877 CHECK(queueDescriptor.m_Outputs.size() == 1);
1883 template <
typename L2NormalizationWorkload, armnn::DataType DataType>
1905 Connect(input, layer, inputTensorInfo);
1906 Connect(layer, output, outputTensorInfo);
1907 CreateTensorHandles(graph, factory);
1910 auto workload = MakeAndCheckWorkload<L2NormalizationWorkload>(*layer, factory);
1913 CHECK((queueDescriptor.m_Parameters.m_DataLayout == dataLayout));
1914 CHECK(queueDescriptor.m_Inputs.size() == 1);
1915 CHECK(queueDescriptor.m_Outputs.size() == 1);
1921 template <
typename ReshapeWorkload, armnn::DataType DataType>
1938 Connect(input, layer, inputTensorInfo);
1939 Connect(layer, output, outputTensorInfo);
1940 CreateTensorHandles(graph, factory);
1943 auto workload = MakeAndCheckWorkload<ReshapeWorkload>(*layer, factory);
1946 CHECK(queueDescriptor.m_Inputs.size() == 1);
1947 CHECK(queueDescriptor.m_Outputs.size() == 1);
1953 template <
typename ConvertFp16ToFp32Float32Workload>
1954 std::unique_ptr<ConvertFp16ToFp32Float32Workload> CreateConvertFp16ToFp32WorkloadTest(
1967 Connect(input, layer, inputTensorInfo);
1968 Connect(layer, output, outputTensorInfo);
1969 CreateTensorHandles(graph, factory);
1972 auto workload = MakeAndCheckWorkload<ConvertFp16ToFp32Float32Workload>(*layer, factory);
1975 CHECK(queueDescriptor.m_Inputs.size() == 1);
1976 CHECK(queueDescriptor.m_Outputs.size() == 1);
1982 template <
typename ConvertFp32ToFp16Float16Workload>
1983 std::unique_ptr<ConvertFp32ToFp16Float16Workload> CreateConvertFp32ToFp16WorkloadTest(
1996 Connect(input, layer, inputTensorInfo);
1997 Connect(layer, output, outputTensorInfo);
1998 CreateTensorHandles(graph, factory);
2001 auto workload = MakeAndCheckWorkload<ConvertFp32ToFp16Float16Workload>(*layer, factory);
2004 CHECK(queueDescriptor.m_Inputs.size() == 1);
2005 CHECK(queueDescriptor.m_Outputs.size() == 1);
2011 template <
typename MeanWorkload, armnn::DataType DataType>
2027 Connect(input, layer, inputTensorInfo);
2028 Connect(layer, output, outputTensorInfo);
2029 CreateTensorHandles(graph, factory);
2032 auto workload = MakeAndCheckWorkload<MeanWorkload>(*layer, factory);
2035 CHECK(queueDescriptor.m_Parameters.m_Axis == descriptor.m_Axis);
2036 CHECK(queueDescriptor.m_Parameters.m_KeepDims == descriptor.m_KeepDims);
2037 CHECK(queueDescriptor.m_Inputs.size() == 1);
2038 CHECK(queueDescriptor.m_Outputs.size() == 1);
2044 template<
typename ConcatWorkload, armnn::DataType DataType>
2048 unsigned int concatAxis)
2058 std::vector<armnn::TensorShape> inputShapes{{ 2, 3, 2, 5 }, { 2, 3, 2, 5 }};
2072 Connect(input0, concat, inputTensorInfo, 0, 0);
2074 Connect(input1, concat, inputTensorInfo, 0, 1);
2076 Connect(concat, output, outputTensorInfo, 0, 0);
2079 CreateTensorHandles(graph, factory);
2082 auto workloadConcat = MakeAndCheckWorkload<ConcatWorkload>(*concat, factory);
2083 CHECK(workloadConcat);
2085 return workloadConcat;
2088 template <
typename PreCompiledWorkload, armnn::DataType dataType>
2089 std::pair<armnn::IOptimizedNetworkPtr, std::unique_ptr<PreCompiledWorkload>> CreatePreCompiledWorkloadTest(
2092 bool biasEnabled =
false)
2107 unsigned int weightsLength = weightsTensorInfo.GetNumElements();
2110 std::vector<WeightType> convWeightsData(weightsLength);
2111 for (
unsigned int i = 0; i < weightsLength; ++i)
2113 convWeightsData[i] =
static_cast<WeightType
>(i);
2126 const std::string convLayerName(
"conv layer");
2134 unsigned int biasLength = biasTensorInfo.GetNumElements();
2137 std::vector<BiasType> biasData(biasLength);
2138 std::fill(biasData.begin(), biasData.end(),
static_cast<BiasType
>(0));
2144 convLayer = net->AddConvolution2dLayer(convDesc2d,
2147 convLayerName.c_str());
2154 convLayer = net->AddConvolution2dLayer(convDesc2d,
2157 convLayerName.c_str());
2169 if (dataType == armnn::DataType::QAsymmU8)
2171 inputTensorInfo.SetQuantizationOffset(0);
2172 inputTensorInfo.SetQuantizationScale(0.9f);
2176 if (dataType == armnn::DataType::QAsymmU8)
2178 outputTensorInfo.SetQuantizationOffset(0);
2179 outputTensorInfo.SetQuantizationScale(0.9f);
2186 convLayer->GetOutputSlot(0).Connect(outputLayer->
GetInputSlot(0));
2187 convLayer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
2190 std::vector<armnn::BackendId> backends = {factory.
GetBackendId()};
2196 CHECK(optimizedNet !=
nullptr);
2200 Layer* preCompiledLayer =
nullptr;
2201 for (
auto& layer : optimisedGraph)
2205 preCompiledLayer = layer;
2208 CHECK(preCompiledLayer !=
nullptr);
2211 CreateTensorHandles(optimisedGraph, factory);
2214 auto workload = MakeAndCheckWorkload<PreCompiledWorkload>(*preCompiledLayer, factory);
2217 CHECK(queueDescriptor.m_Inputs.size() == 1);
2218 CHECK(queueDescriptor.m_Outputs.size() == 1);
2223 return std::make_pair(std::move(optimizedNet), std::move(workload));
2226 template<
typename ConstantWorkload, armnn::DataType DataType>
2236 constant->m_LayerOutput = std::make_unique<ScopedTensorHandle>(outputTensorInfo);
2242 Connect(constant, output, outputTensorInfo, 0, 0);
2245 CreateTensorHandles(graph, factory);
2248 auto workloadConstant = MakeAndCheckWorkload<ConstantWorkload>(*constant, factory);
2249 CHECK(workloadConstant);
2251 return workloadConstant;
2254 template <
typename PreluWorkload>
2264 CHECK(layer !=
nullptr);
2270 CHECK(input !=
nullptr);
2271 CHECK(alpha !=
nullptr);
2272 CHECK(output !=
nullptr);
2278 Connect(input, layer, inputTensorInfo, 0, 0);
2279 Connect(alpha, layer, alphaTensorInfo, 0, 1);
2280 Connect(layer, output, outputTensorInfo, 0, 0);
2281 CreateTensorHandles(graph, factory);
2284 auto workload = MakeAndCheckWorkload<PreluWorkload>(*layer, factory);
2287 CHECK(queueDescriptor.m_Inputs.size() == 2);
2288 CHECK(queueDescriptor.m_Outputs.size() == 1);
2294 template <
typename SpaceToDepthWorkload, armnn::DataType DataType>
2310 Connect(input, layer, inputTensorInfo);
2311 Connect(layer, output, outputTensorInfo);
2313 CreateTensorHandles(graph, factory);
2316 auto workload = MakeAndCheckWorkload<SpaceToDepthWorkload>(*layer, factory);
2319 CHECK(queueDescriptor.m_Inputs.size() == 1);
2320 CHECK(queueDescriptor.m_Outputs.size() == 1);
2325 template <
typename StackWorkload, armnn::DataType DataType>
2331 unsigned int numInputs)
2339 CHECK(stackLayer !=
nullptr);
2342 std::vector<Layer*> inputs;
2343 for (
unsigned int i=0; i<numInputs; ++i)
2346 static_cast<int>(i),
2347 (
"input" + std::to_string(i)).c_str()
2349 CHECK(inputs[i] !=
nullptr);
2352 CHECK(output !=
nullptr);
2355 for (
unsigned int i=0; i<numInputs; ++i)
2357 Connect(inputs[i], stackLayer, inputTensorInfo, 0, i);
2359 Connect(stackLayer, output, outputTensorInfo, 0, 0);
2361 CreateTensorHandles(graph, factory);
2363 auto stackWorkload = MakeAndCheckWorkload<StackWorkload>(*stackLayer, factory);
2365 CHECK(queueDescriptor.m_Inputs.size() == numInputs);
2366 CHECK(queueDescriptor.m_Outputs.size() == 1);
2368 return stackWorkload;
A layer that the constant data can be bound to.
std::shared_ptr< ConstTensorHandle > m_ForgetGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
std::shared_ptr< ConstTensorHandle > m_OutputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
uint32_t m_PadBottom
Padding bottom value in the height dimension.
bool m_BiasEnabled
Enable/disable bias.
bool m_ProjectionEnabled
Enable/disable the projection layer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
This layer represents a split operation.
static IRuntimePtr Create(const CreationOptions &options)
virtual const BackendId & GetBackendId() const =0
LstmBasicParameters m_BasicParameters
This layer represents a batch normalization operation.
A ViewsDescriptor for the SplitterLayer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
uint32_t m_PadBottom
Padding bottom value in the height dimension.
bool m_BiasEnabled
Enable/disable bias.
std::shared_ptr< ConstTensorHandle > m_CellToForgetWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
unsigned int GetWidthIndex() const
float m_K
Kappa value used for the across channel normalization equation.
int m_Axis
Scalar, defaulted to the last index (-1), specifying the dimension the activation will be performed o...
uint32_t m_PadBottom
Padding bottom value in the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
float m_ClippingThresProj
Clipping threshold value for the projection.
A ReshapeDescriptor for the ReshapeLayer.
std::shared_ptr< ConstTensorHandle > m_OutputGateBias
A unique pointer to represent 1D bias tensor with dimensions [num_units] (int32). ...
#define ARMNN_NO_DEPRECATE_WARN_BEGIN
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
This layer represents a depthwise convolution 2d operation.
std::shared_ptr< ConstTensorHandle > m_LayerOutput
LayerT * AddLayer(Args &&... args)
Adds a new layer, of type LayerType, to the graph constructed with the arguments passed.
bool m_TransposeWeightMatrix
Enable/disable transpose weight matrix.
std::vector< BackendOptions > ModelOptions
uint32_t m_PoolWidth
Pooling width value.
bool m_PeepholeEnabled
Enable/disable peephole.
A Convolution2dDescriptor for the Convolution2dLayer.
float m_Alpha
Alpha value for the normalization equation.
uint32_t m_PadLeft
Padding left value in the width dimension.
This layer converts data type Float 16 to Float 32.
float m_HiddenStateScale
Hidden State quantization scale.
float m_OutputIntermediateScale
Output intermediate quantization scale.
ResizeMethod m_Method
The Interpolation method to use (Bilinear, NearestNeighbor).
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
std::shared_ptr< ConstTensorHandle > m_ForgetLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
float m_Eps
Value to add to the variance. Used to avoid dividing by zero.
This layer represents a SpaceToDepth operation.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
This layer represents a reshape operation.
typename ResolveTypeImpl< DT >::Type ResolveType
std::shared_ptr< ConstTensorHandle > m_Weight
A unique pointer to store Weight values.
std::shared_ptr< ConstTensorHandle > m_InputToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8)...
This layer represents an activation operation with the specified activation function.
uint32_t m_PadTop
Padding top value in the height dimension.
std::shared_ptr< ConstTensorHandle > m_Mean
A unique pointer to store Mean values.
uint32_t m_PadRight
Padding right value in the width dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
Copyright (c) 2021 ARM Limited and Contributors.
std::shared_ptr< ConstTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
This layer represents a LSTM operation.
void IgnoreUnused(Ts &&...)
void SetBackendId(const BackendId &id)
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
std::shared_ptr< ConstTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8)...
std::shared_ptr< ConstTensorHandle > m_Beta
A unique pointer to store Beta values.
unsigned int GetHeightIndex() const
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
QLstmOptLayerNormParameters m_LayerNormParameters
NormalizationAlgorithmMethod m_NormMethodType
Normalization method algorithm to use (LocalBrightness, LocalContrast).
This layer represents a elementwiseUnary operation.
A ResizeBilinearDescriptor for the ResizeBilinearLayer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
A StackDescriptor for the StackLayer.
std::shared_ptr< ConstTensorHandle > m_CellBias
A unique pointer to represent 1D bias tensor with dimensions [num_units] (int32). ...
TensorShape m_TargetShape
Target shape value.
std::shared_ptr< ConstTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
uint32_t m_PoolHeight
Pooling height value.
uint32_t m_PadTop
Padding top value in the height dimension.
std::shared_ptr< ConstTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8)...
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
std::shared_ptr< ConstTensorHandle > m_RecurrentToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
A layer user-provided data can be bound to (e.g. inputs, outputs).
std::shared_ptr< ConstTensorHandle > m_CellBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
bool m_LayerNormEnabled
Enable/disable layer normalization.
This layer represents a fully connected operation.
An LstmDescriptor for the LstmLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
#define ARMNN_NO_DEPRECATE_WARN_END
std::shared_ptr< ConstTensorHandle > m_Weight
A unique pointer to store Weight values.
uint32_t m_PadTop
Padding top value in the height dimension.
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
std::shared_ptr< ConstTensorHandle > m_CellLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
This layer represents a QuantizedLstm operation.
This layer represents a log softmax operation.
std::shared_ptr< ConstTensorHandle > m_ForgetGateBias
A unique pointer to represent 1D bias tensor with dimensions [num_units] (int32). ...
A L2NormalizationDescriptor for the L2NormalizationLayer.
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout...
An OriginsDescriptor for the ConcatLayer.
float m_ProjectionClip
Clipping threshold value for the projection.
A FullyConnectedDescriptor for the FullyConnectedLayer.
bool m_BiasEnabled
Enable/disable bias.
This layer represents a stack operation.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
float m_InputIntermediateScale
Input intermediate quantization scale.
This layer represents a merge operation.
This layer represents a softmax operation.
uint32_t m_TargetWidth
Target width value.
bool m_PeepholeEnabled
Enable/disable peephole.
This layer represents a BatchToSpaceNd operation.
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
#define ARMNN_ASSERT(COND)
A QLstmDescriptor for the QLstmLayer.
std::shared_ptr< ConstTensorHandle > m_RecurrentToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
std::shared_ptr< ConstTensorHandle > m_Gamma
A unique pointer to store Gamma values.
GPU Execution: OpenCL: ArmCompute.
static bool IsLayerSupported(const BackendId &backendId, const IConnectableLayer &layer, Optional< DataType > dataType, std::string &outReasonIfUnsupported)
ArmNN performs an optimization on each model/network before it gets loaded for execution.
An ActivationDescriptor for the ActivationLayer.
min(a, max(b, input)) ReLu1 & ReLu6.
std::shared_ptr< ConstTensorHandle > m_OutputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
std::shared_ptr< ConstTensorHandle > m_Variance
A unique pointer to store Variance values.
uint32_t m_TargetHeight
Target height value.
uint32_t m_ActivationFunc
The activation function to use.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
This layer represents a normalization operation.
This layer represents a pooling 2d operation.
std::shared_ptr< ConstTensorHandle > m_Bias
A unique pointer to store Bias values.
std::shared_ptr< ConstTensorHandle > m_RecurrentToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, outputSize] (QSymmS8)...
float m_ClippingThresCell
Clipping threshold value for the cell state.
This layer converts data type Float 32 to Float 16.
unsigned int m_BlockSize
Scalar specifying the input block size. It must be >= 1.
DataType GetBiasDataType(DataType inputDataType)
void SetAdditionalInfoForObject(const AdditionalInfoObjectPtr &additionalInfo)
float m_ForgetIntermediateScale
Forget intermediate quantization scale.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
This layer represents an addition operation.
QLstmBasicParameters m_BasicParameters
LstmOptPeepholeParameters m_PeepholeParameters
std::shared_ptr< ConstTensorHandle > m_RecurrentToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, outputSize] (QSymmS8)...
Graph & GetGraphForTesting(IOptimizedNetwork *optNet)
NormalizationAlgorithmChannel m_NormChannelType
Normalization channel algorithm to use (Across, Within).
This layer represents a QLstm operation.
float m_CellClip
Clipping threshold value for the cell state.
float m_A
Alpha upper bound value used by the activation functions. (BoundedReLu, Linear, TanH, Elu).
This layer represents a subtraction operation.
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
std::shared_ptr< ConstTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
PoolingAlgorithm m_PoolType
The pooling algorithm to use (Max. Average, L2).
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
std::shared_ptr< ConstTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
This layer represents a L2 normalization operation.
std::shared_ptr< ConstTensorHandle > m_Bias
A unique pointer to store Bias values.
std::shared_ptr< ConstTensorHandle > m_Weight
A unique pointer to store Weight values.
CPU Execution: NEON: ArmCompute.
bool m_ProjectionEnabled
Enable/disable the projection layer.
OutputShapeRounding m_OutputShapeRounding
The rounding method for the output shape. (Floor, Ceiling).
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
A MeanDescriptor for the MeanLayer.
void SetConstant(const bool IsConstant=true)
Marks the data corresponding to this tensor info as constant.
DataType GetDataType() const
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
This layer represents a convolution 2d operation.
void SetQuantizationOffset(int32_t offset)
void Connect(armnn::IConnectableLayer *from, armnn::IConnectableLayer *to, const armnn::TensorInfo &tensorInfo, unsigned int fromIndex, unsigned int toIndex)
OriginsDescriptor CreateDescriptorForConcatenation(TensorShapeIt first, TensorShapeIt last, unsigned int concatenationDimension)
Convenience template to create an OriginsDescriptor to use when creating a ConcatLayer for performing...
Graph & TopologicalSort()
Sorts layers in topological order and return this.
This layer represents a mean operation.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
virtual int Connect(IInputSlot &destination)=0
Krichevsky 2012: Local Brightness Normalization.
A Pooling2dDescriptor for the Pooling2dLayer.
A NormalizationDescriptor for the NormalizationLayer.
std::shared_ptr< ConstTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, outputSize] (QSymmS8)...
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
This layer represents a multiplication operation.
virtual void CreateTensorHandles(const TensorHandleFactoryRegistry ®istry, const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const =0
float m_CellIntermediateScale
Cell intermediate quantization scale.
static INetworkPtr Create(NetworkOptions networkOptions={})
float m_B
Beta lower bound value used by the activation functions. (BoundedReLu, Linear, TanH).
A SoftmaxDescriptor for the SoftmaxLayer.
float m_Beta
Beta value for the normalization equation.
bool m_CifgEnabled
Enable/disable CIFG (coupled input & forget gate).
uint32_t m_NormSize
Depth radius value.
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu, LeakyReLu, Abs, Sqrt, Square, Elu).
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
Depthwise Convolution 2D layer workload data.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
uint32_t m_PadLeft
Padding left value in the width dimension.
std::shared_ptr< T > GetAdditionalInformation() const
This layer represents a resize operation.
std::shared_ptr< ConstTensorHandle > m_InputToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below...
uint32_t m_PadRight
Padding right value in the width dimension.
int32_t m_HiddenStateZeroPoint
Hidden State zero point.
bool m_ConstantWeights
Enable/disable constant weights and biases.