blob: 067c2f5977d828d77fb1ac30f3338f2b13cd5ed3 [file] [log] [blame]
Michael Butler60296322019-01-17 17:54:51 -08001/*
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 Butler89e99ba2019-01-24 02:36:37 -080017#define LOG_TAG "ExecutionBurstServer"
18
Michael Butler60296322019-01-17 17:54:51 -080019#include "ExecutionBurstServer.h"
20
21#include <android-base/logging.h>
Michael Butlerc932ebb2019-04-11 14:24:06 -070022#include <limits>
Michael Butler3db6fe52019-01-29 11:20:30 -080023#include "Tracing.h"
Michael Butler60296322019-01-17 17:54:51 -080024
Michael Butler3db6fe52019-01-29 11:20:30 -080025namespace android::nn {
Michael Butler238fe722019-03-21 12:17:27 -070026namespace {
Michael Butler60296322019-01-17 17:54:51 -080027
Michael Butlerc932ebb2019-04-11 14:24:06 -070028constexpr Timing kNoTiming = {std::numeric_limits<uint64_t>::max(),
29 std::numeric_limits<uint64_t>::max()};
30
Michael Butler238fe722019-03-21 12:17:27 -070031// DefaultBurstExecutorWithCache adapts an IPreparedModel so that it can be
32// used as an IBurstExecutorWithCache. Specifically, the cache simply stores the
33// hidl_memory object, and the execution forwards calls to the provided
34// IPreparedModel's "executeSynchronously" method. With this class, hidl_memory
35// must be mapped and unmapped for each execution.
36class DefaultBurstExecutorWithCache : public ExecutionBurstServer::IBurstExecutorWithCache {
37 public:
38 DefaultBurstExecutorWithCache(IPreparedModel* preparedModel) : mpPreparedModel(preparedModel) {}
Michael Butler60296322019-01-17 17:54:51 -080039
Michael Butler238fe722019-03-21 12:17:27 -070040 bool isCacheEntryPresent(int32_t slot) const override {
Michael Butler47c988f62019-03-14 17:34:48 -070041 return slot < mMemoryCache.size() && mMemoryCache[slot].valid();
Michael Butler238fe722019-03-21 12:17:27 -070042 }
Michael Butler47c988f62019-03-14 17:34:48 -070043
Michael Butler238fe722019-03-21 12:17:27 -070044 void addCacheEntry(const hidl_memory& memory, int32_t slot) override {
45 if (slot >= mMemoryCache.size()) {
46 mMemoryCache.resize(slot + 1);
47 }
48 mMemoryCache[slot] = memory;
49 }
Michael Butler60296322019-01-17 17:54:51 -080050
Michael Butler238fe722019-03-21 12:17:27 -070051 void removeCacheEntry(int32_t slot) override {
52 if (slot < mMemoryCache.size()) {
53 mMemoryCache[slot] = {};
54 }
55 }
56
57 std::tuple<ErrorStatus, hidl_vec<OutputShape>, Timing> execute(
58 const Request& request, const std::vector<int32_t>& slots,
59 MeasureTiming measure) override {
60 // convert slots to pools
61 hidl_vec<hidl_memory> pools(slots.size());
62 std::transform(slots.begin(), slots.end(), pools.begin(), [this](int32_t slot) {
63 return slot < mMemoryCache.size() ? mMemoryCache[slot] : hidl_memory{};
64 });
65
66 // create full request
67 Request fullRequest = request;
68 fullRequest.pools = std::move(pools);
69
70 // setup execution
71 ErrorStatus returnedStatus = ErrorStatus::GENERAL_FAILURE;
72 hidl_vec<OutputShape> returnedOutputShapes;
73 Timing returnedTiming;
74 auto cb = [&returnedStatus, &returnedOutputShapes, &returnedTiming](
75 ErrorStatus status, const hidl_vec<OutputShape>& outputShapes,
76 const Timing& timing) {
77 returnedStatus = status;
78 returnedOutputShapes = outputShapes;
79 returnedTiming = timing;
Michael Butler47c988f62019-03-14 17:34:48 -070080 };
Michael Butler60296322019-01-17 17:54:51 -080081
Michael Butler238fe722019-03-21 12:17:27 -070082 // execute
83 const Return<void> ret = mpPreparedModel->executeSynchronously(fullRequest, measure, cb);
84 if (!ret.isOk() || returnedStatus != ErrorStatus::NONE) {
85 LOG(ERROR) << "IPreparedModelAdapter::execute -- Error executing";
86 return {ErrorStatus::GENERAL_FAILURE, {}, {}};
Michael Butler89e99ba2019-01-24 02:36:37 -080087 }
Michael Butler60296322019-01-17 17:54:51 -080088
Michael Butler238fe722019-03-21 12:17:27 -070089 return std::make_tuple(returnedStatus, std::move(returnedOutputShapes), returnedTiming);
Michael Butler60296322019-01-17 17:54:51 -080090 }
91
Michael Butler238fe722019-03-21 12:17:27 -070092 private:
93 IPreparedModel* const mpPreparedModel;
94 std::vector<hidl_memory> mMemoryCache;
95};
Michael Butler47c988f62019-03-14 17:34:48 -070096
Michael Butler238fe722019-03-21 12:17:27 -070097} // anonymous namespace
Michael Butler60296322019-01-17 17:54:51 -080098
Michael Butler60296322019-01-17 17:54:51 -080099// serialize result
Michael Butlerc932ebb2019-04-11 14:24:06 -0700100std::vector<FmqResultDatum> serialize(ErrorStatus errorStatus,
101 const std::vector<OutputShape>& outputShapes, Timing timing) {
Michael Butler60296322019-01-17 17:54:51 -0800102 // count how many elements need to be sent for a request
103 size_t count = 2 + outputShapes.size();
104 for (const auto& outputShape : outputShapes) {
105 count += outputShape.dimensions.size();
106 }
107
108 // create buffer to temporarily store elements
109 std::vector<FmqResultDatum> data;
110 data.reserve(count);
111
112 // package packetInfo
113 {
114 FmqResultDatum datum;
115 datum.packetInformation({/*.packetSize=*/static_cast<uint32_t>(count),
116 /*.errorStatus=*/errorStatus,
117 /*.numberOfOperands=*/static_cast<uint32_t>(outputShapes.size())});
118 data.push_back(datum);
119 }
120
121 // package output shape data
122 for (const auto& operand : outputShapes) {
123 // package operand information
124 FmqResultDatum datum;
125 datum.operandInformation(
126 {/*.isSufficient=*/operand.isSufficient,
127 /*.numberOfDimensions=*/static_cast<uint32_t>(operand.dimensions.size())});
128 data.push_back(datum);
129
130 // package operand dimensions
131 for (uint32_t dimension : operand.dimensions) {
132 FmqResultDatum datum;
133 datum.operandDimensionValue(dimension);
134 data.push_back(datum);
135 }
136 }
137
138 // package executionTiming
139 {
140 FmqResultDatum datum;
141 datum.executionTiming(timing);
142 data.push_back(datum);
143 }
144
145 // return result
146 return data;
147}
148
Michael Butlerc932ebb2019-04-11 14:24:06 -0700149// deserialize request
150std::optional<std::tuple<Request, std::vector<int32_t>, MeasureTiming>> deserialize(
151 const std::vector<FmqRequestDatum>& data) {
152 using discriminator = FmqRequestDatum::hidl_discriminator;
Michael Butler60296322019-01-17 17:54:51 -0800153
Michael Butlerc932ebb2019-04-11 14:24:06 -0700154 size_t index = 0;
155
156 // validate packet information
157 if (data[index].getDiscriminator() != discriminator::packetInformation) {
158 LOG(ERROR) << "FMQ Request packet ill-formed";
159 return std::nullopt;
160 }
161
162 // unpackage packet information
163 const FmqRequestDatum::PacketInformation& packetInfo = data[index].packetInformation();
164 index++;
165 const uint32_t packetSize = packetInfo.packetSize;
166 const uint32_t numberOfInputOperands = packetInfo.numberOfInputOperands;
167 const uint32_t numberOfOutputOperands = packetInfo.numberOfOutputOperands;
168 const uint32_t numberOfPools = packetInfo.numberOfPools;
169
170 // unpackage input operands
171 std::vector<RequestArgument> inputs;
172 inputs.reserve(numberOfInputOperands);
173 for (size_t operand = 0; operand < numberOfInputOperands; ++operand) {
174 // validate input operand information
175 if (data[index].getDiscriminator() != discriminator::inputOperandInformation) {
176 LOG(ERROR) << "FMQ Request packet ill-formed";
177 return std::nullopt;
Michael Butler60296322019-01-17 17:54:51 -0800178 }
179
Michael Butlerc932ebb2019-04-11 14:24:06 -0700180 // unpackage operand information
181 const FmqRequestDatum::OperandInformation& operandInfo =
182 data[index].inputOperandInformation();
183 index++;
184 const bool hasNoValue = operandInfo.hasNoValue;
185 const DataLocation location = operandInfo.location;
186 const uint32_t numberOfDimensions = operandInfo.numberOfDimensions;
Michael Butler3db6fe52019-01-29 11:20:30 -0800187
Michael Butlerc932ebb2019-04-11 14:24:06 -0700188 // unpackage operand dimensions
189 std::vector<uint32_t> dimensions;
190 dimensions.reserve(numberOfDimensions);
191 for (size_t i = 0; i < numberOfDimensions; ++i) {
192 // validate dimension
193 if (data[index].getDiscriminator() != discriminator::inputOperandDimensionValue) {
194 LOG(ERROR) << "FMQ Request packet ill-formed";
195 return std::nullopt;
196 }
197
198 // unpackage dimension
199 const uint32_t dimension = data[index].inputOperandDimensionValue();
200 index++;
201
202 // store result
203 dimensions.push_back(dimension);
204 }
205
206 // store result
207 inputs.push_back(
208 {/*.hasNoValue=*/hasNoValue, /*.location=*/location, /*.dimensions=*/dimensions});
209 }
210
211 // unpackage output operands
212 std::vector<RequestArgument> outputs;
213 outputs.reserve(numberOfOutputOperands);
214 for (size_t operand = 0; operand < numberOfOutputOperands; ++operand) {
215 // validate output operand information
216 if (data[index].getDiscriminator() != discriminator::outputOperandInformation) {
217 LOG(ERROR) << "FMQ Request packet ill-formed";
218 return std::nullopt;
219 }
220
221 // unpackage operand information
222 const FmqRequestDatum::OperandInformation& operandInfo =
223 data[index].outputOperandInformation();
224 index++;
225 const bool hasNoValue = operandInfo.hasNoValue;
226 const DataLocation location = operandInfo.location;
227 const uint32_t numberOfDimensions = operandInfo.numberOfDimensions;
228
229 // unpackage operand dimensions
230 std::vector<uint32_t> dimensions;
231 dimensions.reserve(numberOfDimensions);
232 for (size_t i = 0; i < numberOfDimensions; ++i) {
233 // validate dimension
234 if (data[index].getDiscriminator() != discriminator::outputOperandDimensionValue) {
235 LOG(ERROR) << "FMQ Request packet ill-formed";
236 return std::nullopt;
237 }
238
239 // unpackage dimension
240 const uint32_t dimension = data[index].outputOperandDimensionValue();
241 index++;
242
243 // store result
244 dimensions.push_back(dimension);
245 }
246
247 // store result
248 outputs.push_back(
249 {/*.hasNoValue=*/hasNoValue, /*.location=*/location, /*.dimensions=*/dimensions});
250 }
251
252 // unpackage pools
253 std::vector<int32_t> slots;
254 slots.reserve(numberOfPools);
255 for (size_t pool = 0; pool < numberOfPools; ++pool) {
256 // validate input operand information
257 if (data[index].getDiscriminator() != discriminator::poolIdentifier) {
258 LOG(ERROR) << "FMQ Request packet ill-formed";
259 return std::nullopt;
260 }
261
262 // unpackage operand information
263 const int32_t poolId = data[index].poolIdentifier();
264 index++;
265
266 // store result
267 slots.push_back(poolId);
268 }
269
270 // validate measureTiming
271 if (data[index].getDiscriminator() != discriminator::measureTiming) {
272 LOG(ERROR) << "FMQ Request packet ill-formed";
273 return std::nullopt;
274 }
275
276 // unpackage measureTiming
277 const MeasureTiming measure = data[index].measureTiming();
278 index++;
279
280 // validate packet information
281 if (index != packetSize) {
282 LOG(ERROR) << "FMQ Result packet ill-formed";
283 return std::nullopt;
284 }
285
286 // return request
287 Request request = {/*.inputs=*/inputs, /*.outputs=*/outputs, /*.pools=*/{}};
288 return std::make_tuple(std::move(request), std::move(slots), measure);
289}
290
291// RequestChannelReceiver methods
292
293std::unique_ptr<RequestChannelReceiver> RequestChannelReceiver::create(
294 const FmqRequestDescriptor& requestChannel) {
295 std::unique_ptr<FmqRequestChannel> fmqRequestChannel =
296 std::make_unique<FmqRequestChannel>(requestChannel);
297 if (!fmqRequestChannel->isValid()) {
298 LOG(ERROR) << "Unable to create RequestChannelReceiver";
299 return nullptr;
300 }
301 const bool blocking = fmqRequestChannel->getEventFlagWord() != nullptr;
302 return std::make_unique<RequestChannelReceiver>(std::move(fmqRequestChannel), blocking);
303}
304
305RequestChannelReceiver::RequestChannelReceiver(std::unique_ptr<FmqRequestChannel> fmqRequestChannel,
306 bool blocking)
307 : mFmqRequestChannel(std::move(fmqRequestChannel)), mBlocking(blocking) {}
308
309std::optional<std::tuple<Request, std::vector<int32_t>, MeasureTiming>>
310RequestChannelReceiver::getBlocking() {
311 const auto packet = getPacketBlocking();
312 if (!packet) {
313 return std::nullopt;
314 }
315
316 return deserialize(*packet);
317}
318
319void RequestChannelReceiver::invalidate() {
320 mTeardown = true;
321
322 // force unblock
323 // ExecutionBurstServer is by default waiting on a request packet. If the
324 // client process destroys its burst object, the server will still be
325 // waiting on the futex (assuming mBlocking is true). This force unblock
326 // wakes up any thread waiting on the futex.
327 if (mBlocking) {
328 // TODO: look for a different/better way to signal/notify the futex to
329 // wake up any thread waiting on it
330 FmqRequestDatum datum;
331 datum.packetInformation({/*.packetSize=*/0, /*.numberOfInputOperands=*/0,
332 /*.numberOfOutputOperands=*/0, /*.numberOfPools=*/0});
333 mFmqRequestChannel->writeBlocking(&datum, 1);
334 }
335}
336
337std::optional<std::vector<FmqRequestDatum>> RequestChannelReceiver::getPacketBlocking() {
338 using discriminator = FmqRequestDatum::hidl_discriminator;
339
340 if (mTeardown) {
341 return std::nullopt;
342 }
343
344 // wait for request packet and read first element of request packet
345 // TODO: have a more elegant way to wait for data, and read it all at once.
346 // For example, EventFlag can be used to directly wait on the futex, and all
347 // the data can be read at once with a non-blocking call to
348 // MessageQueue::read. For further optimization, MessageQueue::beginRead and
349 // MessageQueue::commitRead can be used to avoid an extra copy of the
350 // metadata.
351 FmqRequestDatum datum;
352 bool success = false;
353 if (mBlocking) {
354 success = mFmqRequestChannel->readBlocking(&datum, 1);
355 } else {
356 while ((success = !mTeardown.load(std::memory_order_relaxed)) &&
357 !mFmqRequestChannel->read(&datum, 1)) {
358 }
359 }
360
361 // terminate loop
362 if (mTeardown) {
363 return std::nullopt;
364 }
365
366 // validate packet information
367 if (!success || datum.getDiscriminator() != discriminator::packetInformation) {
368 LOG(ERROR) << "FMQ Request packet ill-formed";
369 return std::make_optional<std::vector<FmqRequestDatum>>();
370 }
371
372 NNTRACE_FULL(NNTRACE_LAYER_IPC, NNTRACE_PHASE_EXECUTION, "ExecutionBurstServer getting packet");
373
374 // unpack packet information
375 const auto& packetInfo = datum.packetInformation();
376 const size_t count = packetInfo.packetSize;
377
378 // retrieve remaining elements
379 // NOTE: all of the data is already available at this point, so there's no
380 // need to do a blocking wait to wait for more data. This is known because
381 // in FMQ, all writes are published (made available) atomically. Currently,
382 // the producer always publishes the entire packet in one function call, so
383 // if the first element of the packet is available, the remaining elements
384 // are also available.
385 std::vector<FmqRequestDatum> packet(count);
386 packet.front() = datum;
387 success = mFmqRequestChannel->read(packet.data() + 1, packet.size() - 1);
388
389 if (!success) {
390 return std::make_optional<std::vector<FmqRequestDatum>>();
391 }
392
393 return packet;
394}
395
396// ResultChannelSender methods
397
398std::unique_ptr<ResultChannelSender> ResultChannelSender::create(
399 const FmqResultDescriptor& resultChannel) {
400 std::unique_ptr<FmqResultChannel> fmqResultChannel =
401 std::make_unique<FmqResultChannel>(resultChannel);
402 if (!fmqResultChannel->isValid()) {
403 LOG(ERROR) << "Unable to create RequestChannelSender";
404 return nullptr;
405 }
406 const bool blocking = fmqResultChannel->getEventFlagWord() != nullptr;
407 return std::make_unique<ResultChannelSender>(std::move(fmqResultChannel), blocking);
408}
409
410ResultChannelSender::ResultChannelSender(std::unique_ptr<FmqResultChannel> fmqResultChannel,
411 bool blocking)
412 : mFmqResultChannel(std::move(fmqResultChannel)), mBlocking(blocking) {}
413
414bool ResultChannelSender::send(ErrorStatus errorStatus,
415 const std::vector<OutputShape>& outputShapes, Timing timing) {
416 const std::vector<FmqResultDatum> serialized = serialize(errorStatus, outputShapes, timing);
417 return sendPacket(serialized);
418}
419
420bool ResultChannelSender::sendPacket(const std::vector<FmqResultDatum>& packet) {
421 if (mBlocking) {
422 return mFmqResultChannel->writeBlocking(packet.data(), packet.size());
423 } else {
424 return mFmqResultChannel->write(packet.data(), packet.size());
425 }
426}
427
428// ExecutionBurstServer methods
429
430sp<ExecutionBurstServer> ExecutionBurstServer::create(
431 const sp<IBurstCallback>& callback, const MQDescriptorSync<FmqRequestDatum>& requestChannel,
432 const MQDescriptorSync<FmqResultDatum>& resultChannel,
433 std::shared_ptr<IBurstExecutorWithCache> executorWithCache) {
434 // check inputs
435 if (callback == nullptr || executorWithCache == nullptr) {
436 LOG(ERROR) << "ExecutionBurstServer::create passed a nullptr";
437 return nullptr;
438 }
439
440 // create FMQ objects
441 std::unique_ptr<RequestChannelReceiver> requestChannelReceiver =
442 RequestChannelReceiver::create(requestChannel);
443 std::unique_ptr<ResultChannelSender> resultChannelSender =
444 ResultChannelSender::create(resultChannel);
445
446 // check FMQ objects
447 if (!requestChannelReceiver || !resultChannelSender) {
448 LOG(ERROR) << "ExecutionBurstServer::create failed to create FastMessageQueue";
449 return nullptr;
450 }
451
452 // make and return context
453 return new ExecutionBurstServer(callback, std::move(requestChannelReceiver),
454 std::move(resultChannelSender), std::move(executorWithCache));
455}
456
457sp<ExecutionBurstServer> ExecutionBurstServer::create(
458 const sp<IBurstCallback>& callback, const MQDescriptorSync<FmqRequestDatum>& requestChannel,
459 const MQDescriptorSync<FmqResultDatum>& resultChannel, IPreparedModel* preparedModel) {
460 // check relevant input
461 if (preparedModel == nullptr) {
462 LOG(ERROR) << "ExecutionBurstServer::create passed a nullptr";
463 return nullptr;
464 }
465
466 // adapt IPreparedModel to have caching
467 const std::shared_ptr<DefaultBurstExecutorWithCache> preparedModelAdapter =
468 std::make_shared<DefaultBurstExecutorWithCache>(preparedModel);
469
470 // make and return context
471 return ExecutionBurstServer::create(callback, requestChannel, resultChannel,
472 preparedModelAdapter);
473}
474
475ExecutionBurstServer::ExecutionBurstServer(
476 const sp<IBurstCallback>& callback, std::unique_ptr<RequestChannelReceiver> requestChannel,
477 std::unique_ptr<ResultChannelSender> resultChannel,
478 std::shared_ptr<IBurstExecutorWithCache> executorWithCache)
479 : mCallback(callback),
480 mRequestChannelReceiver(std::move(requestChannel)),
481 mResultChannelSender(std::move(resultChannel)),
482 mExecutorWithCache(std::move(executorWithCache)) {
483 // TODO: highly document the threading behavior of this class
484 mWorker = std::thread([this] { task(); });
485}
486
487ExecutionBurstServer::~ExecutionBurstServer() {
488 // set teardown flag
489 mTeardown = true;
490 mRequestChannelReceiver->invalidate();
491
492 // wait for task thread to end
493 mWorker.join();
494}
495
496Return<void> ExecutionBurstServer::freeMemory(int32_t slot) {
497 mExecutorWithCache->removeCacheEntry(slot);
498 return Void();
499}
500
501void ExecutionBurstServer::ensureCacheEntriesArePresentLocked(const std::vector<int32_t>& slots) {
502 const auto slotIsKnown = [this](int32_t slot) {
503 return mExecutorWithCache->isCacheEntryPresent(slot);
504 };
505
506 // find unique unknown slots
507 std::vector<int32_t> unknownSlots = slots;
508 auto unknownSlotsEnd = unknownSlots.end();
509 std::sort(unknownSlots.begin(), unknownSlotsEnd);
510 unknownSlotsEnd = std::unique(unknownSlots.begin(), unknownSlotsEnd);
511 unknownSlotsEnd = std::remove_if(unknownSlots.begin(), unknownSlotsEnd, slotIsKnown);
512 unknownSlots.erase(unknownSlotsEnd, unknownSlots.end());
513
514 // quick-exit if all slots are known
515 if (unknownSlots.empty()) {
516 return;
517 }
518
519 ErrorStatus errorStatus = ErrorStatus::GENERAL_FAILURE;
520 std::vector<hidl_memory> returnedMemories;
521 auto cb = [&errorStatus, &returnedMemories](ErrorStatus status,
522 const hidl_vec<hidl_memory>& memories) {
523 errorStatus = status;
524 returnedMemories = memories;
525 };
526
527 const Return<void> ret = mCallback->getMemories(unknownSlots, cb);
528
529 if (!ret.isOk() || errorStatus != ErrorStatus::NONE ||
530 returnedMemories.size() != unknownSlots.size()) {
531 LOG(ERROR) << "Error retrieving memories";
532 return;
533 }
534
535 // add memories to unknown slots
536 for (size_t i = 0; i < unknownSlots.size(); ++i) {
537 mExecutorWithCache->addCacheEntry(returnedMemories[i], unknownSlots[i]);
538 }
539}
540
541void ExecutionBurstServer::task() {
542 // loop until the burst object is being destroyed
543 while (!mTeardown) {
544 // receive request
545 auto arguments = mRequestChannelReceiver->getBlocking();
546
547 // if the request packet was not properly received, return a generic
548 // error and skip the execution
549 //
550 // if the burst is being torn down, skip the execution exection so the
551 // "task" function can end
552 if (!arguments) {
553 if (!mTeardown) {
554 mResultChannelSender->send(ErrorStatus::GENERAL_FAILURE, {}, kNoTiming);
555 }
556 continue;
557 }
558
559 // otherwise begin tracing execution
560 NNTRACE_FULL(NNTRACE_LAYER_IPC, NNTRACE_PHASE_EXECUTION,
561 "ExecutionBurstServer getting memory, executing, and returning results");
562
563 // unpack the arguments; types are Request, std::vector<int32_t>, and
Michael Butler238fe722019-03-21 12:17:27 -0700564 // MeasureTiming, respectively
Michael Butlerc932ebb2019-04-11 14:24:06 -0700565 const auto [requestWithoutPools, slotsOfPools, measure] = std::move(*arguments);
Michael Butler60296322019-01-17 17:54:51 -0800566
Michael Butler238fe722019-03-21 12:17:27 -0700567 // ensure executor with cache has required memory
568 std::lock_guard<std::mutex> hold(mMutex);
569 ensureCacheEntriesArePresentLocked(slotsOfPools);
570
571 // perform computation; types are ErrorStatus, hidl_vec<OutputShape>,
572 // and Timing, respectively
573 const auto [errorStatus, outputShapes, returnedTiming] =
574 mExecutorWithCache->execute(requestWithoutPools, slotsOfPools, measure);
Michael Butler60296322019-01-17 17:54:51 -0800575
576 // return result
Michael Butlerc932ebb2019-04-11 14:24:06 -0700577 mResultChannelSender->send(errorStatus, outputShapes, returnedTiming);
Michael Butler60296322019-01-17 17:54:51 -0800578 }
579}
580
Michael Butler3db6fe52019-01-29 11:20:30 -0800581} // namespace android::nn