blob: 4047e5ad8e51540548328335bae0bff9a9a9d3b2 [file] [log] [blame]
Cian McGriskin160edb32023-07-25 14:15:45 +01001//
2// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5#pragma once
6#include "armnn/INetwork.hpp"
7#include "armnnUtils/QuantizeHelper.hpp"
8#include <CommonTestUtils.hpp>
9#include <ResolveType.hpp>
10#include <doctest/doctest.h>
11
12namespace
13{
14using namespace armnn;
15armnn::INetworkPtr CreateTileNetwork(TileDescriptor& descriptor,
16 const armnn::TensorInfo& inputInfo,
17 const armnn::TensorInfo& outputInfo)
18{
19 INetworkPtr network(INetwork::Create());
20 IConnectableLayer* inputLayer = network->AddInputLayer(0, "input");
21 IConnectableLayer* tileLayer = network->AddTileLayer(descriptor, "tile");
22 IConnectableLayer* outputLayer = network->AddOutputLayer(0, "output");
23 Connect(inputLayer, tileLayer, inputInfo, 0, 0);
24 Connect(tileLayer, outputLayer, outputInfo, 0, 0);
25 return network;
26}
27
28template <armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
29void TileEndToEnd(const std::vector<BackendId>& backends)
30{
31 float qScale = 1.0f;
32 int32_t qOffset = 0;
33 bool qConst = true;
34
35 const TensorShape inputTensorShape = { 2, 3 };
36 const TensorShape outputTensorShape = { 4, 6 };
37
38 TensorInfo inputInfo (inputTensorShape, ArmnnType, qScale, qOffset, qConst);
39 TensorInfo outputInfo (outputTensorShape, ArmnnType,qScale, qOffset);
40
41 std::vector<T> inputData = armnnUtils::QuantizedVector<T>({
42 0.f, 1.f, 2.f,
43 3.f, 4.f, 5.f
44 }, qScale, qOffset);
45
46 std::vector<T> expectedOutputData = armnnUtils::QuantizedVector<T>({
47 0.f, 1.f, 2.f, 0.f, 1.f, 2.f,
48 3.f, 4.f, 5.f, 3.f, 4.f, 5.f,
49 0.f, 1.f, 2.f, 0.f, 1.f, 2.f,
50 3.f, 4.f, 5.f, 3.f, 4.f, 5.f
51 }, qScale, qOffset);
52
53 auto descriptor = armnn::TileDescriptor(std::vector<uint32_t>{ 2, 2 });
54 INetworkPtr network = CreateTileNetwork(descriptor, inputInfo, outputInfo);
55
56 std::map<int, std::vector<T>> inputTensor = { { 0, inputData } };
57 std::map<int, std::vector<T>> expectedOutputTensor = { { 0, expectedOutputData } };
58 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(std::move(network), inputTensor, expectedOutputTensor, backends);
59}
60
61} // anonymous namespace