aboutsummaryrefslogtreecommitdiff
path: root/test/1.2/Capabilities.cpp
blob: aa0c6423b1e1f21be1a257e66abae23f5c420dde (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
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "../../1.2/ArmnnDriverImpl.hpp"

#include "Utils.h"

#include <armnn/utility/Assert.hpp>

// Un-define some of the macros as they clash in 'third-party/doctest/doctest.h'
// and 'system/core/base/include/android-base/logging.h'
// macro redefined error[-Werror,-Wmacro-redefined]
#ifdef CHECK
#undef CHECK
#endif
#ifdef CHECK_EQ
#undef CHECK_EQ
#endif
#ifdef CHECK_NE
#undef CHECK_NE
#endif
#ifdef CHECK_GT
#undef CHECK_GT
#endif
#ifdef CHECK_LT
#undef CHECK_LT
#endif
#ifdef CHECK_GE
#undef CHECK_GE
#endif
#ifdef CHECK_LE
#undef CHECK_LE
#endif
#include <doctest/doctest.h>

#include <sys/system_properties.h>

#include <cfloat>

using namespace std;

struct CapabilitiesFixture
{
    CapabilitiesFixture()
    {
        // CleanUp before the execution of each test
        CleanUp();
    }

    ~CapabilitiesFixture()
    {
        // CleanUp after the execution of each test
        CleanUp();
    }

    void CleanUp()
    {
        const char* nullStr = "";

        __system_property_set("Armnn.operandTypeTensorFloat32Performance.execTime", nullStr);
        __system_property_set("Armnn.operandTypeTensorFloat32Performance.powerUsage", nullStr);
        __system_property_set("Armnn.operandTypeFloat32Performance.execTime", nullStr);
        __system_property_set("Armnn.operandTypeFloat32Performance.powerUsage", nullStr);
        __system_property_set("Armnn.operandTypeTensorFloat16Performance.execTime", nullStr);
        __system_property_set("Armnn.operandTypeTensorFloat16Performance.powerUsage", nullStr);
        __system_property_set("Armnn.operandTypeFloat16Performance.execTime", nullStr);
        __system_property_set("Armnn.operandTypeFloat16Performance.powerUsage", nullStr);
        __system_property_set("Armnn.operandTypeTensorQuant8AsymmPerformance.execTime", nullStr);
        __system_property_set("Armnn.operandTypeTensorQuant8AsymmPerformance.powerUsage", nullStr);
        __system_property_set("Armnn.operandTypeTensorQuant16SymmPerformance.execTime", nullStr);
        __system_property_set("Armnn.operandTypeTensorQuant16SymmPerformance.powerUsage", nullStr);
        __system_property_set("Armnn.operandTypeTensorInt32Performance.execTime", nullStr);
        __system_property_set("Armnn.operandTypeTensorInt32Performance.powerUsage", nullStr);
        __system_property_set("Armnn.operandTypeInt32Performance.execTime", nullStr);
        __system_property_set("Armnn.operandTypeInt32Performance.powerUsage", nullStr);
        __system_property_set("Armnn.operandTypeTensorQuant8SymmPerformance.execTime", nullStr);
        __system_property_set("Armnn.operandTypeTensorQuant8SymmPerformance.powerUsage", nullStr);
        __system_property_set("Armnn.operandTypeTensorQuant8SymmPerChannelPerformance.execTime", nullStr);
        __system_property_set("Armnn.operandTypeTensorQuant8SymmPerChannelPerformance.powerUsage", nullStr);
    }
};

void CheckOperandType(const V1_2::Capabilities& capabilities, V1_2::OperandType type, float execTime, float powerUsage)
{
    using namespace armnn_driver::hal_1_2;
    V1_0::PerformanceInfo perfInfo = android::nn::lookup(capabilities.operandPerformance, type);
    ARMNN_ASSERT(perfInfo.execTime == execTime);
    ARMNN_ASSERT(perfInfo.powerUsage == powerUsage);
}

TEST_SUITE("CapabilitiesTests")
{
TEST_CASE_FIXTURE(CapabilitiesFixture, "PerformanceCapabilitiesWithRuntime")
{
    using namespace armnn_driver::hal_1_2;
    using namespace android::nn;

    auto getCapabilitiesFn = [&](V1_0::ErrorStatus error, const V1_2::Capabilities& capabilities)
        {
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_FLOAT32, 2.0f, 2.1f);
            CheckOperandType(capabilities, V1_2::OperandType::FLOAT32, 2.2f, 2.3f);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_FLOAT16, 2.4f, 2.5f);
            CheckOperandType(capabilities, V1_2::OperandType::FLOAT16, 2.6f, 2.7f);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_ASYMM, 2.8f, 2.9f);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT16_SYMM, 3.0f, 3.1f);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_INT32, 3.2f, 3.3f);
            CheckOperandType(capabilities, V1_2::OperandType::INT32, 3.4f, 3.5f);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_SYMM, 2.8f, 2.9f);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL, 2.8f, 2.9f);

            // Unsupported operands take FLT_MAX value
            CheckOperandType(capabilities, V1_2::OperandType::UINT32, FLT_MAX, FLT_MAX);
            CheckOperandType(capabilities, V1_2::OperandType::BOOL, FLT_MAX, FLT_MAX);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT16_ASYMM, FLT_MAX, FLT_MAX);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_BOOL8, FLT_MAX, FLT_MAX);
            CheckOperandType(capabilities, V1_2::OperandType::OEM, FLT_MAX, FLT_MAX);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_OEM_BYTE, FLT_MAX, FLT_MAX);

            ARMNN_ASSERT(error == V1_0::ErrorStatus::NONE);
        };

    __system_property_set("Armnn.operandTypeTensorFloat32Performance.execTime", "2.0f");
    __system_property_set("Armnn.operandTypeTensorFloat32Performance.powerUsage", "2.1f");
    __system_property_set("Armnn.operandTypeFloat32Performance.execTime", "2.2f");
    __system_property_set("Armnn.operandTypeFloat32Performance.powerUsage", "2.3f");
    __system_property_set("Armnn.operandTypeTensorFloat16Performance.execTime", "2.4f");
    __system_property_set("Armnn.operandTypeTensorFloat16Performance.powerUsage", "2.5f");
    __system_property_set("Armnn.operandTypeFloat16Performance.execTime", "2.6f");
    __system_property_set("Armnn.operandTypeFloat16Performance.powerUsage", "2.7f");
    __system_property_set("Armnn.operandTypeTensorQuant8AsymmPerformance.execTime", "2.8f");
    __system_property_set("Armnn.operandTypeTensorQuant8AsymmPerformance.powerUsage", "2.9f");
    __system_property_set("Armnn.operandTypeTensorQuant16SymmPerformance.execTime", "3.0f");
    __system_property_set("Armnn.operandTypeTensorQuant16SymmPerformance.powerUsage", "3.1f");
    __system_property_set("Armnn.operandTypeTensorInt32Performance.execTime", "3.2f");
    __system_property_set("Armnn.operandTypeTensorInt32Performance.powerUsage", "3.3f");
    __system_property_set("Armnn.operandTypeInt32Performance.execTime", "3.4f");
    __system_property_set("Armnn.operandTypeInt32Performance.powerUsage", "3.5f");
    __system_property_set("Armnn.operandTypeTensorQuant8SymmPerformance.execTime", "2.8f");
    __system_property_set("Armnn.operandTypeTensorQuant8SymmPerformance.powerUsage", "2.9f");
    __system_property_set("Armnn.operandTypeTensorQuant8SymmPerChannelPerformance.execTime", "2.8f");
    __system_property_set("Armnn.operandTypeTensorQuant8SymmPerChannelPerformance.powerUsage", "2.9f");

    armnn::IRuntime::CreationOptions options;
    armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));

    ArmnnDriverImpl::getCapabilities_1_2(runtime, getCapabilitiesFn);
}

