• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <CommonTestUtils.hpp>
9 
10 #include <armnn/INetwork.hpp>
11 #include <armnn/TypesUtils.hpp>
12 
13 #include <ResolveType.hpp>
14 
15 #include <doctest/doctest.h>
16 
17 namespace
18 {
19 
CreateFillNetwork(const armnn::TensorInfo & inputTensorInfo,const armnn::TensorInfo & outputTensorInfo,armnn::FillDescriptor descriptor)20 armnn::INetworkPtr CreateFillNetwork(const armnn::TensorInfo& inputTensorInfo,
21                                      const armnn::TensorInfo& outputTensorInfo,
22                                      armnn::FillDescriptor descriptor)
23 {
24     armnn::INetworkPtr network(armnn::INetwork::Create());
25 
26     armnn::IConnectableLayer* inputLayer  = network->AddInputLayer(0, "Input");
27     armnn::IConnectableLayer* fillLayer   = network->AddFillLayer(descriptor, "Fill");
28     armnn::IConnectableLayer* outputLayer = network->AddOutputLayer(0, "Output");
29 
30     Connect(inputLayer, fillLayer, inputTensorInfo, 0, 0);
31     Connect(fillLayer, outputLayer, outputTensorInfo, 0, 0);
32 
33     return network;
34 }
35 
36 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
FillEndToEnd(const std::vector<armnn::BackendId> & backends)37 void FillEndToEnd(const std::vector<armnn::BackendId>& backends)
38 {
39     using namespace armnn;
40 
41     FillDescriptor descriptor;
42     descriptor.m_Value = 9;
43 
44     std::vector<int32_t> inputData {
45             1, 1, 5, 3
46     };
47 
48     std::vector<float> floatExpectedOutputData {
49             9, 9, 9, 9, 9,
50             9, 9, 9, 9, 9,
51             9, 9, 9, 9, 9
52     };
53     std::vector<T> expectedOutputData = armnnUtils::QuantizedVector<T>(floatExpectedOutputData);
54 
55     TensorInfo inputInfo ({ 4 }, DataType::Signed32, 0.0f, 0, true);
56     TensorInfo outputInfo({ 1, 1, 5, 3 }, ArmnnType);
57 
58     armnn::INetworkPtr network = CreateFillNetwork(inputInfo, outputInfo, descriptor);
59 
60     CHECK(network);
61 
62     std::map<int, std::vector<int32_t>> inputTensorData    = {{ 0, inputData }};
63     std::map<int, std::vector<T>> expectedOutputTensorData = {{ 0, expectedOutputData }};
64 
65     EndToEndLayerTestImpl<DataType::Signed32, ArmnnType>(move(network),
66                                                          inputTensorData,
67                                                          expectedOutputTensorData,
68                                                          backends);
69 }
70 
71 } // anonymous namespace