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> |
Xusong Wang | 1b3f426 | 2019-10-25 12:07:17 -0700 | [diff] [blame] | 32 | #include <android/hardware/neuralnetworks/1.3/IPreparedModel.h> |
Xusong Wang | cc47dff | 2019-10-23 10:35:07 -0700 | [diff] [blame] | 33 | #include <android/hardware/neuralnetworks/1.3/IPreparedModelCallback.h> |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 34 | #include <android/hardware/neuralnetworks/1.3/types.h> |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 35 | #include <android/hidl/allocator/1.0/IAllocator.h> |
| 36 | #include <android/hidl/memory/1.0/IMemory.h> |
| 37 | #include <hidlmemory/mapping.h> |
| 38 | |
| 39 | #include <gtest/gtest.h> |
| 40 | #include <algorithm> |
Michael Butler | 648ada5 | 2019-07-25 17:22:11 -0700 | [diff] [blame] | 41 | #include <chrono> |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 42 | #include <iostream> |
| 43 | #include <numeric> |
| 44 | |
| 45 | #include "1.0/Utils.h" |
| 46 | #include "1.2/Callbacks.h" |
Xusong Wang | cc47dff | 2019-10-23 10:35:07 -0700 | [diff] [blame] | 47 | #include "1.3/Callbacks.h" |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 48 | #include "ExecutionBurstController.h" |
| 49 | #include "MemoryUtils.h" |
| 50 | #include "TestHarness.h" |
| 51 | #include "Utils.h" |
| 52 | #include "VtsHalNeuralnetworks.h" |
| 53 | |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 54 | namespace android::hardware::neuralnetworks::V1_3::vts::functional { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 55 | |
| 56 | using namespace test_helper; |
| 57 | using hidl::memory::V1_0::IMemory; |
Xusong Wang | cc47dff | 2019-10-23 10:35:07 -0700 | [diff] [blame] | 58 | using implementation::PreparedModelCallback; |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 59 | using V1_0::DataLocation; |
| 60 | using V1_0::ErrorStatus; |
| 61 | using V1_0::OperandLifeTime; |
| 62 | using V1_0::Request; |
| 63 | using V1_1::ExecutionPreference; |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 64 | using V1_2::Constant; |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 65 | using V1_2::MeasureTiming; |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 66 | using V1_2::OutputShape; |
| 67 | using V1_2::SymmPerChannelQuantParams; |
| 68 | using V1_2::Timing; |
| 69 | using V1_2::implementation::ExecutionCallback; |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 70 | using HidlToken = hidl_array<uint8_t, static_cast<uint32_t>(Constant::BYTE_SIZE_OF_CACHE_TOKEN)>; |
| 71 | |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame^] | 72 | namespace { |
| 73 | |
| 74 | enum class Executor { ASYNC, SYNC, BURST }; |
| 75 | |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 76 | enum class OutputType { FULLY_SPECIFIED, UNSPECIFIED, INSUFFICIENT }; |
| 77 | |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame^] | 78 | struct TestConfig { |
| 79 | Executor executor; |
| 80 | MeasureTiming measureTiming; |
| 81 | OutputType outputType; |
| 82 | }; |
| 83 | |
| 84 | } // namespace |
| 85 | |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 86 | Model createModel(const TestModel& testModel) { |
| 87 | // Model operands. |
| 88 | hidl_vec<Operand> operands(testModel.operands.size()); |
| 89 | size_t constCopySize = 0, constRefSize = 0; |
| 90 | for (uint32_t i = 0; i < testModel.operands.size(); i++) { |
| 91 | const auto& op = testModel.operands[i]; |
| 92 | |
| 93 | DataLocation loc = {}; |
| 94 | if (op.lifetime == TestOperandLifeTime::CONSTANT_COPY) { |
| 95 | loc = {.poolIndex = 0, |
| 96 | .offset = static_cast<uint32_t>(constCopySize), |
| 97 | .length = static_cast<uint32_t>(op.data.size())}; |
| 98 | constCopySize += op.data.alignedSize(); |
| 99 | } else if (op.lifetime == TestOperandLifeTime::CONSTANT_REFERENCE) { |
| 100 | loc = {.poolIndex = 0, |
| 101 | .offset = static_cast<uint32_t>(constRefSize), |
| 102 | .length = static_cast<uint32_t>(op.data.size())}; |
| 103 | constRefSize += op.data.alignedSize(); |
| 104 | } |
| 105 | |
| 106 | Operand::ExtraParams extraParams; |
| 107 | if (op.type == TestOperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL) { |
| 108 | extraParams.channelQuant(SymmPerChannelQuantParams{ |
| 109 | .scales = op.channelQuant.scales, .channelDim = op.channelQuant.channelDim}); |
| 110 | } |
| 111 | |
| 112 | operands[i] = {.type = static_cast<OperandType>(op.type), |
| 113 | .dimensions = op.dimensions, |
| 114 | .numberOfConsumers = op.numberOfConsumers, |
| 115 | .scale = op.scale, |
| 116 | .zeroPoint = op.zeroPoint, |
| 117 | .lifetime = static_cast<OperandLifeTime>(op.lifetime), |
| 118 | .location = loc, |
| 119 | .extraParams = std::move(extraParams)}; |
| 120 | } |
| 121 | |
| 122 | // Model operations. |
| 123 | hidl_vec<Operation> operations(testModel.operations.size()); |
| 124 | std::transform(testModel.operations.begin(), testModel.operations.end(), operations.begin(), |
| 125 | [](const TestOperation& op) -> Operation { |
| 126 | return {.type = static_cast<OperationType>(op.type), |
| 127 | .inputs = op.inputs, |
| 128 | .outputs = op.outputs}; |
| 129 | }); |
| 130 | |
| 131 | // Constant copies. |
| 132 | hidl_vec<uint8_t> operandValues(constCopySize); |
| 133 | for (uint32_t i = 0; i < testModel.operands.size(); i++) { |
| 134 | const auto& op = testModel.operands[i]; |
| 135 | if (op.lifetime == TestOperandLifeTime::CONSTANT_COPY) { |
| 136 | const uint8_t* begin = op.data.get<uint8_t>(); |
| 137 | const uint8_t* end = begin + op.data.size(); |
| 138 | std::copy(begin, end, operandValues.data() + operands[i].location.offset); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | // Shared memory. |
| 143 | hidl_vec<hidl_memory> pools = {}; |
| 144 | if (constRefSize > 0) { |
| 145 | hidl_vec_push_back(&pools, nn::allocateSharedMemory(constRefSize)); |
| 146 | CHECK_NE(pools[0].size(), 0u); |
| 147 | |
| 148 | // load data |
| 149 | sp<IMemory> mappedMemory = mapMemory(pools[0]); |
| 150 | CHECK(mappedMemory.get() != nullptr); |
| 151 | uint8_t* mappedPtr = |
| 152 | reinterpret_cast<uint8_t*>(static_cast<void*>(mappedMemory->getPointer())); |
| 153 | CHECK(mappedPtr != nullptr); |
| 154 | |
| 155 | for (uint32_t i = 0; i < testModel.operands.size(); i++) { |
| 156 | const auto& op = testModel.operands[i]; |
| 157 | if (op.lifetime == TestOperandLifeTime::CONSTANT_REFERENCE) { |
| 158 | const uint8_t* begin = op.data.get<uint8_t>(); |
| 159 | const uint8_t* end = begin + op.data.size(); |
| 160 | std::copy(begin, end, mappedPtr + operands[i].location.offset); |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | return {.operands = std::move(operands), |
| 166 | .operations = std::move(operations), |
| 167 | .inputIndexes = testModel.inputIndexes, |
| 168 | .outputIndexes = testModel.outputIndexes, |
| 169 | .operandValues = std::move(operandValues), |
| 170 | .pools = std::move(pools), |
| 171 | .relaxComputationFloat32toFloat16 = testModel.isRelaxed}; |
| 172 | } |
| 173 | |
| 174 | static bool isOutputSizeGreaterThanOne(const TestModel& testModel, uint32_t index) { |
| 175 | const auto byteSize = testModel.operands[testModel.outputIndexes[index]].data.size(); |
| 176 | return byteSize > 1u; |
| 177 | } |
| 178 | |
| 179 | static void makeOutputInsufficientSize(uint32_t outputIndex, Request* request) { |
| 180 | auto& length = request->outputs[outputIndex].location.length; |
| 181 | ASSERT_GT(length, 1u); |
| 182 | length -= 1u; |
| 183 | } |
| 184 | |
| 185 | static void makeOutputDimensionsUnspecified(Model* model) { |
| 186 | for (auto i : model->outputIndexes) { |
| 187 | auto& dims = model->operands[i].dimensions; |
| 188 | std::fill(dims.begin(), dims.end(), 0); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | static Return<ErrorStatus> ExecutePreparedModel(const sp<IPreparedModel>& preparedModel, |
| 193 | const Request& request, MeasureTiming measure, |
| 194 | sp<ExecutionCallback>& callback) { |
Xusong Wang | 1b3f426 | 2019-10-25 12:07:17 -0700 | [diff] [blame] | 195 | return preparedModel->execute_1_3(request, measure, callback); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 196 | } |
| 197 | static Return<ErrorStatus> ExecutePreparedModel(const sp<IPreparedModel>& preparedModel, |
| 198 | const Request& request, MeasureTiming measure, |
| 199 | hidl_vec<OutputShape>* outputShapes, |
| 200 | Timing* timing) { |
| 201 | ErrorStatus result; |
| 202 | Return<void> ret = preparedModel->executeSynchronously( |
| 203 | request, measure, |
| 204 | [&result, outputShapes, timing](ErrorStatus error, const hidl_vec<OutputShape>& shapes, |
| 205 | const Timing& time) { |
| 206 | result = error; |
| 207 | *outputShapes = shapes; |
| 208 | *timing = time; |
| 209 | }); |
| 210 | if (!ret.isOk()) { |
| 211 | return ErrorStatus::GENERAL_FAILURE; |
| 212 | } |
| 213 | return result; |
| 214 | } |
| 215 | static std::shared_ptr<::android::nn::ExecutionBurstController> CreateBurst( |
| 216 | const sp<IPreparedModel>& preparedModel) { |
Michael Butler | 648ada5 | 2019-07-25 17:22:11 -0700 | [diff] [blame] | 217 | return android::nn::ExecutionBurstController::create(preparedModel, |
| 218 | std::chrono::microseconds{0}); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 219 | } |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 220 | |
| 221 | void EvaluatePreparedModel(const sp<IPreparedModel>& preparedModel, const TestModel& testModel, |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame^] | 222 | const TestConfig& testConfig) { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 223 | // 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^] | 224 | if (testConfig.outputType == OutputType::INSUFFICIENT && |
| 225 | !isOutputSizeGreaterThanOne(testModel, 0)) { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 226 | return; |
| 227 | } |
| 228 | |
| 229 | Request request = createRequest(testModel); |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame^] | 230 | if (testConfig.outputType == OutputType::INSUFFICIENT) { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 231 | makeOutputInsufficientSize(/*outputIndex=*/0, &request); |
| 232 | } |
| 233 | |
| 234 | ErrorStatus executionStatus; |
| 235 | hidl_vec<OutputShape> outputShapes; |
| 236 | Timing timing; |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame^] | 237 | switch (testConfig.executor) { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 238 | case Executor::ASYNC: { |
| 239 | SCOPED_TRACE("asynchronous"); |
| 240 | |
| 241 | // launch execution |
| 242 | sp<ExecutionCallback> executionCallback = new ExecutionCallback(); |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame^] | 243 | Return<ErrorStatus> executionLaunchStatus = ExecutePreparedModel( |
| 244 | preparedModel, request, testConfig.measureTiming, executionCallback); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 245 | ASSERT_TRUE(executionLaunchStatus.isOk()); |
| 246 | EXPECT_EQ(ErrorStatus::NONE, static_cast<ErrorStatus>(executionLaunchStatus)); |
| 247 | |
| 248 | // retrieve execution status |
| 249 | executionCallback->wait(); |
| 250 | executionStatus = executionCallback->getStatus(); |
| 251 | outputShapes = executionCallback->getOutputShapes(); |
| 252 | timing = executionCallback->getTiming(); |
| 253 | |
| 254 | break; |
| 255 | } |
| 256 | case Executor::SYNC: { |
| 257 | SCOPED_TRACE("synchronous"); |
| 258 | |
| 259 | // execute |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame^] | 260 | Return<ErrorStatus> executionReturnStatus = ExecutePreparedModel( |
| 261 | preparedModel, request, testConfig.measureTiming, &outputShapes, &timing); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 262 | ASSERT_TRUE(executionReturnStatus.isOk()); |
| 263 | executionStatus = static_cast<ErrorStatus>(executionReturnStatus); |
| 264 | |
| 265 | break; |
| 266 | } |
| 267 | case Executor::BURST: { |
| 268 | SCOPED_TRACE("burst"); |
| 269 | |
| 270 | // create burst |
| 271 | const std::shared_ptr<::android::nn::ExecutionBurstController> controller = |
| 272 | CreateBurst(preparedModel); |
| 273 | ASSERT_NE(nullptr, controller.get()); |
| 274 | |
| 275 | // create memory keys |
| 276 | std::vector<intptr_t> keys(request.pools.size()); |
| 277 | for (size_t i = 0; i < keys.size(); ++i) { |
| 278 | keys[i] = reinterpret_cast<intptr_t>(&request.pools[i]); |
| 279 | } |
| 280 | |
| 281 | // execute burst |
Michael Butler | 648ada5 | 2019-07-25 17:22:11 -0700 | [diff] [blame] | 282 | int n; |
| 283 | std::tie(n, outputShapes, timing, std::ignore) = |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame^] | 284 | controller->compute(request, testConfig.measureTiming, keys); |
Michael Butler | 648ada5 | 2019-07-25 17:22:11 -0700 | [diff] [blame] | 285 | executionStatus = nn::convertResultCodeToErrorStatus(n); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 286 | |
| 287 | break; |
| 288 | } |
| 289 | } |
| 290 | |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame^] | 291 | if (testConfig.outputType != OutputType::FULLY_SPECIFIED && |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 292 | executionStatus == ErrorStatus::GENERAL_FAILURE) { |
| 293 | LOG(INFO) << "NN VTS: Early termination of test because vendor service cannot " |
| 294 | "execute model that it does not support."; |
| 295 | std::cout << "[ ] Early termination of test because vendor service cannot " |
| 296 | "execute model that it does not support." |
| 297 | << std::endl; |
| 298 | GTEST_SKIP(); |
| 299 | } |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame^] | 300 | if (testConfig.measureTiming == MeasureTiming::NO) { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 301 | EXPECT_EQ(UINT64_MAX, timing.timeOnDevice); |
| 302 | EXPECT_EQ(UINT64_MAX, timing.timeInDriver); |
| 303 | } else { |
| 304 | if (timing.timeOnDevice != UINT64_MAX && timing.timeInDriver != UINT64_MAX) { |
| 305 | EXPECT_LE(timing.timeOnDevice, timing.timeInDriver); |
| 306 | } |
| 307 | } |
| 308 | |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame^] | 309 | switch (testConfig.outputType) { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 310 | case OutputType::FULLY_SPECIFIED: |
| 311 | // If the model output operands are fully specified, outputShapes must be either |
| 312 | // either empty, or have the same number of elements as the number of outputs. |
| 313 | ASSERT_EQ(ErrorStatus::NONE, executionStatus); |
| 314 | ASSERT_TRUE(outputShapes.size() == 0 || |
| 315 | outputShapes.size() == testModel.outputIndexes.size()); |
| 316 | break; |
| 317 | case OutputType::UNSPECIFIED: |
| 318 | // If the model output operands are not fully specified, outputShapes must have |
| 319 | // the same number of elements as the number of outputs. |
| 320 | ASSERT_EQ(ErrorStatus::NONE, executionStatus); |
| 321 | ASSERT_EQ(outputShapes.size(), testModel.outputIndexes.size()); |
| 322 | break; |
| 323 | case OutputType::INSUFFICIENT: |
| 324 | ASSERT_EQ(ErrorStatus::OUTPUT_INSUFFICIENT_SIZE, executionStatus); |
| 325 | ASSERT_EQ(outputShapes.size(), testModel.outputIndexes.size()); |
| 326 | ASSERT_FALSE(outputShapes[0].isSufficient); |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | // Go through all outputs, check returned output shapes. |
| 331 | for (uint32_t i = 0; i < outputShapes.size(); i++) { |
| 332 | EXPECT_TRUE(outputShapes[i].isSufficient); |
| 333 | const auto& expect = testModel.operands[testModel.outputIndexes[i]].dimensions; |
| 334 | const std::vector<uint32_t> actual = outputShapes[i].dimensions; |
| 335 | EXPECT_EQ(expect, actual); |
| 336 | } |
| 337 | |
| 338 | // Retrieve execution results. |
| 339 | const std::vector<TestBuffer> outputs = getOutputBuffers(request); |
| 340 | |
| 341 | // We want "close-enough" results. |
| 342 | checkResults(testModel, outputs); |
| 343 | } |
| 344 | |
| 345 | void EvaluatePreparedModel(const sp<IPreparedModel>& preparedModel, const TestModel& testModel, |
| 346 | bool testDynamicOutputShape) { |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame^] | 347 | std::initializer_list<OutputType> outputTypesList; |
| 348 | std::initializer_list<MeasureTiming> measureTimingList; |
| 349 | std::initializer_list<Executor> executorList; |
| 350 | |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 351 | if (testDynamicOutputShape) { |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame^] | 352 | outputTypesList = {OutputType::UNSPECIFIED, OutputType::INSUFFICIENT}; |
| 353 | measureTimingList = {MeasureTiming::NO, MeasureTiming::YES}; |
| 354 | executorList = {Executor::ASYNC, Executor::SYNC, Executor::BURST}; |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 355 | } else { |
Lev Proleev | 0d4ba3f | 2019-10-02 17:32:06 +0100 | [diff] [blame^] | 356 | outputTypesList = {OutputType::FULLY_SPECIFIED}; |
| 357 | measureTimingList = {MeasureTiming::NO, MeasureTiming::YES}; |
| 358 | executorList = {Executor::ASYNC, Executor::SYNC, Executor::BURST}; |
| 359 | } |
| 360 | |
| 361 | for (const OutputType outputType : outputTypesList) { |
| 362 | for (const MeasureTiming measureTiming : measureTimingList) { |
| 363 | for (const Executor executor : executorList) { |
| 364 | const TestConfig testConfig = {.executor = executor, |
| 365 | .measureTiming = measureTiming, |
| 366 | .outputType = outputType}; |
| 367 | EvaluatePreparedModel(preparedModel, testModel, testConfig); |
| 368 | } |
| 369 | } |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | |
| 373 | void Execute(const sp<IDevice>& device, const TestModel& testModel, bool testDynamicOutputShape) { |
| 374 | Model model = createModel(testModel); |
| 375 | if (testDynamicOutputShape) { |
| 376 | makeOutputDimensionsUnspecified(&model); |
| 377 | } |
| 378 | |
| 379 | sp<IPreparedModel> preparedModel; |
| 380 | createPreparedModel(device, model, &preparedModel); |
| 381 | if (preparedModel == nullptr) return; |
| 382 | |
| 383 | EvaluatePreparedModel(preparedModel, testModel, testDynamicOutputShape); |
| 384 | } |
| 385 | |
| 386 | void GeneratedTestBase::SetUp() { |
| 387 | testing::TestWithParam<GeneratedTestParam>::SetUp(); |
| 388 | ASSERT_NE(kDevice, nullptr); |
| 389 | } |
| 390 | |
| 391 | std::vector<NamedModel> getNamedModels(const FilterFn& filter) { |
| 392 | return TestModelManager::get().getTestModels(filter); |
| 393 | } |
| 394 | |
| 395 | std::string printGeneratedTest(const testing::TestParamInfo<GeneratedTestParam>& info) { |
| 396 | const auto& [namedDevice, namedModel] = info.param; |
| 397 | return gtestCompliantName(getName(namedDevice) + "_" + getName(namedModel)); |
| 398 | } |
| 399 | |
| 400 | // Tag for the generated tests |
| 401 | class GeneratedTest : public GeneratedTestBase {}; |
| 402 | |
| 403 | // Tag for the dynamic output shape tests |
| 404 | class DynamicOutputShapeTest : public GeneratedTest {}; |
| 405 | |
| 406 | TEST_P(GeneratedTest, Test) { |
| 407 | Execute(kDevice, kTestModel, /*testDynamicOutputShape=*/false); |
| 408 | } |
| 409 | |
| 410 | TEST_P(DynamicOutputShapeTest, Test) { |
| 411 | Execute(kDevice, kTestModel, /*testDynamicOutputShape=*/true); |
| 412 | } |
| 413 | |
| 414 | INSTANTIATE_GENERATED_TEST(GeneratedTest, |
| 415 | [](const TestModel& testModel) { return !testModel.expectFailure; }); |
| 416 | |
| 417 | INSTANTIATE_GENERATED_TEST(DynamicOutputShapeTest, |
| 418 | [](const TestModel& testModel) { return !testModel.expectFailure; }); |
| 419 | |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 420 | } // namespace android::hardware::neuralnetworks::V1_3::vts::functional |