blob: a1d414c7009021cb4ed1cb2bb515e96492bccf43 [file] [log] [blame]
Michael Butlerb98aa6d2020-02-22 22:37:59 -08001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "Conversions.h"
18
19#include <android-base/logging.h>
20#include <android/hardware/neuralnetworks/1.3/types.h>
21#include <nnapi/OperandTypes.h>
22#include <nnapi/OperationTypes.h>
23#include <nnapi/Result.h>
24#include <nnapi/SharedMemory.h>
25#include <nnapi/TypeUtils.h>
26#include <nnapi/Types.h>
Michael Butler6547b2a2020-11-22 19:36:30 -080027#include <nnapi/Validation.h>
Michael Butlerb98aa6d2020-02-22 22:37:59 -080028#include <nnapi/hal/1.0/Conversions.h>
29#include <nnapi/hal/1.2/Conversions.h>
30#include <nnapi/hal/CommonUtils.h>
31
32#include <algorithm>
33#include <chrono>
34#include <functional>
35#include <iterator>
36#include <limits>
37#include <type_traits>
38#include <utility>
39
Michael Butler388bceb2021-02-03 15:15:43 -080040#include "Utils.h"
41
Michael Butlerb98aa6d2020-02-22 22:37:59 -080042namespace {
43
Michael Butler382d5132021-03-18 21:15:09 -070044std::chrono::nanoseconds makeNanosFromUint64(uint64_t nanoseconds) {
45 constexpr auto kMaxCount = std::chrono::nanoseconds::max().count();
46 using CommonType = std::common_type_t<std::chrono::nanoseconds::rep, uint64_t>;
47 const auto count = std::min<CommonType>(kMaxCount, nanoseconds);
48 return std::chrono::nanoseconds{static_cast<std::chrono::nanoseconds::rep>(count)};
49}
50
51uint64_t makeUint64FromNanos(std::chrono::nanoseconds nanoseconds) {
52 if (nanoseconds < std::chrono::nanoseconds::zero()) {
53 return 0;
54 }
55 constexpr auto kMaxCount = std::numeric_limits<uint64_t>::max();
56 using CommonType = std::common_type_t<std::chrono::nanoseconds::rep, uint64_t>;
57 const auto count = std::min<CommonType>(kMaxCount, nanoseconds.count());
58 return static_cast<uint64_t>(count);
59}
60
Michael Butlerb98aa6d2020-02-22 22:37:59 -080061template <typename Type>
62constexpr std::underlying_type_t<Type> underlyingType(Type value) {
63 return static_cast<std::underlying_type_t<Type>>(value);
64}
65
66} // namespace
67
68namespace android::nn {
69namespace {
70
Michael Butlerb98aa6d2020-02-22 22:37:59 -080071using hardware::hidl_vec;
72
73template <typename Input>
Michael Butler388bceb2021-02-03 15:15:43 -080074using UnvalidatedConvertOutput =
Michael Butler6547b2a2020-11-22 19:36:30 -080075 std::decay_t<decltype(unvalidatedConvert(std::declval<Input>()).value())>;
Michael Butlerb98aa6d2020-02-22 22:37:59 -080076
77template <typename Type>
Michael Butler388bceb2021-02-03 15:15:43 -080078GeneralResult<std::vector<UnvalidatedConvertOutput<Type>>> unvalidatedConvert(
Michael Butler6547b2a2020-11-22 19:36:30 -080079 const hidl_vec<Type>& arguments) {
Michael Butler388bceb2021-02-03 15:15:43 -080080 std::vector<UnvalidatedConvertOutput<Type>> canonical;
Michael Butlerb98aa6d2020-02-22 22:37:59 -080081 canonical.reserve(arguments.size());
82 for (const auto& argument : arguments) {
Michael Butler6547b2a2020-11-22 19:36:30 -080083 canonical.push_back(NN_TRY(nn::unvalidatedConvert(argument)));
Michael Butlerb98aa6d2020-02-22 22:37:59 -080084 }
85 return canonical;
86}
87
88template <typename Type>
Michael Butler388bceb2021-02-03 15:15:43 -080089GeneralResult<UnvalidatedConvertOutput<Type>> validatedConvert(const Type& halObject) {
Michael Butler6547b2a2020-11-22 19:36:30 -080090 auto canonical = NN_TRY(nn::unvalidatedConvert(halObject));
Michael Butler388bceb2021-02-03 15:15:43 -080091 NN_TRY(hal::V1_3::utils::compliantVersion(canonical));
Michael Butler6547b2a2020-11-22 19:36:30 -080092 return canonical;
93}
94
95template <typename Type>
Michael Butler388bceb2021-02-03 15:15:43 -080096GeneralResult<std::vector<UnvalidatedConvertOutput<Type>>> validatedConvert(
Michael Butler6547b2a2020-11-22 19:36:30 -080097 const hidl_vec<Type>& arguments) {
Michael Butler388bceb2021-02-03 15:15:43 -080098 std::vector<UnvalidatedConvertOutput<Type>> canonical;
Michael Butler6547b2a2020-11-22 19:36:30 -080099 canonical.reserve(arguments.size());
100 for (const auto& argument : arguments) {
101 canonical.push_back(NN_TRY(validatedConvert(argument)));
102 }
103 return canonical;
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800104}
105
106} // anonymous namespace
107
Michael Butler6547b2a2020-11-22 19:36:30 -0800108GeneralResult<OperandType> unvalidatedConvert(const hal::V1_3::OperandType& operandType) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800109 return static_cast<OperandType>(operandType);
110}
111
Michael Butler6547b2a2020-11-22 19:36:30 -0800112GeneralResult<OperationType> unvalidatedConvert(const hal::V1_3::OperationType& operationType) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800113 return static_cast<OperationType>(operationType);
114}
115
Michael Butler6547b2a2020-11-22 19:36:30 -0800116GeneralResult<Priority> unvalidatedConvert(const hal::V1_3::Priority& priority) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800117 return static_cast<Priority>(priority);
118}
119
Michael Butler6547b2a2020-11-22 19:36:30 -0800120GeneralResult<Capabilities> unvalidatedConvert(const hal::V1_3::Capabilities& capabilities) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800121 const bool validOperandTypes = std::all_of(
122 capabilities.operandPerformance.begin(), capabilities.operandPerformance.end(),
123 [](const hal::V1_3::Capabilities::OperandPerformance& operandPerformance) {
Michael Butler388bceb2021-02-03 15:15:43 -0800124 return validatedConvert(operandPerformance.type).has_value();
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800125 });
126 if (!validOperandTypes) {
Michael Butler4b276a72020-08-06 23:22:35 -0700127 return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE)
Michael Butler6547b2a2020-11-22 19:36:30 -0800128 << "Invalid OperandType when unvalidatedConverting OperandPerformance in "
129 "Capabilities";
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800130 }
131
Michael Butler6547b2a2020-11-22 19:36:30 -0800132 auto operandPerformance = NN_TRY(unvalidatedConvert(capabilities.operandPerformance));
Michael Butlerff9a5a52021-10-15 16:23:20 -0700133 auto table =
134 NN_TRY(Capabilities::OperandPerformanceTable::create(std::move(operandPerformance)));
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800135
136 return Capabilities{
Michael Butler6547b2a2020-11-22 19:36:30 -0800137 .relaxedFloat32toFloat16PerformanceScalar = NN_TRY(
138 unvalidatedConvert(capabilities.relaxedFloat32toFloat16PerformanceScalar)),
139 .relaxedFloat32toFloat16PerformanceTensor = NN_TRY(
140 unvalidatedConvert(capabilities.relaxedFloat32toFloat16PerformanceTensor)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800141 .operandPerformance = std::move(table),
Michael Butler6547b2a2020-11-22 19:36:30 -0800142 .ifPerformance = NN_TRY(unvalidatedConvert(capabilities.ifPerformance)),
143 .whilePerformance = NN_TRY(unvalidatedConvert(capabilities.whilePerformance)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800144 };
145}
146
Michael Butler6547b2a2020-11-22 19:36:30 -0800147GeneralResult<Capabilities::OperandPerformance> unvalidatedConvert(
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800148 const hal::V1_3::Capabilities::OperandPerformance& operandPerformance) {
149 return Capabilities::OperandPerformance{
Michael Butler6547b2a2020-11-22 19:36:30 -0800150 .type = NN_TRY(unvalidatedConvert(operandPerformance.type)),
151 .info = NN_TRY(unvalidatedConvert(operandPerformance.info)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800152 };
153}
154
Michael Butler6547b2a2020-11-22 19:36:30 -0800155GeneralResult<Operation> unvalidatedConvert(const hal::V1_3::Operation& operation) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800156 return Operation{
Michael Butler6547b2a2020-11-22 19:36:30 -0800157 .type = NN_TRY(unvalidatedConvert(operation.type)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800158 .inputs = operation.inputs,
159 .outputs = operation.outputs,
160 };
161}
162
Michael Butler6547b2a2020-11-22 19:36:30 -0800163GeneralResult<Operand::LifeTime> unvalidatedConvert(
164 const hal::V1_3::OperandLifeTime& operandLifeTime) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800165 return static_cast<Operand::LifeTime>(operandLifeTime);
166}
167
Michael Butler6547b2a2020-11-22 19:36:30 -0800168GeneralResult<Operand> unvalidatedConvert(const hal::V1_3::Operand& operand) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800169 return Operand{
Michael Butler6547b2a2020-11-22 19:36:30 -0800170 .type = NN_TRY(unvalidatedConvert(operand.type)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800171 .dimensions = operand.dimensions,
172 .scale = operand.scale,
173 .zeroPoint = operand.zeroPoint,
Michael Butler6547b2a2020-11-22 19:36:30 -0800174 .lifetime = NN_TRY(unvalidatedConvert(operand.lifetime)),
175 .location = NN_TRY(unvalidatedConvert(operand.location)),
176 .extraParams = NN_TRY(unvalidatedConvert(operand.extraParams)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800177 };
178}
179
Michael Butler6547b2a2020-11-22 19:36:30 -0800180GeneralResult<Model> unvalidatedConvert(const hal::V1_3::Model& model) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800181 return Model{
Michael Butler6547b2a2020-11-22 19:36:30 -0800182 .main = NN_TRY(unvalidatedConvert(model.main)),
183 .referenced = NN_TRY(unvalidatedConvert(model.referenced)),
184 .operandValues = NN_TRY(unvalidatedConvert(model.operandValues)),
185 .pools = NN_TRY(unvalidatedConvert(model.pools)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800186 .relaxComputationFloat32toFloat16 = model.relaxComputationFloat32toFloat16,
Michael Butler6547b2a2020-11-22 19:36:30 -0800187 .extensionNameToPrefix = NN_TRY(unvalidatedConvert(model.extensionNameToPrefix)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800188 };
189}
190
Michael Butler6547b2a2020-11-22 19:36:30 -0800191GeneralResult<Model::Subgraph> unvalidatedConvert(const hal::V1_3::Subgraph& subgraph) {
192 auto operations = NN_TRY(unvalidatedConvert(subgraph.operations));
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800193
194 // Verify number of consumers.
195 const auto numberOfConsumers =
Michael Butler301ef062021-10-14 22:04:59 -0700196 NN_TRY(countNumberOfConsumers(subgraph.operands.size(), operations));
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800197 CHECK(subgraph.operands.size() == numberOfConsumers.size());
198 for (size_t i = 0; i < subgraph.operands.size(); ++i) {
199 if (subgraph.operands[i].numberOfConsumers != numberOfConsumers[i]) {
Michael Butler4b276a72020-08-06 23:22:35 -0700200 return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE)
201 << "Invalid numberOfConsumers for operand " << i << ", expected "
202 << numberOfConsumers[i] << " but found "
203 << subgraph.operands[i].numberOfConsumers;
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800204 }
205 }
206
207 return Model::Subgraph{
Michael Butler6547b2a2020-11-22 19:36:30 -0800208 .operands = NN_TRY(unvalidatedConvert(subgraph.operands)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800209 .operations = std::move(operations),
210 .inputIndexes = subgraph.inputIndexes,
211 .outputIndexes = subgraph.outputIndexes,
212 };
213}
214
Michael Butler6547b2a2020-11-22 19:36:30 -0800215GeneralResult<BufferDesc> unvalidatedConvert(const hal::V1_3::BufferDesc& bufferDesc) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800216 return BufferDesc{.dimensions = bufferDesc.dimensions};
217}
218
Michael Butler6547b2a2020-11-22 19:36:30 -0800219GeneralResult<BufferRole> unvalidatedConvert(const hal::V1_3::BufferRole& bufferRole) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800220 return BufferRole{
221 .modelIndex = bufferRole.modelIndex,
222 .ioIndex = bufferRole.ioIndex,
Xusong Wang3633d072021-03-19 13:58:24 -0700223 .probability = bufferRole.frequency,
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800224 };
225}
226
Michael Butler6547b2a2020-11-22 19:36:30 -0800227GeneralResult<Request> unvalidatedConvert(const hal::V1_3::Request& request) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800228 return Request{
Michael Butler6547b2a2020-11-22 19:36:30 -0800229 .inputs = NN_TRY(unvalidatedConvert(request.inputs)),
230 .outputs = NN_TRY(unvalidatedConvert(request.outputs)),
231 .pools = NN_TRY(unvalidatedConvert(request.pools)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800232 };
233}
234
Michael Butler6547b2a2020-11-22 19:36:30 -0800235GeneralResult<Request::MemoryPool> unvalidatedConvert(
236 const hal::V1_3::Request::MemoryPool& memoryPool) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800237 using Discriminator = hal::V1_3::Request::MemoryPool::hidl_discriminator;
238 switch (memoryPool.getDiscriminator()) {
239 case Discriminator::hidlMemory:
Michael Butlere52a77e2021-06-07 13:10:58 -0700240 return unvalidatedConvert(memoryPool.hidlMemory());
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800241 case Discriminator::token:
242 return static_cast<Request::MemoryDomainToken>(memoryPool.token());
243 }
Michael Butler4b276a72020-08-06 23:22:35 -0700244 return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE)
245 << "Invalid Request::MemoryPool discriminator "
246 << underlyingType(memoryPool.getDiscriminator());
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800247}
248
Michael Butler6547b2a2020-11-22 19:36:30 -0800249GeneralResult<OptionalTimePoint> unvalidatedConvert(
250 const hal::V1_3::OptionalTimePoint& optionalTimePoint) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800251 using Discriminator = hal::V1_3::OptionalTimePoint::hidl_discriminator;
252 switch (optionalTimePoint.getDiscriminator()) {
253 case Discriminator::none:
Michael Butler4024d8f2020-12-04 17:38:20 -0800254 return {};
Michael Butler382d5132021-03-18 21:15:09 -0700255 case Discriminator::nanosecondsSinceEpoch: {
256 const auto currentSteadyTime = std::chrono::steady_clock::now();
257 const auto currentBootTime = Clock::now();
258
259 const auto timeSinceEpoch =
260 makeNanosFromUint64(optionalTimePoint.nanosecondsSinceEpoch());
261 const auto steadyTimePoint = std::chrono::steady_clock::time_point{timeSinceEpoch};
262
263 // Both steadyTimePoint and currentSteadyTime are guaranteed to be non-negative, so this
264 // subtraction will never overflow or underflow.
265 const auto timeRemaining = steadyTimePoint - currentSteadyTime;
266
267 // currentBootTime is guaranteed to be non-negative, so this code only protects against
268 // an overflow.
269 nn::TimePoint bootTimePoint;
270 constexpr auto kZeroNano = std::chrono::nanoseconds::zero();
271 constexpr auto kMaxTime = nn::TimePoint::max();
272 if (timeRemaining > kZeroNano && currentBootTime > kMaxTime - timeRemaining) {
273 bootTimePoint = kMaxTime;
274 } else {
275 bootTimePoint = currentBootTime + timeRemaining;
276 }
277
278 constexpr auto kZeroTime = nn::TimePoint{};
279 return std::max(bootTimePoint, kZeroTime);
280 }
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800281 }
Michael Butler4b276a72020-08-06 23:22:35 -0700282 return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE)
283 << "Invalid OptionalTimePoint discriminator "
284 << underlyingType(optionalTimePoint.getDiscriminator());
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800285}
286
Michael Butler4024d8f2020-12-04 17:38:20 -0800287GeneralResult<OptionalDuration> unvalidatedConvert(
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800288 const hal::V1_3::OptionalTimeoutDuration& optionalTimeoutDuration) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800289 using Discriminator = hal::V1_3::OptionalTimeoutDuration::hidl_discriminator;
290 switch (optionalTimeoutDuration.getDiscriminator()) {
291 case Discriminator::none:
Michael Butler4024d8f2020-12-04 17:38:20 -0800292 return {};
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800293 case Discriminator::nanoseconds:
Michael Butler4024d8f2020-12-04 17:38:20 -0800294 return Duration(optionalTimeoutDuration.nanoseconds());
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800295 }
Michael Butler4b276a72020-08-06 23:22:35 -0700296 return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE)
297 << "Invalid OptionalTimeoutDuration discriminator "
298 << underlyingType(optionalTimeoutDuration.getDiscriminator());
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800299}
300
Michael Butler6547b2a2020-11-22 19:36:30 -0800301GeneralResult<ErrorStatus> unvalidatedConvert(const hal::V1_3::ErrorStatus& status) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800302 switch (status) {
303 case hal::V1_3::ErrorStatus::NONE:
304 case hal::V1_3::ErrorStatus::DEVICE_UNAVAILABLE:
305 case hal::V1_3::ErrorStatus::GENERAL_FAILURE:
306 case hal::V1_3::ErrorStatus::OUTPUT_INSUFFICIENT_SIZE:
307 case hal::V1_3::ErrorStatus::INVALID_ARGUMENT:
308 case hal::V1_3::ErrorStatus::MISSED_DEADLINE_TRANSIENT:
309 case hal::V1_3::ErrorStatus::MISSED_DEADLINE_PERSISTENT:
310 case hal::V1_3::ErrorStatus::RESOURCE_EXHAUSTED_TRANSIENT:
311 case hal::V1_3::ErrorStatus::RESOURCE_EXHAUSTED_PERSISTENT:
312 return static_cast<ErrorStatus>(status);
313 }
Michael Butler4b276a72020-08-06 23:22:35 -0700314 return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE)
315 << "Invalid ErrorStatus " << underlyingType(status);
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800316}
317
Michael Butler6547b2a2020-11-22 19:36:30 -0800318GeneralResult<Priority> convert(const hal::V1_3::Priority& priority) {
319 return validatedConvert(priority);
320}
321
322GeneralResult<Capabilities> convert(const hal::V1_3::Capabilities& capabilities) {
323 return validatedConvert(capabilities);
324}
325
326GeneralResult<Model> convert(const hal::V1_3::Model& model) {
327 return validatedConvert(model);
328}
329
330GeneralResult<BufferDesc> convert(const hal::V1_3::BufferDesc& bufferDesc) {
331 return validatedConvert(bufferDesc);
332}
333
334GeneralResult<Request> convert(const hal::V1_3::Request& request) {
335 return validatedConvert(request);
336}
337
338GeneralResult<OptionalTimePoint> convert(const hal::V1_3::OptionalTimePoint& optionalTimePoint) {
339 return validatedConvert(optionalTimePoint);
340}
341
Michael Butler4024d8f2020-12-04 17:38:20 -0800342GeneralResult<OptionalDuration> convert(
Michael Butler6547b2a2020-11-22 19:36:30 -0800343 const hal::V1_3::OptionalTimeoutDuration& optionalTimeoutDuration) {
344 return validatedConvert(optionalTimeoutDuration);
345}
346
347GeneralResult<ErrorStatus> convert(const hal::V1_3::ErrorStatus& errorStatus) {
348 return validatedConvert(errorStatus);
349}
350
351GeneralResult<SharedHandle> convert(const hardware::hidl_handle& handle) {
352 return validatedConvert(handle);
353}
354
Michael Butler4b276a72020-08-06 23:22:35 -0700355GeneralResult<std::vector<BufferRole>> convert(
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800356 const hardware::hidl_vec<hal::V1_3::BufferRole>& bufferRoles) {
Michael Butler6547b2a2020-11-22 19:36:30 -0800357 return validatedConvert(bufferRoles);
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800358}
359
360} // namespace android::nn
361
362namespace android::hardware::neuralnetworks::V1_3::utils {
363namespace {
364
Michael Butler6547b2a2020-11-22 19:36:30 -0800365using utils::unvalidatedConvert;
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800366
Michael Butler6547b2a2020-11-22 19:36:30 -0800367nn::GeneralResult<V1_0::PerformanceInfo> unvalidatedConvert(
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800368 const nn::Capabilities::PerformanceInfo& performanceInfo) {
Michael Butler6547b2a2020-11-22 19:36:30 -0800369 return V1_0::utils::unvalidatedConvert(performanceInfo);
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800370}
371
Michael Butler6547b2a2020-11-22 19:36:30 -0800372nn::GeneralResult<V1_0::DataLocation> unvalidatedConvert(const nn::DataLocation& dataLocation) {
373 return V1_0::utils::unvalidatedConvert(dataLocation);
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800374}
375
Michael Butler6547b2a2020-11-22 19:36:30 -0800376nn::GeneralResult<hidl_vec<uint8_t>> unvalidatedConvert(
377 const nn::Model::OperandValues& operandValues) {
378 return V1_0::utils::unvalidatedConvert(operandValues);
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800379}
380
Michael Butler6547b2a2020-11-22 19:36:30 -0800381nn::GeneralResult<hidl_handle> unvalidatedConvert(const nn::SharedHandle& handle) {
Michael Butler15965822021-10-14 23:45:11 -0700382 return V1_0::utils::unvalidatedConvert(handle);
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800383}
384
Michael Butlerfadeb8a2021-02-07 00:11:13 -0800385nn::GeneralResult<hidl_memory> unvalidatedConvert(const nn::SharedMemory& memory) {
Michael Butler6547b2a2020-11-22 19:36:30 -0800386 return V1_0::utils::unvalidatedConvert(memory);
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800387}
388
Michael Butler6547b2a2020-11-22 19:36:30 -0800389nn::GeneralResult<V1_0::RequestArgument> unvalidatedConvert(const nn::Request::Argument& argument) {
390 return V1_0::utils::unvalidatedConvert(argument);
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800391}
392
Michael Butler6547b2a2020-11-22 19:36:30 -0800393nn::GeneralResult<V1_2::Operand::ExtraParams> unvalidatedConvert(
394 const nn::Operand::ExtraParams& extraParams) {
395 return V1_2::utils::unvalidatedConvert(extraParams);
396}
397
398nn::GeneralResult<V1_2::Model::ExtensionNameAndPrefix> unvalidatedConvert(
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800399 const nn::Model::ExtensionNameAndPrefix& extensionNameAndPrefix) {
Michael Butler6547b2a2020-11-22 19:36:30 -0800400 return V1_2::utils::unvalidatedConvert(extensionNameAndPrefix);
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800401}
402
403template <typename Input>
Michael Butler388bceb2021-02-03 15:15:43 -0800404using UnvalidatedConvertOutput =
Michael Butler6547b2a2020-11-22 19:36:30 -0800405 std::decay_t<decltype(unvalidatedConvert(std::declval<Input>()).value())>;
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800406
407template <typename Type>
Michael Butler388bceb2021-02-03 15:15:43 -0800408nn::GeneralResult<hidl_vec<UnvalidatedConvertOutput<Type>>> unvalidatedConvert(
Michael Butler6547b2a2020-11-22 19:36:30 -0800409 const std::vector<Type>& arguments) {
Michael Butler388bceb2021-02-03 15:15:43 -0800410 hidl_vec<UnvalidatedConvertOutput<Type>> halObject(arguments.size());
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800411 for (size_t i = 0; i < arguments.size(); ++i) {
Michael Butler6547b2a2020-11-22 19:36:30 -0800412 halObject[i] = NN_TRY(unvalidatedConvert(arguments[i]));
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800413 }
414 return halObject;
415}
416
Michael Butlerfadeb8a2021-02-07 00:11:13 -0800417nn::GeneralResult<Request::MemoryPool> makeMemoryPool(const nn::SharedMemory& memory) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800418 Request::MemoryPool ret;
Michael Butler6547b2a2020-11-22 19:36:30 -0800419 ret.hidlMemory(NN_TRY(unvalidatedConvert(memory)));
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800420 return ret;
421}
422
Michael Butler4b276a72020-08-06 23:22:35 -0700423nn::GeneralResult<Request::MemoryPool> makeMemoryPool(const nn::Request::MemoryDomainToken& token) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800424 Request::MemoryPool ret;
425 ret.token(underlyingType(token));
426 return ret;
427}
428
Michael Butler4b276a72020-08-06 23:22:35 -0700429nn::GeneralResult<Request::MemoryPool> makeMemoryPool(const nn::SharedBuffer& /*buffer*/) {
430 return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE) << "Unable to make memory pool from IBuffer";
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800431}
432
Michael Butler6547b2a2020-11-22 19:36:30 -0800433using utils::unvalidatedConvert;
434
435template <typename Type>
Michael Butler388bceb2021-02-03 15:15:43 -0800436nn::GeneralResult<UnvalidatedConvertOutput<Type>> validatedConvert(const Type& canonical) {
437 NN_TRY(compliantVersion(canonical));
Michael Butler6547b2a2020-11-22 19:36:30 -0800438 return unvalidatedConvert(canonical);
439}
440
441template <typename Type>
Michael Butler388bceb2021-02-03 15:15:43 -0800442nn::GeneralResult<hidl_vec<UnvalidatedConvertOutput<Type>>> validatedConvert(
Michael Butler6547b2a2020-11-22 19:36:30 -0800443 const std::vector<Type>& arguments) {
Michael Butler388bceb2021-02-03 15:15:43 -0800444 hidl_vec<UnvalidatedConvertOutput<Type>> halObject(arguments.size());
Michael Butler6547b2a2020-11-22 19:36:30 -0800445 for (size_t i = 0; i < arguments.size(); ++i) {
446 halObject[i] = NN_TRY(validatedConvert(arguments[i]));
447 }
448 return halObject;
449}
450
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800451} // anonymous namespace
452
Michael Butler6547b2a2020-11-22 19:36:30 -0800453nn::GeneralResult<OperandType> unvalidatedConvert(const nn::OperandType& operandType) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800454 return static_cast<OperandType>(operandType);
455}
456
Michael Butler6547b2a2020-11-22 19:36:30 -0800457nn::GeneralResult<OperationType> unvalidatedConvert(const nn::OperationType& operationType) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800458 return static_cast<OperationType>(operationType);
459}
460
Michael Butler6547b2a2020-11-22 19:36:30 -0800461nn::GeneralResult<Priority> unvalidatedConvert(const nn::Priority& priority) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800462 return static_cast<Priority>(priority);
463}
464
Michael Butler6547b2a2020-11-22 19:36:30 -0800465nn::GeneralResult<Capabilities> unvalidatedConvert(const nn::Capabilities& capabilities) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800466 std::vector<nn::Capabilities::OperandPerformance> operandPerformance;
467 operandPerformance.reserve(capabilities.operandPerformance.asVector().size());
468 std::copy_if(capabilities.operandPerformance.asVector().begin(),
469 capabilities.operandPerformance.asVector().end(),
470 std::back_inserter(operandPerformance),
471 [](const nn::Capabilities::OperandPerformance& operandPerformance) {
Michael Butler388bceb2021-02-03 15:15:43 -0800472 return compliantVersion(operandPerformance.type).has_value();
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800473 });
474
475 return Capabilities{
Michael Butler6547b2a2020-11-22 19:36:30 -0800476 .relaxedFloat32toFloat16PerformanceScalar = NN_TRY(
477 unvalidatedConvert(capabilities.relaxedFloat32toFloat16PerformanceScalar)),
478 .relaxedFloat32toFloat16PerformanceTensor = NN_TRY(
479 unvalidatedConvert(capabilities.relaxedFloat32toFloat16PerformanceTensor)),
480 .operandPerformance = NN_TRY(unvalidatedConvert(operandPerformance)),
481 .ifPerformance = NN_TRY(unvalidatedConvert(capabilities.ifPerformance)),
482 .whilePerformance = NN_TRY(unvalidatedConvert(capabilities.whilePerformance)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800483 };
484}
485
Michael Butler6547b2a2020-11-22 19:36:30 -0800486nn::GeneralResult<Capabilities::OperandPerformance> unvalidatedConvert(
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800487 const nn::Capabilities::OperandPerformance& operandPerformance) {
488 return Capabilities::OperandPerformance{
Michael Butler6547b2a2020-11-22 19:36:30 -0800489 .type = NN_TRY(unvalidatedConvert(operandPerformance.type)),
490 .info = NN_TRY(unvalidatedConvert(operandPerformance.info)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800491 };
492}
493
Michael Butler6547b2a2020-11-22 19:36:30 -0800494nn::GeneralResult<Operation> unvalidatedConvert(const nn::Operation& operation) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800495 return Operation{
Michael Butler6547b2a2020-11-22 19:36:30 -0800496 .type = NN_TRY(unvalidatedConvert(operation.type)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800497 .inputs = operation.inputs,
498 .outputs = operation.outputs,
499 };
500}
501
Michael Butler6547b2a2020-11-22 19:36:30 -0800502nn::GeneralResult<OperandLifeTime> unvalidatedConvert(
503 const nn::Operand::LifeTime& operandLifeTime) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800504 if (operandLifeTime == nn::Operand::LifeTime::POINTER) {
Michael Butler4b276a72020-08-06 23:22:35 -0700505 return NN_ERROR(nn::ErrorStatus::INVALID_ARGUMENT)
Michael Butler6547b2a2020-11-22 19:36:30 -0800506 << "Model cannot be unvalidatedConverted because it contains pointer-based memory";
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800507 }
508 return static_cast<OperandLifeTime>(operandLifeTime);
509}
510
Michael Butler6547b2a2020-11-22 19:36:30 -0800511nn::GeneralResult<Operand> unvalidatedConvert(const nn::Operand& operand) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800512 return Operand{
Michael Butler6547b2a2020-11-22 19:36:30 -0800513 .type = NN_TRY(unvalidatedConvert(operand.type)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800514 .dimensions = operand.dimensions,
515 .numberOfConsumers = 0,
516 .scale = operand.scale,
517 .zeroPoint = operand.zeroPoint,
Michael Butler6547b2a2020-11-22 19:36:30 -0800518 .lifetime = NN_TRY(unvalidatedConvert(operand.lifetime)),
519 .location = NN_TRY(unvalidatedConvert(operand.location)),
520 .extraParams = NN_TRY(unvalidatedConvert(operand.extraParams)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800521 };
522}
523
Michael Butler6547b2a2020-11-22 19:36:30 -0800524nn::GeneralResult<Model> unvalidatedConvert(const nn::Model& model) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800525 if (!hal::utils::hasNoPointerData(model)) {
Michael Butler4b276a72020-08-06 23:22:35 -0700526 return NN_ERROR(nn::ErrorStatus::INVALID_ARGUMENT)
Michael Butler6547b2a2020-11-22 19:36:30 -0800527 << "Model cannot be unvalidatedConverted because it contains pointer-based memory";
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800528 }
529
530 return Model{
Michael Butler6547b2a2020-11-22 19:36:30 -0800531 .main = NN_TRY(unvalidatedConvert(model.main)),
532 .referenced = NN_TRY(unvalidatedConvert(model.referenced)),
533 .operandValues = NN_TRY(unvalidatedConvert(model.operandValues)),
534 .pools = NN_TRY(unvalidatedConvert(model.pools)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800535 .relaxComputationFloat32toFloat16 = model.relaxComputationFloat32toFloat16,
Michael Butler6547b2a2020-11-22 19:36:30 -0800536 .extensionNameToPrefix = NN_TRY(unvalidatedConvert(model.extensionNameToPrefix)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800537 };
538}
539
Michael Butler6547b2a2020-11-22 19:36:30 -0800540nn::GeneralResult<Subgraph> unvalidatedConvert(const nn::Model::Subgraph& subgraph) {
541 auto operands = NN_TRY(unvalidatedConvert(subgraph.operands));
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800542
543 // Update number of consumers.
544 const auto numberOfConsumers =
Michael Butler301ef062021-10-14 22:04:59 -0700545 NN_TRY(countNumberOfConsumers(operands.size(), subgraph.operations));
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800546 CHECK(operands.size() == numberOfConsumers.size());
547 for (size_t i = 0; i < operands.size(); ++i) {
548 operands[i].numberOfConsumers = numberOfConsumers[i];
549 }
550
551 return Subgraph{
552 .operands = std::move(operands),
Michael Butler6547b2a2020-11-22 19:36:30 -0800553 .operations = NN_TRY(unvalidatedConvert(subgraph.operations)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800554 .inputIndexes = subgraph.inputIndexes,
555 .outputIndexes = subgraph.outputIndexes,
556 };
557}
558
Michael Butler6547b2a2020-11-22 19:36:30 -0800559nn::GeneralResult<BufferDesc> unvalidatedConvert(const nn::BufferDesc& bufferDesc) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800560 return BufferDesc{.dimensions = bufferDesc.dimensions};
561}
562
Michael Butler6547b2a2020-11-22 19:36:30 -0800563nn::GeneralResult<BufferRole> unvalidatedConvert(const nn::BufferRole& bufferRole) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800564 return BufferRole{
565 .modelIndex = bufferRole.modelIndex,
566 .ioIndex = bufferRole.ioIndex,
Xusong Wang3633d072021-03-19 13:58:24 -0700567 .frequency = bufferRole.probability,
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800568 };
569}
570
Michael Butler6547b2a2020-11-22 19:36:30 -0800571nn::GeneralResult<Request> unvalidatedConvert(const nn::Request& request) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800572 if (!hal::utils::hasNoPointerData(request)) {
Michael Butler4b276a72020-08-06 23:22:35 -0700573 return NN_ERROR(nn::ErrorStatus::INVALID_ARGUMENT)
Michael Butler6547b2a2020-11-22 19:36:30 -0800574 << "Request cannot be unvalidatedConverted because it contains pointer-based memory";
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800575 }
576
577 return Request{
Michael Butler6547b2a2020-11-22 19:36:30 -0800578 .inputs = NN_TRY(unvalidatedConvert(request.inputs)),
579 .outputs = NN_TRY(unvalidatedConvert(request.outputs)),
580 .pools = NN_TRY(unvalidatedConvert(request.pools)),
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800581 };
582}
583
Michael Butler6547b2a2020-11-22 19:36:30 -0800584nn::GeneralResult<Request::MemoryPool> unvalidatedConvert(
585 const nn::Request::MemoryPool& memoryPool) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800586 return std::visit([](const auto& o) { return makeMemoryPool(o); }, memoryPool);
587}
588
Michael Butler6547b2a2020-11-22 19:36:30 -0800589nn::GeneralResult<OptionalTimePoint> unvalidatedConvert(
590 const nn::OptionalTimePoint& optionalTimePoint) {
Michael Butler382d5132021-03-18 21:15:09 -0700591 const auto currentSteadyTime = std::chrono::steady_clock::now();
592 const auto currentBootTime = nn::Clock::now();
593
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800594 OptionalTimePoint ret;
595 if (optionalTimePoint.has_value()) {
Michael Butler382d5132021-03-18 21:15:09 -0700596 const auto bootTimePoint = optionalTimePoint.value();
597
598 if (bootTimePoint < nn::TimePoint{}) {
599 return NN_ERROR() << "Trying to cast invalid time point";
600 }
601
602 // Both bootTimePoint and currentBootTime are guaranteed to be non-negative, so this
603 // subtraction will never overflow or underflow.
604 const auto timeRemaining = bootTimePoint - currentBootTime;
605
606 // currentSteadyTime is guaranteed to be non-negative, so this code only protects against an
607 // overflow.
608 std::chrono::steady_clock::time_point steadyTimePoint;
609 constexpr auto kZeroNano = std::chrono::nanoseconds::zero();
610 constexpr auto kMaxTime = std::chrono::steady_clock::time_point::max();
611 if (timeRemaining > kZeroNano && currentSteadyTime > kMaxTime - timeRemaining) {
612 steadyTimePoint = kMaxTime;
613 } else {
614 steadyTimePoint = currentSteadyTime + timeRemaining;
615 }
616
617 const uint64_t count = makeUint64FromNanos(steadyTimePoint.time_since_epoch());
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800618 ret.nanosecondsSinceEpoch(count);
619 }
620 return ret;
621}
622
Michael Butler6547b2a2020-11-22 19:36:30 -0800623nn::GeneralResult<OptionalTimeoutDuration> unvalidatedConvert(
Michael Butler4024d8f2020-12-04 17:38:20 -0800624 const nn::OptionalDuration& optionalTimeoutDuration) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800625 OptionalTimeoutDuration ret;
626 if (optionalTimeoutDuration.has_value()) {
627 const auto count = optionalTimeoutDuration.value().count();
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800628 ret.nanoseconds(count);
629 }
630 return ret;
631}
632
Michael Butler6547b2a2020-11-22 19:36:30 -0800633nn::GeneralResult<ErrorStatus> unvalidatedConvert(const nn::ErrorStatus& errorStatus) {
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800634 switch (errorStatus) {
635 case nn::ErrorStatus::NONE:
636 case nn::ErrorStatus::DEVICE_UNAVAILABLE:
637 case nn::ErrorStatus::GENERAL_FAILURE:
638 case nn::ErrorStatus::OUTPUT_INSUFFICIENT_SIZE:
639 case nn::ErrorStatus::INVALID_ARGUMENT:
640 case nn::ErrorStatus::MISSED_DEADLINE_TRANSIENT:
641 case nn::ErrorStatus::MISSED_DEADLINE_PERSISTENT:
642 case nn::ErrorStatus::RESOURCE_EXHAUSTED_TRANSIENT:
643 case nn::ErrorStatus::RESOURCE_EXHAUSTED_PERSISTENT:
644 return static_cast<ErrorStatus>(errorStatus);
645 default:
646 return ErrorStatus::GENERAL_FAILURE;
647 }
648}
649
Michael Butler6547b2a2020-11-22 19:36:30 -0800650nn::GeneralResult<Priority> convert(const nn::Priority& priority) {
651 return validatedConvert(priority);
652}
653
654nn::GeneralResult<Capabilities> convert(const nn::Capabilities& capabilities) {
655 return validatedConvert(capabilities);
656}
657
658nn::GeneralResult<Model> convert(const nn::Model& model) {
659 return validatedConvert(model);
660}
661
662nn::GeneralResult<BufferDesc> convert(const nn::BufferDesc& bufferDesc) {
663 return validatedConvert(bufferDesc);
664}
665
666nn::GeneralResult<Request> convert(const nn::Request& request) {
667 return validatedConvert(request);
668}
669
670nn::GeneralResult<OptionalTimePoint> convert(const nn::OptionalTimePoint& optionalTimePoint) {
671 return validatedConvert(optionalTimePoint);
672}
673
674nn::GeneralResult<OptionalTimeoutDuration> convert(
Michael Butler4024d8f2020-12-04 17:38:20 -0800675 const nn::OptionalDuration& optionalTimeoutDuration) {
Michael Butler6547b2a2020-11-22 19:36:30 -0800676 return validatedConvert(optionalTimeoutDuration);
677}
678
679nn::GeneralResult<ErrorStatus> convert(const nn::ErrorStatus& errorStatus) {
680 return validatedConvert(errorStatus);
681}
682
683nn::GeneralResult<hidl_handle> convert(const nn::SharedHandle& handle) {
684 return validatedConvert(handle);
685}
686
Michael Butlerfadeb8a2021-02-07 00:11:13 -0800687nn::GeneralResult<hidl_memory> convert(const nn::SharedMemory& memory) {
Michael Butler6547b2a2020-11-22 19:36:30 -0800688 return validatedConvert(memory);
689}
690
Michael Butler4b276a72020-08-06 23:22:35 -0700691nn::GeneralResult<hidl_vec<BufferRole>> convert(const std::vector<nn::BufferRole>& bufferRoles) {
Michael Butler6547b2a2020-11-22 19:36:30 -0800692 return validatedConvert(bufferRoles);
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800693}
694
Michael Butler7fd03c22020-12-06 21:50:59 -0800695nn::GeneralResult<V1_0::DeviceStatus> convert(const nn::DeviceStatus& deviceStatus) {
696 return V1_2::utils::convert(deviceStatus);
697}
698
699nn::GeneralResult<V1_1::ExecutionPreference> convert(
700 const nn::ExecutionPreference& executionPreference) {
701 return V1_2::utils::convert(executionPreference);
702}
703
704nn::GeneralResult<hidl_vec<V1_2::Extension>> convert(const std::vector<nn::Extension>& extensions) {
705 return V1_2::utils::convert(extensions);
706}
707
708nn::GeneralResult<hidl_vec<hidl_handle>> convert(const std::vector<nn::SharedHandle>& handles) {
709 return V1_2::utils::convert(handles);
710}
711
712nn::GeneralResult<hidl_vec<V1_2::OutputShape>> convert(
713 const std::vector<nn::OutputShape>& outputShapes) {
714 return V1_2::utils::convert(outputShapes);
715}
716
717nn::GeneralResult<V1_2::DeviceType> convert(const nn::DeviceType& deviceType) {
718 return V1_2::utils::convert(deviceType);
719}
720
721nn::GeneralResult<V1_2::MeasureTiming> convert(const nn::MeasureTiming& measureTiming) {
722 return V1_2::utils::convert(measureTiming);
723}
724
725nn::GeneralResult<V1_2::Timing> convert(const nn::Timing& timing) {
726 return V1_2::utils::convert(timing);
727}
728
Michael Butler15965822021-10-14 23:45:11 -0700729nn::GeneralResult<hidl_vec<hidl_handle>> convertSyncFences(
730 const std::vector<nn::SyncFence>& syncFences) {
731 std::vector<nn::SharedHandle> handles;
732 handles.reserve(syncFences.size());
733 std::transform(syncFences.begin(), syncFences.end(), std::back_inserter(handles),
734 [](const nn::SyncFence& syncFence) { return syncFence.getSharedHandle(); });
735 return convert(handles);
736}
737
Michael Butlerb98aa6d2020-02-22 22:37:59 -0800738} // namespace android::hardware::neuralnetworks::V1_3::utils