blob: 82f34ff779baa592ec897c7a40a2cf4287d41c33 [file] [log] [blame]
Lev Proleev13fdfcd2019-08-30 11:35:34 +01001/*
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 Proleev26d1bc82019-08-30 11:57:18 +010030#include <android/hardware/neuralnetworks/1.2/types.h>
31#include <android/hardware/neuralnetworks/1.3/IDevice.h>
Miao Wang2b5c4cd2019-12-26 18:03:56 -080032#include <android/hardware/neuralnetworks/1.3/IFencedExecutionCallback.h>
Xusong Wang1b3f4262019-10-25 12:07:17 -070033#include <android/hardware/neuralnetworks/1.3/IPreparedModel.h>
Xusong Wangcc47dff2019-10-23 10:35:07 -070034#include <android/hardware/neuralnetworks/1.3/IPreparedModelCallback.h>
Lev Proleev26d1bc82019-08-30 11:57:18 +010035#include <android/hardware/neuralnetworks/1.3/types.h>
Lev Proleev13fdfcd2019-08-30 11:35:34 +010036#include <android/hidl/allocator/1.0/IAllocator.h>
37#include <android/hidl/memory/1.0/IMemory.h>
Miao Wang2b5c4cd2019-12-26 18:03:56 -080038#include <android/sync.h>
Lev Proleev56cda832019-12-05 14:49:47 +000039#include <gtest/gtest.h>
Lev Proleev13fdfcd2019-08-30 11:35:34 +010040#include <hidlmemory/mapping.h>
41
Lev Proleev13fdfcd2019-08-30 11:35:34 +010042#include <algorithm>
Michael Butler648ada52019-07-25 17:22:11 -070043#include <chrono>
Lev Proleev13fdfcd2019-08-30 11:35:34 +010044#include <iostream>
45#include <numeric>
Lev Proleev56cda832019-12-05 14:49:47 +000046#include <vector>
Lev Proleev13fdfcd2019-08-30 11:35:34 +010047
48#include "1.0/Utils.h"
Xusong Wangcc47dff2019-10-23 10:35:07 -070049#include "1.3/Callbacks.h"
Michael Butler95899b32020-01-07 14:52:44 -080050#include "1.3/Utils.h"
Lev Proleev13fdfcd2019-08-30 11:35:34 +010051#include "ExecutionBurstController.h"
52#include "MemoryUtils.h"
53#include "TestHarness.h"
54#include "Utils.h"
55#include "VtsHalNeuralnetworks.h"
56
Lev Proleev26d1bc82019-08-30 11:57:18 +010057namespace android::hardware::neuralnetworks::V1_3::vts::functional {
Lev Proleev13fdfcd2019-08-30 11:35:34 +010058
59using namespace test_helper;
60using hidl::memory::V1_0::IMemory;
Michael Butler79a41d72019-12-11 19:08:08 -080061using implementation::ExecutionCallback;
Xusong Wangcc47dff2019-10-23 10:35:07 -070062using implementation::PreparedModelCallback;
Lev Proleev13fdfcd2019-08-30 11:35:34 +010063using V1_0::DataLocation;
Xusong Wange9da9852020-01-13 11:44:45 -080064using V1_0::RequestArgument;
Lev Proleev13fdfcd2019-08-30 11:35:34 +010065using V1_1::ExecutionPreference;
Lev Proleev26d1bc82019-08-30 11:57:18 +010066using V1_2::Constant;
Lev Proleev26d1bc82019-08-30 11:57:18 +010067using V1_2::MeasureTiming;
Lev Proleev26d1bc82019-08-30 11:57:18 +010068using V1_2::OutputShape;
69using V1_2::SymmPerChannelQuantParams;
70using V1_2::Timing;
Lev Proleev13fdfcd2019-08-30 11:35:34 +010071using HidlToken = hidl_array<uint8_t, static_cast<uint32_t>(Constant::BYTE_SIZE_OF_CACHE_TOKEN)>;
72
Lev Proleev0d4ba3f2019-10-02 17:32:06 +010073namespace {
74
Miao Wang2b5c4cd2019-12-26 18:03:56 -080075enum class Executor { ASYNC, SYNC, BURST, FENCED };
Lev Proleev0d4ba3f2019-10-02 17:32:06 +010076
Lev Proleev13fdfcd2019-08-30 11:35:34 +010077enum class OutputType { FULLY_SPECIFIED, UNSPECIFIED, INSUFFICIENT };
78
Xusong Wange9da9852020-01-13 11:44:45 -080079enum class MemoryType { SHARED, DEVICE };
80
81enum class IOType { INPUT, OUTPUT };
82
Miao Wang99753d92020-01-21 13:15:09 -080083static void waitForSyncFence(int syncFd) {
84 constexpr int kInfiniteTimeout = -1;
85 ASSERT_GT(syncFd, 0);
86 int r = sync_wait(syncFd, kInfiniteTimeout);
87 ASSERT_GE(r, 0);
88}
89
Lev Proleev0d4ba3f2019-10-02 17:32:06 +010090struct TestConfig {
91 Executor executor;
92 MeasureTiming measureTiming;
93 OutputType outputType;
Xusong Wange9da9852020-01-13 11:44:45 -080094 MemoryType memoryType;
Lev Proleev9226c1e2019-10-03 14:43:18 +010095 // `reportSkipping` indicates if a test should print an info message in case
96 // it is skipped. The field is set to true by default and is set to false in
97 // quantization coupling tests to suppress skipping a test
98 bool reportSkipping;
Xusong Wange9da9852020-01-13 11:44:45 -080099 TestConfig(Executor executor, MeasureTiming measureTiming, OutputType outputType,
100 MemoryType memoryType)
Lev Proleev9226c1e2019-10-03 14:43:18 +0100101 : executor(executor),
102 measureTiming(measureTiming),
103 outputType(outputType),
Xusong Wange9da9852020-01-13 11:44:45 -0800104 memoryType(memoryType),
Lev Proleev9226c1e2019-10-03 14:43:18 +0100105 reportSkipping(true) {}
106 TestConfig(Executor executor, MeasureTiming measureTiming, OutputType outputType,
Xusong Wange9da9852020-01-13 11:44:45 -0800107 MemoryType memoryType, bool reportSkipping)
Lev Proleev9226c1e2019-10-03 14:43:18 +0100108 : executor(executor),
109 measureTiming(measureTiming),
110 outputType(outputType),
Xusong Wange9da9852020-01-13 11:44:45 -0800111 memoryType(memoryType),
Lev Proleev9226c1e2019-10-03 14:43:18 +0100112 reportSkipping(reportSkipping) {}
Lev Proleev0d4ba3f2019-10-02 17:32:06 +0100113};
114
Xusong Wange9da9852020-01-13 11:44:45 -0800115class DeviceMemoryAllocator {
116 public:
117 DeviceMemoryAllocator(const sp<IDevice>& device, const sp<IPreparedModel>& preparedModel,
118 const TestModel& testModel)
119 : kDevice(device), kPreparedModel(preparedModel), kTestModel(testModel) {}
120
121 // Allocate device memory for a target input/output operand.
122 // Return {IBuffer object, token} if successful.
123 // Return {nullptr, 0} if device memory is not supported.
124 template <IOType ioType>
Michael Butlerc3e1a292020-02-04 16:15:04 -0800125 std::pair<sp<IBuffer>, uint32_t> allocate(uint32_t index) {
126 std::pair<sp<IBuffer>, uint32_t> buffer;
Xusong Wange9da9852020-01-13 11:44:45 -0800127 allocateInternal<ioType>(index, &buffer);
128 return buffer;
129 }
130
131 private:
132 template <IOType ioType>
Michael Butlerc3e1a292020-02-04 16:15:04 -0800133 void allocateInternal(uint32_t index, std::pair<sp<IBuffer>, uint32_t>* result) {
Xusong Wange9da9852020-01-13 11:44:45 -0800134 ASSERT_NE(result, nullptr);
135
136 // Prepare arguments.
137 BufferRole role = {.modelIndex = 0, .ioIndex = index, .frequency = 1.0f};
138 hidl_vec<BufferRole> inputRoles, outputRoles;
139 if constexpr (ioType == IOType::INPUT) {
140 inputRoles = {role};
141 } else {
142 outputRoles = {role};
143 }
144
145 // Allocate device memory.
146 ErrorStatus status;
147 sp<IBuffer> buffer;
Michael Butlerc3e1a292020-02-04 16:15:04 -0800148 uint32_t token;
149 auto cb = [&status, &buffer, &token](ErrorStatus error, const sp<IBuffer>& buf,
150 uint32_t tok) {
151 status = error;
152 buffer = buf;
153 token = tok;
154 };
155 const auto ret = kDevice->allocate({}, {kPreparedModel}, inputRoles, outputRoles, cb);
Xusong Wange9da9852020-01-13 11:44:45 -0800156
157 // Check allocation results.
158 ASSERT_TRUE(ret.isOk());
159 if (status == ErrorStatus::NONE) {
160 ASSERT_NE(buffer, nullptr);
161 ASSERT_GT(token, 0);
162 } else {
163 ASSERT_EQ(status, ErrorStatus::GENERAL_FAILURE);
164 ASSERT_EQ(buffer, nullptr);
165 ASSERT_EQ(token, 0);
166 }
167
168 // Initialize input data from TestBuffer.
169 if constexpr (ioType == IOType::INPUT) {
170 if (buffer != nullptr) {
171 // TestBuffer -> Shared memory.
172 const auto& testBuffer = kTestModel.operands[kTestModel.inputIndexes[index]].data;
173 ASSERT_GT(testBuffer.size(), 0);
174 hidl_memory tmp = nn::allocateSharedMemory(testBuffer.size());
175 sp<IMemory> inputMemory = mapMemory(tmp);
176 ASSERT_NE(inputMemory.get(), nullptr);
177 uint8_t* inputPtr =
178 static_cast<uint8_t*>(static_cast<void*>(inputMemory->getPointer()));
179 ASSERT_NE(inputPtr, nullptr);
180 const uint8_t* begin = testBuffer.get<uint8_t>();
181 const uint8_t* end = begin + testBuffer.size();
182 std::copy(begin, end, inputPtr);
183
184 // Shared memory -> IBuffer.
185 auto ret = buffer->copyFrom(tmp, {});
186 ASSERT_TRUE(ret.isOk());
187 ASSERT_EQ(static_cast<ErrorStatus>(ret), ErrorStatus::NONE);
188 }
189 }
190 *result = {std::move(buffer), token};
191 }
192
193 const sp<IDevice> kDevice;
194 const sp<IPreparedModel> kPreparedModel;
195 const TestModel& kTestModel;
196};
197
Lev Proleev0d4ba3f2019-10-02 17:32:06 +0100198} // namespace
199
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100200Model createModel(const TestModel& testModel) {
201 // Model operands.
202 hidl_vec<Operand> operands(testModel.operands.size());
203 size_t constCopySize = 0, constRefSize = 0;
204 for (uint32_t i = 0; i < testModel.operands.size(); i++) {
205 const auto& op = testModel.operands[i];
206
207 DataLocation loc = {};
208 if (op.lifetime == TestOperandLifeTime::CONSTANT_COPY) {
209 loc = {.poolIndex = 0,
210 .offset = static_cast<uint32_t>(constCopySize),
211 .length = static_cast<uint32_t>(op.data.size())};
212 constCopySize += op.data.alignedSize();
213 } else if (op.lifetime == TestOperandLifeTime::CONSTANT_REFERENCE) {
214 loc = {.poolIndex = 0,
215 .offset = static_cast<uint32_t>(constRefSize),
216 .length = static_cast<uint32_t>(op.data.size())};
217 constRefSize += op.data.alignedSize();
218 }
219
Michael Butlerc3e1a292020-02-04 16:15:04 -0800220 V1_2::Operand::ExtraParams extraParams;
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100221 if (op.type == TestOperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL) {
222 extraParams.channelQuant(SymmPerChannelQuantParams{
223 .scales = op.channelQuant.scales, .channelDim = op.channelQuant.channelDim});
224 }
225
226 operands[i] = {.type = static_cast<OperandType>(op.type),
227 .dimensions = op.dimensions,
228 .numberOfConsumers = op.numberOfConsumers,
229 .scale = op.scale,
230 .zeroPoint = op.zeroPoint,
231 .lifetime = static_cast<OperandLifeTime>(op.lifetime),
232 .location = loc,
233 .extraParams = std::move(extraParams)};
234 }
235
236 // Model operations.
237 hidl_vec<Operation> operations(testModel.operations.size());
238 std::transform(testModel.operations.begin(), testModel.operations.end(), operations.begin(),
239 [](const TestOperation& op) -> Operation {
240 return {.type = static_cast<OperationType>(op.type),
241 .inputs = op.inputs,
242 .outputs = op.outputs};
243 });
244
245 // Constant copies.
246 hidl_vec<uint8_t> operandValues(constCopySize);
247 for (uint32_t i = 0; i < testModel.operands.size(); i++) {
248 const auto& op = testModel.operands[i];
249 if (op.lifetime == TestOperandLifeTime::CONSTANT_COPY) {
250 const uint8_t* begin = op.data.get<uint8_t>();
251 const uint8_t* end = begin + op.data.size();
252 std::copy(begin, end, operandValues.data() + operands[i].location.offset);
253 }
254 }
255
256 // Shared memory.
257 hidl_vec<hidl_memory> pools = {};
258 if (constRefSize > 0) {
259 hidl_vec_push_back(&pools, nn::allocateSharedMemory(constRefSize));
260 CHECK_NE(pools[0].size(), 0u);
261
262 // load data
263 sp<IMemory> mappedMemory = mapMemory(pools[0]);
264 CHECK(mappedMemory.get() != nullptr);
265 uint8_t* mappedPtr =
266 reinterpret_cast<uint8_t*>(static_cast<void*>(mappedMemory->getPointer()));
267 CHECK(mappedPtr != nullptr);
268
269 for (uint32_t i = 0; i < testModel.operands.size(); i++) {
270 const auto& op = testModel.operands[i];
271 if (op.lifetime == TestOperandLifeTime::CONSTANT_REFERENCE) {
272 const uint8_t* begin = op.data.get<uint8_t>();
273 const uint8_t* end = begin + op.data.size();
274 std::copy(begin, end, mappedPtr + operands[i].location.offset);
275 }
276 }
277 }
278
Slava Shklyaevf8124a82019-12-13 12:24:35 +0000279 return {.main = {.operands = std::move(operands),
280 .operations = std::move(operations),
281 .inputIndexes = testModel.inputIndexes,
282 .outputIndexes = testModel.outputIndexes},
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100283 .operandValues = std::move(operandValues),
284 .pools = std::move(pools),
285 .relaxComputationFloat32toFloat16 = testModel.isRelaxed};
286}
287
288static bool isOutputSizeGreaterThanOne(const TestModel& testModel, uint32_t index) {
289 const auto byteSize = testModel.operands[testModel.outputIndexes[index]].data.size();
290 return byteSize > 1u;
291}
292
Xusong Wange9da9852020-01-13 11:44:45 -0800293static void makeOutputInsufficientSize(uint32_t outputIndex, Request* request) {
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100294 auto& length = request->outputs[outputIndex].location.length;
295 ASSERT_GT(length, 1u);
296 length -= 1u;
297}
298
299static void makeOutputDimensionsUnspecified(Model* model) {
Slava Shklyaevf8124a82019-12-13 12:24:35 +0000300 for (auto i : model->main.outputIndexes) {
301 auto& dims = model->main.operands[i].dimensions;
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100302 std::fill(dims.begin(), dims.end(), 0);
303 }
304}
305
Xusong Wange9da9852020-01-13 11:44:45 -0800306constexpr uint32_t kInputPoolIndex = 0;
307constexpr uint32_t kOutputPoolIndex = 1;
308constexpr uint32_t kDeviceMemoryBeginIndex = 2;
309
310static std::pair<Request, std::vector<sp<IBuffer>>> createRequest(
311 const sp<IDevice>& device, const sp<IPreparedModel>& preparedModel,
312 const TestModel& testModel, bool preferDeviceMemory) {
313 // Memory pools are organized as:
314 // - 0: Input shared memory pool
315 // - 1: Output shared memory pool
316 // - [2, 2+i): Input device memories
317 // - [2+i, 2+i+o): Output device memories
318 DeviceMemoryAllocator allocator(device, preparedModel, testModel);
319 std::vector<sp<IBuffer>> buffers;
Michael Butlerc3e1a292020-02-04 16:15:04 -0800320 std::vector<uint32_t> tokens;
Xusong Wange9da9852020-01-13 11:44:45 -0800321
322 // Model inputs.
323 hidl_vec<RequestArgument> inputs(testModel.inputIndexes.size());
324 size_t inputSize = 0;
325 for (uint32_t i = 0; i < testModel.inputIndexes.size(); i++) {
326 const auto& op = testModel.operands[testModel.inputIndexes[i]];
327 if (op.data.size() == 0) {
328 // Omitted input.
329 inputs[i] = {.hasNoValue = true};
330 continue;
331 } else if (preferDeviceMemory) {
332 SCOPED_TRACE("Input index = " + std::to_string(i));
333 auto [buffer, token] = allocator.allocate<IOType::INPUT>(i);
334 if (buffer != nullptr) {
335 DataLocation loc = {.poolIndex = static_cast<uint32_t>(buffers.size() +
336 kDeviceMemoryBeginIndex)};
337 buffers.push_back(std::move(buffer));
338 tokens.push_back(token);
339 inputs[i] = {.hasNoValue = false, .location = loc, .dimensions = {}};
340 continue;
341 }
342 }
343
344 // Reserve shared memory for input.
345 DataLocation loc = {.poolIndex = kInputPoolIndex,
346 .offset = static_cast<uint32_t>(inputSize),
347 .length = static_cast<uint32_t>(op.data.size())};
348 inputSize += op.data.alignedSize();
349 inputs[i] = {.hasNoValue = false, .location = loc, .dimensions = {}};
350 }
351
352 // Model outputs.
353 hidl_vec<RequestArgument> outputs(testModel.outputIndexes.size());
354 size_t outputSize = 0;
355 for (uint32_t i = 0; i < testModel.outputIndexes.size(); i++) {
356 const auto& op = testModel.operands[testModel.outputIndexes[i]];
357 if (preferDeviceMemory) {
358 SCOPED_TRACE("Output index = " + std::to_string(i));
359 auto [buffer, token] = allocator.allocate<IOType::OUTPUT>(i);
360 if (buffer != nullptr) {
361 DataLocation loc = {.poolIndex = static_cast<uint32_t>(buffers.size() +
362 kDeviceMemoryBeginIndex)};
363 buffers.push_back(std::move(buffer));
364 tokens.push_back(token);
365 outputs[i] = {.hasNoValue = false, .location = loc, .dimensions = {}};
366 continue;
367 }
368 }
369
370 // In the case of zero-sized output, we should at least provide a one-byte buffer.
371 // This is because zero-sized tensors are only supported internally to the driver, or
372 // reported in output shapes. It is illegal for the client to pre-specify a zero-sized
373 // tensor as model output. Otherwise, we will have two semantic conflicts:
374 // - "Zero dimension" conflicts with "unspecified dimension".
375 // - "Omitted operand buffer" conflicts with "zero-sized operand buffer".
376 size_t bufferSize = std::max<size_t>(op.data.size(), 1);
377
378 // Reserve shared memory for output.
379 DataLocation loc = {.poolIndex = kOutputPoolIndex,
380 .offset = static_cast<uint32_t>(outputSize),
381 .length = static_cast<uint32_t>(bufferSize)};
382 outputSize += op.data.size() == 0 ? TestBuffer::kAlignment : op.data.alignedSize();
383 outputs[i] = {.hasNoValue = false, .location = loc, .dimensions = {}};
384 }
385
386 // Memory pools.
387 hidl_vec<Request::MemoryPool> pools(kDeviceMemoryBeginIndex + buffers.size());
388 pools[kInputPoolIndex].hidlMemory(nn::allocateSharedMemory(std::max<size_t>(inputSize, 1)));
389 pools[kOutputPoolIndex].hidlMemory(nn::allocateSharedMemory(std::max<size_t>(outputSize, 1)));
390 CHECK_NE(pools[kInputPoolIndex].hidlMemory().size(), 0u);
391 CHECK_NE(pools[kOutputPoolIndex].hidlMemory().size(), 0u);
392 for (uint32_t i = 0; i < buffers.size(); i++) {
393 pools[kDeviceMemoryBeginIndex + i].token(tokens[i]);
394 }
395
396 // Copy input data to the input shared memory pool.
397 sp<IMemory> inputMemory = mapMemory(pools[kInputPoolIndex].hidlMemory());
398 CHECK(inputMemory.get() != nullptr);
399 uint8_t* inputPtr = static_cast<uint8_t*>(static_cast<void*>(inputMemory->getPointer()));
400 CHECK(inputPtr != nullptr);
401 for (uint32_t i = 0; i < testModel.inputIndexes.size(); i++) {
402 if (!inputs[i].hasNoValue && inputs[i].location.poolIndex == kInputPoolIndex) {
403 const auto& op = testModel.operands[testModel.inputIndexes[i]];
404 const uint8_t* begin = op.data.get<uint8_t>();
405 const uint8_t* end = begin + op.data.size();
406 std::copy(begin, end, inputPtr + inputs[i].location.offset);
407 }
408 }
409
410 Request request = {
411 .inputs = std::move(inputs), .outputs = std::move(outputs), .pools = std::move(pools)};
412 return {std::move(request), std::move(buffers)};
413}
414
415// Get a TestBuffer with data copied from an IBuffer object.
416static void getBuffer(const sp<IBuffer>& buffer, size_t size, TestBuffer* testBuffer) {
417 // IBuffer -> Shared memory.
418 hidl_memory tmp = nn::allocateSharedMemory(size);
419 const auto ret = buffer->copyTo(tmp);
420 ASSERT_TRUE(ret.isOk());
421 ASSERT_EQ(static_cast<ErrorStatus>(ret), ErrorStatus::NONE);
422
423 // Shared memory -> TestBuffer.
424 sp<IMemory> outputMemory = mapMemory(tmp);
425 ASSERT_NE(outputMemory.get(), nullptr);
426 uint8_t* outputPtr = static_cast<uint8_t*>(static_cast<void*>(outputMemory->getPointer()));
427 ASSERT_NE(outputPtr, nullptr);
428 ASSERT_NE(testBuffer, nullptr);
429 *testBuffer = TestBuffer(size, outputPtr);
430}
431
432static std::vector<TestBuffer> getOutputBuffers(const TestModel& testModel, const Request& request,
433 const std::vector<sp<IBuffer>>& buffers) {
434 sp<IMemory> outputMemory = mapMemory(request.pools[kOutputPoolIndex].hidlMemory());
435 CHECK(outputMemory.get() != nullptr);
436 uint8_t* outputPtr = static_cast<uint8_t*>(static_cast<void*>(outputMemory->getPointer()));
437 CHECK(outputPtr != nullptr);
438
439 // Copy out output results.
440 std::vector<TestBuffer> outputBuffers;
441 for (uint32_t i = 0; i < request.outputs.size(); i++) {
442 const auto& outputLoc = request.outputs[i].location;
443 if (outputLoc.poolIndex == kOutputPoolIndex) {
444 outputBuffers.emplace_back(outputLoc.length, outputPtr + outputLoc.offset);
445 } else {
446 const auto& op = testModel.operands[testModel.outputIndexes[i]];
447 if (op.data.size() == 0) {
448 outputBuffers.emplace_back();
449 } else {
450 SCOPED_TRACE("Output index = " + std::to_string(i));
451 const uint32_t bufferIndex = outputLoc.poolIndex - kDeviceMemoryBeginIndex;
452 TestBuffer buffer;
453 getBuffer(buffers[bufferIndex], op.data.size(), &buffer);
454 outputBuffers.push_back(std::move(buffer));
455 }
456 }
457 }
458 return outputBuffers;
459}
460
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100461static Return<ErrorStatus> ExecutePreparedModel(const sp<IPreparedModel>& preparedModel,
462 const Request& request, MeasureTiming measure,
463 sp<ExecutionCallback>& callback) {
Michael Butler79a41d72019-12-11 19:08:08 -0800464 return preparedModel->execute_1_3(request, measure, {}, callback);
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100465}
466static Return<ErrorStatus> ExecutePreparedModel(const sp<IPreparedModel>& preparedModel,
467 const Request& request, MeasureTiming measure,
468 hidl_vec<OutputShape>* outputShapes,
469 Timing* timing) {
470 ErrorStatus result;
Xusong Wangd4a060b2019-10-28 11:11:19 -0700471 Return<void> ret = preparedModel->executeSynchronously_1_3(
Michael Butler79a41d72019-12-11 19:08:08 -0800472 request, measure, {},
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100473 [&result, outputShapes, timing](ErrorStatus error, const hidl_vec<OutputShape>& shapes,
474 const Timing& time) {
475 result = error;
476 *outputShapes = shapes;
477 *timing = time;
478 });
479 if (!ret.isOk()) {
480 return ErrorStatus::GENERAL_FAILURE;
481 }
482 return result;
483}
484static std::shared_ptr<::android::nn::ExecutionBurstController> CreateBurst(
485 const sp<IPreparedModel>& preparedModel) {
Michael Butler648ada52019-07-25 17:22:11 -0700486 return android::nn::ExecutionBurstController::create(preparedModel,
487 std::chrono::microseconds{0});
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100488}
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100489
Xusong Wange9da9852020-01-13 11:44:45 -0800490void EvaluatePreparedModel(const sp<IDevice>& device, const sp<IPreparedModel>& preparedModel,
491 const TestModel& testModel, const TestConfig& testConfig,
492 bool* skipped = nullptr) {
Lev Proleev9226c1e2019-10-03 14:43:18 +0100493 if (skipped != nullptr) {
494 *skipped = false;
495 }
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100496 // If output0 does not have size larger than one byte, we can not test with insufficient buffer.
Lev Proleev0d4ba3f2019-10-02 17:32:06 +0100497 if (testConfig.outputType == OutputType::INSUFFICIENT &&
498 !isOutputSizeGreaterThanOne(testModel, 0)) {
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100499 return;
500 }
501
Xusong Wange9da9852020-01-13 11:44:45 -0800502 auto [request, buffers] =
503 createRequest(device, preparedModel, testModel,
504 /*preferDeviceMemory=*/testConfig.memoryType == MemoryType::DEVICE);
505 // Skip if testing memory domain but no device memory has been allocated.
506 if (testConfig.memoryType == MemoryType::DEVICE && buffers.empty()) {
507 return;
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100508 }
Xusong Wange9da9852020-01-13 11:44:45 -0800509 if (testConfig.outputType == OutputType::INSUFFICIENT) {
510 makeOutputInsufficientSize(/*outputIndex=*/0, &request);
511 }
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100512
513 ErrorStatus executionStatus;
514 hidl_vec<OutputShape> outputShapes;
515 Timing timing;
Lev Proleev0d4ba3f2019-10-02 17:32:06 +0100516 switch (testConfig.executor) {
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100517 case Executor::ASYNC: {
518 SCOPED_TRACE("asynchronous");
519
520 // launch execution
521 sp<ExecutionCallback> executionCallback = new ExecutionCallback();
Lev Proleev0d4ba3f2019-10-02 17:32:06 +0100522 Return<ErrorStatus> executionLaunchStatus = ExecutePreparedModel(
523 preparedModel, request, testConfig.measureTiming, executionCallback);
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100524 ASSERT_TRUE(executionLaunchStatus.isOk());
525 EXPECT_EQ(ErrorStatus::NONE, static_cast<ErrorStatus>(executionLaunchStatus));
526
527 // retrieve execution status
528 executionCallback->wait();
529 executionStatus = executionCallback->getStatus();
530 outputShapes = executionCallback->getOutputShapes();
531 timing = executionCallback->getTiming();
532
533 break;
534 }
535 case Executor::SYNC: {
536 SCOPED_TRACE("synchronous");
537
538 // execute
Lev Proleev0d4ba3f2019-10-02 17:32:06 +0100539 Return<ErrorStatus> executionReturnStatus = ExecutePreparedModel(
540 preparedModel, request, testConfig.measureTiming, &outputShapes, &timing);
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100541 ASSERT_TRUE(executionReturnStatus.isOk());
542 executionStatus = static_cast<ErrorStatus>(executionReturnStatus);
543
544 break;
545 }
546 case Executor::BURST: {
Xusong Wangb345a462019-11-27 12:46:48 -0800547 // TODO(butlermichael): Check if we need to test burst in V1_3 if the interface remains
548 // V1_2.
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100549 SCOPED_TRACE("burst");
550
Xusong Wange9da9852020-01-13 11:44:45 -0800551 // check compliance
552 ASSERT_TRUE(nn::compliantWithV1_0(request));
553 V1_0::Request request10 = nn::convertToV1_0(request);
554
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100555 // create burst
556 const std::shared_ptr<::android::nn::ExecutionBurstController> controller =
557 CreateBurst(preparedModel);
558 ASSERT_NE(nullptr, controller.get());
559
560 // create memory keys
Xusong Wangb345a462019-11-27 12:46:48 -0800561 std::vector<intptr_t> keys(request10.pools.size());
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100562 for (size_t i = 0; i < keys.size(); ++i) {
Xusong Wangb345a462019-11-27 12:46:48 -0800563 keys[i] = reinterpret_cast<intptr_t>(&request10.pools[i]);
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100564 }
565
566 // execute burst
Michael Butler648ada52019-07-25 17:22:11 -0700567 int n;
568 std::tie(n, outputShapes, timing, std::ignore) =
Xusong Wangb345a462019-11-27 12:46:48 -0800569 controller->compute(request10, testConfig.measureTiming, keys);
Michael Butler648ada52019-07-25 17:22:11 -0700570 executionStatus = nn::convertResultCodeToErrorStatus(n);
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100571
572 break;
573 }
Miao Wang2b5c4cd2019-12-26 18:03:56 -0800574 case Executor::FENCED: {
575 SCOPED_TRACE("fenced");
576 ErrorStatus result;
Miao Wang99753d92020-01-21 13:15:09 -0800577 hidl_handle syncFenceHandle;
578 sp<IFencedExecutionCallback> fencedCallback;
Miao Wang2b5c4cd2019-12-26 18:03:56 -0800579 Return<void> ret = preparedModel->executeFenced(
Miao Wang99753d92020-01-21 13:15:09 -0800580 request, {}, testConfig.measureTiming, {}, {},
581 [&result, &syncFenceHandle, &fencedCallback](
Miao Wang2b5c4cd2019-12-26 18:03:56 -0800582 ErrorStatus error, const hidl_handle& handle,
583 const sp<IFencedExecutionCallback>& callback) {
584 result = error;
Miao Wang99753d92020-01-21 13:15:09 -0800585 syncFenceHandle = handle;
586 fencedCallback = callback;
Miao Wang2b5c4cd2019-12-26 18:03:56 -0800587 });
588 ASSERT_TRUE(ret.isOk());
589 if (result != ErrorStatus::NONE) {
Miao Wang99753d92020-01-21 13:15:09 -0800590 ASSERT_EQ(syncFenceHandle.getNativeHandle(), nullptr);
591 ASSERT_EQ(fencedCallback, nullptr);
Miao Wang2b5c4cd2019-12-26 18:03:56 -0800592 executionStatus = ErrorStatus::GENERAL_FAILURE;
Miao Wang99753d92020-01-21 13:15:09 -0800593 } else if (syncFenceHandle.getNativeHandle()) {
594 waitForSyncFence(syncFenceHandle.getNativeHandle()->data[0]);
Miao Wang2b5c4cd2019-12-26 18:03:56 -0800595 }
596 if (result == ErrorStatus::NONE) {
Miao Wang99753d92020-01-21 13:15:09 -0800597 ASSERT_NE(fencedCallback, nullptr);
598 Return<void> ret = fencedCallback->getExecutionInfo(
599 [&executionStatus, &timing](ErrorStatus error, Timing t, Timing) {
Miao Wang2b5c4cd2019-12-26 18:03:56 -0800600 executionStatus = error;
601 timing = t;
602 });
603 ASSERT_TRUE(ret.isOk());
604 }
605 break;
606 }
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100607 }
608
Miao Wange51e4a92020-01-23 13:53:21 -0800609 // The driver is allowed to reject executeFenced, and if they do, we should skip.
610 if ((testConfig.outputType != OutputType::FULLY_SPECIFIED ||
611 testConfig.executor == Executor::FENCED) &&
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100612 executionStatus == ErrorStatus::GENERAL_FAILURE) {
Lev Proleev9226c1e2019-10-03 14:43:18 +0100613 if (skipped != nullptr) {
614 *skipped = true;
615 }
616 if (!testConfig.reportSkipping) {
617 return;
618 }
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100619 LOG(INFO) << "NN VTS: Early termination of test because vendor service cannot "
620 "execute model that it does not support.";
621 std::cout << "[ ] Early termination of test because vendor service cannot "
622 "execute model that it does not support."
623 << std::endl;
624 GTEST_SKIP();
625 }
Lev Proleev0d4ba3f2019-10-02 17:32:06 +0100626 if (testConfig.measureTiming == MeasureTiming::NO) {
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100627 EXPECT_EQ(UINT64_MAX, timing.timeOnDevice);
628 EXPECT_EQ(UINT64_MAX, timing.timeInDriver);
629 } else {
630 if (timing.timeOnDevice != UINT64_MAX && timing.timeInDriver != UINT64_MAX) {
631 EXPECT_LE(timing.timeOnDevice, timing.timeInDriver);
632 }
633 }
634
Lev Proleev0d4ba3f2019-10-02 17:32:06 +0100635 switch (testConfig.outputType) {
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100636 case OutputType::FULLY_SPECIFIED:
637 // If the model output operands are fully specified, outputShapes must be either
638 // either empty, or have the same number of elements as the number of outputs.
639 ASSERT_EQ(ErrorStatus::NONE, executionStatus);
640 ASSERT_TRUE(outputShapes.size() == 0 ||
641 outputShapes.size() == testModel.outputIndexes.size());
642 break;
643 case OutputType::UNSPECIFIED:
644 // If the model output operands are not fully specified, outputShapes must have
645 // the same number of elements as the number of outputs.
646 ASSERT_EQ(ErrorStatus::NONE, executionStatus);
647 ASSERT_EQ(outputShapes.size(), testModel.outputIndexes.size());
648 break;
649 case OutputType::INSUFFICIENT:
650 ASSERT_EQ(ErrorStatus::OUTPUT_INSUFFICIENT_SIZE, executionStatus);
651 ASSERT_EQ(outputShapes.size(), testModel.outputIndexes.size());
652 ASSERT_FALSE(outputShapes[0].isSufficient);
653 return;
654 }
655
656 // Go through all outputs, check returned output shapes.
657 for (uint32_t i = 0; i < outputShapes.size(); i++) {
658 EXPECT_TRUE(outputShapes[i].isSufficient);
659 const auto& expect = testModel.operands[testModel.outputIndexes[i]].dimensions;
660 const std::vector<uint32_t> actual = outputShapes[i].dimensions;
661 EXPECT_EQ(expect, actual);
662 }
663
664 // Retrieve execution results.
Xusong Wange9da9852020-01-13 11:44:45 -0800665 const std::vector<TestBuffer> outputs = getOutputBuffers(testModel, request, buffers);
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100666
667 // We want "close-enough" results.
668 checkResults(testModel, outputs);
669}
670
Xusong Wange9da9852020-01-13 11:44:45 -0800671void EvaluatePreparedModel(const sp<IDevice>& device, const sp<IPreparedModel>& preparedModel,
672 const TestModel& testModel, TestKind testKind) {
Lev Proleev56cda832019-12-05 14:49:47 +0000673 std::vector<OutputType> outputTypesList;
674 std::vector<MeasureTiming> measureTimingList;
675 std::vector<Executor> executorList;
Xusong Wange9da9852020-01-13 11:44:45 -0800676 MemoryType memoryType = MemoryType::SHARED;
Lev Proleev0d4ba3f2019-10-02 17:32:06 +0100677
Lev Proleev9226c1e2019-10-03 14:43:18 +0100678 switch (testKind) {
679 case TestKind::GENERAL: {
680 outputTypesList = {OutputType::FULLY_SPECIFIED};
681 measureTimingList = {MeasureTiming::NO, MeasureTiming::YES};
Miao Wange51e4a92020-01-23 13:53:21 -0800682 executorList = {Executor::ASYNC, Executor::SYNC, Executor::BURST};
Lev Proleev9226c1e2019-10-03 14:43:18 +0100683 } break;
684 case TestKind::DYNAMIC_SHAPE: {
685 outputTypesList = {OutputType::UNSPECIFIED, OutputType::INSUFFICIENT};
686 measureTimingList = {MeasureTiming::NO, MeasureTiming::YES};
687 executorList = {Executor::ASYNC, Executor::SYNC, Executor::BURST};
688 } break;
Xusong Wange9da9852020-01-13 11:44:45 -0800689 case TestKind::MEMORY_DOMAIN: {
690 outputTypesList = {OutputType::FULLY_SPECIFIED};
691 measureTimingList = {MeasureTiming::NO};
692 executorList = {Executor::ASYNC, Executor::SYNC};
693 memoryType = MemoryType::DEVICE;
694 } break;
Miao Wange51e4a92020-01-23 13:53:21 -0800695 case TestKind::FENCED_COMPUTE: {
696 outputTypesList = {OutputType::FULLY_SPECIFIED};
697 measureTimingList = {MeasureTiming::NO, MeasureTiming::YES};
698 executorList = {Executor::FENCED};
699 } break;
Lev Proleev9226c1e2019-10-03 14:43:18 +0100700 case TestKind::QUANTIZATION_COUPLING: {
701 LOG(FATAL) << "Wrong TestKind for EvaluatePreparedModel";
702 return;
703 } break;
Lev Proleev0d4ba3f2019-10-02 17:32:06 +0100704 }
705
706 for (const OutputType outputType : outputTypesList) {
707 for (const MeasureTiming measureTiming : measureTimingList) {
708 for (const Executor executor : executorList) {
Xusong Wange9da9852020-01-13 11:44:45 -0800709 const TestConfig testConfig(executor, measureTiming, outputType, memoryType);
710 EvaluatePreparedModel(device, preparedModel, testModel, testConfig);
Lev Proleev0d4ba3f2019-10-02 17:32:06 +0100711 }
712 }
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100713 }
714}
715
Xusong Wange9da9852020-01-13 11:44:45 -0800716void EvaluatePreparedCoupledModels(const sp<IDevice>& device,
717 const sp<IPreparedModel>& preparedModel,
Lev Proleev9226c1e2019-10-03 14:43:18 +0100718 const TestModel& testModel,
719 const sp<IPreparedModel>& preparedCoupledModel,
720 const TestModel& coupledModel) {
Lev Proleev56cda832019-12-05 14:49:47 +0000721 const std::vector<OutputType> outputTypesList = {OutputType::FULLY_SPECIFIED};
722 const std::vector<MeasureTiming> measureTimingList = {MeasureTiming::NO, MeasureTiming::YES};
Miao Wang2b5c4cd2019-12-26 18:03:56 -0800723 const std::vector<Executor> executorList = {Executor::ASYNC, Executor::SYNC, Executor::BURST,
724 Executor::FENCED};
Lev Proleev9226c1e2019-10-03 14:43:18 +0100725
726 for (const OutputType outputType : outputTypesList) {
727 for (const MeasureTiming measureTiming : measureTimingList) {
728 for (const Executor executor : executorList) {
Xusong Wange9da9852020-01-13 11:44:45 -0800729 const TestConfig testConfig(executor, measureTiming, outputType, MemoryType::SHARED,
Lev Proleev9226c1e2019-10-03 14:43:18 +0100730 /*reportSkipping=*/false);
731 bool baseSkipped = false;
Xusong Wange9da9852020-01-13 11:44:45 -0800732 EvaluatePreparedModel(device, preparedModel, testModel, testConfig, &baseSkipped);
Lev Proleev9226c1e2019-10-03 14:43:18 +0100733 bool coupledSkipped = false;
Xusong Wange9da9852020-01-13 11:44:45 -0800734 EvaluatePreparedModel(device, preparedCoupledModel, coupledModel, testConfig,
Lev Proleev9226c1e2019-10-03 14:43:18 +0100735 &coupledSkipped);
736 ASSERT_EQ(baseSkipped, coupledSkipped);
737 if (baseSkipped) {
738 LOG(INFO) << "NN VTS: Early termination of test because vendor service cannot "
739 "execute model that it does not support.";
740 std::cout << "[ ] Early termination of test because vendor service "
741 "cannot "
742 "execute model that it does not support."
743 << std::endl;
744 GTEST_SKIP();
745 }
746 }
747 }
748 }
749}
750
751void Execute(const sp<IDevice>& device, const TestModel& testModel, TestKind testKind) {
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100752 Model model = createModel(testModel);
Lev Proleev9226c1e2019-10-03 14:43:18 +0100753 if (testKind == TestKind::DYNAMIC_SHAPE) {
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100754 makeOutputDimensionsUnspecified(&model);
755 }
756
757 sp<IPreparedModel> preparedModel;
Lev Proleev9226c1e2019-10-03 14:43:18 +0100758 switch (testKind) {
Xusong Wange9da9852020-01-13 11:44:45 -0800759 case TestKind::GENERAL:
760 case TestKind::DYNAMIC_SHAPE:
Miao Wange51e4a92020-01-23 13:53:21 -0800761 case TestKind::MEMORY_DOMAIN:
762 case TestKind::FENCED_COMPUTE: {
Lev Proleev9226c1e2019-10-03 14:43:18 +0100763 createPreparedModel(device, model, &preparedModel);
764 if (preparedModel == nullptr) return;
Xusong Wange9da9852020-01-13 11:44:45 -0800765 EvaluatePreparedModel(device, preparedModel, testModel, testKind);
Lev Proleev9226c1e2019-10-03 14:43:18 +0100766 } break;
767 case TestKind::QUANTIZATION_COUPLING: {
Lev Proleev673fdcf2020-01-02 18:22:30 +0000768 ASSERT_TRUE(testModel.hasQuant8CoupledOperands());
Michael Butler95899b32020-01-07 14:52:44 -0800769 createPreparedModel(device, model, &preparedModel,
770 /*reportSkipping*/ false);
Lev Proleev9226c1e2019-10-03 14:43:18 +0100771 TestModel signedQuantizedModel = convertQuant8AsymmOperandsToSigned(testModel);
772 sp<IPreparedModel> preparedCoupledModel;
773 createPreparedModel(device, createModel(signedQuantizedModel), &preparedCoupledModel,
774 /*reportSkipping*/ false);
775 // If we couldn't prepare a model with unsigned quantization, we must
776 // fail to prepare a model with signed quantization as well.
777 if (preparedModel == nullptr) {
778 ASSERT_EQ(preparedCoupledModel, nullptr);
779 // If we failed to prepare both of the models, we can safely skip
780 // the test.
781 LOG(INFO) << "NN VTS: Early termination of test because vendor service cannot "
782 "prepare model that it does not support.";
783 std::cout
784 << "[ ] Early termination of test because vendor service cannot "
785 "prepare model that it does not support."
786 << std::endl;
787 GTEST_SKIP();
788 }
789 ASSERT_NE(preparedCoupledModel, nullptr);
Xusong Wange9da9852020-01-13 11:44:45 -0800790 EvaluatePreparedCoupledModels(device, preparedModel, testModel, preparedCoupledModel,
Lev Proleev9226c1e2019-10-03 14:43:18 +0100791 signedQuantizedModel);
792 } break;
793 }
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100794}
795
796void GeneratedTestBase::SetUp() {
797 testing::TestWithParam<GeneratedTestParam>::SetUp();
798 ASSERT_NE(kDevice, nullptr);
Michael Butler95899b32020-01-07 14:52:44 -0800799
800 const Return<void> ret =
801 kDevice->supportsDeadlines([this](bool prepareModelDeadline, bool executionDeadline) {
802 mSupportsDeadlines = {prepareModelDeadline, executionDeadline};
803 });
804 ASSERT_TRUE(ret.isOk());
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100805}
806
807std::vector<NamedModel> getNamedModels(const FilterFn& filter) {
808 return TestModelManager::get().getTestModels(filter);
809}
810
811std::string printGeneratedTest(const testing::TestParamInfo<GeneratedTestParam>& info) {
812 const auto& [namedDevice, namedModel] = info.param;
813 return gtestCompliantName(getName(namedDevice) + "_" + getName(namedModel));
814}
815
816// Tag for the generated tests
817class GeneratedTest : public GeneratedTestBase {};
818
819// Tag for the dynamic output shape tests
820class DynamicOutputShapeTest : public GeneratedTest {};
821
Xusong Wange9da9852020-01-13 11:44:45 -0800822// Tag for the memory domain tests
823class MemoryDomainTest : public GeneratedTest {};
824
Miao Wange51e4a92020-01-23 13:53:21 -0800825// Tag for the fenced compute tests
826class FencedComputeTest : public GeneratedTest {};
827
Lev Proleev9226c1e2019-10-03 14:43:18 +0100828// Tag for the dynamic output shape tests
Lev Proleev3c68b342020-01-09 16:37:28 +0000829class QuantizationCouplingTest : public GeneratedTest {};
Lev Proleev9226c1e2019-10-03 14:43:18 +0100830
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100831TEST_P(GeneratedTest, Test) {
Lev Proleev9226c1e2019-10-03 14:43:18 +0100832 Execute(kDevice, kTestModel, /*testKind=*/TestKind::GENERAL);
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100833}
834
835TEST_P(DynamicOutputShapeTest, Test) {
Lev Proleev9226c1e2019-10-03 14:43:18 +0100836 Execute(kDevice, kTestModel, /*testKind=*/TestKind::DYNAMIC_SHAPE);
837}
838
Xusong Wange9da9852020-01-13 11:44:45 -0800839TEST_P(MemoryDomainTest, Test) {
840 Execute(kDevice, kTestModel, /*testKind=*/TestKind::MEMORY_DOMAIN);
841}
842
Miao Wange51e4a92020-01-23 13:53:21 -0800843TEST_P(FencedComputeTest, Test) {
844 Execute(kDevice, kTestModel, /*testKind=*/TestKind::FENCED_COMPUTE);
845}
846
Lev Proleev3c68b342020-01-09 16:37:28 +0000847TEST_P(QuantizationCouplingTest, Test) {
Lev Proleev9226c1e2019-10-03 14:43:18 +0100848 Execute(kDevice, kTestModel, /*testKind=*/TestKind::QUANTIZATION_COUPLING);
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100849}
850
851INSTANTIATE_GENERATED_TEST(GeneratedTest,
852 [](const TestModel& testModel) { return !testModel.expectFailure; });
853
Lev Proleev53a51cb2020-01-20 18:54:46 +0000854INSTANTIATE_GENERATED_TEST(DynamicOutputShapeTest, [](const TestModel& testModel) {
855 return !testModel.expectFailure && !testModel.hasScalarOutputs();
856});
Lev Proleev13fdfcd2019-08-30 11:35:34 +0100857
Xusong Wange9da9852020-01-13 11:44:45 -0800858INSTANTIATE_GENERATED_TEST(MemoryDomainTest,
859 [](const TestModel& testModel) { return !testModel.expectFailure; });
860
Miao Wange51e4a92020-01-23 13:53:21 -0800861INSTANTIATE_GENERATED_TEST(FencedComputeTest,
862 [](const TestModel& testModel) { return !testModel.expectFailure; });
863
Lev Proleev3c68b342020-01-09 16:37:28 +0000864INSTANTIATE_GENERATED_TEST(QuantizationCouplingTest, [](const TestModel& testModel) {
Lev Proleev673fdcf2020-01-02 18:22:30 +0000865 return testModel.hasQuant8CoupledOperands() && testModel.operations.size() == 1;
Lev Proleev9226c1e2019-10-03 14:43:18 +0100866});
867
Lev Proleev26d1bc82019-08-30 11:57:18 +0100868} // namespace android::hardware::neuralnetworks::V1_3::vts::functional