aboutsummaryrefslogtreecommitdiff
path: root/delegate/src/test/FullyConnectedTest.cpp
blob: 1d33381d6e75a24a24e8ee7b36857d25c2767938 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//
// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "FullyConnectedTestHelper.hpp"

namespace
{

TEST_SUITE("FullyConnectedTest")
{

void FullyConnectedFp32Test(std::vector<armnn::BackendId>& backends)
{
    std::vector<int32_t> inputTensorShape   { 1, 4, 1, 1 };
    std::vector<int32_t> weightsTensorShape { 1, 4 };
    std::vector<int32_t> biasTensorShape    { 1 };
    std::vector<int32_t> outputTensorShape  { 1, 1 };

    std::vector<float> inputValues = { 10, 20, 30, 40 };
    std::vector<float> weightsData = { 2, 3, 4, 5 };

    std::vector<float> expectedOutputValues = { (400 + 10) };

    // bias is set std::vector<float> biasData = { 10 } in the model
    FullyConnectedTest<float>(backends,
                              ::tflite::TensorType_FLOAT32,
                              tflite::ActivationFunctionType_NONE,
                              inputTensorShape,
                              weightsTensorShape,
                              biasTensorShape,
                              outputTensorShape,
                              inputValues,
                              expectedOutputValues,
                              weightsData);
}

void FullyConnectedActicationTest(std::vector<armnn::BackendId>& backends)
{
    std::vector<int32_t> inputTensorShape   { 1, 4, 1, 1 };
    std::vector<int32_t> weightsTensorShape { 1, 4 };
    std::vector<int32_t> biasTensorShape    { 1 };
    std::vector<int32_t> outputTensorShape  { 1, 1 };

    std::vector<float> inputValues = { -10, 20, 30, 40 };
    std::vector<float> weightsData = { 2, 3, 4, -5 };

    std::vector<float> expectedOutputValues = { 0 };

    // bias is set std::vector<float> biasData = { 10 } in the model
    FullyConnectedTest<float>(backends,
                              ::tflite::TensorType_FLOAT32,
                              tflite::ActivationFunctionType_RELU,
                              inputTensorShape,
                              weightsTensorShape,
                              biasTensorShape,
                              outputTensorShape,
                              inputValues,
                              expectedOutputValues,
                              weightsData);
}

void FullyConnectedUint8Test(std::vector<armnn::BackendId>& backends)
{
    std::vector<int32_t> inputTensorShape   { 1, 4, 2, 1 };
    std::vector<int32_t> weightsTensorShape { 1, 4 };
    std::vector<int32_t> biasTensorShape    { 1 };
    std::vector<int32_t> outputTensorShape  { 2, 1 };

    std::vector<uint8_t> inputValues = { 1, 2, 3, 4, 10, 20, 30, 40 };
    std::vector<uint8_t> weightsData = { 2, 3, 4, 5 };

    std::vector<uint8_t> expectedOutputValues = { (40 + 10) / 2, (400 + 10) / 2 };

    // bias is set std::vector<int32_t> biasData = { 10 } in the model
    // input and weights quantization scale 1.0f and offset 0 in the model
    // output quantization scale 2.0f and offset 0 in the model
    FullyConnectedTest<uint8_t>(backends,
                              ::tflite::TensorType_UINT8,
                              tflite::ActivationFunctionType_NONE,
                              inputTensorShape,
                              weightsTensorShape,
                              biasTensorShape,
                              outputTensorShape,
                              inputValues,
                              expectedOutputValues,
                              weightsData);
}

TEST_CASE ("FULLY_CONNECTED_FP32_GpuAcc_Test")
{
    std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc,
                                               armnn::Compute::CpuRef };
    FullyConnectedFp32Test(backends);
}

TEST_CASE ("FULLY_CONNECTED_FP32_CpuAcc_Test")
{
    std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc,
                                               armnn::Compute::CpuRef };
    FullyConnectedFp32Test(backends);
}

TEST_CASE ("FULLY_CONNECTED_UINT8_GpuAcc_Test")
{
    std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc,
                                               armnn::Compute::CpuRef };
    FullyConnectedUint8Test(backends);
}

TEST_CASE ("FULLY_CONNECTED_UINT8_CpuAcc_Test")
{
    std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc,
                                               armnn::Compute::CpuRef };
    FullyConnectedUint8Test(backends);
}

TEST_CASE ("FULLY_CONNECTED_Activation_GpuAcc_Test")
{
    std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc,
                                               armnn::Compute::CpuRef };
    FullyConnectedActicationTest(backends);
}

} // End of TEST_SUITE("FullyConnectedTest")

} // anonymous namespace