I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
Xusong Wang | 3405878 | 2019-01-18 17:28:26 -0800 | [diff] [blame^] | 17 | #include "GeneratedTestHarness.h" |
Michael Butler | cf22a57 | 2017-09-22 13:26:12 -0700 | [diff] [blame] | 18 | #include "Callbacks.h" |
Michael Butler | 814d837 | 2019-01-15 11:02:55 -0800 | [diff] [blame] | 19 | #include "ExecutionBurstController.h" |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 20 | #include "TestHarness.h" |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 21 | #include "Utils.h" |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 22 | |
| 23 | #include <android-base/logging.h> |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 24 | #include <android/hardware/neuralnetworks/1.0/IDevice.h> |
| 25 | #include <android/hardware/neuralnetworks/1.0/IExecutionCallback.h> |
| 26 | #include <android/hardware/neuralnetworks/1.0/IPreparedModel.h> |
| 27 | #include <android/hardware/neuralnetworks/1.0/IPreparedModelCallback.h> |
| 28 | #include <android/hardware/neuralnetworks/1.0/types.h> |
Xusong Wang | b5cb8f7 | 2018-10-31 08:43:12 -0700 | [diff] [blame] | 29 | #include <android/hardware/neuralnetworks/1.1/IDevice.h> |
| 30 | #include <android/hardware/neuralnetworks/1.2/IDevice.h> |
| 31 | #include <android/hardware/neuralnetworks/1.2/IExecutionCallback.h> |
| 32 | #include <android/hardware/neuralnetworks/1.2/IPreparedModel.h> |
| 33 | #include <android/hardware/neuralnetworks/1.2/IPreparedModelCallback.h> |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 34 | #include <android/hidl/allocator/1.0/IAllocator.h> |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 35 | #include <android/hidl/memory/1.0/IMemory.h> |
| 36 | #include <hidlmemory/mapping.h> |
Michael Butler | 0897ab3 | 2017-10-04 02:38:42 -0700 | [diff] [blame] | 37 | #include <iostream> |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 38 | |
| 39 | namespace android { |
| 40 | namespace hardware { |
| 41 | namespace neuralnetworks { |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 42 | |
| 43 | namespace generated_tests { |
Xusong Wang | b5cb8f7 | 2018-10-31 08:43:12 -0700 | [diff] [blame] | 44 | using ::android::hardware::neuralnetworks::V1_2::implementation::ExecutionCallback; |
| 45 | using ::android::hardware::neuralnetworks::V1_2::implementation::PreparedModelCallback; |
Slava Shklyaev | 9e3fad1 | 2018-11-30 17:55:12 +0000 | [diff] [blame] | 46 | using ::test_helper::bool8; |
Michael K. Sanders | 941d61a | 2018-10-19 14:39:09 +0100 | [diff] [blame] | 47 | using ::test_helper::compare; |
| 48 | using ::test_helper::expectMultinomialDistributionWithinTolerance; |
Mika Raento | de16694 | 2018-04-17 16:49:50 +0100 | [diff] [blame] | 49 | using ::test_helper::filter; |
| 50 | using ::test_helper::for_all; |
| 51 | using ::test_helper::for_each; |
Michael K. Sanders | 941d61a | 2018-10-19 14:39:09 +0100 | [diff] [blame] | 52 | using ::test_helper::MixedTyped; |
| 53 | using ::test_helper::MixedTypedExample; |
Michael K. Sanders | 941d61a | 2018-10-19 14:39:09 +0100 | [diff] [blame] | 54 | using ::test_helper::resize_accordingly; |
I-Jui (Ray) Sung | f6b8550 | 2017-09-20 13:45:50 -0700 | [diff] [blame] | 55 | |
I-Jui (Ray) Sung | 5bf4edf | 2017-10-06 13:22:39 -0700 | [diff] [blame] | 56 | template <typename T> |
Xusong Wang | a316581 | 2018-11-19 18:26:08 -0800 | [diff] [blame] | 57 | void copy_back_(std::map<int, std::vector<T>>* dst, const std::vector<RequestArgument>& ra, |
| 58 | char* src) { |
| 59 | for_each<T>(*dst, [&ra, src](int index, std::vector<T>& m) { |
I-Jui (Ray) Sung | 5bf4edf | 2017-10-06 13:22:39 -0700 | [diff] [blame] | 60 | ASSERT_EQ(m.size(), ra[index].location.length / sizeof(T)); |
I-Jui (Ray) Sung | f6b8550 | 2017-09-20 13:45:50 -0700 | [diff] [blame] | 61 | char* begin = src + ra[index].location.offset; |
| 62 | memcpy(m.data(), begin, ra[index].location.length); |
| 63 | }); |
| 64 | } |
| 65 | |
| 66 | void copy_back(MixedTyped* dst, const std::vector<RequestArgument>& ra, char* src) { |
Xusong Wang | a316581 | 2018-11-19 18:26:08 -0800 | [diff] [blame] | 67 | copy_back_(&dst->float32Operands, ra, src); |
| 68 | copy_back_(&dst->int32Operands, ra, src); |
Xusong Wang | d49f665 | 2019-01-16 18:32:24 -0800 | [diff] [blame] | 69 | copy_back_(&dst->quant8AsymmOperands, ra, src); |
| 70 | copy_back_(&dst->quant16SymmOperands, ra, src); |
Xusong Wang | a316581 | 2018-11-19 18:26:08 -0800 | [diff] [blame] | 71 | copy_back_(&dst->float16Operands, ra, src); |
| 72 | copy_back_(&dst->bool8Operands, ra, src); |
| 73 | copy_back_(&dst->quant8ChannelOperands, ra, src); |
Xusong Wang | d49f665 | 2019-01-16 18:32:24 -0800 | [diff] [blame] | 74 | copy_back_(&dst->quant16AsymmOperands, ra, src); |
| 75 | static_assert(8 == MixedTyped::kNumTypes, |
Lev Proleev | 9b490f4 | 2018-11-02 12:44:11 +0000 | [diff] [blame] | 76 | "Number of types in MixedTyped changed, but copy_back function wasn't updated"); |
I-Jui (Ray) Sung | f6b8550 | 2017-09-20 13:45:50 -0700 | [diff] [blame] | 77 | } |
| 78 | |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 79 | // Top level driver for models and examples generated by test_generator.py |
| 80 | // Test driver for those generated from ml/nn/runtime/test/spec |
Xusong Wang | b5cb8f7 | 2018-10-31 08:43:12 -0700 | [diff] [blame] | 81 | static Return<ErrorStatus> ExecutePreparedModel(sp<V1_0::IPreparedModel>& preparedModel, |
David Gross | e301349 | 2019-01-23 14:01:52 -0800 | [diff] [blame] | 82 | const Request& request, MeasureTiming, |
Xusong Wang | b5cb8f7 | 2018-10-31 08:43:12 -0700 | [diff] [blame] | 83 | sp<ExecutionCallback>& callback) { |
| 84 | return preparedModel->execute(request, callback); |
| 85 | } |
| 86 | static Return<ErrorStatus> ExecutePreparedModel(sp<V1_2::IPreparedModel>& preparedModel, |
David Gross | e301349 | 2019-01-23 14:01:52 -0800 | [diff] [blame] | 87 | const Request& request, MeasureTiming measure, |
Xusong Wang | b5cb8f7 | 2018-10-31 08:43:12 -0700 | [diff] [blame] | 88 | sp<ExecutionCallback>& callback) { |
David Gross | e301349 | 2019-01-23 14:01:52 -0800 | [diff] [blame] | 89 | return preparedModel->execute_1_2(request, measure, callback); |
Xusong Wang | b5cb8f7 | 2018-10-31 08:43:12 -0700 | [diff] [blame] | 90 | } |
Xusong Wang | 187c597 | 2018-11-07 09:33:59 -0800 | [diff] [blame] | 91 | static Return<ErrorStatus> ExecutePreparedModel(sp<V1_0::IPreparedModel>&, const Request&, |
David Gross | e301349 | 2019-01-23 14:01:52 -0800 | [diff] [blame] | 92 | MeasureTiming, hidl_vec<OutputShape>*, Timing*) { |
David Gross | 49e4167 | 2018-12-21 11:20:26 -0800 | [diff] [blame] | 93 | ADD_FAILURE() << "asking for synchronous execution at V1_0"; |
| 94 | return ErrorStatus::GENERAL_FAILURE; |
| 95 | } |
| 96 | static Return<ErrorStatus> ExecutePreparedModel(sp<V1_2::IPreparedModel>& preparedModel, |
David Gross | e301349 | 2019-01-23 14:01:52 -0800 | [diff] [blame] | 97 | const Request& request, MeasureTiming measure, |
| 98 | hidl_vec<OutputShape>* outputShapes, |
| 99 | Timing* timing) { |
Xusong Wang | 187c597 | 2018-11-07 09:33:59 -0800 | [diff] [blame] | 100 | ErrorStatus result; |
| 101 | Return<void> ret = preparedModel->executeSynchronously( |
David Gross | e301349 | 2019-01-23 14:01:52 -0800 | [diff] [blame] | 102 | request, measure, |
| 103 | [&result, outputShapes, timing](ErrorStatus error, const hidl_vec<OutputShape>& shapes, |
| 104 | const Timing& time) { |
| 105 | result = error; |
| 106 | *outputShapes = shapes; |
| 107 | *timing = time; |
| 108 | }); |
Xusong Wang | 187c597 | 2018-11-07 09:33:59 -0800 | [diff] [blame] | 109 | if (!ret.isOk()) { |
| 110 | return ErrorStatus::GENERAL_FAILURE; |
| 111 | } |
| 112 | return result; |
David Gross | 49e4167 | 2018-12-21 11:20:26 -0800 | [diff] [blame] | 113 | } |
Michael Butler | 814d837 | 2019-01-15 11:02:55 -0800 | [diff] [blame] | 114 | static std::unique_ptr<::android::nn::ExecutionBurstController> CreateBurst( |
| 115 | const sp<V1_0::IPreparedModel>&) { |
| 116 | ADD_FAILURE() << "asking for burst execution at V1_0"; |
| 117 | return nullptr; |
| 118 | } |
| 119 | static std::unique_ptr<::android::nn::ExecutionBurstController> CreateBurst( |
| 120 | const sp<V1_2::IPreparedModel>& preparedModel) { |
| 121 | return ::android::nn::createExecutionBurstController(preparedModel, /*blocking=*/true); |
| 122 | } |
| 123 | enum class Executor { ASYNC, SYNC, BURST }; |
Xusong Wang | 929fd21 | 2019-01-27 23:08:12 -0800 | [diff] [blame] | 124 | enum class OutputType { FULLY_SPECIFIED, UNSPECIFIED, INSUFFICIENT }; |
David Gross | 49e4167 | 2018-12-21 11:20:26 -0800 | [diff] [blame] | 125 | const float kDefaultAtol = 1e-5f; |
| 126 | const float kDefaultRtol = 1e-5f; |
Xusong Wang | b5cb8f7 | 2018-10-31 08:43:12 -0700 | [diff] [blame] | 127 | template <typename T_IPreparedModel> |
| 128 | void EvaluatePreparedModel(sp<T_IPreparedModel>& preparedModel, std::function<bool(int)> is_ignored, |
Michael K. Sanders | efa4c81 | 2018-10-30 14:44:48 +0000 | [diff] [blame] | 129 | const std::vector<MixedTypedExample>& examples, |
David Gross | e301349 | 2019-01-23 14:01:52 -0800 | [diff] [blame] | 130 | bool hasRelaxedFloat32Model, float fpAtol, float fpRtol, |
Xusong Wang | 929fd21 | 2019-01-27 23:08:12 -0800 | [diff] [blame] | 131 | Executor executor, MeasureTiming measure, OutputType outputType) { |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 132 | const uint32_t INPUT = 0; |
| 133 | const uint32_t OUTPUT = 1; |
| 134 | |
| 135 | int example_no = 1; |
| 136 | for (auto& example : examples) { |
| 137 | SCOPED_TRACE(example_no++); |
Michael K. Sanders | 941d61a | 2018-10-19 14:39:09 +0100 | [diff] [blame] | 138 | const MixedTyped& inputs = example.operands.first; |
| 139 | const MixedTyped& golden = example.operands.second; |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 140 | |
Xusong Wang | a316581 | 2018-11-19 18:26:08 -0800 | [diff] [blame] | 141 | const bool hasFloat16Inputs = !inputs.float16Operands.empty(); |
Michael K. Sanders | efa4c81 | 2018-10-30 14:44:48 +0000 | [diff] [blame] | 142 | if (hasRelaxedFloat32Model || hasFloat16Inputs) { |
| 143 | // TODO: Adjust the error limit based on testing. |
| 144 | // If in relaxed mode, set the absolute tolerance to be 5ULP of FP16. |
| 145 | fpAtol = 5.0f * 0.0009765625f; |
| 146 | // Set the relative tolerance to be 5ULP of the corresponding FP precision. |
| 147 | fpRtol = 5.0f * 0.0009765625f; |
| 148 | } |
| 149 | |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 150 | std::vector<RequestArgument> inputs_info, outputs_info; |
| 151 | uint32_t inputSize = 0, outputSize = 0; |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 152 | // This function only partially specifies the metadata (vector of RequestArguments). |
| 153 | // The contents are copied over below. |
| 154 | for_all(inputs, [&inputs_info, &inputSize](int index, auto, auto s) { |
| 155 | if (inputs_info.size() <= static_cast<size_t>(index)) inputs_info.resize(index + 1); |
| 156 | RequestArgument arg = { |
| 157 | .location = {.poolIndex = INPUT, .offset = 0, .length = static_cast<uint32_t>(s)}, |
| 158 | .dimensions = {}, |
| 159 | }; |
I-Jui (Ray) Sung | 959cd78 | 2017-10-04 20:49:57 -0700 | [diff] [blame] | 160 | RequestArgument arg_empty = { |
| 161 | .hasNoValue = true, |
| 162 | }; |
| 163 | inputs_info[index] = s ? arg : arg_empty; |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 164 | inputSize += s; |
| 165 | }); |
| 166 | // Compute offset for inputs 1 and so on |
| 167 | { |
| 168 | size_t offset = 0; |
| 169 | for (auto& i : inputs_info) { |
I-Jui (Ray) Sung | 959cd78 | 2017-10-04 20:49:57 -0700 | [diff] [blame] | 170 | if (!i.hasNoValue) i.location.offset = offset; |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 171 | offset += i.location.length; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | MixedTyped test; // holding test results |
| 176 | |
| 177 | // Go through all outputs, initialize RequestArgument descriptors |
I-Jui (Ray) Sung | f6b8550 | 2017-09-20 13:45:50 -0700 | [diff] [blame] | 178 | resize_accordingly(golden, test); |
Xusong Wang | 929fd21 | 2019-01-27 23:08:12 -0800 | [diff] [blame] | 179 | bool sizeLargerThanOne = true; |
| 180 | for_all(golden, [&outputs_info, &outputSize, &outputType, &sizeLargerThanOne]( |
| 181 | int index, auto, auto s) { |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 182 | if (outputs_info.size() <= static_cast<size_t>(index)) outputs_info.resize(index + 1); |
Xusong Wang | 929fd21 | 2019-01-27 23:08:12 -0800 | [diff] [blame] | 183 | if (index == 0) { |
| 184 | // On OutputType::INSUFFICIENT, set the output operand with index 0 with |
| 185 | // buffer size one byte less than needed. |
| 186 | if (outputType == OutputType::INSUFFICIENT) { |
| 187 | if (s > 1) |
| 188 | s -= 1; |
| 189 | else |
| 190 | sizeLargerThanOne = false; |
| 191 | } |
| 192 | } |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 193 | RequestArgument arg = { |
| 194 | .location = {.poolIndex = OUTPUT, .offset = 0, .length = static_cast<uint32_t>(s)}, |
| 195 | .dimensions = {}, |
| 196 | }; |
| 197 | outputs_info[index] = arg; |
| 198 | outputSize += s; |
| 199 | }); |
Xusong Wang | 929fd21 | 2019-01-27 23:08:12 -0800 | [diff] [blame] | 200 | // If output0 does not have size larger than one byte, |
| 201 | // we can not provide an insufficient buffer |
| 202 | if (!sizeLargerThanOne && outputType == OutputType::INSUFFICIENT) return; |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 203 | // Compute offset for outputs 1 and so on |
| 204 | { |
| 205 | size_t offset = 0; |
| 206 | for (auto& i : outputs_info) { |
| 207 | i.location.offset = offset; |
| 208 | offset += i.location.length; |
| 209 | } |
| 210 | } |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 211 | std::vector<hidl_memory> pools = {nn::allocateSharedMemory(inputSize), |
| 212 | nn::allocateSharedMemory(outputSize)}; |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 213 | ASSERT_NE(0ull, pools[INPUT].size()); |
| 214 | ASSERT_NE(0ull, pools[OUTPUT].size()); |
| 215 | |
| 216 | // load data |
| 217 | sp<IMemory> inputMemory = mapMemory(pools[INPUT]); |
| 218 | sp<IMemory> outputMemory = mapMemory(pools[OUTPUT]); |
| 219 | ASSERT_NE(nullptr, inputMemory.get()); |
| 220 | ASSERT_NE(nullptr, outputMemory.get()); |
| 221 | char* inputPtr = reinterpret_cast<char*>(static_cast<void*>(inputMemory->getPointer())); |
| 222 | char* outputPtr = reinterpret_cast<char*>(static_cast<void*>(outputMemory->getPointer())); |
| 223 | ASSERT_NE(nullptr, inputPtr); |
| 224 | ASSERT_NE(nullptr, outputPtr); |
| 225 | inputMemory->update(); |
| 226 | outputMemory->update(); |
| 227 | |
| 228 | // Go through all inputs, copy the values |
| 229 | for_all(inputs, [&inputs_info, inputPtr](int index, auto p, auto s) { |
| 230 | char* begin = (char*)p; |
| 231 | char* end = begin + s; |
| 232 | // TODO: handle more than one input |
| 233 | std::copy(begin, end, inputPtr + inputs_info[index].location.offset); |
| 234 | }); |
| 235 | |
| 236 | inputMemory->commit(); |
| 237 | outputMemory->commit(); |
Michael Butler | cf22a57 | 2017-09-22 13:26:12 -0700 | [diff] [blame] | 238 | |
Michael Butler | 814d837 | 2019-01-15 11:02:55 -0800 | [diff] [blame] | 239 | const Request request = {.inputs = inputs_info, .outputs = outputs_info, .pools = pools}; |
| 240 | |
Xusong Wang | 187c597 | 2018-11-07 09:33:59 -0800 | [diff] [blame] | 241 | ErrorStatus executionStatus; |
| 242 | hidl_vec<OutputShape> outputShapes; |
David Gross | e301349 | 2019-01-23 14:01:52 -0800 | [diff] [blame] | 243 | Timing timing; |
Michael Butler | 814d837 | 2019-01-15 11:02:55 -0800 | [diff] [blame] | 244 | switch (executor) { |
| 245 | case Executor::ASYNC: { |
| 246 | SCOPED_TRACE("asynchronous"); |
Michael Butler | cf22a57 | 2017-09-22 13:26:12 -0700 | [diff] [blame] | 247 | |
Michael Butler | 814d837 | 2019-01-15 11:02:55 -0800 | [diff] [blame] | 248 | // launch execution |
| 249 | sp<ExecutionCallback> executionCallback = new ExecutionCallback(); |
| 250 | ASSERT_NE(nullptr, executionCallback.get()); |
| 251 | Return<ErrorStatus> executionLaunchStatus = |
| 252 | ExecutePreparedModel(preparedModel, request, measure, executionCallback); |
| 253 | ASSERT_TRUE(executionLaunchStatus.isOk()); |
| 254 | EXPECT_EQ(ErrorStatus::NONE, static_cast<ErrorStatus>(executionLaunchStatus)); |
David Gross | 49e4167 | 2018-12-21 11:20:26 -0800 | [diff] [blame] | 255 | |
Michael Butler | 814d837 | 2019-01-15 11:02:55 -0800 | [diff] [blame] | 256 | // retrieve execution status |
| 257 | executionCallback->wait(); |
| 258 | executionStatus = executionCallback->getStatus(); |
| 259 | outputShapes = executionCallback->getOutputShapes(); |
| 260 | timing = executionCallback->getTiming(); |
David Gross | 49e4167 | 2018-12-21 11:20:26 -0800 | [diff] [blame] | 261 | |
Michael Butler | 814d837 | 2019-01-15 11:02:55 -0800 | [diff] [blame] | 262 | break; |
| 263 | } |
| 264 | case Executor::SYNC: { |
| 265 | SCOPED_TRACE("synchronous"); |
| 266 | |
| 267 | // execute |
| 268 | Return<ErrorStatus> executionReturnStatus = ExecutePreparedModel( |
| 269 | preparedModel, request, measure, &outputShapes, &timing); |
| 270 | ASSERT_TRUE(executionReturnStatus.isOk()); |
| 271 | executionStatus = static_cast<ErrorStatus>(executionReturnStatus); |
| 272 | |
| 273 | break; |
| 274 | } |
| 275 | case Executor::BURST: { |
| 276 | SCOPED_TRACE("burst"); |
| 277 | |
| 278 | // create burst |
| 279 | const std::unique_ptr<::android::nn::ExecutionBurstController> controller = |
| 280 | CreateBurst(preparedModel); |
| 281 | ASSERT_NE(nullptr, controller.get()); |
| 282 | |
| 283 | // create memory keys |
| 284 | std::vector<intptr_t> keys(request.pools.size()); |
| 285 | for (size_t i = 0; i < keys.size(); ++i) { |
| 286 | keys[i] = reinterpret_cast<intptr_t>(&request.pools[i]); |
| 287 | } |
| 288 | |
| 289 | // execute burst |
| 290 | std::tie(executionStatus, outputShapes, timing) = |
| 291 | controller->compute(request, measure, keys); |
| 292 | |
| 293 | break; |
| 294 | } |
David Gross | 49e4167 | 2018-12-21 11:20:26 -0800 | [diff] [blame] | 295 | } |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 296 | |
Xusong Wang | 929fd21 | 2019-01-27 23:08:12 -0800 | [diff] [blame] | 297 | if (outputType != OutputType::FULLY_SPECIFIED && |
| 298 | executionStatus == ErrorStatus::GENERAL_FAILURE) { |
Xusong Wang | a316581 | 2018-11-19 18:26:08 -0800 | [diff] [blame] | 299 | LOG(INFO) << "NN VTS: Early termination of test because vendor service cannot " |
| 300 | "execute model that it does not support."; |
| 301 | std::cout << "[ ] Early termination of test because vendor service cannot " |
| 302 | "execute model that it does not support." |
| 303 | << std::endl; |
Xusong Wang | 929fd21 | 2019-01-27 23:08:12 -0800 | [diff] [blame] | 304 | GTEST_SKIP(); |
Xusong Wang | a316581 | 2018-11-19 18:26:08 -0800 | [diff] [blame] | 305 | } |
David Gross | e301349 | 2019-01-23 14:01:52 -0800 | [diff] [blame] | 306 | if (measure == MeasureTiming::NO) { |
| 307 | EXPECT_EQ(UINT64_MAX, timing.timeOnDevice); |
| 308 | EXPECT_EQ(UINT64_MAX, timing.timeInDriver); |
| 309 | } else { |
| 310 | if (timing.timeOnDevice != UINT64_MAX && timing.timeInDriver != UINT64_MAX) { |
| 311 | EXPECT_LE(timing.timeOnDevice, timing.timeInDriver); |
| 312 | } |
| 313 | } |
Xusong Wang | a316581 | 2018-11-19 18:26:08 -0800 | [diff] [blame] | 314 | |
Xusong Wang | 929fd21 | 2019-01-27 23:08:12 -0800 | [diff] [blame] | 315 | switch (outputType) { |
| 316 | case OutputType::FULLY_SPECIFIED: |
| 317 | // If the model output operands are fully specified, outputShapes must be either |
| 318 | // either empty, or have the same number of elements as the number of outputs. |
| 319 | ASSERT_EQ(ErrorStatus::NONE, executionStatus); |
| 320 | ASSERT_TRUE(outputShapes.size() == 0 || |
| 321 | outputShapes.size() == test.operandDimensions.size()); |
| 322 | break; |
| 323 | case OutputType::UNSPECIFIED: |
| 324 | // If the model output operands are not fully specified, outputShapes must have |
| 325 | // the same number of elements as the number of outputs. |
| 326 | ASSERT_EQ(ErrorStatus::NONE, executionStatus); |
| 327 | ASSERT_EQ(outputShapes.size(), test.operandDimensions.size()); |
| 328 | break; |
| 329 | case OutputType::INSUFFICIENT: |
| 330 | ASSERT_EQ(ErrorStatus::OUTPUT_INSUFFICIENT_SIZE, executionStatus); |
| 331 | ASSERT_EQ(outputShapes.size(), test.operandDimensions.size()); |
| 332 | ASSERT_FALSE(outputShapes[0].isSufficient); |
| 333 | return; |
| 334 | } |
Xusong Wang | a316581 | 2018-11-19 18:26:08 -0800 | [diff] [blame] | 335 | // Go through all outputs, overwrite output dimensions with returned output shapes |
Xusong Wang | 929fd21 | 2019-01-27 23:08:12 -0800 | [diff] [blame] | 336 | if (outputShapes.size() > 0) { |
Xusong Wang | a316581 | 2018-11-19 18:26:08 -0800 | [diff] [blame] | 337 | for_each<uint32_t>(test.operandDimensions, |
| 338 | [&outputShapes](int idx, std::vector<uint32_t>& dim) { |
| 339 | dim = outputShapes[idx].dimensions; |
| 340 | }); |
| 341 | } |
Xusong Wang | 187c597 | 2018-11-07 09:33:59 -0800 | [diff] [blame] | 342 | |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 343 | // validate results |
| 344 | outputMemory->read(); |
I-Jui (Ray) Sung | f6b8550 | 2017-09-20 13:45:50 -0700 | [diff] [blame] | 345 | copy_back(&test, outputs_info, outputPtr); |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 346 | outputMemory->commit(); |
I-Jui (Ray) Sung | 7d765bd | 2017-09-13 18:47:12 -0700 | [diff] [blame] | 347 | // Filter out don't cares |
I-Jui (Ray) Sung | 5bf4edf | 2017-10-06 13:22:39 -0700 | [diff] [blame] | 348 | MixedTyped filtered_golden = filter(golden, is_ignored); |
| 349 | MixedTyped filtered_test = filter(test, is_ignored); |
I-Jui (Ray) Sung | 7d765bd | 2017-09-13 18:47:12 -0700 | [diff] [blame] | 350 | |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 351 | // We want "close-enough" results for float |
Xusong Wang | 10d77e4 | 2018-08-28 16:50:01 -0700 | [diff] [blame] | 352 | compare(filtered_golden, filtered_test, fpAtol, fpRtol); |
Michael K. Sanders | 941d61a | 2018-10-19 14:39:09 +0100 | [diff] [blame] | 353 | |
| 354 | if (example.expectedMultinomialDistributionTolerance > 0) { |
| 355 | expectMultinomialDistributionWithinTolerance(test, example); |
| 356 | } |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 357 | } |
| 358 | } |
David Gross | 49e4167 | 2018-12-21 11:20:26 -0800 | [diff] [blame] | 359 | template <typename T_IPreparedModel> |
| 360 | void EvaluatePreparedModel(sp<T_IPreparedModel>& preparedModel, std::function<bool(int)> is_ignored, |
| 361 | const std::vector<MixedTypedExample>& examples, |
Michael Butler | 814d837 | 2019-01-15 11:02:55 -0800 | [diff] [blame] | 362 | bool hasRelaxedFloat32Model, Executor executor, MeasureTiming measure, |
Xusong Wang | 929fd21 | 2019-01-27 23:08:12 -0800 | [diff] [blame] | 363 | OutputType outputType) { |
David Gross | 49e4167 | 2018-12-21 11:20:26 -0800 | [diff] [blame] | 364 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, kDefaultAtol, |
Xusong Wang | 929fd21 | 2019-01-27 23:08:12 -0800 | [diff] [blame] | 365 | kDefaultRtol, executor, measure, outputType); |
David Gross | 49e4167 | 2018-12-21 11:20:26 -0800 | [diff] [blame] | 366 | } |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 367 | |
Xusong Wang | 3405878 | 2019-01-18 17:28:26 -0800 | [diff] [blame^] | 368 | void EvaluatePreparedModel(sp<V1_2::IPreparedModel>& preparedModel, |
| 369 | std::function<bool(int)> is_ignored, |
| 370 | const std::vector<MixedTypedExample>& examples, |
| 371 | bool hasRelaxedFloat32Model, bool testDynamicOutputShape) { |
| 372 | if (testDynamicOutputShape) { |
| 373 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 374 | Executor::ASYNC, MeasureTiming::NO, OutputType::UNSPECIFIED); |
| 375 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 376 | Executor::SYNC, MeasureTiming::NO, OutputType::UNSPECIFIED); |
| 377 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 378 | Executor::BURST, MeasureTiming::NO, OutputType::UNSPECIFIED); |
| 379 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 380 | Executor::ASYNC, MeasureTiming::YES, OutputType::UNSPECIFIED); |
| 381 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 382 | Executor::SYNC, MeasureTiming::YES, OutputType::UNSPECIFIED); |
| 383 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 384 | Executor::BURST, MeasureTiming::YES, OutputType::UNSPECIFIED); |
| 385 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 386 | Executor::ASYNC, MeasureTiming::NO, OutputType::INSUFFICIENT); |
| 387 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 388 | Executor::SYNC, MeasureTiming::NO, OutputType::INSUFFICIENT); |
| 389 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 390 | Executor::BURST, MeasureTiming::NO, OutputType::INSUFFICIENT); |
| 391 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 392 | Executor::ASYNC, MeasureTiming::YES, OutputType::INSUFFICIENT); |
| 393 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 394 | Executor::SYNC, MeasureTiming::YES, OutputType::INSUFFICIENT); |
| 395 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 396 | Executor::BURST, MeasureTiming::YES, OutputType::INSUFFICIENT); |
| 397 | } else { |
| 398 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 399 | Executor::ASYNC, MeasureTiming::NO, OutputType::FULLY_SPECIFIED); |
| 400 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 401 | Executor::SYNC, MeasureTiming::NO, OutputType::FULLY_SPECIFIED); |
| 402 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 403 | Executor::BURST, MeasureTiming::NO, OutputType::FULLY_SPECIFIED); |
| 404 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 405 | Executor::ASYNC, MeasureTiming::YES, OutputType::FULLY_SPECIFIED); |
| 406 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 407 | Executor::SYNC, MeasureTiming::YES, OutputType::FULLY_SPECIFIED); |
| 408 | EvaluatePreparedModel(preparedModel, is_ignored, examples, hasRelaxedFloat32Model, |
| 409 | Executor::BURST, MeasureTiming::YES, OutputType::FULLY_SPECIFIED); |
| 410 | } |
| 411 | } |
| 412 | |
Xusong Wang | b5cb8f7 | 2018-10-31 08:43:12 -0700 | [diff] [blame] | 413 | static void getPreparedModel(sp<PreparedModelCallback> callback, |
| 414 | sp<V1_0::IPreparedModel>* preparedModel) { |
| 415 | *preparedModel = callback->getPreparedModel(); |
| 416 | } |
| 417 | static void getPreparedModel(sp<PreparedModelCallback> callback, |
| 418 | sp<V1_2::IPreparedModel>* preparedModel) { |
| 419 | sp<V1_0::IPreparedModel> preparedModelV1_0 = callback->getPreparedModel(); |
| 420 | *preparedModel = V1_2::IPreparedModel::castFrom(preparedModelV1_0).withDefault(nullptr); |
| 421 | } |
| 422 | |
Michael Butler | f76acd0 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 423 | void Execute(const sp<V1_0::IDevice>& device, std::function<V1_0::Model(void)> create_model, |
Michael K. Sanders | 941d61a | 2018-10-19 14:39:09 +0100 | [diff] [blame] | 424 | std::function<bool(int)> is_ignored, const std::vector<MixedTypedExample>& examples) { |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 425 | V1_0::Model model = create_model(); |
| 426 | |
| 427 | // see if service can handle model |
| 428 | bool fullySupportsModel = false; |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 429 | Return<void> supportedCall = device->getSupportedOperations( |
Michael Butler | 4d5bb10 | 2018-02-26 15:24:46 -0800 | [diff] [blame] | 430 | model, [&fullySupportsModel](ErrorStatus status, const hidl_vec<bool>& supported) { |
| 431 | ASSERT_EQ(ErrorStatus::NONE, status); |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 432 | ASSERT_NE(0ul, supported.size()); |
| 433 | fullySupportsModel = |
| 434 | std::all_of(supported.begin(), supported.end(), [](bool valid) { return valid; }); |
| 435 | }); |
| 436 | ASSERT_TRUE(supportedCall.isOk()); |
Michael Butler | 4d5bb10 | 2018-02-26 15:24:46 -0800 | [diff] [blame] | 437 | |
| 438 | // launch prepare model |
| 439 | sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback(); |
| 440 | ASSERT_NE(nullptr, preparedModelCallback.get()); |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 441 | Return<ErrorStatus> prepareLaunchStatus = device->prepareModel(model, preparedModelCallback); |
| 442 | ASSERT_TRUE(prepareLaunchStatus.isOk()); |
Michael Butler | 4d5bb10 | 2018-02-26 15:24:46 -0800 | [diff] [blame] | 443 | ASSERT_EQ(ErrorStatus::NONE, static_cast<ErrorStatus>(prepareLaunchStatus)); |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 444 | |
| 445 | // retrieve prepared model |
| 446 | preparedModelCallback->wait(); |
| 447 | ErrorStatus prepareReturnStatus = preparedModelCallback->getStatus(); |
Xusong Wang | b5cb8f7 | 2018-10-31 08:43:12 -0700 | [diff] [blame] | 448 | sp<V1_0::IPreparedModel> preparedModel; |
| 449 | getPreparedModel(preparedModelCallback, &preparedModel); |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 450 | |
| 451 | // early termination if vendor service cannot fully prepare model |
Michael Butler | 4d5bb10 | 2018-02-26 15:24:46 -0800 | [diff] [blame] | 452 | if (!fullySupportsModel && prepareReturnStatus != ErrorStatus::NONE) { |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 453 | ASSERT_EQ(nullptr, preparedModel.get()); |
| 454 | LOG(INFO) << "NN VTS: Early termination of test because vendor service cannot " |
| 455 | "prepare model that it does not support."; |
| 456 | std::cout << "[ ] Early termination of test because vendor service cannot " |
| 457 | "prepare model that it does not support." |
| 458 | << std::endl; |
Miao Wang | bb685a4 | 2019-01-08 12:27:35 -0800 | [diff] [blame] | 459 | GTEST_SKIP(); |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 460 | } |
Michael Butler | 4d5bb10 | 2018-02-26 15:24:46 -0800 | [diff] [blame] | 461 | EXPECT_EQ(ErrorStatus::NONE, prepareReturnStatus); |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 462 | ASSERT_NE(nullptr, preparedModel.get()); |
| 463 | |
Xusong Wang | 10d77e4 | 2018-08-28 16:50:01 -0700 | [diff] [blame] | 464 | float fpAtol = 1e-5f, fpRtol = 5.0f * 1.1920928955078125e-7f; |
Michael K. Sanders | efa4c81 | 2018-10-30 14:44:48 +0000 | [diff] [blame] | 465 | EvaluatePreparedModel(preparedModel, is_ignored, examples, |
Michael Butler | 814d837 | 2019-01-15 11:02:55 -0800 | [diff] [blame] | 466 | /*hasRelaxedFloat32Model=*/false, fpAtol, fpRtol, Executor::ASYNC, |
Xusong Wang | 929fd21 | 2019-01-27 23:08:12 -0800 | [diff] [blame] | 467 | MeasureTiming::NO, OutputType::FULLY_SPECIFIED); |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 468 | } |
| 469 | |
Michael Butler | f76acd0 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 470 | void Execute(const sp<V1_1::IDevice>& device, std::function<V1_1::Model(void)> create_model, |
Michael K. Sanders | 941d61a | 2018-10-19 14:39:09 +0100 | [diff] [blame] | 471 | std::function<bool(int)> is_ignored, const std::vector<MixedTypedExample>& examples) { |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 472 | V1_1::Model model = create_model(); |
| 473 | |
| 474 | // see if service can handle model |
| 475 | bool fullySupportsModel = false; |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 476 | Return<void> supportedCall = device->getSupportedOperations_1_1( |
Michael Butler | 4d5bb10 | 2018-02-26 15:24:46 -0800 | [diff] [blame] | 477 | model, [&fullySupportsModel](ErrorStatus status, const hidl_vec<bool>& supported) { |
| 478 | ASSERT_EQ(ErrorStatus::NONE, status); |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 479 | ASSERT_NE(0ul, supported.size()); |
| 480 | fullySupportsModel = |
| 481 | std::all_of(supported.begin(), supported.end(), [](bool valid) { return valid; }); |
| 482 | }); |
| 483 | ASSERT_TRUE(supportedCall.isOk()); |
Michael Butler | 4d5bb10 | 2018-02-26 15:24:46 -0800 | [diff] [blame] | 484 | |
| 485 | // launch prepare model |
| 486 | sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback(); |
| 487 | ASSERT_NE(nullptr, preparedModelCallback.get()); |
Michael Butler | 2504c2f | 2018-04-11 16:30:09 -0700 | [diff] [blame] | 488 | Return<ErrorStatus> prepareLaunchStatus = device->prepareModel_1_1( |
| 489 | model, ExecutionPreference::FAST_SINGLE_ANSWER, preparedModelCallback); |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 490 | ASSERT_TRUE(prepareLaunchStatus.isOk()); |
Michael Butler | 4d5bb10 | 2018-02-26 15:24:46 -0800 | [diff] [blame] | 491 | ASSERT_EQ(ErrorStatus::NONE, static_cast<ErrorStatus>(prepareLaunchStatus)); |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 492 | |
| 493 | // retrieve prepared model |
| 494 | preparedModelCallback->wait(); |
| 495 | ErrorStatus prepareReturnStatus = preparedModelCallback->getStatus(); |
Xusong Wang | b5cb8f7 | 2018-10-31 08:43:12 -0700 | [diff] [blame] | 496 | sp<V1_0::IPreparedModel> preparedModel; |
| 497 | getPreparedModel(preparedModelCallback, &preparedModel); |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 498 | |
| 499 | // early termination if vendor service cannot fully prepare model |
Michael Butler | 4d5bb10 | 2018-02-26 15:24:46 -0800 | [diff] [blame] | 500 | if (!fullySupportsModel && prepareReturnStatus != ErrorStatus::NONE) { |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 501 | ASSERT_EQ(nullptr, preparedModel.get()); |
| 502 | LOG(INFO) << "NN VTS: Early termination of test because vendor service cannot " |
| 503 | "prepare model that it does not support."; |
| 504 | std::cout << "[ ] Early termination of test because vendor service cannot " |
| 505 | "prepare model that it does not support." |
| 506 | << std::endl; |
Miao Wang | bb685a4 | 2019-01-08 12:27:35 -0800 | [diff] [blame] | 507 | GTEST_SKIP(); |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 508 | } |
Michael Butler | 4d5bb10 | 2018-02-26 15:24:46 -0800 | [diff] [blame] | 509 | EXPECT_EQ(ErrorStatus::NONE, prepareReturnStatus); |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 510 | ASSERT_NE(nullptr, preparedModel.get()); |
| 511 | |
Michael K. Sanders | efa4c81 | 2018-10-30 14:44:48 +0000 | [diff] [blame] | 512 | EvaluatePreparedModel(preparedModel, is_ignored, examples, |
Michael Butler | 814d837 | 2019-01-15 11:02:55 -0800 | [diff] [blame] | 513 | model.relaxComputationFloat32toFloat16, 1e-5f, 1e-5f, Executor::ASYNC, |
Xusong Wang | 929fd21 | 2019-01-27 23:08:12 -0800 | [diff] [blame] | 514 | MeasureTiming::NO, OutputType::FULLY_SPECIFIED); |
Miao Wang | a2d04c8 | 2018-02-05 17:26:54 -0800 | [diff] [blame] | 515 | } |
| 516 | |
Xusong Wang | 3405878 | 2019-01-18 17:28:26 -0800 | [diff] [blame^] | 517 | void PrepareModel(const sp<V1_2::IDevice>& device, const V1_2::Model& model, |
| 518 | sp<V1_2::IPreparedModel>* preparedModel) { |
Slava Shklyaev | 871be94 | 2018-09-12 14:52:02 +0100 | [diff] [blame] | 519 | // see if service can handle model |
| 520 | bool fullySupportsModel = false; |
| 521 | Return<void> supportedCall = device->getSupportedOperations_1_2( |
| 522 | model, [&fullySupportsModel](ErrorStatus status, const hidl_vec<bool>& supported) { |
| 523 | ASSERT_EQ(ErrorStatus::NONE, status); |
| 524 | ASSERT_NE(0ul, supported.size()); |
| 525 | fullySupportsModel = |
| 526 | std::all_of(supported.begin(), supported.end(), [](bool valid) { return valid; }); |
| 527 | }); |
| 528 | ASSERT_TRUE(supportedCall.isOk()); |
| 529 | |
| 530 | // launch prepare model |
| 531 | sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback(); |
| 532 | ASSERT_NE(nullptr, preparedModelCallback.get()); |
| 533 | Return<ErrorStatus> prepareLaunchStatus = device->prepareModel_1_2( |
| 534 | model, ExecutionPreference::FAST_SINGLE_ANSWER, preparedModelCallback); |
| 535 | ASSERT_TRUE(prepareLaunchStatus.isOk()); |
| 536 | ASSERT_EQ(ErrorStatus::NONE, static_cast<ErrorStatus>(prepareLaunchStatus)); |
| 537 | |
| 538 | // retrieve prepared model |
| 539 | preparedModelCallback->wait(); |
| 540 | ErrorStatus prepareReturnStatus = preparedModelCallback->getStatus(); |
Xusong Wang | 3405878 | 2019-01-18 17:28:26 -0800 | [diff] [blame^] | 541 | getPreparedModel(preparedModelCallback, preparedModel); |
Slava Shklyaev | 871be94 | 2018-09-12 14:52:02 +0100 | [diff] [blame] | 542 | |
| 543 | // early termination if vendor service cannot fully prepare model |
| 544 | if (!fullySupportsModel && prepareReturnStatus != ErrorStatus::NONE) { |
Xusong Wang | 3405878 | 2019-01-18 17:28:26 -0800 | [diff] [blame^] | 545 | ASSERT_EQ(nullptr, preparedModel->get()); |
Slava Shklyaev | 871be94 | 2018-09-12 14:52:02 +0100 | [diff] [blame] | 546 | LOG(INFO) << "NN VTS: Early termination of test because vendor service cannot " |
| 547 | "prepare model that it does not support."; |
| 548 | std::cout << "[ ] Early termination of test because vendor service cannot " |
| 549 | "prepare model that it does not support." |
| 550 | << std::endl; |
Miao Wang | bb685a4 | 2019-01-08 12:27:35 -0800 | [diff] [blame] | 551 | GTEST_SKIP(); |
Slava Shklyaev | 871be94 | 2018-09-12 14:52:02 +0100 | [diff] [blame] | 552 | } |
| 553 | EXPECT_EQ(ErrorStatus::NONE, prepareReturnStatus); |
Xusong Wang | 3405878 | 2019-01-18 17:28:26 -0800 | [diff] [blame^] | 554 | ASSERT_NE(nullptr, preparedModel->get()); |
| 555 | } |
Slava Shklyaev | 871be94 | 2018-09-12 14:52:02 +0100 | [diff] [blame] | 556 | |
Xusong Wang | 3405878 | 2019-01-18 17:28:26 -0800 | [diff] [blame^] | 557 | // TODO: Reduce code duplication. |
| 558 | void Execute(const sp<V1_2::IDevice>& device, std::function<V1_2::Model(void)> create_model, |
| 559 | std::function<bool(int)> is_ignored, const std::vector<MixedTypedExample>& examples, |
| 560 | bool testDynamicOutputShape) { |
| 561 | V1_2::Model model = create_model(); |
| 562 | sp<V1_2::IPreparedModel> preparedModel = nullptr; |
| 563 | PrepareModel(device, model, &preparedModel); |
| 564 | EvaluatePreparedModel(preparedModel, is_ignored, examples, |
| 565 | model.relaxComputationFloat32toFloat16, testDynamicOutputShape); |
Slava Shklyaev | 871be94 | 2018-09-12 14:52:02 +0100 | [diff] [blame] | 566 | } |
| 567 | |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 568 | } // namespace generated_tests |
| 569 | |
I-Jui (Ray) Sung | 2c4e136 | 2017-09-06 02:15:54 -0700 | [diff] [blame] | 570 | } // namespace neuralnetworks |
| 571 | } // namespace hardware |
| 572 | } // namespace android |