TEST_CASE_FIXTURE(CapabilitiesFixture, "PerformanceCapabilitiesUndefined")
{
    using namespace armnn_driver::hal_1_2;
    using namespace android::nn;

    float defaultValue = .1f;

    auto getCapabilitiesFn = [&](V1_0::ErrorStatus error, const V1_2::Capabilities& capabilities)
        {
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_FLOAT32, defaultValue, defaultValue);
            CheckOperandType(capabilities, V1_2::OperandType::FLOAT32, defaultValue, defaultValue);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_FLOAT16, defaultValue, defaultValue);
            CheckOperandType(capabilities, V1_2::OperandType::FLOAT16, defaultValue, defaultValue);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_ASYMM, defaultValue, defaultValue);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT16_SYMM, defaultValue, defaultValue);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_INT32, defaultValue, defaultValue);
            CheckOperandType(capabilities, V1_2::OperandType::INT32, defaultValue, defaultValue);
            CheckOperandType(capabilities,
                             V1_2::OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL,
                             defaultValue,
                             defaultValue);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_SYMM, defaultValue, defaultValue);

            // Unsupported operands take FLT_MAX value
            CheckOperandType(capabilities, V1_2::OperandType::UINT32, FLT_MAX, FLT_MAX);
            CheckOperandType(capabilities, V1_2::OperandType::BOOL, FLT_MAX, FLT_MAX);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT16_ASYMM, FLT_MAX, FLT_MAX);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_BOOL8, FLT_MAX, FLT_MAX);
            CheckOperandType(capabilities, V1_2::OperandType::OEM, FLT_MAX, FLT_MAX);
            CheckOperandType(capabilities, V1_2::OperandType::TENSOR_OEM_BYTE, FLT_MAX, FLT_MAX);

            ARMNN_ASSERT(error == V1_0::ErrorStatus::NONE);
        };

    armnn::IRuntime::CreationOptions options;
    armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));

    ArmnnDriverImpl::getCapabilities_1_2(runtime, getCapabilitiesFn);
}

}