Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "GeneratedTestHarness.h" |
| 18 | |
| 19 | #include <android-base/logging.h> |
| 20 | #include <android/hardware/neuralnetworks/1.0/IDevice.h> |
| 21 | #include <android/hardware/neuralnetworks/1.0/IExecutionCallback.h> |
| 22 | #include <android/hardware/neuralnetworks/1.0/IPreparedModel.h> |
| 23 | #include <android/hardware/neuralnetworks/1.0/IPreparedModelCallback.h> |
| 24 | #include <android/hardware/neuralnetworks/1.0/types.h> |
| 25 | #include <android/hardware/neuralnetworks/1.1/IDevice.h> |
| 26 | #include <android/hardware/neuralnetworks/1.2/IDevice.h> |
| 27 | #include <android/hardware/neuralnetworks/1.2/IExecutionCallback.h> |
| 28 | #include <android/hardware/neuralnetworks/1.2/IPreparedModel.h> |
| 29 | #include <android/hardware/neuralnetworks/1.2/IPreparedModelCallback.h> |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 30 | #include <android/hardware/neuralnetworks/1.2/types.h> |
| 31 | #include <android/hardware/neuralnetworks/1.3/IDevice.h> |
Miao Wang | 2c4e023 | 2019-12-26 18:03:56 -0800 | [diff] [blame] | 32 | #include <android/hardware/neuralnetworks/1.3/IFencedExecutionCallback.h> |
Xusong Wang | 1b3f426 | 2019-10-25 12:07:17 -0700 | [diff] [blame] | 33 | #include <android/hardware/neuralnetworks/1.3/IPreparedModel.h> |
Xusong Wang | cc47dff | 2019-10-23 10:35:07 -0700 | [diff] [blame] | 34 | #include <android/hardware/neuralnetworks/1.3/IPreparedModelCallback.h> |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 35 | #include <android/hardware/neuralnetworks/1.3/types.h> |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 36 | #include <android/hidl/allocator/1.0/IAllocator.h> |
| 37 | #include <android/hidl/memory/1.0/IMemory.h> |
Miao Wang | 2c4e023 | 2019-12-26 18:03:56 -0800 | [diff] [blame] | 38 | #include <android/sync.h> |
Lev Proleev | 56cda83 | 2019-12-05 14:49:47 +0000 | [diff] [blame] | 39 | #include <gtest/gtest.h> |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 40 | #include <hidlmemory/mapping.h> |
| 41 | |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 42 | #include <algorithm> |
Michael Butler | 648ada5 | 2019-07-25 17:22:11 -0700 | [diff] [blame] | 43 | #include <chrono> |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 44 | #include <iostream> |
| 45 | #include <numeric> |
Lev Proleev | 56cda83 | 2019-12-05 14:49:47 +0000 | [diff] [blame] | 46 | #include <vector> |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 47 | |
| 48 | #include "1.0/Utils.h" |
Xusong Wang | cc47dff | 2019-10-23 10:35:07 -0700 | [diff] [blame] | 49 | #include "1.3/Callbacks.h" |
Michael Butler | 616701d | 2020-01-07 14:52:44 -0800 | [diff] [blame] | 50 | #include "1.3/Utils.h" |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 51 | #include "ExecutionBurstController.h" |
| 52 | #include "MemoryUtils.h" |
| 53 | #include "TestHarness.h" |
| 54 | #include "Utils.h" |
| 55 | #include "VtsHalNeuralnetworks.h" |
| 56 | |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 57 | namespace android::hardware::neuralnetworks::V1_3::vts::functional { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 58 | |
| 59 | using namespace test_helper; |
| 60 | using hidl::memory::V1_0::IMemory; |
Michael Butler | 9449a28 | 2019-12-11 19:08:08 -0800 | [diff] [blame] | 61 | using implementation::ExecutionCallback; |
Xusong Wang | cc47dff | 2019-10-23 10:35:07 -0700 | [diff] [blame] | 62 | using implementation::PreparedModelCallback; |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 63 | using V1_0::DataLocation; |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 64 | using V1_0::RequestArgument; |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 65 | using V1_1::ExecutionPreference; |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 66 | using V1_2::Constant; |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 67 | using V1_2::MeasureTiming; |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 68 | using V1_2::OutputShape; |
| 69 | using V1_2::SymmPerChannelQuantParams; |
| 70 | using V1_2::Timing; |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 71 | using HidlToken = hidl_array<uint8_t, static_cast<uint32_t>(Constant::BYTE_SIZE_OF_CACHE_TOKEN)>; |
| 72 | |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame] | 73 | namespace { |
| 74 | |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 75 | enum class OutputType { FULLY_SPECIFIED, UNSPECIFIED, INSUFFICIENT, MISSED_DEADLINE }; |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 76 | |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 77 | enum class MemoryType { SHARED, DEVICE }; |
| 78 | |
| 79 | enum class IOType { INPUT, OUTPUT }; |
| 80 | |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame] | 81 | struct TestConfig { |
| 82 | Executor executor; |
| 83 | MeasureTiming measureTiming; |
| 84 | OutputType outputType; |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 85 | MemoryType memoryType; |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 86 | // `reportSkipping` indicates if a test should print an info message in case |
| 87 | // it is skipped. The field is set to true by default and is set to false in |
| 88 | // quantization coupling tests to suppress skipping a test |
| 89 | bool reportSkipping; |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 90 | TestConfig(Executor executor, MeasureTiming measureTiming, OutputType outputType, |
| 91 | MemoryType memoryType) |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 92 | : executor(executor), |
| 93 | measureTiming(measureTiming), |
| 94 | outputType(outputType), |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 95 | memoryType(memoryType), |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 96 | reportSkipping(true) {} |
| 97 | TestConfig(Executor executor, MeasureTiming measureTiming, OutputType outputType, |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 98 | MemoryType memoryType, bool reportSkipping) |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 99 | : executor(executor), |
| 100 | measureTiming(measureTiming), |
| 101 | outputType(outputType), |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 102 | memoryType(memoryType), |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 103 | reportSkipping(reportSkipping) {} |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame] | 104 | }; |
| 105 | |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 106 | class DeviceMemoryAllocator { |
| 107 | public: |
| 108 | DeviceMemoryAllocator(const sp<IDevice>& device, const sp<IPreparedModel>& preparedModel, |
| 109 | const TestModel& testModel) |
| 110 | : kDevice(device), kPreparedModel(preparedModel), kTestModel(testModel) {} |
| 111 | |
| 112 | // Allocate device memory for a target input/output operand. |
| 113 | // Return {IBuffer object, token} if successful. |
| 114 | // Return {nullptr, 0} if device memory is not supported. |
| 115 | template <IOType ioType> |
Michael Butler | 6a4172c | 2020-02-04 16:15:04 -0800 | [diff] [blame] | 116 | std::pair<sp<IBuffer>, uint32_t> allocate(uint32_t index) { |
| 117 | std::pair<sp<IBuffer>, uint32_t> buffer; |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 118 | allocateInternal<ioType>(index, &buffer); |
| 119 | return buffer; |
| 120 | } |
| 121 | |
| 122 | private: |
| 123 | template <IOType ioType> |
Michael Butler | 6a4172c | 2020-02-04 16:15:04 -0800 | [diff] [blame] | 124 | void allocateInternal(uint32_t index, std::pair<sp<IBuffer>, uint32_t>* result) { |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 125 | ASSERT_NE(result, nullptr); |
| 126 | |
| 127 | // Prepare arguments. |
| 128 | BufferRole role = {.modelIndex = 0, .ioIndex = index, .frequency = 1.0f}; |
| 129 | hidl_vec<BufferRole> inputRoles, outputRoles; |
| 130 | if constexpr (ioType == IOType::INPUT) { |
| 131 | inputRoles = {role}; |
| 132 | } else { |
| 133 | outputRoles = {role}; |
| 134 | } |
| 135 | |
| 136 | // Allocate device memory. |
| 137 | ErrorStatus status; |
| 138 | sp<IBuffer> buffer; |
Michael Butler | 6a4172c | 2020-02-04 16:15:04 -0800 | [diff] [blame] | 139 | uint32_t token; |
| 140 | auto cb = [&status, &buffer, &token](ErrorStatus error, const sp<IBuffer>& buf, |
| 141 | uint32_t tok) { |
| 142 | status = error; |
| 143 | buffer = buf; |
| 144 | token = tok; |
| 145 | }; |
| 146 | const auto ret = kDevice->allocate({}, {kPreparedModel}, inputRoles, outputRoles, cb); |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 147 | |
| 148 | // Check allocation results. |
| 149 | ASSERT_TRUE(ret.isOk()); |
| 150 | if (status == ErrorStatus::NONE) { |
| 151 | ASSERT_NE(buffer, nullptr); |
| 152 | ASSERT_GT(token, 0); |
| 153 | } else { |
| 154 | ASSERT_EQ(status, ErrorStatus::GENERAL_FAILURE); |
| 155 | ASSERT_EQ(buffer, nullptr); |
| 156 | ASSERT_EQ(token, 0); |
| 157 | } |
| 158 | |
| 159 | // Initialize input data from TestBuffer. |
| 160 | if constexpr (ioType == IOType::INPUT) { |
| 161 | if (buffer != nullptr) { |
| 162 | // TestBuffer -> Shared memory. |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 163 | const auto& testBuffer = |
| 164 | kTestModel.main.operands[kTestModel.main.inputIndexes[index]].data; |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 165 | ASSERT_GT(testBuffer.size(), 0); |
| 166 | hidl_memory tmp = nn::allocateSharedMemory(testBuffer.size()); |
| 167 | sp<IMemory> inputMemory = mapMemory(tmp); |
| 168 | ASSERT_NE(inputMemory.get(), nullptr); |
| 169 | uint8_t* inputPtr = |
| 170 | static_cast<uint8_t*>(static_cast<void*>(inputMemory->getPointer())); |
| 171 | ASSERT_NE(inputPtr, nullptr); |
| 172 | const uint8_t* begin = testBuffer.get<uint8_t>(); |
| 173 | const uint8_t* end = begin + testBuffer.size(); |
| 174 | std::copy(begin, end, inputPtr); |
| 175 | |
| 176 | // Shared memory -> IBuffer. |
| 177 | auto ret = buffer->copyFrom(tmp, {}); |
| 178 | ASSERT_TRUE(ret.isOk()); |
| 179 | ASSERT_EQ(static_cast<ErrorStatus>(ret), ErrorStatus::NONE); |
| 180 | } |
| 181 | } |
| 182 | *result = {std::move(buffer), token}; |
| 183 | } |
| 184 | |
| 185 | const sp<IDevice> kDevice; |
| 186 | const sp<IPreparedModel> kPreparedModel; |
| 187 | const TestModel& kTestModel; |
| 188 | }; |
| 189 | |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 190 | Subgraph createSubgraph(const TestSubgraph& testSubgraph, uint32_t* constCopySize, |
| 191 | std::vector<const TestBuffer*>* constCopies, uint32_t* constRefSize, |
| 192 | std::vector<const TestBuffer*>* constReferences) { |
| 193 | CHECK(constCopySize != nullptr); |
| 194 | CHECK(constCopies != nullptr); |
| 195 | CHECK(constRefSize != nullptr); |
| 196 | CHECK(constReferences != nullptr); |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame] | 197 | |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 198 | // Operands. |
| 199 | hidl_vec<Operand> operands(testSubgraph.operands.size()); |
| 200 | for (uint32_t i = 0; i < testSubgraph.operands.size(); i++) { |
| 201 | const auto& op = testSubgraph.operands[i]; |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 202 | |
| 203 | DataLocation loc = {}; |
| 204 | if (op.lifetime == TestOperandLifeTime::CONSTANT_COPY) { |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 205 | loc = { |
| 206 | .poolIndex = 0, |
| 207 | .offset = *constCopySize, |
| 208 | .length = static_cast<uint32_t>(op.data.size()), |
| 209 | }; |
| 210 | constCopies->push_back(&op.data); |
| 211 | *constCopySize += op.data.alignedSize(); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 212 | } else if (op.lifetime == TestOperandLifeTime::CONSTANT_REFERENCE) { |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 213 | loc = { |
| 214 | .poolIndex = 0, |
| 215 | .offset = *constRefSize, |
| 216 | .length = static_cast<uint32_t>(op.data.size()), |
| 217 | }; |
| 218 | constReferences->push_back(&op.data); |
| 219 | *constRefSize += op.data.alignedSize(); |
| 220 | } else if (op.lifetime == TestOperandLifeTime::SUBGRAPH) { |
| 221 | loc = { |
| 222 | .poolIndex = 0, |
| 223 | .offset = *op.data.get<uint32_t>(), |
| 224 | .length = 0, |
| 225 | }; |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 226 | } |
| 227 | |
Michael Butler | 6a4172c | 2020-02-04 16:15:04 -0800 | [diff] [blame] | 228 | V1_2::Operand::ExtraParams extraParams; |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 229 | if (op.type == TestOperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL) { |
| 230 | extraParams.channelQuant(SymmPerChannelQuantParams{ |
| 231 | .scales = op.channelQuant.scales, .channelDim = op.channelQuant.channelDim}); |
| 232 | } |
| 233 | |
| 234 | operands[i] = {.type = static_cast<OperandType>(op.type), |
| 235 | .dimensions = op.dimensions, |
| 236 | .numberOfConsumers = op.numberOfConsumers, |
| 237 | .scale = op.scale, |
| 238 | .zeroPoint = op.zeroPoint, |
| 239 | .lifetime = static_cast<OperandLifeTime>(op.lifetime), |
| 240 | .location = loc, |
| 241 | .extraParams = std::move(extraParams)}; |
| 242 | } |
| 243 | |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 244 | // Operations. |
| 245 | hidl_vec<Operation> operations(testSubgraph.operations.size()); |
| 246 | std::transform(testSubgraph.operations.begin(), testSubgraph.operations.end(), |
| 247 | operations.begin(), [](const TestOperation& op) -> Operation { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 248 | return {.type = static_cast<OperationType>(op.type), |
| 249 | .inputs = op.inputs, |
| 250 | .outputs = op.outputs}; |
| 251 | }); |
| 252 | |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 253 | return {.operands = std::move(operands), |
| 254 | .operations = std::move(operations), |
| 255 | .inputIndexes = testSubgraph.inputIndexes, |
| 256 | .outputIndexes = testSubgraph.outputIndexes}; |
| 257 | } |
| 258 | |
| 259 | void copyTestBuffers(const std::vector<const TestBuffer*>& buffers, uint8_t* output) { |
| 260 | uint32_t offset = 0; |
| 261 | for (const TestBuffer* buffer : buffers) { |
| 262 | const uint8_t* begin = buffer->get<uint8_t>(); |
| 263 | const uint8_t* end = begin + buffer->size(); |
| 264 | std::copy(begin, end, output + offset); |
| 265 | offset += buffer->alignedSize(); |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | } // namespace |
| 270 | |
Xusong Wang | 9c41591 | 2020-03-20 14:49:54 -0700 | [diff] [blame^] | 271 | void waitForSyncFence(int syncFd) { |
| 272 | constexpr int kInfiniteTimeout = -1; |
| 273 | ASSERT_GT(syncFd, 0); |
| 274 | int r = sync_wait(syncFd, kInfiniteTimeout); |
| 275 | ASSERT_GE(r, 0); |
| 276 | } |
| 277 | |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 278 | Model createModel(const TestModel& testModel) { |
| 279 | uint32_t constCopySize = 0; |
| 280 | uint32_t constRefSize = 0; |
| 281 | std::vector<const TestBuffer*> constCopies; |
| 282 | std::vector<const TestBuffer*> constReferences; |
| 283 | |
| 284 | Subgraph mainSubgraph = createSubgraph(testModel.main, &constCopySize, &constCopies, |
| 285 | &constRefSize, &constReferences); |
| 286 | hidl_vec<Subgraph> refSubgraphs(testModel.referenced.size()); |
| 287 | std::transform(testModel.referenced.begin(), testModel.referenced.end(), refSubgraphs.begin(), |
| 288 | [&constCopySize, &constCopies, &constRefSize, |
| 289 | &constReferences](const TestSubgraph& testSubgraph) { |
| 290 | return createSubgraph(testSubgraph, &constCopySize, &constCopies, |
| 291 | &constRefSize, &constReferences); |
| 292 | }); |
| 293 | |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 294 | // Constant copies. |
| 295 | hidl_vec<uint8_t> operandValues(constCopySize); |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 296 | copyTestBuffers(constCopies, operandValues.data()); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 297 | |
| 298 | // Shared memory. |
| 299 | hidl_vec<hidl_memory> pools = {}; |
| 300 | if (constRefSize > 0) { |
| 301 | hidl_vec_push_back(&pools, nn::allocateSharedMemory(constRefSize)); |
| 302 | CHECK_NE(pools[0].size(), 0u); |
| 303 | |
| 304 | // load data |
| 305 | sp<IMemory> mappedMemory = mapMemory(pools[0]); |
| 306 | CHECK(mappedMemory.get() != nullptr); |
| 307 | uint8_t* mappedPtr = |
| 308 | reinterpret_cast<uint8_t*>(static_cast<void*>(mappedMemory->getPointer())); |
| 309 | CHECK(mappedPtr != nullptr); |
| 310 | |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 311 | copyTestBuffers(constReferences, mappedPtr); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 312 | } |
| 313 | |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 314 | return {.main = std::move(mainSubgraph), |
| 315 | .referenced = std::move(refSubgraphs), |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 316 | .operandValues = std::move(operandValues), |
| 317 | .pools = std::move(pools), |
| 318 | .relaxComputationFloat32toFloat16 = testModel.isRelaxed}; |
| 319 | } |
| 320 | |
| 321 | static bool isOutputSizeGreaterThanOne(const TestModel& testModel, uint32_t index) { |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 322 | const auto byteSize = testModel.main.operands[testModel.main.outputIndexes[index]].data.size(); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 323 | return byteSize > 1u; |
| 324 | } |
| 325 | |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 326 | static void makeOutputInsufficientSize(uint32_t outputIndex, Request* request) { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 327 | auto& length = request->outputs[outputIndex].location.length; |
| 328 | ASSERT_GT(length, 1u); |
| 329 | length -= 1u; |
| 330 | } |
| 331 | |
| 332 | static void makeOutputDimensionsUnspecified(Model* model) { |
Slava Shklyaev | a785a3f | 2019-12-13 12:24:35 +0000 | [diff] [blame] | 333 | for (auto i : model->main.outputIndexes) { |
| 334 | auto& dims = model->main.operands[i].dimensions; |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 335 | std::fill(dims.begin(), dims.end(), 0); |
| 336 | } |
| 337 | } |
| 338 | |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 339 | constexpr uint32_t kInputPoolIndex = 0; |
| 340 | constexpr uint32_t kOutputPoolIndex = 1; |
| 341 | constexpr uint32_t kDeviceMemoryBeginIndex = 2; |
| 342 | |
| 343 | static std::pair<Request, std::vector<sp<IBuffer>>> createRequest( |
| 344 | const sp<IDevice>& device, const sp<IPreparedModel>& preparedModel, |
| 345 | const TestModel& testModel, bool preferDeviceMemory) { |
| 346 | // Memory pools are organized as: |
| 347 | // - 0: Input shared memory pool |
| 348 | // - 1: Output shared memory pool |
| 349 | // - [2, 2+i): Input device memories |
| 350 | // - [2+i, 2+i+o): Output device memories |
| 351 | DeviceMemoryAllocator allocator(device, preparedModel, testModel); |
| 352 | std::vector<sp<IBuffer>> buffers; |
Michael Butler | 6a4172c | 2020-02-04 16:15:04 -0800 | [diff] [blame] | 353 | std::vector<uint32_t> tokens; |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 354 | |
| 355 | // Model inputs. |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 356 | hidl_vec<RequestArgument> inputs(testModel.main.inputIndexes.size()); |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 357 | size_t inputSize = 0; |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 358 | for (uint32_t i = 0; i < testModel.main.inputIndexes.size(); i++) { |
| 359 | const auto& op = testModel.main.operands[testModel.main.inputIndexes[i]]; |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 360 | if (op.data.size() == 0) { |
| 361 | // Omitted input. |
| 362 | inputs[i] = {.hasNoValue = true}; |
| 363 | continue; |
| 364 | } else if (preferDeviceMemory) { |
| 365 | SCOPED_TRACE("Input index = " + std::to_string(i)); |
| 366 | auto [buffer, token] = allocator.allocate<IOType::INPUT>(i); |
| 367 | if (buffer != nullptr) { |
| 368 | DataLocation loc = {.poolIndex = static_cast<uint32_t>(buffers.size() + |
| 369 | kDeviceMemoryBeginIndex)}; |
| 370 | buffers.push_back(std::move(buffer)); |
| 371 | tokens.push_back(token); |
| 372 | inputs[i] = {.hasNoValue = false, .location = loc, .dimensions = {}}; |
| 373 | continue; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | // Reserve shared memory for input. |
| 378 | DataLocation loc = {.poolIndex = kInputPoolIndex, |
| 379 | .offset = static_cast<uint32_t>(inputSize), |
| 380 | .length = static_cast<uint32_t>(op.data.size())}; |
| 381 | inputSize += op.data.alignedSize(); |
| 382 | inputs[i] = {.hasNoValue = false, .location = loc, .dimensions = {}}; |
| 383 | } |
| 384 | |
| 385 | // Model outputs. |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 386 | hidl_vec<RequestArgument> outputs(testModel.main.outputIndexes.size()); |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 387 | size_t outputSize = 0; |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 388 | for (uint32_t i = 0; i < testModel.main.outputIndexes.size(); i++) { |
| 389 | const auto& op = testModel.main.operands[testModel.main.outputIndexes[i]]; |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 390 | if (preferDeviceMemory) { |
| 391 | SCOPED_TRACE("Output index = " + std::to_string(i)); |
| 392 | auto [buffer, token] = allocator.allocate<IOType::OUTPUT>(i); |
| 393 | if (buffer != nullptr) { |
| 394 | DataLocation loc = {.poolIndex = static_cast<uint32_t>(buffers.size() + |
| 395 | kDeviceMemoryBeginIndex)}; |
| 396 | buffers.push_back(std::move(buffer)); |
| 397 | tokens.push_back(token); |
| 398 | outputs[i] = {.hasNoValue = false, .location = loc, .dimensions = {}}; |
| 399 | continue; |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | // In the case of zero-sized output, we should at least provide a one-byte buffer. |
| 404 | // This is because zero-sized tensors are only supported internally to the driver, or |
| 405 | // reported in output shapes. It is illegal for the client to pre-specify a zero-sized |
| 406 | // tensor as model output. Otherwise, we will have two semantic conflicts: |
| 407 | // - "Zero dimension" conflicts with "unspecified dimension". |
| 408 | // - "Omitted operand buffer" conflicts with "zero-sized operand buffer". |
| 409 | size_t bufferSize = std::max<size_t>(op.data.size(), 1); |
| 410 | |
| 411 | // Reserve shared memory for output. |
| 412 | DataLocation loc = {.poolIndex = kOutputPoolIndex, |
| 413 | .offset = static_cast<uint32_t>(outputSize), |
| 414 | .length = static_cast<uint32_t>(bufferSize)}; |
| 415 | outputSize += op.data.size() == 0 ? TestBuffer::kAlignment : op.data.alignedSize(); |
| 416 | outputs[i] = {.hasNoValue = false, .location = loc, .dimensions = {}}; |
| 417 | } |
| 418 | |
| 419 | // Memory pools. |
| 420 | hidl_vec<Request::MemoryPool> pools(kDeviceMemoryBeginIndex + buffers.size()); |
| 421 | pools[kInputPoolIndex].hidlMemory(nn::allocateSharedMemory(std::max<size_t>(inputSize, 1))); |
| 422 | pools[kOutputPoolIndex].hidlMemory(nn::allocateSharedMemory(std::max<size_t>(outputSize, 1))); |
| 423 | CHECK_NE(pools[kInputPoolIndex].hidlMemory().size(), 0u); |
| 424 | CHECK_NE(pools[kOutputPoolIndex].hidlMemory().size(), 0u); |
| 425 | for (uint32_t i = 0; i < buffers.size(); i++) { |
| 426 | pools[kDeviceMemoryBeginIndex + i].token(tokens[i]); |
| 427 | } |
| 428 | |
| 429 | // Copy input data to the input shared memory pool. |
| 430 | sp<IMemory> inputMemory = mapMemory(pools[kInputPoolIndex].hidlMemory()); |
| 431 | CHECK(inputMemory.get() != nullptr); |
| 432 | uint8_t* inputPtr = static_cast<uint8_t*>(static_cast<void*>(inputMemory->getPointer())); |
| 433 | CHECK(inputPtr != nullptr); |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 434 | for (uint32_t i = 0; i < testModel.main.inputIndexes.size(); i++) { |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 435 | if (!inputs[i].hasNoValue && inputs[i].location.poolIndex == kInputPoolIndex) { |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 436 | const auto& op = testModel.main.operands[testModel.main.inputIndexes[i]]; |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 437 | const uint8_t* begin = op.data.get<uint8_t>(); |
| 438 | const uint8_t* end = begin + op.data.size(); |
| 439 | std::copy(begin, end, inputPtr + inputs[i].location.offset); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | Request request = { |
| 444 | .inputs = std::move(inputs), .outputs = std::move(outputs), .pools = std::move(pools)}; |
| 445 | return {std::move(request), std::move(buffers)}; |
| 446 | } |
| 447 | |
| 448 | // Get a TestBuffer with data copied from an IBuffer object. |
| 449 | static void getBuffer(const sp<IBuffer>& buffer, size_t size, TestBuffer* testBuffer) { |
| 450 | // IBuffer -> Shared memory. |
| 451 | hidl_memory tmp = nn::allocateSharedMemory(size); |
| 452 | const auto ret = buffer->copyTo(tmp); |
| 453 | ASSERT_TRUE(ret.isOk()); |
| 454 | ASSERT_EQ(static_cast<ErrorStatus>(ret), ErrorStatus::NONE); |
| 455 | |
| 456 | // Shared memory -> TestBuffer. |
| 457 | sp<IMemory> outputMemory = mapMemory(tmp); |
| 458 | ASSERT_NE(outputMemory.get(), nullptr); |
| 459 | uint8_t* outputPtr = static_cast<uint8_t*>(static_cast<void*>(outputMemory->getPointer())); |
| 460 | ASSERT_NE(outputPtr, nullptr); |
| 461 | ASSERT_NE(testBuffer, nullptr); |
| 462 | *testBuffer = TestBuffer(size, outputPtr); |
| 463 | } |
| 464 | |
| 465 | static std::vector<TestBuffer> getOutputBuffers(const TestModel& testModel, const Request& request, |
| 466 | const std::vector<sp<IBuffer>>& buffers) { |
| 467 | sp<IMemory> outputMemory = mapMemory(request.pools[kOutputPoolIndex].hidlMemory()); |
| 468 | CHECK(outputMemory.get() != nullptr); |
| 469 | uint8_t* outputPtr = static_cast<uint8_t*>(static_cast<void*>(outputMemory->getPointer())); |
| 470 | CHECK(outputPtr != nullptr); |
| 471 | |
| 472 | // Copy out output results. |
| 473 | std::vector<TestBuffer> outputBuffers; |
| 474 | for (uint32_t i = 0; i < request.outputs.size(); i++) { |
| 475 | const auto& outputLoc = request.outputs[i].location; |
| 476 | if (outputLoc.poolIndex == kOutputPoolIndex) { |
| 477 | outputBuffers.emplace_back(outputLoc.length, outputPtr + outputLoc.offset); |
| 478 | } else { |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 479 | const auto& op = testModel.main.operands[testModel.main.outputIndexes[i]]; |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 480 | if (op.data.size() == 0) { |
| 481 | outputBuffers.emplace_back(); |
| 482 | } else { |
| 483 | SCOPED_TRACE("Output index = " + std::to_string(i)); |
| 484 | const uint32_t bufferIndex = outputLoc.poolIndex - kDeviceMemoryBeginIndex; |
| 485 | TestBuffer buffer; |
| 486 | getBuffer(buffers[bufferIndex], op.data.size(), &buffer); |
| 487 | outputBuffers.push_back(std::move(buffer)); |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | return outputBuffers; |
| 492 | } |
| 493 | |
Xusong Wang | 5882d6d | 2020-03-13 10:02:36 -0700 | [diff] [blame] | 494 | static bool hasZeroSizedOutput(const TestModel& testModel) { |
| 495 | return std::any_of(testModel.main.outputIndexes.begin(), testModel.main.outputIndexes.end(), |
| 496 | [&testModel](uint32_t index) { |
| 497 | return testModel.main.operands[index].data.size() == 0; |
| 498 | }); |
| 499 | } |
| 500 | |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 501 | static Return<ErrorStatus> ExecutePreparedModel(const sp<IPreparedModel>& preparedModel, |
| 502 | const Request& request, MeasureTiming measure, |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 503 | const OptionalTimeoutDuration& loopTimeoutDuration, |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 504 | sp<ExecutionCallback>& callback) { |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 505 | return preparedModel->execute_1_3(request, measure, {}, loopTimeoutDuration, callback); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 506 | } |
| 507 | static Return<ErrorStatus> ExecutePreparedModel(const sp<IPreparedModel>& preparedModel, |
| 508 | const Request& request, MeasureTiming measure, |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 509 | const OptionalTimeoutDuration& loopTimeoutDuration, |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 510 | hidl_vec<OutputShape>* outputShapes, |
| 511 | Timing* timing) { |
| 512 | ErrorStatus result; |
Xusong Wang | ebd88ba | 2019-10-28 11:11:19 -0700 | [diff] [blame] | 513 | Return<void> ret = preparedModel->executeSynchronously_1_3( |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 514 | request, measure, {}, loopTimeoutDuration, |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 515 | [&result, outputShapes, timing](ErrorStatus error, const hidl_vec<OutputShape>& shapes, |
| 516 | const Timing& time) { |
| 517 | result = error; |
| 518 | *outputShapes = shapes; |
| 519 | *timing = time; |
| 520 | }); |
| 521 | if (!ret.isOk()) { |
| 522 | return ErrorStatus::GENERAL_FAILURE; |
| 523 | } |
| 524 | return result; |
| 525 | } |
| 526 | static std::shared_ptr<::android::nn::ExecutionBurstController> CreateBurst( |
| 527 | const sp<IPreparedModel>& preparedModel) { |
Michael Butler | 648ada5 | 2019-07-25 17:22:11 -0700 | [diff] [blame] | 528 | return android::nn::ExecutionBurstController::create(preparedModel, |
| 529 | std::chrono::microseconds{0}); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 530 | } |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 531 | |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 532 | void EvaluatePreparedModel(const sp<IDevice>& device, const sp<IPreparedModel>& preparedModel, |
| 533 | const TestModel& testModel, const TestConfig& testConfig, |
| 534 | bool* skipped = nullptr) { |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 535 | if (skipped != nullptr) { |
| 536 | *skipped = false; |
| 537 | } |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 538 | // If output0 does not have size larger than one byte, we can not test with insufficient buffer. |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame] | 539 | if (testConfig.outputType == OutputType::INSUFFICIENT && |
| 540 | !isOutputSizeGreaterThanOne(testModel, 0)) { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 541 | return; |
| 542 | } |
| 543 | |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 544 | auto [request, buffers] = |
| 545 | createRequest(device, preparedModel, testModel, |
| 546 | /*preferDeviceMemory=*/testConfig.memoryType == MemoryType::DEVICE); |
| 547 | // Skip if testing memory domain but no device memory has been allocated. |
| 548 | if (testConfig.memoryType == MemoryType::DEVICE && buffers.empty()) { |
| 549 | return; |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 550 | } |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 551 | if (testConfig.outputType == OutputType::INSUFFICIENT) { |
| 552 | makeOutputInsufficientSize(/*outputIndex=*/0, &request); |
| 553 | } |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 554 | |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 555 | OptionalTimeoutDuration loopTimeoutDuration; |
| 556 | // OutputType::MISSED_DEADLINE is only used by |
| 557 | // TestKind::INTINITE_LOOP_TIMEOUT tests to verify that an infinite loop is |
| 558 | // aborted after a timeout. |
| 559 | if (testConfig.outputType == OutputType::MISSED_DEADLINE) { |
| 560 | // Override the default loop timeout duration with a small value to |
| 561 | // speed up test execution. |
| 562 | constexpr uint64_t kMillisecond = 1'000'000; |
| 563 | loopTimeoutDuration.nanoseconds(1 * kMillisecond); |
| 564 | } |
| 565 | |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 566 | ErrorStatus executionStatus; |
| 567 | hidl_vec<OutputShape> outputShapes; |
| 568 | Timing timing; |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame] | 569 | switch (testConfig.executor) { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 570 | case Executor::ASYNC: { |
| 571 | SCOPED_TRACE("asynchronous"); |
| 572 | |
| 573 | // launch execution |
| 574 | sp<ExecutionCallback> executionCallback = new ExecutionCallback(); |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 575 | Return<ErrorStatus> executionLaunchStatus = |
| 576 | ExecutePreparedModel(preparedModel, request, testConfig.measureTiming, |
| 577 | loopTimeoutDuration, executionCallback); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 578 | ASSERT_TRUE(executionLaunchStatus.isOk()); |
| 579 | EXPECT_EQ(ErrorStatus::NONE, static_cast<ErrorStatus>(executionLaunchStatus)); |
| 580 | |
| 581 | // retrieve execution status |
| 582 | executionCallback->wait(); |
| 583 | executionStatus = executionCallback->getStatus(); |
| 584 | outputShapes = executionCallback->getOutputShapes(); |
| 585 | timing = executionCallback->getTiming(); |
| 586 | |
| 587 | break; |
| 588 | } |
| 589 | case Executor::SYNC: { |
| 590 | SCOPED_TRACE("synchronous"); |
| 591 | |
| 592 | // execute |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 593 | Return<ErrorStatus> executionReturnStatus = |
| 594 | ExecutePreparedModel(preparedModel, request, testConfig.measureTiming, |
| 595 | loopTimeoutDuration, &outputShapes, &timing); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 596 | ASSERT_TRUE(executionReturnStatus.isOk()); |
| 597 | executionStatus = static_cast<ErrorStatus>(executionReturnStatus); |
| 598 | |
| 599 | break; |
| 600 | } |
| 601 | case Executor::BURST: { |
Xusong Wang | 931d5a1 | 2019-11-27 12:46:48 -0800 | [diff] [blame] | 602 | // TODO(butlermichael): Check if we need to test burst in V1_3 if the interface remains |
| 603 | // V1_2. |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 604 | SCOPED_TRACE("burst"); |
| 605 | |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 606 | // check compliance |
| 607 | ASSERT_TRUE(nn::compliantWithV1_0(request)); |
| 608 | V1_0::Request request10 = nn::convertToV1_0(request); |
| 609 | |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 610 | // create burst |
| 611 | const std::shared_ptr<::android::nn::ExecutionBurstController> controller = |
| 612 | CreateBurst(preparedModel); |
| 613 | ASSERT_NE(nullptr, controller.get()); |
| 614 | |
| 615 | // create memory keys |
Xusong Wang | 931d5a1 | 2019-11-27 12:46:48 -0800 | [diff] [blame] | 616 | std::vector<intptr_t> keys(request10.pools.size()); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 617 | for (size_t i = 0; i < keys.size(); ++i) { |
Xusong Wang | 931d5a1 | 2019-11-27 12:46:48 -0800 | [diff] [blame] | 618 | keys[i] = reinterpret_cast<intptr_t>(&request10.pools[i]); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | // execute burst |
Michael Butler | 648ada5 | 2019-07-25 17:22:11 -0700 | [diff] [blame] | 622 | int n; |
| 623 | std::tie(n, outputShapes, timing, std::ignore) = |
Xusong Wang | 931d5a1 | 2019-11-27 12:46:48 -0800 | [diff] [blame] | 624 | controller->compute(request10, testConfig.measureTiming, keys); |
Michael Butler | 648ada5 | 2019-07-25 17:22:11 -0700 | [diff] [blame] | 625 | executionStatus = nn::convertResultCodeToErrorStatus(n); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 626 | |
| 627 | break; |
| 628 | } |
Miao Wang | 2c4e023 | 2019-12-26 18:03:56 -0800 | [diff] [blame] | 629 | case Executor::FENCED: { |
| 630 | SCOPED_TRACE("fenced"); |
| 631 | ErrorStatus result; |
Miao Wang | 3fd70b0 | 2020-01-21 13:15:09 -0800 | [diff] [blame] | 632 | hidl_handle syncFenceHandle; |
| 633 | sp<IFencedExecutionCallback> fencedCallback; |
Miao Wang | 34dfa2f | 2020-02-25 15:54:08 -0800 | [diff] [blame] | 634 | auto callbackFunc = [&result, &syncFenceHandle, &fencedCallback]( |
| 635 | ErrorStatus error, const hidl_handle& handle, |
| 636 | const sp<IFencedExecutionCallback>& callback) { |
| 637 | result = error; |
| 638 | syncFenceHandle = handle; |
| 639 | fencedCallback = callback; |
| 640 | }; |
| 641 | Return<void> ret = |
| 642 | preparedModel->executeFenced(request, {}, testConfig.measureTiming, {}, |
| 643 | loopTimeoutDuration, {}, callbackFunc); |
Miao Wang | 2c4e023 | 2019-12-26 18:03:56 -0800 | [diff] [blame] | 644 | ASSERT_TRUE(ret.isOk()); |
| 645 | if (result != ErrorStatus::NONE) { |
Miao Wang | 3fd70b0 | 2020-01-21 13:15:09 -0800 | [diff] [blame] | 646 | ASSERT_EQ(syncFenceHandle.getNativeHandle(), nullptr); |
| 647 | ASSERT_EQ(fencedCallback, nullptr); |
Miao Wang | fa161c7 | 2020-02-25 16:57:53 -0800 | [diff] [blame] | 648 | executionStatus = result; |
Miao Wang | 3fd70b0 | 2020-01-21 13:15:09 -0800 | [diff] [blame] | 649 | } else if (syncFenceHandle.getNativeHandle()) { |
Miao Wang | 34dfa2f | 2020-02-25 15:54:08 -0800 | [diff] [blame] | 650 | // If a sync fence is returned, try start another run waiting for the sync fence. |
| 651 | ret = preparedModel->executeFenced(request, {syncFenceHandle}, |
| 652 | testConfig.measureTiming, {}, |
| 653 | loopTimeoutDuration, {}, callbackFunc); |
| 654 | ASSERT_TRUE(ret.isOk()); |
| 655 | ASSERT_EQ(result, ErrorStatus::NONE); |
Miao Wang | 3fd70b0 | 2020-01-21 13:15:09 -0800 | [diff] [blame] | 656 | waitForSyncFence(syncFenceHandle.getNativeHandle()->data[0]); |
Miao Wang | 2c4e023 | 2019-12-26 18:03:56 -0800 | [diff] [blame] | 657 | } |
| 658 | if (result == ErrorStatus::NONE) { |
Miao Wang | 3fd70b0 | 2020-01-21 13:15:09 -0800 | [diff] [blame] | 659 | ASSERT_NE(fencedCallback, nullptr); |
| 660 | Return<void> ret = fencedCallback->getExecutionInfo( |
| 661 | [&executionStatus, &timing](ErrorStatus error, Timing t, Timing) { |
Miao Wang | 2c4e023 | 2019-12-26 18:03:56 -0800 | [diff] [blame] | 662 | executionStatus = error; |
| 663 | timing = t; |
| 664 | }); |
| 665 | ASSERT_TRUE(ret.isOk()); |
| 666 | } |
| 667 | break; |
| 668 | } |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 669 | } |
| 670 | |
Miao Wang | fa161c7 | 2020-02-25 16:57:53 -0800 | [diff] [blame] | 671 | if (testConfig.outputType != OutputType::FULLY_SPECIFIED && |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 672 | executionStatus == ErrorStatus::GENERAL_FAILURE) { |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 673 | if (skipped != nullptr) { |
| 674 | *skipped = true; |
| 675 | } |
| 676 | if (!testConfig.reportSkipping) { |
| 677 | return; |
| 678 | } |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 679 | LOG(INFO) << "NN VTS: Early termination of test because vendor service cannot " |
| 680 | "execute model that it does not support."; |
| 681 | std::cout << "[ ] Early termination of test because vendor service cannot " |
| 682 | "execute model that it does not support." |
| 683 | << std::endl; |
| 684 | GTEST_SKIP(); |
| 685 | } |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame] | 686 | if (testConfig.measureTiming == MeasureTiming::NO) { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 687 | EXPECT_EQ(UINT64_MAX, timing.timeOnDevice); |
| 688 | EXPECT_EQ(UINT64_MAX, timing.timeInDriver); |
| 689 | } else { |
| 690 | if (timing.timeOnDevice != UINT64_MAX && timing.timeInDriver != UINT64_MAX) { |
| 691 | EXPECT_LE(timing.timeOnDevice, timing.timeInDriver); |
| 692 | } |
| 693 | } |
| 694 | |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame] | 695 | switch (testConfig.outputType) { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 696 | case OutputType::FULLY_SPECIFIED: |
Xusong Wang | 5882d6d | 2020-03-13 10:02:36 -0700 | [diff] [blame] | 697 | if (testConfig.executor == Executor::FENCED && hasZeroSizedOutput(testModel)) { |
| 698 | // Executor::FENCED does not support zero-sized output. |
| 699 | ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, executionStatus); |
| 700 | return; |
| 701 | } |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 702 | // If the model output operands are fully specified, outputShapes must be either |
| 703 | // either empty, or have the same number of elements as the number of outputs. |
| 704 | ASSERT_EQ(ErrorStatus::NONE, executionStatus); |
| 705 | ASSERT_TRUE(outputShapes.size() == 0 || |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 706 | outputShapes.size() == testModel.main.outputIndexes.size()); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 707 | break; |
| 708 | case OutputType::UNSPECIFIED: |
Miao Wang | fa161c7 | 2020-02-25 16:57:53 -0800 | [diff] [blame] | 709 | if (testConfig.executor == Executor::FENCED) { |
| 710 | // For Executor::FENCED, the output shape must be fully specified. |
| 711 | ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, executionStatus); |
| 712 | return; |
| 713 | } |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 714 | // If the model output operands are not fully specified, outputShapes must have |
| 715 | // the same number of elements as the number of outputs. |
| 716 | ASSERT_EQ(ErrorStatus::NONE, executionStatus); |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 717 | ASSERT_EQ(outputShapes.size(), testModel.main.outputIndexes.size()); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 718 | break; |
| 719 | case OutputType::INSUFFICIENT: |
Miao Wang | fa161c7 | 2020-02-25 16:57:53 -0800 | [diff] [blame] | 720 | if (testConfig.executor == Executor::FENCED) { |
| 721 | // For Executor::FENCED, the output shape must be fully specified. |
| 722 | ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, executionStatus); |
| 723 | return; |
| 724 | } |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 725 | ASSERT_EQ(ErrorStatus::OUTPUT_INSUFFICIENT_SIZE, executionStatus); |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 726 | ASSERT_EQ(outputShapes.size(), testModel.main.outputIndexes.size()); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 727 | ASSERT_FALSE(outputShapes[0].isSufficient); |
| 728 | return; |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 729 | case OutputType::MISSED_DEADLINE: |
| 730 | ASSERT_TRUE(executionStatus == ErrorStatus::MISSED_DEADLINE_TRANSIENT || |
| 731 | executionStatus == ErrorStatus::MISSED_DEADLINE_PERSISTENT) |
| 732 | << "executionStatus = " << executionStatus; |
| 733 | return; |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | // Go through all outputs, check returned output shapes. |
| 737 | for (uint32_t i = 0; i < outputShapes.size(); i++) { |
| 738 | EXPECT_TRUE(outputShapes[i].isSufficient); |
Slava Shklyaev | 1f98e2e | 2020-01-31 15:14:24 +0000 | [diff] [blame] | 739 | const auto& expect = testModel.main.operands[testModel.main.outputIndexes[i]].dimensions; |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 740 | const std::vector<uint32_t> actual = outputShapes[i].dimensions; |
| 741 | EXPECT_EQ(expect, actual); |
| 742 | } |
| 743 | |
| 744 | // Retrieve execution results. |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 745 | const std::vector<TestBuffer> outputs = getOutputBuffers(testModel, request, buffers); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 746 | |
| 747 | // We want "close-enough" results. |
| 748 | checkResults(testModel, outputs); |
| 749 | } |
| 750 | |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 751 | void EvaluatePreparedModel(const sp<IDevice>& device, const sp<IPreparedModel>& preparedModel, |
| 752 | const TestModel& testModel, TestKind testKind) { |
Lev Proleev | 56cda83 | 2019-12-05 14:49:47 +0000 | [diff] [blame] | 753 | std::vector<OutputType> outputTypesList; |
| 754 | std::vector<MeasureTiming> measureTimingList; |
| 755 | std::vector<Executor> executorList; |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 756 | MemoryType memoryType = MemoryType::SHARED; |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame] | 757 | |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 758 | switch (testKind) { |
| 759 | case TestKind::GENERAL: { |
| 760 | outputTypesList = {OutputType::FULLY_SPECIFIED}; |
| 761 | measureTimingList = {MeasureTiming::NO, MeasureTiming::YES}; |
Miao Wang | 33173a3 | 2020-01-23 13:53:21 -0800 | [diff] [blame] | 762 | executorList = {Executor::ASYNC, Executor::SYNC, Executor::BURST}; |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 763 | } break; |
| 764 | case TestKind::DYNAMIC_SHAPE: { |
| 765 | outputTypesList = {OutputType::UNSPECIFIED, OutputType::INSUFFICIENT}; |
| 766 | measureTimingList = {MeasureTiming::NO, MeasureTiming::YES}; |
Miao Wang | fa161c7 | 2020-02-25 16:57:53 -0800 | [diff] [blame] | 767 | executorList = {Executor::ASYNC, Executor::SYNC, Executor::BURST, Executor::FENCED}; |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 768 | } break; |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 769 | case TestKind::MEMORY_DOMAIN: { |
| 770 | outputTypesList = {OutputType::FULLY_SPECIFIED}; |
| 771 | measureTimingList = {MeasureTiming::NO}; |
Miao Wang | 34dfa2f | 2020-02-25 15:54:08 -0800 | [diff] [blame] | 772 | executorList = {Executor::ASYNC, Executor::SYNC, Executor::FENCED}; |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 773 | memoryType = MemoryType::DEVICE; |
| 774 | } break; |
Miao Wang | 33173a3 | 2020-01-23 13:53:21 -0800 | [diff] [blame] | 775 | case TestKind::FENCED_COMPUTE: { |
| 776 | outputTypesList = {OutputType::FULLY_SPECIFIED}; |
| 777 | measureTimingList = {MeasureTiming::NO, MeasureTiming::YES}; |
| 778 | executorList = {Executor::FENCED}; |
| 779 | } break; |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 780 | case TestKind::QUANTIZATION_COUPLING: { |
| 781 | LOG(FATAL) << "Wrong TestKind for EvaluatePreparedModel"; |
| 782 | return; |
| 783 | } break; |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 784 | case TestKind::INTINITE_LOOP_TIMEOUT: { |
| 785 | outputTypesList = {OutputType::MISSED_DEADLINE}; |
| 786 | measureTimingList = {MeasureTiming::NO, MeasureTiming::YES}; |
| 787 | // Burst does not support V1_3 loop timeout. |
| 788 | executorList = {Executor::ASYNC, Executor::SYNC, Executor::FENCED}; |
| 789 | } break; |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | for (const OutputType outputType : outputTypesList) { |
| 793 | for (const MeasureTiming measureTiming : measureTimingList) { |
| 794 | for (const Executor executor : executorList) { |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 795 | const TestConfig testConfig(executor, measureTiming, outputType, memoryType); |
| 796 | EvaluatePreparedModel(device, preparedModel, testModel, testConfig); |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame] | 797 | } |
| 798 | } |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 799 | } |
| 800 | } |
| 801 | |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 802 | void EvaluatePreparedCoupledModels(const sp<IDevice>& device, |
| 803 | const sp<IPreparedModel>& preparedModel, |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 804 | const TestModel& testModel, |
| 805 | const sp<IPreparedModel>& preparedCoupledModel, |
| 806 | const TestModel& coupledModel) { |
Lev Proleev | 56cda83 | 2019-12-05 14:49:47 +0000 | [diff] [blame] | 807 | const std::vector<OutputType> outputTypesList = {OutputType::FULLY_SPECIFIED}; |
| 808 | const std::vector<MeasureTiming> measureTimingList = {MeasureTiming::NO, MeasureTiming::YES}; |
Miao Wang | 2c4e023 | 2019-12-26 18:03:56 -0800 | [diff] [blame] | 809 | const std::vector<Executor> executorList = {Executor::ASYNC, Executor::SYNC, Executor::BURST, |
| 810 | Executor::FENCED}; |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 811 | |
| 812 | for (const OutputType outputType : outputTypesList) { |
| 813 | for (const MeasureTiming measureTiming : measureTimingList) { |
| 814 | for (const Executor executor : executorList) { |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 815 | const TestConfig testConfig(executor, measureTiming, outputType, MemoryType::SHARED, |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 816 | /*reportSkipping=*/false); |
| 817 | bool baseSkipped = false; |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 818 | EvaluatePreparedModel(device, preparedModel, testModel, testConfig, &baseSkipped); |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 819 | bool coupledSkipped = false; |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 820 | EvaluatePreparedModel(device, preparedCoupledModel, coupledModel, testConfig, |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 821 | &coupledSkipped); |
| 822 | ASSERT_EQ(baseSkipped, coupledSkipped); |
| 823 | if (baseSkipped) { |
| 824 | LOG(INFO) << "NN VTS: Early termination of test because vendor service cannot " |
| 825 | "execute model that it does not support."; |
| 826 | std::cout << "[ ] Early termination of test because vendor service " |
| 827 | "cannot " |
| 828 | "execute model that it does not support." |
| 829 | << std::endl; |
| 830 | GTEST_SKIP(); |
| 831 | } |
| 832 | } |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | void Execute(const sp<IDevice>& device, const TestModel& testModel, TestKind testKind) { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 838 | Model model = createModel(testModel); |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 839 | if (testKind == TestKind::DYNAMIC_SHAPE) { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 840 | makeOutputDimensionsUnspecified(&model); |
| 841 | } |
| 842 | |
| 843 | sp<IPreparedModel> preparedModel; |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 844 | switch (testKind) { |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 845 | case TestKind::GENERAL: |
| 846 | case TestKind::DYNAMIC_SHAPE: |
Miao Wang | 33173a3 | 2020-01-23 13:53:21 -0800 | [diff] [blame] | 847 | case TestKind::MEMORY_DOMAIN: |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 848 | case TestKind::FENCED_COMPUTE: |
| 849 | case TestKind::INTINITE_LOOP_TIMEOUT: { |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 850 | createPreparedModel(device, model, &preparedModel); |
| 851 | if (preparedModel == nullptr) return; |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 852 | EvaluatePreparedModel(device, preparedModel, testModel, testKind); |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 853 | } break; |
| 854 | case TestKind::QUANTIZATION_COUPLING: { |
Lev Proleev | 6a1d5e4 | 2020-01-02 18:22:30 +0000 | [diff] [blame] | 855 | ASSERT_TRUE(testModel.hasQuant8CoupledOperands()); |
Michael Butler | 616701d | 2020-01-07 14:52:44 -0800 | [diff] [blame] | 856 | createPreparedModel(device, model, &preparedModel, |
| 857 | /*reportSkipping*/ false); |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 858 | TestModel signedQuantizedModel = convertQuant8AsymmOperandsToSigned(testModel); |
| 859 | sp<IPreparedModel> preparedCoupledModel; |
| 860 | createPreparedModel(device, createModel(signedQuantizedModel), &preparedCoupledModel, |
| 861 | /*reportSkipping*/ false); |
| 862 | // If we couldn't prepare a model with unsigned quantization, we must |
| 863 | // fail to prepare a model with signed quantization as well. |
| 864 | if (preparedModel == nullptr) { |
| 865 | ASSERT_EQ(preparedCoupledModel, nullptr); |
| 866 | // If we failed to prepare both of the models, we can safely skip |
| 867 | // the test. |
| 868 | LOG(INFO) << "NN VTS: Early termination of test because vendor service cannot " |
| 869 | "prepare model that it does not support."; |
| 870 | std::cout |
| 871 | << "[ ] Early termination of test because vendor service cannot " |
| 872 | "prepare model that it does not support." |
| 873 | << std::endl; |
| 874 | GTEST_SKIP(); |
| 875 | } |
| 876 | ASSERT_NE(preparedCoupledModel, nullptr); |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 877 | EvaluatePreparedCoupledModels(device, preparedModel, testModel, preparedCoupledModel, |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 878 | signedQuantizedModel); |
| 879 | } break; |
| 880 | } |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | void GeneratedTestBase::SetUp() { |
| 884 | testing::TestWithParam<GeneratedTestParam>::SetUp(); |
| 885 | ASSERT_NE(kDevice, nullptr); |
| 886 | } |
| 887 | |
| 888 | std::vector<NamedModel> getNamedModels(const FilterFn& filter) { |
| 889 | return TestModelManager::get().getTestModels(filter); |
| 890 | } |
| 891 | |
| 892 | std::string printGeneratedTest(const testing::TestParamInfo<GeneratedTestParam>& info) { |
| 893 | const auto& [namedDevice, namedModel] = info.param; |
| 894 | return gtestCompliantName(getName(namedDevice) + "_" + getName(namedModel)); |
| 895 | } |
| 896 | |
| 897 | // Tag for the generated tests |
| 898 | class GeneratedTest : public GeneratedTestBase {}; |
| 899 | |
| 900 | // Tag for the dynamic output shape tests |
| 901 | class DynamicOutputShapeTest : public GeneratedTest {}; |
| 902 | |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 903 | // Tag for the memory domain tests |
| 904 | class MemoryDomainTest : public GeneratedTest {}; |
| 905 | |
Miao Wang | 33173a3 | 2020-01-23 13:53:21 -0800 | [diff] [blame] | 906 | // Tag for the fenced compute tests |
| 907 | class FencedComputeTest : public GeneratedTest {}; |
| 908 | |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 909 | // Tag for the dynamic output shape tests |
Lev Proleev | baac15d | 2020-01-09 16:37:28 +0000 | [diff] [blame] | 910 | class QuantizationCouplingTest : public GeneratedTest {}; |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 911 | |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 912 | // Tag for the loop timeout tests |
| 913 | class InfiniteLoopTimeoutTest : public GeneratedTest {}; |
| 914 | |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 915 | TEST_P(GeneratedTest, Test) { |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 916 | Execute(kDevice, kTestModel, TestKind::GENERAL); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | TEST_P(DynamicOutputShapeTest, Test) { |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 920 | Execute(kDevice, kTestModel, TestKind::DYNAMIC_SHAPE); |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 921 | } |
| 922 | |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 923 | TEST_P(MemoryDomainTest, Test) { |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 924 | Execute(kDevice, kTestModel, TestKind::MEMORY_DOMAIN); |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 925 | } |
| 926 | |
Miao Wang | 33173a3 | 2020-01-23 13:53:21 -0800 | [diff] [blame] | 927 | TEST_P(FencedComputeTest, Test) { |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 928 | Execute(kDevice, kTestModel, TestKind::FENCED_COMPUTE); |
Miao Wang | 33173a3 | 2020-01-23 13:53:21 -0800 | [diff] [blame] | 929 | } |
| 930 | |
Lev Proleev | baac15d | 2020-01-09 16:37:28 +0000 | [diff] [blame] | 931 | TEST_P(QuantizationCouplingTest, Test) { |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 932 | Execute(kDevice, kTestModel, TestKind::QUANTIZATION_COUPLING); |
| 933 | } |
| 934 | |
| 935 | TEST_P(InfiniteLoopTimeoutTest, Test) { |
| 936 | Execute(kDevice, kTestModel, TestKind::INTINITE_LOOP_TIMEOUT); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | INSTANTIATE_GENERATED_TEST(GeneratedTest, |
| 940 | [](const TestModel& testModel) { return !testModel.expectFailure; }); |
| 941 | |
Lev Proleev | 8b3f240 | 2020-01-20 18:54:46 +0000 | [diff] [blame] | 942 | INSTANTIATE_GENERATED_TEST(DynamicOutputShapeTest, [](const TestModel& testModel) { |
| 943 | return !testModel.expectFailure && !testModel.hasScalarOutputs(); |
| 944 | }); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 945 | |
Xusong Wang | 1f50e54 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 946 | INSTANTIATE_GENERATED_TEST(MemoryDomainTest, |
| 947 | [](const TestModel& testModel) { return !testModel.expectFailure; }); |
| 948 | |
Xusong Wang | 5882d6d | 2020-03-13 10:02:36 -0700 | [diff] [blame] | 949 | INSTANTIATE_GENERATED_TEST(FencedComputeTest, |
| 950 | [](const TestModel& testModel) { return !testModel.expectFailure; }); |
Miao Wang | 33173a3 | 2020-01-23 13:53:21 -0800 | [diff] [blame] | 951 | |
Lev Proleev | baac15d | 2020-01-09 16:37:28 +0000 | [diff] [blame] | 952 | INSTANTIATE_GENERATED_TEST(QuantizationCouplingTest, [](const TestModel& testModel) { |
Xusong Wang | 962fdb2 | 2020-03-16 17:13:41 -0700 | [diff] [blame] | 953 | return !testModel.expectFailure && testModel.hasQuant8CoupledOperands() && |
| 954 | testModel.main.operations.size() == 1; |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 955 | }); |
| 956 | |
Slava Shklyaev | cc873ae | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 957 | INSTANTIATE_GENERATED_TEST(InfiniteLoopTimeoutTest, [](const TestModel& testModel) { |
| 958 | return testModel.isInfiniteLoopTimeoutTest(); |
| 959 | }); |
| 960 | |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 961 | } // namespace android::hardware::neuralnetworks::V1_3::vts::functional |