aboutsummaryrefslogtreecommitdiff
path: root/test/GenericLayerTests.cpp
blob: 7116f0b044b8f5ea812aff711df94f7571344dd8 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// See LICENSE file in the project root for full license information.
//
#include "DriverTestHelpers.hpp"
#include <boost/test/unit_test.hpp>
#include <log/log.h>

BOOST_AUTO_TEST_SUITE(GenericLayerTests)

using ArmnnDriver = armnn_driver::ArmnnDriver;
using DriverOptions = armnn_driver::DriverOptions;
using namespace driverTestHelpers;

BOOST_AUTO_TEST_CASE(GetSupportedOperations)
{
    auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));

    ErrorStatus error;
    std::vector<bool> sup;

    ArmnnDriver::getSupportedOperations_cb cb = [&](ErrorStatus status, const std::vector<bool>& supported)
    {
        error = status;
        sup = supported;
    };

    V1_0::Model model1 = {};

    // add operands
    int32_t actValue      = 0;
    float   weightValue[] = {2, 4, 1};
    float   biasValue[]   = {4};

    AddInputOperand(model1, hidl_vec<uint32_t>{1, 3});
    AddTensorOperand(model1, hidl_vec<uint32_t>{1, 3}, weightValue);
    AddTensorOperand(model1, hidl_vec<uint32_t>{1}, biasValue);
    AddIntOperand(model1, actValue);
    AddOutputOperand(model1, hidl_vec<uint32_t>{1, 1});

    // make a correct fully connected operation
    model1.operations.resize(2);
    model1.operations[0].type = V1_0::OperationType::FULLY_CONNECTED;
    model1.operations[0].inputs  = hidl_vec<uint32_t>{0, 1, 2, 3};
    model1.operations[0].outputs = hidl_vec<uint32_t>{4};

    // make an incorrect fully connected operation
    AddIntOperand(model1, actValue);
    AddOutputOperand(model1, hidl_vec<uint32_t>{1, 1});
    model1.operations[1].type = V1_0::OperationType::FULLY_CONNECTED;
    model1.operations[1].inputs = hidl_vec<uint32_t>{4};
    model1.operations[1].outputs = hidl_vec<uint32_t>{5};

    driver->getSupportedOperations(model1, cb);
    BOOST_TEST((int)error == (int)ErrorStatus::NONE);
    BOOST_TEST(sup[0] == true);
    BOOST_TEST(sup[1] == false);

    // Broadcast add/mul are not supported
    V1_0::Model model2 = {};

    AddInputOperand(model2, hidl_vec<uint32_t>{1, 1, 3, 4});
    AddInputOperand(model2, hidl_vec<uint32_t>{4});
    AddOutputOperand(model2, hidl_vec<uint32_t>{1, 1, 3, 4});
    AddOutputOperand(model2, hidl_vec<uint32_t>{1, 1, 3, 4});

    model2.operations.resize(2);

    model2.operations[0].type = V1_0::OperationType::ADD;
    model2.operations[0].inputs = hidl_vec<uint32_t>{0,1};
    model2.operations[0].outputs = hidl_vec<uint32_t>{2};

    model2.operations[1].type = V1_0::OperationType::MUL;
    model2.operations[1].inputs = hidl_vec<uint32_t>{0,1};
    model2.operations[1].outputs = hidl_vec<uint32_t>{3};

    driver->getSupportedOperations(model2, cb);
    BOOST_TEST((int)error == (int)ErrorStatus::NONE);
    BOOST_TEST(sup[0] == false);
    BOOST_TEST(sup[1] == false);

    V1_0::Model model3 = {};

    // Add unsupported operation, should return no error but we don't support it
    AddInputOperand(model3, hidl_vec<uint32_t>{1, 1, 1, 8});
    AddIntOperand(model3, 2);
    AddOutputOperand(model3, hidl_vec<uint32_t>{1, 2, 2, 2});
    model3.operations.resize(1);
    model3.operations[0].type = V1_0::OperationType::DEPTH_TO_SPACE;
    model1.operations[0].inputs = hidl_vec<uint32_t>{0, 1};
    model3.operations[0].outputs = hidl_vec<uint32_t>{2};

    driver->getSupportedOperations(model3, cb);
    BOOST_TEST((int)error == (int)ErrorStatus::NONE);
    BOOST_TEST(sup[0] == false);

    // Add invalid operation
    V1_0::Model model4 = {};
    AddIntOperand(model4, 0);
    model4.operations.resize(1);
    model4.operations[0].type = static_cast<V1_0::OperationType>(100);
    model4.operations[0].outputs = hidl_vec<uint32_t>{0};

    driver->getSupportedOperations(model4, cb);
    BOOST_TEST((int)error == (int)ErrorStatus::INVALID_ARGUMENT);
}

