blob: 41d5ee5342186a51e31ffecda9045b7b8cbe005f [file] [log] [blame]
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +01001//
Mike Kellye2d611e2021-10-14 12:35:58 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +01003// SPDX-License-Identifier: MIT
4//
5
Mike Kellye2d611e2021-10-14 12:35:58 +01006#include "../DriverTestHelpers.hpp"
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +01007#include "Utils.h"
8
Mike Kellye2d611e2021-10-14 12:35:58 +01009#include <1.2/ArmnnDriverImpl.hpp>
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +010010
11#include <sys/system_properties.h>
12
13#include <cfloat>
14
15using namespace std;
16
17struct CapabilitiesFixture
18{
19 CapabilitiesFixture()
20 {
Ferran Balaguer3892a362019-07-25 13:47:52 +010021 // CleanUp before the execution of each test
22 CleanUp();
23 }
24
25 ~CapabilitiesFixture()
26 {
27 // CleanUp after the execution of each test
28 CleanUp();
29 }
30
31 void CleanUp()
32 {
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +010033 const char* nullStr = "";
34
35 __system_property_set("Armnn.operandTypeTensorFloat32Performance.execTime", nullStr);
36 __system_property_set("Armnn.operandTypeTensorFloat32Performance.powerUsage", nullStr);
37 __system_property_set("Armnn.operandTypeFloat32Performance.execTime", nullStr);
38 __system_property_set("Armnn.operandTypeFloat32Performance.powerUsage", nullStr);
39 __system_property_set("Armnn.operandTypeTensorFloat16Performance.execTime", nullStr);
40 __system_property_set("Armnn.operandTypeTensorFloat16Performance.powerUsage", nullStr);
41 __system_property_set("Armnn.operandTypeFloat16Performance.execTime", nullStr);
42 __system_property_set("Armnn.operandTypeFloat16Performance.powerUsage", nullStr);
43 __system_property_set("Armnn.operandTypeTensorQuant8AsymmPerformance.execTime", nullStr);
44 __system_property_set("Armnn.operandTypeTensorQuant8AsymmPerformance.powerUsage", nullStr);
45 __system_property_set("Armnn.operandTypeTensorQuant16SymmPerformance.execTime", nullStr);
46 __system_property_set("Armnn.operandTypeTensorQuant16SymmPerformance.powerUsage", nullStr);
47 __system_property_set("Armnn.operandTypeTensorInt32Performance.execTime", nullStr);
48 __system_property_set("Armnn.operandTypeTensorInt32Performance.powerUsage", nullStr);
49 __system_property_set("Armnn.operandTypeInt32Performance.execTime", nullStr);
50 __system_property_set("Armnn.operandTypeInt32Performance.powerUsage", nullStr);
Kevin May87cb7612019-11-11 17:30:35 +000051 __system_property_set("Armnn.operandTypeTensorQuant8SymmPerformance.execTime", nullStr);
52 __system_property_set("Armnn.operandTypeTensorQuant8SymmPerformance.powerUsage", nullStr);
53 __system_property_set("Armnn.operandTypeTensorQuant8SymmPerChannelPerformance.execTime", nullStr);
54 __system_property_set("Armnn.operandTypeTensorQuant8SymmPerChannelPerformance.powerUsage", nullStr);
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +010055 }
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +010056};
57
Kevin Mayec1e5b82020-02-26 17:00:39 +000058void CheckOperandType(const V1_2::Capabilities& capabilities, V1_2::OperandType type, float execTime, float powerUsage)
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +010059{
Kevin Mayec1e5b82020-02-26 17:00:39 +000060 using namespace armnn_driver::hal_1_2;
Sadik Armagan188675f2021-02-12 17:16:42 +000061 V1_0::PerformanceInfo perfInfo = android::nn::lookup(capabilities.operandPerformance, type);
Mike Kellye2d611e2021-10-14 12:35:58 +010062 DOCTEST_CHECK(perfInfo.execTime == execTime);
63 DOCTEST_CHECK(perfInfo.powerUsage == powerUsage);
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +010064}
65
Mike Kellye2d611e2021-10-14 12:35:58 +010066DOCTEST_TEST_SUITE("CapabilitiesTests")
Sadik Armagan9150bff2021-05-26 15:40:53 +010067{
Mike Kellye2d611e2021-10-14 12:35:58 +010068DOCTEST_TEST_CASE_FIXTURE(CapabilitiesFixture, "PerformanceCapabilitiesWithRuntime")
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +010069{
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +010070 using namespace android::nn;
71
Kevin Mayec1e5b82020-02-26 17:00:39 +000072 auto getCapabilitiesFn = [&](V1_0::ErrorStatus error, const V1_2::Capabilities& capabilities)
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +010073 {
Kevin Mayec1e5b82020-02-26 17:00:39 +000074 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_FLOAT32, 2.0f, 2.1f);
75 CheckOperandType(capabilities, V1_2::OperandType::FLOAT32, 2.2f, 2.3f);
76 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_FLOAT16, 2.4f, 2.5f);
77 CheckOperandType(capabilities, V1_2::OperandType::FLOAT16, 2.6f, 2.7f);
78 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_ASYMM, 2.8f, 2.9f);
79 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT16_SYMM, 3.0f, 3.1f);
80 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_INT32, 3.2f, 3.3f);
81 CheckOperandType(capabilities, V1_2::OperandType::INT32, 3.4f, 3.5f);
82 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_SYMM, 2.8f, 2.9f);
83 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL, 2.8f, 2.9f);
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +010084
85 // Unsupported operands take FLT_MAX value
Kevin Mayec1e5b82020-02-26 17:00:39 +000086 CheckOperandType(capabilities, V1_2::OperandType::UINT32, FLT_MAX, FLT_MAX);
87 CheckOperandType(capabilities, V1_2::OperandType::BOOL, FLT_MAX, FLT_MAX);
88 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT16_ASYMM, FLT_MAX, FLT_MAX);
89 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_BOOL8, FLT_MAX, FLT_MAX);
90 CheckOperandType(capabilities, V1_2::OperandType::OEM, FLT_MAX, FLT_MAX);
91 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_OEM_BYTE, FLT_MAX, FLT_MAX);
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +010092
Mike Kellye2d611e2021-10-14 12:35:58 +010093 bool result = (error == V1_0::ErrorStatus::NONE);
94 DOCTEST_CHECK(result);
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +010095 };
96
97 __system_property_set("Armnn.operandTypeTensorFloat32Performance.execTime", "2.0f");
98 __system_property_set("Armnn.operandTypeTensorFloat32Performance.powerUsage", "2.1f");
99 __system_property_set("Armnn.operandTypeFloat32Performance.execTime", "2.2f");
100 __system_property_set("Armnn.operandTypeFloat32Performance.powerUsage", "2.3f");
101 __system_property_set("Armnn.operandTypeTensorFloat16Performance.execTime", "2.4f");
102 __system_property_set("Armnn.operandTypeTensorFloat16Performance.powerUsage", "2.5f");
103 __system_property_set("Armnn.operandTypeFloat16Performance.execTime", "2.6f");
104 __system_property_set("Armnn.operandTypeFloat16Performance.powerUsage", "2.7f");
105 __system_property_set("Armnn.operandTypeTensorQuant8AsymmPerformance.execTime", "2.8f");
106 __system_property_set("Armnn.operandTypeTensorQuant8AsymmPerformance.powerUsage", "2.9f");
107 __system_property_set("Armnn.operandTypeTensorQuant16SymmPerformance.execTime", "3.0f");
108 __system_property_set("Armnn.operandTypeTensorQuant16SymmPerformance.powerUsage", "3.1f");
109 __system_property_set("Armnn.operandTypeTensorInt32Performance.execTime", "3.2f");
110 __system_property_set("Armnn.operandTypeTensorInt32Performance.powerUsage", "3.3f");
111 __system_property_set("Armnn.operandTypeInt32Performance.execTime", "3.4f");
112 __system_property_set("Armnn.operandTypeInt32Performance.powerUsage", "3.5f");
Kevin May87cb7612019-11-11 17:30:35 +0000113 __system_property_set("Armnn.operandTypeTensorQuant8SymmPerformance.execTime", "2.8f");
114 __system_property_set("Armnn.operandTypeTensorQuant8SymmPerformance.powerUsage", "2.9f");
115 __system_property_set("Armnn.operandTypeTensorQuant8SymmPerChannelPerformance.execTime", "2.8f");
116 __system_property_set("Armnn.operandTypeTensorQuant8SymmPerChannelPerformance.powerUsage", "2.9f");
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +0100117
118 armnn::IRuntime::CreationOptions options;
119 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
120
Mike Kellye2d611e2021-10-14 12:35:58 +0100121 armnn_driver::hal_1_2::ArmnnDriverImpl::getCapabilities_1_2(runtime, getCapabilitiesFn);
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +0100122}
123
Mike Kellye2d611e2021-10-14 12:35:58 +0100124DOCTEST_TEST_CASE_FIXTURE(CapabilitiesFixture, "PerformanceCapabilitiesUndefined")
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +0100125{
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +0100126 using namespace android::nn;
127
128 float defaultValue = .1f;
129
Kevin Mayec1e5b82020-02-26 17:00:39 +0000130 auto getCapabilitiesFn = [&](V1_0::ErrorStatus error, const V1_2::Capabilities& capabilities)
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +0100131 {
Kevin Mayec1e5b82020-02-26 17:00:39 +0000132 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_FLOAT32, defaultValue, defaultValue);
133 CheckOperandType(capabilities, V1_2::OperandType::FLOAT32, defaultValue, defaultValue);
134 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_FLOAT16, defaultValue, defaultValue);
135 CheckOperandType(capabilities, V1_2::OperandType::FLOAT16, defaultValue, defaultValue);
136 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_ASYMM, defaultValue, defaultValue);
137 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT16_SYMM, defaultValue, defaultValue);
138 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_INT32, defaultValue, defaultValue);
139 CheckOperandType(capabilities, V1_2::OperandType::INT32, defaultValue, defaultValue);
140 CheckOperandType(capabilities,
141 V1_2::OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL,
142 defaultValue,
143 defaultValue);
144 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_SYMM, defaultValue, defaultValue);
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +0100145
146 // Unsupported operands take FLT_MAX value
Kevin Mayec1e5b82020-02-26 17:00:39 +0000147 CheckOperandType(capabilities, V1_2::OperandType::UINT32, FLT_MAX, FLT_MAX);
148 CheckOperandType(capabilities, V1_2::OperandType::BOOL, FLT_MAX, FLT_MAX);
149 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT16_ASYMM, FLT_MAX, FLT_MAX);
150 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_BOOL8, FLT_MAX, FLT_MAX);
151 CheckOperandType(capabilities, V1_2::OperandType::OEM, FLT_MAX, FLT_MAX);
152 CheckOperandType(capabilities, V1_2::OperandType::TENSOR_OEM_BYTE, FLT_MAX, FLT_MAX);
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +0100153
Mike Kellye2d611e2021-10-14 12:35:58 +0100154 bool result = (error == V1_0::ErrorStatus::NONE);
155 DOCTEST_CHECK(result);
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +0100156 };
157
158 armnn::IRuntime::CreationOptions options;
159 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
160
Mike Kellye2d611e2021-10-14 12:35:58 +0100161 armnn_driver::hal_1_2::ArmnnDriverImpl::getCapabilities_1_2(runtime, getCapabilitiesFn);
Ferran Balaguerd7c8eb92019-07-01 13:37:44 +0100162}
163
Sadik Armagan9150bff2021-05-26 15:40:53 +0100164}