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