// The purpose of this test is to ensure that when encountering an unsupported operation
//      it is skipped and getSupportedOperations() continues (rather than failing and stopping).
//      As per IVGCVSW-710.
BOOST_AUTO_TEST_CASE(UnsupportedLayerContinueOnFailure)
{
    auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));

    ErrorStatus error;
    std::vector<bool> sup;

    ArmnnDriver::getSupportedOperations_cb cb = [&](ErrorStatus status, const std::vector<bool>& supported)
    {
        error = status;
        sup = supported;
    };

    V1_0::Model model = {};

    // operands
    int32_t actValue      = 0;
    float   weightValue[] = {2, 4, 1};
    float   biasValue[]   = {4};

    // broadcast add is unsupported at the time of writing this test, but any unsupported layer will do
    AddInputOperand(model, hidl_vec<uint32_t>{1, 1, 3, 4});
    AddInputOperand(model, hidl_vec<uint32_t>{4});
    AddOutputOperand(model, hidl_vec<uint32_t>{1, 1, 3, 4});

    // fully connected
    AddInputOperand(model, hidl_vec<uint32_t>{1, 3});
    AddTensorOperand(model, hidl_vec<uint32_t>{1, 3}, weightValue);
    AddTensorOperand(model, hidl_vec<uint32_t>{1}, biasValue);
    AddIntOperand(model, actValue);
    AddOutputOperand(model, hidl_vec<uint32_t>{1, 1});

    // broadcast mul is unsupported
    AddOutputOperand(model, hidl_vec<uint32_t>{1, 1, 3, 4});

    model.operations.resize(3);

    // unsupported
    model.operations[0].type = V1_0::OperationType::ADD;
    model.operations[0].inputs = hidl_vec<uint32_t>{0,1};
    model.operations[0].outputs = hidl_vec<uint32_t>{2};

    // supported
    model.operations[1].type = V1_0::OperationType::FULLY_CONNECTED;
    model.operations[1].inputs  = hidl_vec<uint32_t>{3, 4, 5, 6};
    model.operations[1].outputs = hidl_vec<uint32_t>{7};

    // unsupported
    model.operations[2].type = V1_0::OperationType::MUL;
    model.operations[2].inputs = hidl_vec<uint32_t>{0,1};
    model.operations[2].outputs = hidl_vec<uint32_t>{8};

    // we are testing that the unsupported layers return false and the test continues
    //      rather than failing and stopping.
    driver->getSupportedOperations(model, cb);
    BOOST_TEST((int)error == (int)ErrorStatus::NONE);
    BOOST_TEST(sup[0] == false);
    BOOST_TEST(sup[1] == true);
    BOOST_TEST(sup[2] == false);
}

// The purpose of this test is to ensure that when encountering an failure
//      during mem pool mapping we properly report an error to the framework via a callback
BOOST_AUTO_TEST_CASE(ModelToINetworkConverterMemPoolFail)
{
    auto driver = std::make_unique<ArmnnDriver>(armnn::Compute::CpuRef);

    ErrorStatus error;
    std::vector<bool> sup;

    ArmnnDriver::getSupportedOperations_cb cb = [&](ErrorStatus status, const std::vector<bool>& supported)
    {
        error = status;
        sup = supported;
    };

    V1_0::Model model = {};

    model.pools = hidl_vec<hidl_memory>{hidl_memory("Unsuported hidl memory type", nullptr, 0)};

    //memory pool mapping should fail, we should report an error
    driver->getSupportedOperations(model, cb);
    BOOST_TEST((int)error == (int)ErrorStatus::GENERAL_FAILURE);
}

BOOST_AUTO_TEST_SUITE_END()