aboutsummaryrefslogtreecommitdiff
path: root/src/backends/backendsCommon/test/TileEndToEndTestImpl.hpp
blob: 4047e5ad8e51540548328335bae0bff9a9a9d3b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
#pragma once
#include "armnn/INetwork.hpp"
#include "armnnUtils/QuantizeHelper.hpp"
#include <CommonTestUtils.hpp>
#include <ResolveType.hpp>
#include <doctest/doctest.h>

namespace
{
using namespace armnn;
armnn::INetworkPtr CreateTileNetwork(TileDescriptor& descriptor,
                                     const armnn::TensorInfo& inputInfo,
                                     const armnn::TensorInfo& outputInfo)
{
    INetworkPtr network(INetwork::Create());
    IConnectableLayer* inputLayer  = network->AddInputLayer(0, "input");
    IConnectableLayer* tileLayer   = network->AddTileLayer(descriptor, "tile");
    IConnectableLayer* outputLayer = network->AddOutputLayer(0, "output");
    Connect(inputLayer,   tileLayer, inputInfo,  0, 0);
    Connect(tileLayer, outputLayer,  outputInfo, 0, 0);
    return network;
}

template <armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
void TileEndToEnd(const std::vector<BackendId>& backends)
{
    float   qScale  = 1.0f;
    int32_t qOffset = 0;
    bool    qConst  = true;

    const TensorShape inputTensorShape =  { 2, 3 };
    const TensorShape outputTensorShape = { 4, 6 };

    TensorInfo inputInfo  (inputTensorShape, ArmnnType, qScale, qOffset, qConst);
    TensorInfo outputInfo (outputTensorShape, ArmnnType,qScale, qOffset);

    std::vector<T> inputData = armnnUtils::QuantizedVector<T>({
        0.f, 1.f, 2.f,
        3.f, 4.f, 5.f
    }, qScale, qOffset);

    std::vector<T> expectedOutputData = armnnUtils::QuantizedVector<T>({
        0.f, 1.f, 2.f, 0.f, 1.f, 2.f,
        3.f, 4.f, 5.f, 3.f, 4.f, 5.f,
        0.f, 1.f, 2.f, 0.f, 1.f, 2.f,
        3.f, 4.f, 5.f, 3.f, 4.f, 5.f
    }, qScale, qOffset);

    auto descriptor = armnn::TileDescriptor(std::vector<uint32_t>{ 2, 2 });
    INetworkPtr network = CreateTileNetwork(descriptor, inputInfo, outputInfo);

    std::map<int, std::vector<T>> inputTensor          = { { 0, inputData  } };
    std::map<int, std::vector<T>> expectedOutputTensor = { { 0, expectedOutputData } };
    EndToEndLayerTestImpl<ArmnnType, ArmnnType>(std::move(network), inputTensor, expectedOutputTensor, backends);
}

} // anonymous namespace