Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "../../1.2/ArmnnDriverImpl.hpp" |
| 7 | |
| 8 | #include "Utils.h" |
| 9 | |
Narumol Prangnawarat | 4d07e5e | 2020-04-06 16:46:21 +0100 | [diff] [blame] | 10 | #include <armnn/utility/Assert.hpp> |
| 11 | |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 12 | #include <boost/test/unit_test.hpp> |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 13 | |
| 14 | #include <sys/system_properties.h> |
| 15 | |
| 16 | #include <cfloat> |
| 17 | |
| 18 | using namespace std; |
| 19 | |
| 20 | struct CapabilitiesFixture |
| 21 | { |
| 22 | CapabilitiesFixture() |
| 23 | { |
Ferran Balaguer | 3892a36 | 2019-07-25 13:47:52 +0100 | [diff] [blame] | 24 | // CleanUp before the execution of each test |
| 25 | CleanUp(); |
| 26 | } |
| 27 | |
| 28 | ~CapabilitiesFixture() |
| 29 | { |
| 30 | // CleanUp after the execution of each test |
| 31 | CleanUp(); |
| 32 | } |
| 33 | |
| 34 | void CleanUp() |
| 35 | { |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 36 | const char* nullStr = ""; |
| 37 | |
| 38 | __system_property_set("Armnn.operandTypeTensorFloat32Performance.execTime", nullStr); |
| 39 | __system_property_set("Armnn.operandTypeTensorFloat32Performance.powerUsage", nullStr); |
| 40 | __system_property_set("Armnn.operandTypeFloat32Performance.execTime", nullStr); |
| 41 | __system_property_set("Armnn.operandTypeFloat32Performance.powerUsage", nullStr); |
| 42 | __system_property_set("Armnn.operandTypeTensorFloat16Performance.execTime", nullStr); |
| 43 | __system_property_set("Armnn.operandTypeTensorFloat16Performance.powerUsage", nullStr); |
| 44 | __system_property_set("Armnn.operandTypeFloat16Performance.execTime", nullStr); |
| 45 | __system_property_set("Armnn.operandTypeFloat16Performance.powerUsage", nullStr); |
| 46 | __system_property_set("Armnn.operandTypeTensorQuant8AsymmPerformance.execTime", nullStr); |
| 47 | __system_property_set("Armnn.operandTypeTensorQuant8AsymmPerformance.powerUsage", nullStr); |
| 48 | __system_property_set("Armnn.operandTypeTensorQuant16SymmPerformance.execTime", nullStr); |
| 49 | __system_property_set("Armnn.operandTypeTensorQuant16SymmPerformance.powerUsage", nullStr); |
| 50 | __system_property_set("Armnn.operandTypeTensorInt32Performance.execTime", nullStr); |
| 51 | __system_property_set("Armnn.operandTypeTensorInt32Performance.powerUsage", nullStr); |
| 52 | __system_property_set("Armnn.operandTypeInt32Performance.execTime", nullStr); |
| 53 | __system_property_set("Armnn.operandTypeInt32Performance.powerUsage", nullStr); |
Kevin May | 87cb761 | 2019-11-11 17:30:35 +0000 | [diff] [blame] | 54 | __system_property_set("Armnn.operandTypeTensorQuant8SymmPerformance.execTime", nullStr); |
| 55 | __system_property_set("Armnn.operandTypeTensorQuant8SymmPerformance.powerUsage", nullStr); |
| 56 | __system_property_set("Armnn.operandTypeTensorQuant8SymmPerChannelPerformance.execTime", nullStr); |
| 57 | __system_property_set("Armnn.operandTypeTensorQuant8SymmPerChannelPerformance.powerUsage", nullStr); |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 58 | } |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 59 | }; |
| 60 | |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 61 | void CheckOperandType(const V1_2::Capabilities& capabilities, V1_2::OperandType type, float execTime, float powerUsage) |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 62 | { |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 63 | using namespace armnn_driver::hal_1_2; |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 64 | PerformanceInfo perfInfo = android::nn::lookup(capabilities.operandPerformance, type); |
Narumol Prangnawarat | 4d07e5e | 2020-04-06 16:46:21 +0100 | [diff] [blame] | 65 | ARMNN_ASSERT(perfInfo.execTime == execTime); |
| 66 | ARMNN_ASSERT(perfInfo.powerUsage == powerUsage); |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Ferran Balaguer | 3892a36 | 2019-07-25 13:47:52 +0100 | [diff] [blame] | 69 | BOOST_FIXTURE_TEST_SUITE(CapabilitiesTests, CapabilitiesFixture) |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 70 | |
| 71 | BOOST_AUTO_TEST_CASE(PerformanceCapabilitiesWithRuntime) |
| 72 | { |
| 73 | using namespace armnn_driver::hal_1_2; |
| 74 | using namespace android::nn; |
| 75 | |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 76 | auto getCapabilitiesFn = [&](V1_0::ErrorStatus error, const V1_2::Capabilities& capabilities) |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 77 | { |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 78 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_FLOAT32, 2.0f, 2.1f); |
| 79 | CheckOperandType(capabilities, V1_2::OperandType::FLOAT32, 2.2f, 2.3f); |
| 80 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_FLOAT16, 2.4f, 2.5f); |
| 81 | CheckOperandType(capabilities, V1_2::OperandType::FLOAT16, 2.6f, 2.7f); |
| 82 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_ASYMM, 2.8f, 2.9f); |
| 83 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT16_SYMM, 3.0f, 3.1f); |
| 84 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_INT32, 3.2f, 3.3f); |
| 85 | CheckOperandType(capabilities, V1_2::OperandType::INT32, 3.4f, 3.5f); |
| 86 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_SYMM, 2.8f, 2.9f); |
| 87 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL, 2.8f, 2.9f); |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 88 | |
| 89 | // Unsupported operands take FLT_MAX value |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 90 | CheckOperandType(capabilities, V1_2::OperandType::UINT32, FLT_MAX, FLT_MAX); |
| 91 | CheckOperandType(capabilities, V1_2::OperandType::BOOL, FLT_MAX, FLT_MAX); |
| 92 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT16_ASYMM, FLT_MAX, FLT_MAX); |
| 93 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_BOOL8, FLT_MAX, FLT_MAX); |
| 94 | CheckOperandType(capabilities, V1_2::OperandType::OEM, FLT_MAX, FLT_MAX); |
| 95 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_OEM_BYTE, FLT_MAX, FLT_MAX); |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 96 | |
Narumol Prangnawarat | 4d07e5e | 2020-04-06 16:46:21 +0100 | [diff] [blame] | 97 | ARMNN_ASSERT(error == V1_0::ErrorStatus::NONE); |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | __system_property_set("Armnn.operandTypeTensorFloat32Performance.execTime", "2.0f"); |
| 101 | __system_property_set("Armnn.operandTypeTensorFloat32Performance.powerUsage", "2.1f"); |
| 102 | __system_property_set("Armnn.operandTypeFloat32Performance.execTime", "2.2f"); |
| 103 | __system_property_set("Armnn.operandTypeFloat32Performance.powerUsage", "2.3f"); |
| 104 | __system_property_set("Armnn.operandTypeTensorFloat16Performance.execTime", "2.4f"); |
| 105 | __system_property_set("Armnn.operandTypeTensorFloat16Performance.powerUsage", "2.5f"); |
| 106 | __system_property_set("Armnn.operandTypeFloat16Performance.execTime", "2.6f"); |
| 107 | __system_property_set("Armnn.operandTypeFloat16Performance.powerUsage", "2.7f"); |
| 108 | __system_property_set("Armnn.operandTypeTensorQuant8AsymmPerformance.execTime", "2.8f"); |
| 109 | __system_property_set("Armnn.operandTypeTensorQuant8AsymmPerformance.powerUsage", "2.9f"); |
| 110 | __system_property_set("Armnn.operandTypeTensorQuant16SymmPerformance.execTime", "3.0f"); |
| 111 | __system_property_set("Armnn.operandTypeTensorQuant16SymmPerformance.powerUsage", "3.1f"); |
| 112 | __system_property_set("Armnn.operandTypeTensorInt32Performance.execTime", "3.2f"); |
| 113 | __system_property_set("Armnn.operandTypeTensorInt32Performance.powerUsage", "3.3f"); |
| 114 | __system_property_set("Armnn.operandTypeInt32Performance.execTime", "3.4f"); |
| 115 | __system_property_set("Armnn.operandTypeInt32Performance.powerUsage", "3.5f"); |
Kevin May | 87cb761 | 2019-11-11 17:30:35 +0000 | [diff] [blame] | 116 | __system_property_set("Armnn.operandTypeTensorQuant8SymmPerformance.execTime", "2.8f"); |
| 117 | __system_property_set("Armnn.operandTypeTensorQuant8SymmPerformance.powerUsage", "2.9f"); |
| 118 | __system_property_set("Armnn.operandTypeTensorQuant8SymmPerChannelPerformance.execTime", "2.8f"); |
| 119 | __system_property_set("Armnn.operandTypeTensorQuant8SymmPerChannelPerformance.powerUsage", "2.9f"); |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 120 | |
| 121 | armnn::IRuntime::CreationOptions options; |
| 122 | armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); |
| 123 | |
| 124 | ArmnnDriverImpl::getCapabilities_1_2(runtime, getCapabilitiesFn); |
| 125 | } |
| 126 | |
| 127 | BOOST_AUTO_TEST_CASE(PerformanceCapabilitiesUndefined) |
| 128 | { |
| 129 | using namespace armnn_driver::hal_1_2; |
| 130 | using namespace android::nn; |
| 131 | |
| 132 | float defaultValue = .1f; |
| 133 | |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 134 | auto getCapabilitiesFn = [&](V1_0::ErrorStatus error, const V1_2::Capabilities& capabilities) |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 135 | { |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 136 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_FLOAT32, defaultValue, defaultValue); |
| 137 | CheckOperandType(capabilities, V1_2::OperandType::FLOAT32, defaultValue, defaultValue); |
| 138 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_FLOAT16, defaultValue, defaultValue); |
| 139 | CheckOperandType(capabilities, V1_2::OperandType::FLOAT16, defaultValue, defaultValue); |
| 140 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_ASYMM, defaultValue, defaultValue); |
| 141 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT16_SYMM, defaultValue, defaultValue); |
| 142 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_INT32, defaultValue, defaultValue); |
| 143 | CheckOperandType(capabilities, V1_2::OperandType::INT32, defaultValue, defaultValue); |
| 144 | CheckOperandType(capabilities, |
| 145 | V1_2::OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL, |
| 146 | defaultValue, |
| 147 | defaultValue); |
| 148 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_SYMM, defaultValue, defaultValue); |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 149 | |
| 150 | // Unsupported operands take FLT_MAX value |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 151 | CheckOperandType(capabilities, V1_2::OperandType::UINT32, FLT_MAX, FLT_MAX); |
| 152 | CheckOperandType(capabilities, V1_2::OperandType::BOOL, FLT_MAX, FLT_MAX); |
| 153 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT16_ASYMM, FLT_MAX, FLT_MAX); |
| 154 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_BOOL8, FLT_MAX, FLT_MAX); |
| 155 | CheckOperandType(capabilities, V1_2::OperandType::OEM, FLT_MAX, FLT_MAX); |
| 156 | CheckOperandType(capabilities, V1_2::OperandType::TENSOR_OEM_BYTE, FLT_MAX, FLT_MAX); |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 157 | |
Narumol Prangnawarat | 4d07e5e | 2020-04-06 16:46:21 +0100 | [diff] [blame] | 158 | ARMNN_ASSERT(error == V1_0::ErrorStatus::NONE); |
Ferran Balaguer | d7c8eb9 | 2019-07-01 13:37:44 +0100 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | armnn::IRuntime::CreationOptions options; |
| 162 | armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); |
| 163 | |
| 164 | ArmnnDriverImpl::getCapabilities_1_2(runtime, getCapabilitiesFn); |
| 165 | } |
| 166 | |
| 167 | BOOST_AUTO_TEST_SUITE_END() |