20 #include <boost/test/unit_test.hpp> 21 #include <boost/cast.hpp> 25 using namespace armnn;
33 template<
typename Workload>
36 std::unique_ptr<IWorkload> workload = layer.
CreateWorkload(factory);
37 BOOST_TEST(workload.get() == boost::polymorphic_downcast<Workload*>(workload.get()),
38 "Cannot convert to derived class");
39 std::string reasonIfUnsupported;
42 return std::unique_ptr<Workload>(
static_cast<Workload*
>(workload.release()));
63 template <
typename ActivationWorkload, armnn::DataType DataType>
71 layerDesc.
m_B = -10.0f;
82 Connect(input, layer, tensorInfo);
83 Connect(layer, output, tensorInfo);
85 CreateTensorHandles(graph, factory);
88 auto workload = MakeAndCheckWorkload<ActivationWorkload>(*layer, factory);
91 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
92 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
93 BOOST_TEST(queueDescriptor.m_Parameters.m_A == 3.5f);
94 BOOST_TEST(queueDescriptor.m_Parameters.m_B == -10.0f);
101 template <
typename WorkloadType,
102 typename DescriptorType,
118 Connect(input1, layer, tensorInfo, 0, 0);
119 Connect(input2, layer, tensorInfo, 0, 1);
120 Connect(layer, output, tensorInfo);
121 CreateTensorHandles(graph, factory);
124 auto workload = MakeAndCheckWorkload<WorkloadType>(*layer, factory);
126 DescriptorType queueDescriptor = workload->GetData();
127 BOOST_TEST(queueDescriptor.m_Inputs.size() == 2);
128 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
134 template <
typename WorkloadType,
135 typename DescriptorType,
148 Connect(input, layer, tensorInfo, 0, 0);
149 Connect(layer, output, tensorInfo, 0, 0);
150 CreateTensorHandles(graph, factory);
152 auto workload = MakeAndCheckWorkload<WorkloadType>(*layer, factory);
153 DescriptorType queueDescriptor = workload->GetData();
155 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
156 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
161 template <
typename BatchNormalizationWorkloadType, armnn::DataType DataType>
162 std::unique_ptr<BatchNormalizationWorkloadType> CreateBatchNormalizationWorkloadTest(
169 tensorShape = { 2, 4, 4, 3 };
173 tensorShape = { 2, 3, 4, 4 };
178 layerDesc.
m_Eps = 0.05f;
184 layer->
m_Mean = std::make_unique<ScopedCpuTensorHandle>(weightInfo);
185 layer->
m_Variance = std::make_unique<ScopedCpuTensorHandle>(weightInfo);
186 layer->
m_Beta = std::make_unique<ScopedCpuTensorHandle>(weightInfo);
187 layer->
m_Gamma = std::make_unique<ScopedCpuTensorHandle>(weightInfo);
188 layer->
m_Mean->Allocate();
190 layer->
m_Beta->Allocate();
199 Connect(input, layer, tensorInfo);
200 Connect(layer, output, tensorInfo);
201 CreateTensorHandles(graph, factory);
204 auto workload = MakeAndCheckWorkload<BatchNormalizationWorkloadType>(*layer, factory);
206 BOOST_TEST(queueDescriptor.m_Parameters.m_Eps == 0.05f);
207 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
208 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
210 BOOST_TEST((queueDescriptor.m_Variance->GetTensorInfo() ==
TensorInfo({3},
DataType)));
213 BOOST_TEST((queueDescriptor.m_Parameters.m_DataLayout == dataLayout));
219 template <
typename Convolution2dWorkload, armnn::DataType DataType>
245 layer->
m_Bias->Allocate();
254 CreateTensorHandles(graph, factory);
257 auto workload = MakeAndCheckWorkload<Convolution2dWorkload>(*layer, factory);
260 BOOST_TEST(queueDescriptor.m_Parameters.m_StrideX == 2);
261 BOOST_TEST(queueDescriptor.m_Parameters.m_StrideY == 4);
262 BOOST_TEST(queueDescriptor.m_Parameters.m_PadLeft == 3);
263 BOOST_TEST(queueDescriptor.m_Parameters.m_PadRight == 3);
264 BOOST_TEST(queueDescriptor.m_Parameters.m_PadTop == 1);
265 BOOST_TEST(queueDescriptor.m_Parameters.m_PadBottom == 1);
266 BOOST_TEST(queueDescriptor.m_Parameters.m_BiasEnabled);
267 BOOST_TEST((queueDescriptor.m_Parameters.m_DataLayout == dataLayout));
269 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
270 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
271 BOOST_TEST((queueDescriptor.m_Weight->GetTensorInfo() ==
TensorInfo(weightShape,
DataType)));
272 BOOST_TEST((queueDescriptor.m_Bias->GetTensorInfo() ==
279 template <
typename LstmWorkload>
292 unsigned int batchSize = 2;
293 unsigned int inputSize = 2;
294 unsigned int numUnits = 4;
295 unsigned int outputSize = 4;
327 if (layerDesc.m_PeepholeEnabled)
350 armnn::TensorInfo lstmTensorInfoScratchBuff({ batchSize, numUnits * (layerDesc.m_CifgEnabled ? 3 : 4) },
352 Connect(input, layer, lstmTensorInfo1, 0, 0);
353 Connect(cellStateIn, layer, lstmTensorInfo2, 0, 1);
354 Connect(outputStateIn, layer, lstmTensorInfo3, 0, 2);
355 Connect(layer, scratchBuffer, lstmTensorInfoScratchBuff, 0, 0);
356 Connect(layer, outputStateOut, lstmTensorInfo3, 1, 0);
357 Connect(layer, cellStateOut, lstmTensorInfo2, 2, 0);
358 Connect(layer, output, lstmTensorInfo3, 3, 0);
360 CreateTensorHandles(graph, factory);
363 auto workload = MakeAndCheckWorkload<LstmWorkload>(*layer, factory);
365 BOOST_TEST(queueDescriptor.m_Parameters.m_ActivationFunc == 4);
366 BOOST_TEST(queueDescriptor.m_Parameters.m_ClippingThresCell == 0.0f);
367 BOOST_TEST(queueDescriptor.m_Parameters.m_ClippingThresProj == 0.0f);
368 BOOST_TEST(queueDescriptor.m_Inputs.size() == 3);
369 BOOST_TEST(queueDescriptor.m_Outputs.size() == 4);
371 BOOST_TEST((queueDescriptor.m_InputToForgetWeights->GetTensorInfo() ==
TensorInfo({ numUnits, inputSize },
373 BOOST_TEST((queueDescriptor.m_OutputGateBias->GetTensorInfo() ==
TensorInfo({ numUnits },
379 template <
typename QuantizedLstmWorkload>
384 unsigned int numBatches = 2;
385 unsigned int inputSize = 2;
386 unsigned int outputSize = 4;
389 float inputOutputScale = 0.0078125f;
390 int32_t inputOutputOffset = 128;
392 float cellStateScale = 0.00048828125f;
393 int32_t cellStateOffset = 0;
395 float weightsScale = 0.00408021f;
396 int32_t weightsOffset = 100;
398 float biasScale = 3.1876640625e-05f;
399 int32_t biasOffset = 0;
418 layer->m_QuantizedLstmParameters.m_InputToInputWeights =
419 std::make_unique<ScopedCpuTensorHandle>(inputWeightsInfo);
420 layer->m_QuantizedLstmParameters.m_InputToForgetWeights =
421 std::make_unique<ScopedCpuTensorHandle>(inputWeightsInfo);
422 layer->m_QuantizedLstmParameters.m_InputToCellWeights =
423 std::make_unique<ScopedCpuTensorHandle>(inputWeightsInfo);
424 layer->m_QuantizedLstmParameters.m_InputToOutputWeights =
425 std::make_unique<ScopedCpuTensorHandle>(inputWeightsInfo);
427 layer->m_QuantizedLstmParameters.m_RecurrentToInputWeights =
428 std::make_unique<ScopedCpuTensorHandle>(recurrentWeightsInfo);
429 layer->m_QuantizedLstmParameters.m_RecurrentToForgetWeights =
430 std::make_unique<ScopedCpuTensorHandle>(recurrentWeightsInfo);
431 layer->m_QuantizedLstmParameters.m_RecurrentToCellWeights =
432 std::make_unique<ScopedCpuTensorHandle>(recurrentWeightsInfo);
433 layer->m_QuantizedLstmParameters.m_RecurrentToOutputWeights =
434 std::make_unique<ScopedCpuTensorHandle>(recurrentWeightsInfo);
436 layer->m_QuantizedLstmParameters.m_InputGateBias = std::make_unique<ScopedCpuTensorHandle>(biasInfo);
437 layer->m_QuantizedLstmParameters.m_ForgetGateBias = std::make_unique<ScopedCpuTensorHandle>(biasInfo);
438 layer->m_QuantizedLstmParameters.m_CellBias = std::make_unique<ScopedCpuTensorHandle>(biasInfo);
439 layer->m_QuantizedLstmParameters.m_OutputGateBias = std::make_unique<ScopedCpuTensorHandle>(biasInfo);
442 layer->m_QuantizedLstmParameters.m_InputToInputWeights->Allocate();
443 layer->m_QuantizedLstmParameters.m_InputToForgetWeights->Allocate();
444 layer->m_QuantizedLstmParameters.m_InputToCellWeights->Allocate();
445 layer->m_QuantizedLstmParameters.m_InputToOutputWeights->Allocate();
447 layer->m_QuantizedLstmParameters.m_RecurrentToInputWeights->Allocate();
448 layer->m_QuantizedLstmParameters.m_RecurrentToForgetWeights->Allocate();
449 layer->m_QuantizedLstmParameters.m_RecurrentToCellWeights->Allocate();
450 layer->m_QuantizedLstmParameters.m_RecurrentToOutputWeights->Allocate();
452 layer->m_QuantizedLstmParameters.m_InputGateBias->Allocate();
453 layer->m_QuantizedLstmParameters.m_ForgetGateBias->Allocate();
454 layer->m_QuantizedLstmParameters.m_CellBias->Allocate();
455 layer->m_QuantizedLstmParameters.m_OutputGateBias->Allocate();
482 Connect(input, layer, inputInfo, 0, 0);
483 Connect(cellStateIn, layer, cellStateInfo, 0, 1);
484 Connect(outputStateIn, layer, outputStateInfo, 0, 2);
486 Connect(layer, cellStateOut, cellStateInfo, 0, 0);
487 Connect(layer, outputStateOut, outputStateInfo, 1, 0);
489 CreateTensorHandles(graph, factory);
492 auto workload = MakeAndCheckWorkload<QuantizedLstmWorkload>(*layer, factory);
496 BOOST_TEST(queueDescriptor.m_Inputs.size() == 3);
497 BOOST_TEST(queueDescriptor.m_Outputs.size() == 2);
500 BOOST_TEST((queueDescriptor.m_InputToInputWeights->GetTensorInfo() == inputWeightsInfo));
501 BOOST_TEST((queueDescriptor.m_InputToForgetWeights->GetTensorInfo() == inputWeightsInfo));
502 BOOST_TEST((queueDescriptor.m_InputToCellWeights->GetTensorInfo() == inputWeightsInfo));
503 BOOST_TEST((queueDescriptor.m_InputToOutputWeights->GetTensorInfo() == inputWeightsInfo));
505 BOOST_TEST((queueDescriptor.m_RecurrentToInputWeights->GetTensorInfo() == recurrentWeightsInfo));
506 BOOST_TEST((queueDescriptor.m_RecurrentToForgetWeights->GetTensorInfo() == recurrentWeightsInfo));
507 BOOST_TEST((queueDescriptor.m_RecurrentToCellWeights->GetTensorInfo() == recurrentWeightsInfo));
508 BOOST_TEST((queueDescriptor.m_RecurrentToOutputWeights->GetTensorInfo() == recurrentWeightsInfo));
510 BOOST_TEST((queueDescriptor.m_InputGateBias->GetTensorInfo() == biasInfo));
511 BOOST_TEST((queueDescriptor.m_ForgetGateBias->GetTensorInfo() == biasInfo));
512 BOOST_TEST((queueDescriptor.m_CellBias->GetTensorInfo() == biasInfo));
513 BOOST_TEST((queueDescriptor.m_OutputGateBias->GetTensorInfo() == biasInfo));
518 template <
typename Convolution2dWorkload, armnn::DataType DataType>
534 float inputsQScale =
DataType == armnn::DataType::QAsymmU8 ? 1.0f : 0.0;
535 float outputQScale =
DataType == armnn::DataType::QAsymmU8 ? 2.0f : 0.0;
538 layer->
m_Bias = std::make_unique<ScopedCpuTensorHandle>
541 layer->
m_Bias->Allocate();
550 CreateTensorHandles(graph, factory);
553 auto workload = MakeAndCheckWorkload<Convolution2dWorkload>(*layer, factory);
556 BOOST_TEST(queueDescriptor.m_Parameters.m_StrideX == 1);
557 BOOST_TEST(queueDescriptor.m_Parameters.m_StrideY == 1);
558 BOOST_TEST(queueDescriptor.m_Parameters.m_PadLeft == 1);
559 BOOST_TEST(queueDescriptor.m_Parameters.m_PadRight == 1);
560 BOOST_TEST(queueDescriptor.m_Parameters.m_PadTop == 1);
561 BOOST_TEST(queueDescriptor.m_Parameters.m_PadBottom == 1);
562 BOOST_TEST(queueDescriptor.m_Parameters.m_BiasEnabled ==
true);
564 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
565 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
566 BOOST_TEST((queueDescriptor.m_Weight->GetTensorInfo() ==
TensorInfo({2, 3, 3, 3},
568 BOOST_TEST((queueDescriptor.m_Bias->GetTensorInfo()
575 template <
typename DepthwiseConvolution2dFloat32Workload, armnn::DataType DataType>
576 std::unique_ptr<DepthwiseConvolution2dFloat32Workload> CreateDepthwiseConvolution2dWorkloadTest(
607 CreateTensorHandles(graph, factory);
610 auto workload = MakeAndCheckWorkload<DepthwiseConvolution2dFloat32Workload>(*layer, factory);
613 BOOST_TEST(queueDescriptor.m_Parameters.m_StrideX == 1);
614 BOOST_TEST(queueDescriptor.m_Parameters.m_StrideY == 1);
615 BOOST_TEST(queueDescriptor.m_Parameters.m_PadLeft == 1);
616 BOOST_TEST(queueDescriptor.m_Parameters.m_PadRight == 2);
617 BOOST_TEST(queueDescriptor.m_Parameters.m_PadTop == 1);
618 BOOST_TEST(queueDescriptor.m_Parameters.m_PadBottom == 2);
619 BOOST_TEST(queueDescriptor.m_Parameters.m_BiasEnabled ==
false);
620 BOOST_TEST((queueDescriptor.m_Parameters.m_DataLayout == dataLayout));
622 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
623 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
624 BOOST_TEST((queueDescriptor.m_Weight->GetTensorInfo() ==
TensorInfo({1, 2, 4, 4},
DataType)));
630 template <
typename FullyConnectedWorkload, armnn::DataType DataType>
641 float inputsQScale =
DataType == armnn::DataType::QAsymmU8 ? 1.0f : 0.0;
642 float outputQScale =
DataType == armnn::DataType::QAsymmU8 ? 2.0f : 0.0;
647 layer->
m_Bias->Allocate();
656 CreateTensorHandles(graph, factory);
659 auto workload = MakeAndCheckWorkload<FullyConnectedWorkload>(*layer, factory);
662 BOOST_TEST(queueDescriptor.m_Parameters.m_BiasEnabled ==
true);
663 BOOST_TEST(queueDescriptor.m_Parameters.m_TransposeWeightMatrix ==
true);
665 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
666 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
667 BOOST_TEST((queueDescriptor.m_Weight->GetTensorInfo() ==
TensorInfo({7, 20},
DataType, inputsQScale)));
674 template <
typename NormalizationWorkload, armnn::DataType DataType>
686 layerDesc.
m_K = 0.2f;
703 Connect(input, layer, inputTensorInfo);
704 Connect(layer, output, outputTensorInfo);
705 CreateTensorHandles(graph, factory);
708 auto workload = MakeAndCheckWorkload<NormalizationWorkload>(*layer, factory);
713 BOOST_TEST(queueDescriptor.m_Parameters.m_NormSize == 3);
714 BOOST_TEST(queueDescriptor.m_Parameters.m_Alpha == 0.5f);
715 BOOST_TEST(queueDescriptor.m_Parameters.m_Beta == -1.0f);
716 BOOST_TEST(queueDescriptor.m_Parameters.m_K == 0.2f);
717 BOOST_TEST((queueDescriptor.m_Parameters.m_DataLayout == dataLayout));
719 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
720 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
726 template <
typename Pooling2dWorkload, armnn::DataType DataType>
757 CreateTensorHandles(graph, factory);
760 auto workload = MakeAndCheckWorkload<Pooling2dWorkload>(*layer, factory);
765 BOOST_TEST(queueDescriptor.m_Parameters.m_PoolWidth == 3);
766 BOOST_TEST(queueDescriptor.m_Parameters.m_PoolHeight == 3);
767 BOOST_TEST(queueDescriptor.m_Parameters.m_StrideX == 2);
768 BOOST_TEST(queueDescriptor.m_Parameters.m_StrideY == 3);
769 BOOST_TEST(queueDescriptor.m_Parameters.m_PadLeft == 2);
770 BOOST_TEST(queueDescriptor.m_Parameters.m_PadRight == 2);
771 BOOST_TEST(queueDescriptor.m_Parameters.m_PadTop == 1);
772 BOOST_TEST(queueDescriptor.m_Parameters.m_PadBottom == 1);
773 BOOST_TEST((queueDescriptor.m_Parameters.m_DataLayout == dataLayout));
775 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
776 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
782 template <
typename SoftmaxWorkload, armnn::DataType DataType>
791 softmaxDescriptor.
m_Axis = 1;
801 Connect(input, layer, tensorInfo);
802 Connect(layer, output, tensorInfo);
803 CreateTensorHandles(graph, factory);
806 auto workload = MakeAndCheckWorkload<SoftmaxWorkload>(*layer, factory);
809 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
810 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
816 template<
typename SplitterWorkload, armnn::DataType DataType>
817 std::unique_ptr<SplitterWorkload>
828 layerDesc.SetViewOriginCoord(0, 0, 0);
829 layerDesc.SetViewOriginCoord(1, 0, 1);
830 layerDesc.SetViewOriginCoord(2, 0, 3);
842 Connect(input, layer, tensorInfo);
848 Connect(layer, output0, output0Info, 0, 0);
849 Connect(layer, output1, output1Info, 1, 0);
850 Connect(layer, output2, output2Info, 2, 0);
852 CreateTensorHandles(graph, factory);
855 auto workload = MakeAndCheckWorkload<SplitterWorkload>(*layer, factory);
858 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
859 BOOST_TEST(queueDescriptor.m_Outputs.size() == 3);
860 BOOST_TEST(queueDescriptor.m_ViewOrigins.size() == 3);
862 BOOST_TEST(queueDescriptor.m_ViewOrigins[0].m_Origin[0] == 0);
863 BOOST_TEST(queueDescriptor.m_ViewOrigins[1].m_Origin[0] == 1);
864 BOOST_TEST(queueDescriptor.m_ViewOrigins[2].m_Origin[0] == 3);
865 BOOST_TEST(queueDescriptor.m_ViewOrigins[0].m_Origin[1] == 0);
866 BOOST_TEST(queueDescriptor.m_ViewOrigins[1].m_Origin[1] == 0);
867 BOOST_TEST(queueDescriptor.m_ViewOrigins[2].m_Origin[1] == 0);
868 BOOST_TEST(queueDescriptor.m_ViewOrigins[0].m_Origin[2] == 0);
869 BOOST_TEST(queueDescriptor.m_ViewOrigins[1].m_Origin[2] == 0);
870 BOOST_TEST(queueDescriptor.m_ViewOrigins[2].m_Origin[2] == 0);
877 template<
typename SplitterWorkload,
typename ConcatWorkload, armnn::DataType DataType>
878 std::pair<std::unique_ptr<SplitterWorkload>, std::unique_ptr<ConcatWorkload>>
890 splitterViews.SetViewOriginCoord(0, 0, 0);
891 splitterViews.SetViewOriginCoord(0, 1, 0);
892 splitterViews.SetViewOriginCoord(0, 2, 0);
893 splitterViews.SetViewOriginCoord(0, 3, 0);
895 splitterViews.SetViewOriginCoord(1, 0, 0);
896 splitterViews.SetViewOriginCoord(1, 1, 1);
897 splitterViews.SetViewOriginCoord(1, 2, 0);
898 splitterViews.SetViewOriginCoord(1, 3, 0);
901 BOOST_TEST_CHECKPOINT(
"created splitter layer");
904 concatViews.SetViewOriginCoord(0, 0, 0);
905 concatViews.SetViewOriginCoord(0, 1, 1);
906 concatViews.SetViewOriginCoord(0, 2, 0);
907 concatViews.SetViewOriginCoord(0, 3, 0);
909 concatViews.SetViewOriginCoord(1, 0, 0);
910 concatViews.SetViewOriginCoord(1, 1, 0);
911 concatViews.SetViewOriginCoord(1, 2, 0);
912 concatViews.SetViewOriginCoord(1, 3, 0);
915 BOOST_TEST_CHECKPOINT(
"created concat layer");
920 Connect(input, splitter, inputTensorInfo, 0, 0);
921 BOOST_TEST_CHECKPOINT(
"connect input to splitter");
922 Connect(splitter, concat, splitTensorInfo1, 0, 1);
923 BOOST_TEST_CHECKPOINT(
"connect splitter[0] to concat[1]");
924 Connect(splitter, concat, splitTensorInfo2, 1, 0);
925 BOOST_TEST_CHECKPOINT(
"connect splitter[1] to concat[0]");
926 Connect(concat, output, inputTensorInfo, 0, 0);
927 BOOST_TEST_CHECKPOINT(
"connect concat to output");
929 CreateTensorHandles(graph, factory);
930 BOOST_TEST_CHECKPOINT(
"created tensor handles");
932 auto workloadSplitter = MakeAndCheckWorkload<SplitterWorkload>(*splitter, factory);
933 BOOST_TEST_CHECKPOINT(
"created splitter workload");
934 auto workloadConcat = MakeAndCheckWorkload<ConcatWorkload>(*concat, factory);
935 BOOST_TEST_CHECKPOINT(
"created concat workload");
937 return {std::move(workloadSplitter), std::move(workloadConcat)};
943 template<
typename SplitterWorkload,
typename ActivationWorkload, armnn::DataType DataType>
945 std::unique_ptr<SplitterWorkload>& wlSplitter,
946 std::unique_ptr<ActivationWorkload>& wlActiv0_0,
947 std::unique_ptr<ActivationWorkload>& wlActiv0_1,
948 std::unique_ptr<ActivationWorkload>& wlActiv1_0,
949 std::unique_ptr<ActivationWorkload>& wlActiv1_1)
960 splitterViews.SetViewOriginCoord(0, 0, 0);
961 splitterViews.SetViewOriginCoord(0, 1, 0);
962 splitterViews.SetViewOriginCoord(0, 2, 0);
963 splitterViews.SetViewOriginCoord(0, 3, 0);
965 splitterViews.SetViewOriginCoord(1, 0, 0);
966 splitterViews.SetViewOriginCoord(1, 1, 1);
967 splitterViews.SetViewOriginCoord(1, 2, 0);
968 splitterViews.SetViewOriginCoord(1, 3, 0);
985 Connect(input, splitter, inputTensorInfo, 0, 0);
986 Connect(splitter, activ0_0, splitTensorInfo1, 0, 0);
987 Connect(splitter, activ0_1, splitTensorInfo1, 0, 0);
989 Connect(splitter, activ1_0, splitTensorInfo2, 1, 0);
990 Connect(splitter, activ1_1, splitTensorInfo2, 1, 0);
992 Connect(activ0_0, output1, splitTensorInfo1, 0, 0);
993 Connect(activ0_1, output2, splitTensorInfo1, 0, 0);
994 Connect(activ1_0, output3, splitTensorInfo2, 0, 0);
995 Connect(activ1_1, output4, splitTensorInfo2, 0, 0);
997 CreateTensorHandles(graph, factory);
999 auto workloadSplitter = MakeAndCheckWorkload<SplitterWorkload>(*splitter, factory);
1000 auto workloadActiv0_0 = MakeAndCheckWorkload<ActivationWorkload>(*activ0_0, factory);
1001 auto workloadActiv0_1 = MakeAndCheckWorkload<ActivationWorkload>(*activ0_1, factory);
1002 auto workloadActiv1_0 = MakeAndCheckWorkload<ActivationWorkload>(*activ1_0, factory);
1003 auto workloadActiv1_1 = MakeAndCheckWorkload<ActivationWorkload>(*activ1_1, factory);
1005 wlSplitter = std::move(workloadSplitter);
1006 wlActiv0_0 = std::move(workloadActiv0_0);
1007 wlActiv0_1 = std::move(workloadActiv0_1);
1008 wlActiv1_0 = std::move(workloadActiv1_0);
1009 wlActiv1_1 = std::move(workloadActiv1_1);
1012 template <
typename ResizeWorkload, armnn::DataType DataType>
1020 switch (dataLayout) {
1022 inputShape = { 2, 4, 4, 3 };
1023 outputShape = { 2, 2, 2, 3 };
1027 inputShape = { 2, 3, 4, 4 };
1028 outputShape = { 2, 3, 2, 2 };
1047 Connect(input, layer, inputTensorInfo);
1048 Connect(layer, output, outputTensorInfo);
1049 CreateTensorHandles(graph, factory);
1052 auto workload = MakeAndCheckWorkload<ResizeWorkload>(*layer, factory);
1054 auto queueDescriptor = workload->GetData();
1055 BOOST_CHECK(queueDescriptor.m_Inputs.size() == 1);
1056 BOOST_CHECK(queueDescriptor.m_Outputs.size() == 1);
1057 BOOST_CHECK(queueDescriptor.m_Parameters.m_DataLayout == dataLayout);
1063 template <
typename BatchToSpaceNdWorkload, armnn::DataType DataType>
1077 Connect(input, layer, tensorInfo);
1078 Connect(layer, output, tensorInfo);
1080 CreateTensorHandles(graph, factory);
1083 auto workload = MakeAndCheckWorkload<BatchToSpaceNdWorkload>(*layer, factory);
1086 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
1087 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
1092 template <
typename L2NormalizationWorkload, armnn::DataType DataType>
1114 Connect(input, layer, inputTensorInfo);
1115 Connect(layer, output, outputTensorInfo);
1116 CreateTensorHandles(graph, factory);
1119 auto workload = MakeAndCheckWorkload<L2NormalizationWorkload>(*layer, factory);
1122 BOOST_TEST((queueDescriptor.m_Parameters.m_DataLayout == dataLayout));
1123 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
1124 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
1130 template <
typename ReshapeWorkload, armnn::DataType DataType>
1147 Connect(input, layer, inputTensorInfo);
1148 Connect(layer, output, outputTensorInfo);
1149 CreateTensorHandles(graph, factory);
1152 auto workload = MakeAndCheckWorkload<ReshapeWorkload>(*layer, factory);
1155 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
1156 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
1162 template <
typename ConvertFp16ToFp32Float32Workload>
1163 std::unique_ptr<ConvertFp16ToFp32Float32Workload> CreateConvertFp16ToFp32WorkloadTest(
1176 Connect(input, layer, inputTensorInfo);
1177 Connect(layer, output, outputTensorInfo);
1178 CreateTensorHandles(graph, factory);
1181 auto workload = MakeAndCheckWorkload<ConvertFp16ToFp32Float32Workload>(*layer, factory);
1184 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
1185 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
1191 template <
typename ConvertFp32ToFp16Float16Workload>
1192 std::unique_ptr<ConvertFp32ToFp16Float16Workload> CreateConvertFp32ToFp16WorkloadTest(
1205 Connect(input, layer, inputTensorInfo);
1206 Connect(layer, output, outputTensorInfo);
1207 CreateTensorHandles(graph, factory);
1210 auto workload = MakeAndCheckWorkload<ConvertFp32ToFp16Float16Workload>(*layer, factory);
1213 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
1214 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
1220 template <
typename MeanWorkload, armnn::DataType DataType>
1236 Connect(input, layer, inputTensorInfo);
1237 Connect(layer, output, outputTensorInfo);
1238 CreateTensorHandles(graph, factory);
1241 auto workload = MakeAndCheckWorkload<MeanWorkload>(*layer, factory);
1244 BOOST_TEST(queueDescriptor.m_Parameters.m_Axis == descriptor.m_Axis);
1245 BOOST_TEST(queueDescriptor.m_Parameters.m_KeepDims == descriptor.m_KeepDims);
1246 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
1247 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
1253 template<
typename ConcatWorkload, armnn::DataType DataType>
1257 unsigned int concatAxis)
1267 std::vector<armnn::TensorShape> inputShapes{{ 2, 3, 2, 5 }, { 2, 3, 2, 5 }};
1274 BOOST_TEST_CHECKPOINT(
"created concat layer");
1279 Connect(input0, concat, inputTensorInfo, 0, 0);
1280 BOOST_TEST_CHECKPOINT(
"connect input0 to concat");
1281 Connect(input1, concat, inputTensorInfo, 0, 1);
1282 BOOST_TEST_CHECKPOINT(
"connect input1 to concat");
1283 Connect(concat, output, outputTensorInfo, 0, 0);
1284 BOOST_TEST_CHECKPOINT(
"connect concat to output");
1286 CreateTensorHandles(graph, factory);
1287 BOOST_TEST_CHECKPOINT(
"created tensor handles");
1289 auto workloadConcat = MakeAndCheckWorkload<ConcatWorkload>(*concat, factory);
1290 BOOST_TEST_CHECKPOINT(
"created concat workload");
1292 return workloadConcat;
1295 template <
typename PreCompiledWorkload, armnn::DataType dataType>
1296 std::pair<armnn::IOptimizedNetworkPtr, std::unique_ptr<PreCompiledWorkload>> CreatePreCompiledWorkloadTest(
1299 bool biasEnabled =
false)
1308 BOOST_TEST(inputLayer);
1314 unsigned int weightsLength = weightsTensorInfo.GetNumElements();
1317 std::vector<WeightType> convWeightsData(weightsLength);
1318 for (
unsigned int i = 0; i < weightsLength; ++i)
1320 convWeightsData[i] =
static_cast<WeightType
>(i);
1333 const std::string convLayerName(
"conv layer");
1341 unsigned int biasLength = biasTensorInfo.GetNumElements();
1344 std::vector<BiasType> biasData(biasLength);
1345 std::fill(biasData.begin(), biasData.end(),
static_cast<BiasType
>(0));
1353 convLayerName.c_str());
1361 convLayerName.c_str());
1364 BOOST_TEST(convLayer);
1368 BOOST_TEST(outputLayer);
1372 if (dataType == armnn::DataType::QAsymmU8)
1374 inputTensorInfo.SetQuantizationOffset(0);
1375 inputTensorInfo.SetQuantizationScale(0.9f);
1379 if (dataType == armnn::DataType::QAsymmU8)
1381 outputTensorInfo.SetQuantizationOffset(0);
1382 outputTensorInfo.SetQuantizationScale(0.9f);
1393 std::vector<armnn::BackendId> backends = {factory.
GetBackendId()};
1403 Layer* preCompiledLayer =
nullptr;
1404 for (
auto& layer : optimisedGraph)
1408 preCompiledLayer = layer;
1414 CreateTensorHandles(optimisedGraph, factory);
1417 auto workload = MakeAndCheckWorkload<PreCompiledWorkload>(*preCompiledLayer, factory);
1420 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
1421 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
1426 return std::make_pair(std::move(optimizedNet), std::move(workload));
1429 template<
typename ConstantWorkload, armnn::DataType DataType>
1437 constant->
m_LayerOutput = std::make_unique<ScopedCpuTensorHandle>(outputTensorInfo);
1438 BOOST_TEST_CHECKPOINT(
"created constant layer");
1443 Connect(constant, output, outputTensorInfo, 0, 0);
1444 BOOST_TEST_CHECKPOINT(
"connect constant to output");
1446 CreateTensorHandles(graph, factory);
1447 BOOST_TEST_CHECKPOINT(
"created tensor handles");
1449 auto workloadConstant = MakeAndCheckWorkload<ConstantWorkload>(*constant, factory);
1450 BOOST_TEST_CHECKPOINT(
"created Constant workload");
1452 return workloadConstant;
1455 template <
typename PreluWorkload>
1479 Connect(input, layer, inputTensorInfo, 0, 0);
1480 Connect(alpha, layer, alphaTensorInfo, 0, 1);
1481 Connect(layer, output, outputTensorInfo, 0, 0);
1482 CreateTensorHandles(graph, factory);
1485 auto workload = MakeAndCheckWorkload<PreluWorkload>(*layer, factory);
1488 BOOST_TEST(queueDescriptor.m_Inputs.size() == 2);
1489 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
1495 template <
typename SpaceToDepthWorkload, armnn::DataType DataType>
1511 Connect(input, layer, inputTensorInfo);
1512 Connect(layer, output, outputTensorInfo);
1514 CreateTensorHandles(graph, factory);
1517 auto workload = MakeAndCheckWorkload<SpaceToDepthWorkload>(*layer, factory);
1520 BOOST_TEST(queueDescriptor.m_Inputs.size() == 1);
1521 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
1526 template <
typename StackWorkload, armnn::DataType DataType>
1532 unsigned int numInputs)
1543 std::vector<Layer*> inputs;
1544 for (
unsigned int i=0; i<numInputs; ++i)
1547 static_cast<int>(i),
1548 (
"input" + std::to_string(i)).c_str()
1556 for (
unsigned int i=0; i<numInputs; ++i)
1558 Connect(inputs[i], stackLayer, inputTensorInfo, 0, i);
1560 Connect(stackLayer, output, outputTensorInfo, 0, 0);
1562 CreateTensorHandles(graph, factory);
1564 auto stackWorkload = MakeAndCheckWorkload<StackWorkload>(*stackLayer, factory);
1566 BOOST_TEST(queueDescriptor.m_Inputs.size() == numInputs);
1567 BOOST_TEST(queueDescriptor.m_Outputs.size() == 1);
1569 return stackWorkload;
A layer that the constant data can be bound to.
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetGateBias
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.
std::unique_ptr< ScopedCpuTensorHandle > m_InputToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
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.
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an output layer to the network.
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.
std::unique_ptr< ScopedCpuTensorHandle > m_Weight
A unique pointer to store Weight values.
float m_ClippingThresProj
Clipping threshold value for the projection.
A ReshapeDescriptor for the ReshapeLayer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
This layer represents a depthwise convolution 2d operation.
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::unique_ptr< ScopedCpuTensorHandle > m_Bias
A unique pointer to store Bias values.
uint32_t m_PoolWidth
Pooling width value.
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.
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
This layer converts data type Float 16 to Float 32.
ResizeMethod m_Method
The Interpolation method to use (Bilinear, NearestNeighbor).
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
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).
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an input layer to the network.
std::unique_ptr< ScopedCpuTensorHandle > m_Gamma
A unique pointer to store Gamma values.
std::unique_ptr< ScopedCpuTensorHandle > m_OutputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
This layer represents a reshape operation.
std::unique_ptr< ScopedCpuTensorHandle > m_Variance
A unique pointer to store Variance values.
typename ResolveTypeImpl< DT >::Type ResolveType
This layer represents an activation operation with the specified activation function.
uint32_t m_PadTop
Padding top value in the height dimension.
uint32_t m_PadRight
Padding right value in the width dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
Copyright (c) 2020 ARM Limited.
This layer represents a LSTM operation.
void IgnoreUnused(Ts &&...)
void SetBackendId(const BackendId &id)
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
std::unique_ptr< ScopedCpuTensorHandle > m_CellBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
unsigned int GetHeightIndex() const
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
NormalizationAlgorithmMethod m_NormMethodType
Normalization method algorithm to use (LocalBrightness, LocalContrast).
This layer represents a elementwiseUnary operation.
A ResizeDescriptor for the ResizeLayer.
std::unique_ptr< ScopedCpuTensorHandle > m_Beta
A unique pointer to store Beta values.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
IConnectableLayer * AddConvolution2dLayer(const Convolution2dDescriptor &convolution2dDescriptor, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name=nullptr) override
Adds a 2D convolution layer to the network.
A StackDescriptor for the StackLayer.
TensorShape m_TargetShape
Target shape value.
uint32_t m_PoolHeight
Pooling height value.
uint32_t m_PadTop
Padding top value in the height dimension.
std::unique_ptr< ScopedCpuTensorHandle > m_CellToForgetWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
std::unique_ptr< ScopedCpuTensorHandle > m_LayerOutput
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).
This layer represents a fully connected operation.
An LstmDescriptor for the LstmLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
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.
This layer represents a QuantizedLstm operation.
std::unique_ptr< ScopedCpuTensorHandle > m_Mean
A unique pointer to store Mean values.
A L2NormalizationDescriptor for the L2NormalizationLayer.
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout...
An OriginsDescriptor for the ConcatLayer.
A FullyConnectedDescriptor for the FullyConnectedLayer.
std::unique_ptr< ScopedCpuTensorHandle > m_Weight
A unique pointer to store Weight values.
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.
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
GPU Execution: OpenCL: ArmCompute.
static bool IsLayerSupported(const BackendId &backendId, const IConnectableLayer &layer, Optional< DataType > dataType, std::string &outReasonIfUnsupported)
An ActivationDescriptor for the ActivationLayer.
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.
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)
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
LstmOptPeepholeParameters m_PeepholeParameters
Private implementation of INetwork.
NormalizationAlgorithmChannel m_NormChannelType
Normalization channel algorithm to use (Across, Within).
float m_A
Alpha upper bound value used by the activation functions. (BoundedReLu, Linear, TanH).
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
std::unique_ptr< ScopedCpuTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
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.
This layer represents a L2 normalization operation.
CPU Execution: NEON: ArmCompute.
OutputShapeRounding m_OutputShapeRounding
The rounding method for the output shape. (Floor, Ceiling).
std::unique_ptr< ScopedCpuTensorHandle > m_Bias
A unique pointer to store Bias values.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
A MeanDescriptor for the MeanLayer.
std::unique_ptr< ScopedCpuTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
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 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.
virtual int Connect(IInputSlot &destination)=0
Krichevsky 2012: Local Brightness Normalization.
std::unique_ptr< ScopedCpuTensorHandle > m_Weight
A unique pointer to store Weight values.
A Pooling2dDescriptor for the Pooling2dLayer.
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
A NormalizationDescriptor for the NormalizationLayer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
virtual void CreateTensorHandles(const TensorHandleFactoryRegistry ®istry, const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const =0
std::unique_ptr< ScopedCpuTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
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.
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).
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
uint32_t m_PadLeft
Padding left value in the width dimension.
This layer represents a resize operation.
uint32_t m_PadRight
Padding right value in the width dimension.