Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [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 | |
Michael Butler | 89e99ba | 2019-01-24 02:36:37 -0800 | [diff] [blame] | 17 | #define LOG_TAG "ExecutionBurstServer" |
| 18 | |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 19 | #include "ExecutionBurstServer.h" |
| 20 | |
| 21 | #include <android-base/logging.h> |
Michael Butler | 3260db9 | 2019-04-26 17:51:23 -0700 | [diff] [blame] | 22 | |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 23 | #include <algorithm> |
Michael Butler | 4ef48f1 | 2019-05-02 14:09:17 -0700 | [diff] [blame] | 24 | #include <cstring> |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 25 | #include <limits> |
Michael Butler | 3260db9 | 2019-04-26 17:51:23 -0700 | [diff] [blame] | 26 | #include <map> |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 27 | #include <memory> |
| 28 | #include <tuple> |
| 29 | #include <utility> |
| 30 | #include <vector> |
Michael Butler | 3260db9 | 2019-04-26 17:51:23 -0700 | [diff] [blame] | 31 | |
Michael Butler | a8f883c | 2020-03-12 15:16:38 -0700 | [diff] [blame] | 32 | #include "HalInterfaces.h" |
Michael Butler | 3db6fe5 | 2019-01-29 11:20:30 -0800 | [diff] [blame] | 33 | #include "Tracing.h" |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 34 | |
Michael Butler | 3db6fe5 | 2019-01-29 11:20:30 -0800 | [diff] [blame] | 35 | namespace android::nn { |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 36 | namespace { |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 37 | |
Michael Butler | 19af9d2 | 2019-07-11 11:45:01 -0700 | [diff] [blame] | 38 | using namespace hal; |
| 39 | |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 40 | using hardware::MQDescriptorSync; |
Michael Butler | a8f883c | 2020-03-12 15:16:38 -0700 | [diff] [blame] | 41 | using V1_2::FmqRequestDatum; |
| 42 | using V1_2::FmqResultDatum; |
| 43 | using V1_2::IBurstCallback; |
| 44 | using V1_2::IBurstContext; |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 45 | |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 46 | constexpr Timing kNoTiming = {std::numeric_limits<uint64_t>::max(), |
| 47 | std::numeric_limits<uint64_t>::max()}; |
| 48 | |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 49 | // DefaultBurstExecutorWithCache adapts an IPreparedModel so that it can be |
| 50 | // used as an IBurstExecutorWithCache. Specifically, the cache simply stores the |
| 51 | // hidl_memory object, and the execution forwards calls to the provided |
| 52 | // IPreparedModel's "executeSynchronously" method. With this class, hidl_memory |
| 53 | // must be mapped and unmapped for each execution. |
| 54 | class DefaultBurstExecutorWithCache : public ExecutionBurstServer::IBurstExecutorWithCache { |
| 55 | public: |
Xusong Wang | 196a187 | 2019-10-25 12:06:20 -0700 | [diff] [blame] | 56 | DefaultBurstExecutorWithCache(V1_2::IPreparedModel* preparedModel) |
| 57 | : mpPreparedModel(preparedModel) {} |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 58 | |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 59 | bool isCacheEntryPresent(int32_t slot) const override { |
Michael Butler | 3260db9 | 2019-04-26 17:51:23 -0700 | [diff] [blame] | 60 | const auto it = mMemoryCache.find(slot); |
Michael Butler | 1ee58a5 | 2019-04-30 13:49:32 -0700 | [diff] [blame] | 61 | return (it != mMemoryCache.end()) && it->second.valid(); |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 62 | } |
Michael Butler | 47c988f6 | 2019-03-14 17:34:48 -0700 | [diff] [blame] | 63 | |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 64 | void addCacheEntry(const hidl_memory& memory, int32_t slot) override { |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 65 | mMemoryCache[slot] = memory; |
| 66 | } |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 67 | |
Michael Butler | 3260db9 | 2019-04-26 17:51:23 -0700 | [diff] [blame] | 68 | void removeCacheEntry(int32_t slot) override { mMemoryCache.erase(slot); } |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 69 | |
Michael Butler | f690d31 | 2019-12-12 16:25:03 -0800 | [diff] [blame] | 70 | std::tuple<V1_0::ErrorStatus, hidl_vec<OutputShape>, Timing> execute( |
Xusong Wang | 7ac6c9d | 2020-01-08 16:52:37 -0800 | [diff] [blame] | 71 | const V1_0::Request& request, const std::vector<int32_t>& slots, |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 72 | MeasureTiming measure) override { |
| 73 | // convert slots to pools |
| 74 | hidl_vec<hidl_memory> pools(slots.size()); |
Michael Butler | 3260db9 | 2019-04-26 17:51:23 -0700 | [diff] [blame] | 75 | std::transform(slots.begin(), slots.end(), pools.begin(), |
| 76 | [this](int32_t slot) { return mMemoryCache[slot]; }); |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 77 | |
| 78 | // create full request |
Xusong Wang | 7ac6c9d | 2020-01-08 16:52:37 -0800 | [diff] [blame] | 79 | V1_0::Request fullRequest = request; |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 80 | fullRequest.pools = std::move(pools); |
| 81 | |
| 82 | // setup execution |
Michael Butler | f690d31 | 2019-12-12 16:25:03 -0800 | [diff] [blame] | 83 | V1_0::ErrorStatus returnedStatus = V1_0::ErrorStatus::GENERAL_FAILURE; |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 84 | hidl_vec<OutputShape> returnedOutputShapes; |
| 85 | Timing returnedTiming; |
| 86 | auto cb = [&returnedStatus, &returnedOutputShapes, &returnedTiming]( |
Michael Butler | f690d31 | 2019-12-12 16:25:03 -0800 | [diff] [blame] | 87 | V1_0::ErrorStatus status, const hidl_vec<OutputShape>& outputShapes, |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 88 | const Timing& timing) { |
| 89 | returnedStatus = status; |
| 90 | returnedOutputShapes = outputShapes; |
| 91 | returnedTiming = timing; |
Michael Butler | 47c988f6 | 2019-03-14 17:34:48 -0700 | [diff] [blame] | 92 | }; |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 93 | |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 94 | // execute |
| 95 | const Return<void> ret = mpPreparedModel->executeSynchronously(fullRequest, measure, cb); |
Michael Butler | f690d31 | 2019-12-12 16:25:03 -0800 | [diff] [blame] | 96 | if (!ret.isOk() || returnedStatus != V1_0::ErrorStatus::NONE) { |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 97 | LOG(ERROR) << "IPreparedModelAdapter::execute -- Error executing"; |
Xusong Wang | a66fee1 | 2020-01-17 10:36:52 -0800 | [diff] [blame] | 98 | return {returnedStatus, std::move(returnedOutputShapes), kNoTiming}; |
Michael Butler | 89e99ba | 2019-01-24 02:36:37 -0800 | [diff] [blame] | 99 | } |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 100 | |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 101 | return std::make_tuple(returnedStatus, std::move(returnedOutputShapes), returnedTiming); |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 104 | private: |
Xusong Wang | 196a187 | 2019-10-25 12:06:20 -0700 | [diff] [blame] | 105 | V1_2::IPreparedModel* const mpPreparedModel; |
Michael Butler | 3260db9 | 2019-04-26 17:51:23 -0700 | [diff] [blame] | 106 | std::map<int32_t, hidl_memory> mMemoryCache; |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 107 | }; |
Michael Butler | 47c988f6 | 2019-03-14 17:34:48 -0700 | [diff] [blame] | 108 | |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 109 | } // anonymous namespace |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 110 | |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 111 | // serialize result |
Michael Butler | f690d31 | 2019-12-12 16:25:03 -0800 | [diff] [blame] | 112 | std::vector<FmqResultDatum> serialize(V1_0::ErrorStatus errorStatus, |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 113 | const std::vector<OutputShape>& outputShapes, Timing timing) { |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 114 | // count how many elements need to be sent for a request |
| 115 | size_t count = 2 + outputShapes.size(); |
| 116 | for (const auto& outputShape : outputShapes) { |
| 117 | count += outputShape.dimensions.size(); |
| 118 | } |
| 119 | |
| 120 | // create buffer to temporarily store elements |
| 121 | std::vector<FmqResultDatum> data; |
| 122 | data.reserve(count); |
| 123 | |
| 124 | // package packetInfo |
| 125 | { |
| 126 | FmqResultDatum datum; |
| 127 | datum.packetInformation({/*.packetSize=*/static_cast<uint32_t>(count), |
| 128 | /*.errorStatus=*/errorStatus, |
| 129 | /*.numberOfOperands=*/static_cast<uint32_t>(outputShapes.size())}); |
| 130 | data.push_back(datum); |
| 131 | } |
| 132 | |
| 133 | // package output shape data |
| 134 | for (const auto& operand : outputShapes) { |
| 135 | // package operand information |
Steven Moreland | 393ac6d | 2019-04-25 15:33:25 -0700 | [diff] [blame] | 136 | FmqResultDatum::OperandInformation info{}; |
| 137 | info.isSufficient = operand.isSufficient; |
| 138 | info.numberOfDimensions = static_cast<uint32_t>(operand.dimensions.size()); |
| 139 | |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 140 | FmqResultDatum datum; |
Steven Moreland | 393ac6d | 2019-04-25 15:33:25 -0700 | [diff] [blame] | 141 | datum.operandInformation(info); |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 142 | data.push_back(datum); |
| 143 | |
| 144 | // package operand dimensions |
| 145 | for (uint32_t dimension : operand.dimensions) { |
| 146 | FmqResultDatum datum; |
| 147 | datum.operandDimensionValue(dimension); |
| 148 | data.push_back(datum); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // package executionTiming |
| 153 | { |
| 154 | FmqResultDatum datum; |
| 155 | datum.executionTiming(timing); |
| 156 | data.push_back(datum); |
| 157 | } |
| 158 | |
| 159 | // return result |
| 160 | return data; |
| 161 | } |
| 162 | |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 163 | // deserialize request |
Xusong Wang | 7ac6c9d | 2020-01-08 16:52:37 -0800 | [diff] [blame] | 164 | std::optional<std::tuple<V1_0::Request, std::vector<int32_t>, MeasureTiming>> deserialize( |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 165 | const std::vector<FmqRequestDatum>& data) { |
| 166 | using discriminator = FmqRequestDatum::hidl_discriminator; |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 167 | |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 168 | size_t index = 0; |
| 169 | |
| 170 | // validate packet information |
Michael Butler | 6b9c50a | 2022-12-01 17:50:37 -0800 | [diff] [blame] | 171 | if (index >= data.size() || |
| 172 | data.at(index).getDiscriminator() != discriminator::packetInformation) { |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 173 | LOG(ERROR) << "FMQ Request packet ill-formed"; |
| 174 | return std::nullopt; |
| 175 | } |
| 176 | |
| 177 | // unpackage packet information |
Michael Butler | 6b9c50a | 2022-12-01 17:50:37 -0800 | [diff] [blame] | 178 | const FmqRequestDatum::PacketInformation& packetInfo = data.at(index).packetInformation(); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 179 | index++; |
| 180 | const uint32_t packetSize = packetInfo.packetSize; |
| 181 | const uint32_t numberOfInputOperands = packetInfo.numberOfInputOperands; |
| 182 | const uint32_t numberOfOutputOperands = packetInfo.numberOfOutputOperands; |
| 183 | const uint32_t numberOfPools = packetInfo.numberOfPools; |
| 184 | |
Michael Butler | 3260db9 | 2019-04-26 17:51:23 -0700 | [diff] [blame] | 185 | // verify packet size |
| 186 | if (data.size() != packetSize) { |
| 187 | LOG(ERROR) << "FMQ Request packet ill-formed"; |
| 188 | return std::nullopt; |
| 189 | } |
| 190 | |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 191 | // unpackage input operands |
| 192 | std::vector<RequestArgument> inputs; |
| 193 | inputs.reserve(numberOfInputOperands); |
| 194 | for (size_t operand = 0; operand < numberOfInputOperands; ++operand) { |
| 195 | // validate input operand information |
Michael Butler | 6b9c50a | 2022-12-01 17:50:37 -0800 | [diff] [blame] | 196 | if (index >= data.size() || |
| 197 | data.at(index).getDiscriminator() != discriminator::inputOperandInformation) { |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 198 | LOG(ERROR) << "FMQ Request packet ill-formed"; |
| 199 | return std::nullopt; |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 200 | } |
| 201 | |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 202 | // unpackage operand information |
| 203 | const FmqRequestDatum::OperandInformation& operandInfo = |
Michael Butler | 6b9c50a | 2022-12-01 17:50:37 -0800 | [diff] [blame] | 204 | data.at(index).inputOperandInformation(); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 205 | index++; |
| 206 | const bool hasNoValue = operandInfo.hasNoValue; |
| 207 | const DataLocation location = operandInfo.location; |
| 208 | const uint32_t numberOfDimensions = operandInfo.numberOfDimensions; |
Michael Butler | 3db6fe5 | 2019-01-29 11:20:30 -0800 | [diff] [blame] | 209 | |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 210 | // unpackage operand dimensions |
| 211 | std::vector<uint32_t> dimensions; |
| 212 | dimensions.reserve(numberOfDimensions); |
| 213 | for (size_t i = 0; i < numberOfDimensions; ++i) { |
| 214 | // validate dimension |
Michael Butler | 6b9c50a | 2022-12-01 17:50:37 -0800 | [diff] [blame] | 215 | if (index >= data.size() || |
| 216 | data.at(index).getDiscriminator() != discriminator::inputOperandDimensionValue) { |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 217 | LOG(ERROR) << "FMQ Request packet ill-formed"; |
| 218 | return std::nullopt; |
| 219 | } |
| 220 | |
| 221 | // unpackage dimension |
Michael Butler | 6b9c50a | 2022-12-01 17:50:37 -0800 | [diff] [blame] | 222 | const uint32_t dimension = data.at(index).inputOperandDimensionValue(); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 223 | index++; |
| 224 | |
| 225 | // store result |
| 226 | dimensions.push_back(dimension); |
| 227 | } |
| 228 | |
| 229 | // store result |
| 230 | inputs.push_back( |
| 231 | {/*.hasNoValue=*/hasNoValue, /*.location=*/location, /*.dimensions=*/dimensions}); |
| 232 | } |
| 233 | |
| 234 | // unpackage output operands |
| 235 | std::vector<RequestArgument> outputs; |
| 236 | outputs.reserve(numberOfOutputOperands); |
| 237 | for (size_t operand = 0; operand < numberOfOutputOperands; ++operand) { |
| 238 | // validate output operand information |
Michael Butler | 6b9c50a | 2022-12-01 17:50:37 -0800 | [diff] [blame] | 239 | if (index >= data.size() || |
| 240 | data.at(index).getDiscriminator() != discriminator::outputOperandInformation) { |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 241 | LOG(ERROR) << "FMQ Request packet ill-formed"; |
| 242 | return std::nullopt; |
| 243 | } |
| 244 | |
| 245 | // unpackage operand information |
| 246 | const FmqRequestDatum::OperandInformation& operandInfo = |
Michael Butler | 6b9c50a | 2022-12-01 17:50:37 -0800 | [diff] [blame] | 247 | data.at(index).outputOperandInformation(); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 248 | index++; |
| 249 | const bool hasNoValue = operandInfo.hasNoValue; |
| 250 | const DataLocation location = operandInfo.location; |
| 251 | const uint32_t numberOfDimensions = operandInfo.numberOfDimensions; |
| 252 | |
| 253 | // unpackage operand dimensions |
| 254 | std::vector<uint32_t> dimensions; |
| 255 | dimensions.reserve(numberOfDimensions); |
| 256 | for (size_t i = 0; i < numberOfDimensions; ++i) { |
| 257 | // validate dimension |
Michael Butler | 6b9c50a | 2022-12-01 17:50:37 -0800 | [diff] [blame] | 258 | if (index >= data.size() || |
| 259 | data.at(index).getDiscriminator() != discriminator::outputOperandDimensionValue) { |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 260 | LOG(ERROR) << "FMQ Request packet ill-formed"; |
| 261 | return std::nullopt; |
| 262 | } |
| 263 | |
| 264 | // unpackage dimension |
Michael Butler | 6b9c50a | 2022-12-01 17:50:37 -0800 | [diff] [blame] | 265 | const uint32_t dimension = data.at(index).outputOperandDimensionValue(); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 266 | index++; |
| 267 | |
| 268 | // store result |
| 269 | dimensions.push_back(dimension); |
| 270 | } |
| 271 | |
| 272 | // store result |
| 273 | outputs.push_back( |
| 274 | {/*.hasNoValue=*/hasNoValue, /*.location=*/location, /*.dimensions=*/dimensions}); |
| 275 | } |
| 276 | |
| 277 | // unpackage pools |
| 278 | std::vector<int32_t> slots; |
| 279 | slots.reserve(numberOfPools); |
| 280 | for (size_t pool = 0; pool < numberOfPools; ++pool) { |
| 281 | // validate input operand information |
Michael Butler | 6b9c50a | 2022-12-01 17:50:37 -0800 | [diff] [blame] | 282 | if (index >= data.size() || |
| 283 | data.at(index).getDiscriminator() != discriminator::poolIdentifier) { |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 284 | LOG(ERROR) << "FMQ Request packet ill-formed"; |
| 285 | return std::nullopt; |
| 286 | } |
| 287 | |
| 288 | // unpackage operand information |
Michael Butler | 6b9c50a | 2022-12-01 17:50:37 -0800 | [diff] [blame] | 289 | const int32_t poolId = data.at(index).poolIdentifier(); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 290 | index++; |
| 291 | |
| 292 | // store result |
| 293 | slots.push_back(poolId); |
| 294 | } |
| 295 | |
| 296 | // validate measureTiming |
Michael Butler | 6b9c50a | 2022-12-01 17:50:37 -0800 | [diff] [blame] | 297 | if (index >= data.size() || data.at(index).getDiscriminator() != discriminator::measureTiming) { |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 298 | LOG(ERROR) << "FMQ Request packet ill-formed"; |
| 299 | return std::nullopt; |
| 300 | } |
| 301 | |
| 302 | // unpackage measureTiming |
Michael Butler | 6b9c50a | 2022-12-01 17:50:37 -0800 | [diff] [blame] | 303 | const MeasureTiming measure = data.at(index).measureTiming(); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 304 | index++; |
| 305 | |
| 306 | // validate packet information |
| 307 | if (index != packetSize) { |
Michael Butler | 6b9c50a | 2022-12-01 17:50:37 -0800 | [diff] [blame] | 308 | LOG(ERROR) << "FMQ Request packet ill-formed"; |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 309 | return std::nullopt; |
| 310 | } |
| 311 | |
| 312 | // return request |
Xusong Wang | 7ac6c9d | 2020-01-08 16:52:37 -0800 | [diff] [blame] | 313 | V1_0::Request request = {/*.inputs=*/inputs, /*.outputs=*/outputs, /*.pools=*/{}}; |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 314 | return std::make_tuple(std::move(request), std::move(slots), measure); |
| 315 | } |
| 316 | |
| 317 | // RequestChannelReceiver methods |
| 318 | |
| 319 | std::unique_ptr<RequestChannelReceiver> RequestChannelReceiver::create( |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 320 | const FmqRequestDescriptor& requestChannel, std::chrono::microseconds pollingTimeWindow) { |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 321 | std::unique_ptr<FmqRequestChannel> fmqRequestChannel = |
| 322 | std::make_unique<FmqRequestChannel>(requestChannel); |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 323 | |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 324 | if (!fmqRequestChannel->isValid()) { |
| 325 | LOG(ERROR) << "Unable to create RequestChannelReceiver"; |
| 326 | return nullptr; |
| 327 | } |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 328 | if (fmqRequestChannel->getEventFlagWord() == nullptr) { |
| 329 | LOG(ERROR) |
| 330 | << "RequestChannelReceiver::create was passed an MQDescriptor without an EventFlag"; |
| 331 | return nullptr; |
| 332 | } |
| 333 | |
| 334 | return std::make_unique<RequestChannelReceiver>(std::move(fmqRequestChannel), |
| 335 | pollingTimeWindow); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | RequestChannelReceiver::RequestChannelReceiver(std::unique_ptr<FmqRequestChannel> fmqRequestChannel, |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 339 | std::chrono::microseconds pollingTimeWindow) |
| 340 | : mFmqRequestChannel(std::move(fmqRequestChannel)), kPollingTimeWindow(pollingTimeWindow) {} |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 341 | |
Xusong Wang | 7ac6c9d | 2020-01-08 16:52:37 -0800 | [diff] [blame] | 342 | std::optional<std::tuple<V1_0::Request, std::vector<int32_t>, MeasureTiming>> |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 343 | RequestChannelReceiver::getBlocking() { |
| 344 | const auto packet = getPacketBlocking(); |
| 345 | if (!packet) { |
| 346 | return std::nullopt; |
| 347 | } |
| 348 | |
| 349 | return deserialize(*packet); |
| 350 | } |
| 351 | |
| 352 | void RequestChannelReceiver::invalidate() { |
| 353 | mTeardown = true; |
| 354 | |
| 355 | // force unblock |
| 356 | // ExecutionBurstServer is by default waiting on a request packet. If the |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 357 | // client process destroys its burst object, the server may still be waiting |
| 358 | // on the futex. This force unblock wakes up any thread waiting on the |
| 359 | // futex. |
| 360 | // TODO: look for a different/better way to signal/notify the futex to wake |
| 361 | // up any thread waiting on it |
| 362 | FmqRequestDatum datum; |
| 363 | datum.packetInformation({/*.packetSize=*/0, /*.numberOfInputOperands=*/0, |
| 364 | /*.numberOfOutputOperands=*/0, /*.numberOfPools=*/0}); |
| 365 | mFmqRequestChannel->writeBlocking(&datum, 1); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | std::optional<std::vector<FmqRequestDatum>> RequestChannelReceiver::getPacketBlocking() { |
| 369 | using discriminator = FmqRequestDatum::hidl_discriminator; |
| 370 | |
| 371 | if (mTeardown) { |
| 372 | return std::nullopt; |
| 373 | } |
| 374 | |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 375 | // First spend time polling if results are available in FMQ instead of |
| 376 | // waiting on the futex. Polling is more responsive (yielding lower |
| 377 | // latencies), but can take up more power, so only poll for a limited period |
| 378 | // of time. |
| 379 | |
| 380 | auto& getCurrentTime = std::chrono::high_resolution_clock::now; |
| 381 | const auto timeToStopPolling = getCurrentTime() + kPollingTimeWindow; |
| 382 | |
| 383 | while (getCurrentTime() < timeToStopPolling) { |
| 384 | // if class is being torn down, immediately return |
| 385 | if (mTeardown.load(std::memory_order_relaxed)) { |
| 386 | return std::nullopt; |
| 387 | } |
| 388 | |
| 389 | // Check if data is available. If it is, immediately retrieve it and |
| 390 | // return. |
| 391 | const size_t available = mFmqRequestChannel->availableToRead(); |
| 392 | if (available > 0) { |
| 393 | // This is the first point when we know an execution is occurring, |
| 394 | // so begin to collect systraces. Note that a similar systrace does |
| 395 | // not exist at the corresponding point in |
| 396 | // ResultChannelReceiver::getPacketBlocking because the execution is |
| 397 | // already in flight. |
| 398 | NNTRACE_FULL(NNTRACE_LAYER_IPC, NNTRACE_PHASE_EXECUTION, |
| 399 | "ExecutionBurstServer getting packet"); |
| 400 | std::vector<FmqRequestDatum> packet(available); |
| 401 | const bool success = mFmqRequestChannel->read(packet.data(), available); |
| 402 | if (!success) { |
| 403 | LOG(ERROR) << "Error receiving packet"; |
| 404 | return std::nullopt; |
| 405 | } |
| 406 | return std::make_optional(std::move(packet)); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 410 | // If we get to this point, we either stopped polling because it was taking |
| 411 | // too long or polling was not allowed. Instead, perform a blocking call |
| 412 | // which uses a futex to save power. |
| 413 | |
| 414 | // wait for request packet and read first element of request packet |
| 415 | FmqRequestDatum datum; |
| 416 | bool success = mFmqRequestChannel->readBlocking(&datum, 1); |
| 417 | |
| 418 | // This is the first point when we know an execution is occurring, so begin |
| 419 | // to collect systraces. Note that a similar systrace does not exist at the |
| 420 | // corresponding point in ResultChannelReceiver::getPacketBlocking because |
| 421 | // the execution is already in flight. |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 422 | NNTRACE_FULL(NNTRACE_LAYER_IPC, NNTRACE_PHASE_EXECUTION, "ExecutionBurstServer getting packet"); |
| 423 | |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 424 | // retrieve remaining elements |
| 425 | // NOTE: all of the data is already available at this point, so there's no |
| 426 | // need to do a blocking wait to wait for more data. This is known because |
| 427 | // in FMQ, all writes are published (made available) atomically. Currently, |
| 428 | // the producer always publishes the entire packet in one function call, so |
| 429 | // if the first element of the packet is available, the remaining elements |
| 430 | // are also available. |
Michael Butler | 3260db9 | 2019-04-26 17:51:23 -0700 | [diff] [blame] | 431 | const size_t count = mFmqRequestChannel->availableToRead(); |
| 432 | std::vector<FmqRequestDatum> packet(count + 1); |
Michael Butler | 4ef48f1 | 2019-05-02 14:09:17 -0700 | [diff] [blame] | 433 | std::memcpy(&packet.front(), &datum, sizeof(datum)); |
Michael Butler | 3260db9 | 2019-04-26 17:51:23 -0700 | [diff] [blame] | 434 | success &= mFmqRequestChannel->read(packet.data() + 1, count); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 435 | |
Michael Butler | 3260db9 | 2019-04-26 17:51:23 -0700 | [diff] [blame] | 436 | // terminate loop |
| 437 | if (mTeardown) { |
| 438 | return std::nullopt; |
| 439 | } |
| 440 | |
| 441 | // ensure packet was successfully received |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 442 | if (!success) { |
Michael Butler | 3260db9 | 2019-04-26 17:51:23 -0700 | [diff] [blame] | 443 | LOG(ERROR) << "Error receiving packet"; |
| 444 | return std::nullopt; |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Michael Butler | 4ef48f1 | 2019-05-02 14:09:17 -0700 | [diff] [blame] | 447 | return std::make_optional(std::move(packet)); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | // ResultChannelSender methods |
| 451 | |
| 452 | std::unique_ptr<ResultChannelSender> ResultChannelSender::create( |
| 453 | const FmqResultDescriptor& resultChannel) { |
| 454 | std::unique_ptr<FmqResultChannel> fmqResultChannel = |
| 455 | std::make_unique<FmqResultChannel>(resultChannel); |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 456 | |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 457 | if (!fmqResultChannel->isValid()) { |
| 458 | LOG(ERROR) << "Unable to create RequestChannelSender"; |
| 459 | return nullptr; |
| 460 | } |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 461 | if (fmqResultChannel->getEventFlagWord() == nullptr) { |
| 462 | LOG(ERROR) << "ResultChannelSender::create was passed an MQDescriptor without an EventFlag"; |
| 463 | return nullptr; |
| 464 | } |
| 465 | |
| 466 | return std::make_unique<ResultChannelSender>(std::move(fmqResultChannel)); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 469 | ResultChannelSender::ResultChannelSender(std::unique_ptr<FmqResultChannel> fmqResultChannel) |
| 470 | : mFmqResultChannel(std::move(fmqResultChannel)) {} |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 471 | |
Michael Butler | f690d31 | 2019-12-12 16:25:03 -0800 | [diff] [blame] | 472 | bool ResultChannelSender::send(V1_0::ErrorStatus errorStatus, |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 473 | const std::vector<OutputShape>& outputShapes, Timing timing) { |
| 474 | const std::vector<FmqResultDatum> serialized = serialize(errorStatus, outputShapes, timing); |
| 475 | return sendPacket(serialized); |
| 476 | } |
| 477 | |
| 478 | bool ResultChannelSender::sendPacket(const std::vector<FmqResultDatum>& packet) { |
Michael Butler | 3260db9 | 2019-04-26 17:51:23 -0700 | [diff] [blame] | 479 | if (packet.size() > mFmqResultChannel->availableToWrite()) { |
| 480 | LOG(ERROR) |
| 481 | << "ResultChannelSender::sendPacket -- packet size exceeds size available in FMQ"; |
| 482 | const std::vector<FmqResultDatum> errorPacket = |
Michael Butler | f690d31 | 2019-12-12 16:25:03 -0800 | [diff] [blame] | 483 | serialize(V1_0::ErrorStatus::GENERAL_FAILURE, {}, kNoTiming); |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 484 | |
| 485 | // Always send the packet with "blocking" because this signals the futex |
| 486 | // and unblocks the consumer if it is waiting on the futex. |
| 487 | return mFmqResultChannel->writeBlocking(errorPacket.data(), errorPacket.size()); |
Michael Butler | 3260db9 | 2019-04-26 17:51:23 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 490 | // Always send the packet with "blocking" because this signals the futex and |
| 491 | // unblocks the consumer if it is waiting on the futex. |
| 492 | return mFmqResultChannel->writeBlocking(packet.data(), packet.size()); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | // ExecutionBurstServer methods |
| 496 | |
| 497 | sp<ExecutionBurstServer> ExecutionBurstServer::create( |
| 498 | const sp<IBurstCallback>& callback, const MQDescriptorSync<FmqRequestDatum>& requestChannel, |
| 499 | const MQDescriptorSync<FmqResultDatum>& resultChannel, |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 500 | std::shared_ptr<IBurstExecutorWithCache> executorWithCache, |
| 501 | std::chrono::microseconds pollingTimeWindow) { |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 502 | // check inputs |
| 503 | if (callback == nullptr || executorWithCache == nullptr) { |
| 504 | LOG(ERROR) << "ExecutionBurstServer::create passed a nullptr"; |
| 505 | return nullptr; |
| 506 | } |
| 507 | |
| 508 | // create FMQ objects |
| 509 | std::unique_ptr<RequestChannelReceiver> requestChannelReceiver = |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 510 | RequestChannelReceiver::create(requestChannel, pollingTimeWindow); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 511 | std::unique_ptr<ResultChannelSender> resultChannelSender = |
| 512 | ResultChannelSender::create(resultChannel); |
| 513 | |
| 514 | // check FMQ objects |
| 515 | if (!requestChannelReceiver || !resultChannelSender) { |
| 516 | LOG(ERROR) << "ExecutionBurstServer::create failed to create FastMessageQueue"; |
| 517 | return nullptr; |
| 518 | } |
| 519 | |
| 520 | // make and return context |
| 521 | return new ExecutionBurstServer(callback, std::move(requestChannelReceiver), |
| 522 | std::move(resultChannelSender), std::move(executorWithCache)); |
| 523 | } |
| 524 | |
| 525 | sp<ExecutionBurstServer> ExecutionBurstServer::create( |
| 526 | const sp<IBurstCallback>& callback, const MQDescriptorSync<FmqRequestDatum>& requestChannel, |
Xusong Wang | 196a187 | 2019-10-25 12:06:20 -0700 | [diff] [blame] | 527 | const MQDescriptorSync<FmqResultDatum>& resultChannel, V1_2::IPreparedModel* preparedModel, |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 528 | std::chrono::microseconds pollingTimeWindow) { |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 529 | // check relevant input |
| 530 | if (preparedModel == nullptr) { |
| 531 | LOG(ERROR) << "ExecutionBurstServer::create passed a nullptr"; |
| 532 | return nullptr; |
| 533 | } |
| 534 | |
| 535 | // adapt IPreparedModel to have caching |
| 536 | const std::shared_ptr<DefaultBurstExecutorWithCache> preparedModelAdapter = |
| 537 | std::make_shared<DefaultBurstExecutorWithCache>(preparedModel); |
| 538 | |
| 539 | // make and return context |
| 540 | return ExecutionBurstServer::create(callback, requestChannel, resultChannel, |
Michael Butler | c82044a | 2019-06-24 10:36:20 -0700 | [diff] [blame] | 541 | preparedModelAdapter, pollingTimeWindow); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | ExecutionBurstServer::ExecutionBurstServer( |
| 545 | const sp<IBurstCallback>& callback, std::unique_ptr<RequestChannelReceiver> requestChannel, |
| 546 | std::unique_ptr<ResultChannelSender> resultChannel, |
| 547 | std::shared_ptr<IBurstExecutorWithCache> executorWithCache) |
| 548 | : mCallback(callback), |
| 549 | mRequestChannelReceiver(std::move(requestChannel)), |
| 550 | mResultChannelSender(std::move(resultChannel)), |
| 551 | mExecutorWithCache(std::move(executorWithCache)) { |
| 552 | // TODO: highly document the threading behavior of this class |
| 553 | mWorker = std::thread([this] { task(); }); |
| 554 | } |
| 555 | |
| 556 | ExecutionBurstServer::~ExecutionBurstServer() { |
| 557 | // set teardown flag |
| 558 | mTeardown = true; |
| 559 | mRequestChannelReceiver->invalidate(); |
| 560 | |
| 561 | // wait for task thread to end |
| 562 | mWorker.join(); |
| 563 | } |
| 564 | |
| 565 | Return<void> ExecutionBurstServer::freeMemory(int32_t slot) { |
Michael Butler | ba59a54 | 2019-06-28 17:06:27 -0700 | [diff] [blame] | 566 | std::lock_guard<std::mutex> hold(mMutex); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 567 | mExecutorWithCache->removeCacheEntry(slot); |
| 568 | return Void(); |
| 569 | } |
| 570 | |
| 571 | void ExecutionBurstServer::ensureCacheEntriesArePresentLocked(const std::vector<int32_t>& slots) { |
| 572 | const auto slotIsKnown = [this](int32_t slot) { |
| 573 | return mExecutorWithCache->isCacheEntryPresent(slot); |
| 574 | }; |
| 575 | |
| 576 | // find unique unknown slots |
| 577 | std::vector<int32_t> unknownSlots = slots; |
| 578 | auto unknownSlotsEnd = unknownSlots.end(); |
| 579 | std::sort(unknownSlots.begin(), unknownSlotsEnd); |
| 580 | unknownSlotsEnd = std::unique(unknownSlots.begin(), unknownSlotsEnd); |
| 581 | unknownSlotsEnd = std::remove_if(unknownSlots.begin(), unknownSlotsEnd, slotIsKnown); |
| 582 | unknownSlots.erase(unknownSlotsEnd, unknownSlots.end()); |
| 583 | |
| 584 | // quick-exit if all slots are known |
| 585 | if (unknownSlots.empty()) { |
| 586 | return; |
| 587 | } |
| 588 | |
Michael Butler | f690d31 | 2019-12-12 16:25:03 -0800 | [diff] [blame] | 589 | V1_0::ErrorStatus errorStatus = V1_0::ErrorStatus::GENERAL_FAILURE; |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 590 | std::vector<hidl_memory> returnedMemories; |
Michael Butler | f690d31 | 2019-12-12 16:25:03 -0800 | [diff] [blame] | 591 | auto cb = [&errorStatus, &returnedMemories](V1_0::ErrorStatus status, |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 592 | const hidl_vec<hidl_memory>& memories) { |
| 593 | errorStatus = status; |
| 594 | returnedMemories = memories; |
| 595 | }; |
| 596 | |
| 597 | const Return<void> ret = mCallback->getMemories(unknownSlots, cb); |
| 598 | |
Michael Butler | f690d31 | 2019-12-12 16:25:03 -0800 | [diff] [blame] | 599 | if (!ret.isOk() || errorStatus != V1_0::ErrorStatus::NONE || |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 600 | returnedMemories.size() != unknownSlots.size()) { |
| 601 | LOG(ERROR) << "Error retrieving memories"; |
| 602 | return; |
| 603 | } |
| 604 | |
| 605 | // add memories to unknown slots |
| 606 | for (size_t i = 0; i < unknownSlots.size(); ++i) { |
| 607 | mExecutorWithCache->addCacheEntry(returnedMemories[i], unknownSlots[i]); |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | void ExecutionBurstServer::task() { |
| 612 | // loop until the burst object is being destroyed |
| 613 | while (!mTeardown) { |
| 614 | // receive request |
| 615 | auto arguments = mRequestChannelReceiver->getBlocking(); |
| 616 | |
| 617 | // if the request packet was not properly received, return a generic |
| 618 | // error and skip the execution |
| 619 | // |
| 620 | // if the burst is being torn down, skip the execution exection so the |
| 621 | // "task" function can end |
| 622 | if (!arguments) { |
| 623 | if (!mTeardown) { |
Michael Butler | f690d31 | 2019-12-12 16:25:03 -0800 | [diff] [blame] | 624 | mResultChannelSender->send(V1_0::ErrorStatus::GENERAL_FAILURE, {}, kNoTiming); |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 625 | } |
| 626 | continue; |
| 627 | } |
| 628 | |
| 629 | // otherwise begin tracing execution |
| 630 | NNTRACE_FULL(NNTRACE_LAYER_IPC, NNTRACE_PHASE_EXECUTION, |
| 631 | "ExecutionBurstServer getting memory, executing, and returning results"); |
| 632 | |
| 633 | // unpack the arguments; types are Request, std::vector<int32_t>, and |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 634 | // MeasureTiming, respectively |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 635 | const auto [requestWithoutPools, slotsOfPools, measure] = std::move(*arguments); |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 636 | |
Michael Butler | 238fe72 | 2019-03-21 12:17:27 -0700 | [diff] [blame] | 637 | // ensure executor with cache has required memory |
| 638 | std::lock_guard<std::mutex> hold(mMutex); |
| 639 | ensureCacheEntriesArePresentLocked(slotsOfPools); |
| 640 | |
| 641 | // perform computation; types are ErrorStatus, hidl_vec<OutputShape>, |
| 642 | // and Timing, respectively |
| 643 | const auto [errorStatus, outputShapes, returnedTiming] = |
| 644 | mExecutorWithCache->execute(requestWithoutPools, slotsOfPools, measure); |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 645 | |
| 646 | // return result |
Michael Butler | c932ebb | 2019-04-11 14:24:06 -0700 | [diff] [blame] | 647 | mResultChannelSender->send(errorStatus, outputShapes, returnedTiming); |
Michael Butler | 6029632 | 2019-01-17 17:54:51 -0800 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | |
Michael Butler | 3db6fe5 | 2019-01-29 11:20:30 -0800 | [diff] [blame] | 651 | } // namespace android::nn |